source: trunk/themes/default/js/ui/jquery.effects.scale.js @ 9559

Last change on this file since 9559 was 9559, checked in by patdenice, 13 years ago

Update jQuery UI to 1.8.10.
Improve jquery ui management in template class.

File size: 6.8 KB
Line 
1/*
2 * jQuery UI Effects Scale 1.8.10
3 *
4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
7 *
8 * http://docs.jquery.com/UI/Effects/Scale
9 *
10 * Depends:
11 *      jquery.effects.core.js
12 */
13(function( $, undefined ) {
14
15$.effects.puff = function(o) {
16        return this.queue(function() {
17                var elem = $(this),
18                        mode = $.effects.setMode(elem, o.options.mode || 'hide'),
19                        percent = parseInt(o.options.percent, 10) || 150,
20                        factor = percent / 100,
21                        original = { height: elem.height(), width: elem.width() };
22
23                $.extend(o.options, {
24                        fade: true,
25                        mode: mode,
26                        percent: mode == 'hide' ? percent : 100,
27                        from: mode == 'hide'
28                                ? original
29                                : {
30                                        height: original.height * factor,
31                                        width: original.width * factor
32                                }
33                });
34
35                elem.effect('scale', o.options, o.duration, o.callback);
36                elem.dequeue();
37        });
38};
39
40$.effects.scale = function(o) {
41
42        return this.queue(function() {
43
44                // Create element
45                var el = $(this);
46
47                // Set options
48                var options = $.extend(true, {}, o.options);
49                var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
50                var percent = parseInt(o.options.percent,10) || (parseInt(o.options.percent,10) == 0 ? 0 : (mode == 'hide' ? 0 : 100)); // Set default scaling percent
51                var direction = o.options.direction || 'both'; // Set default axis
52                var origin = o.options.origin; // The origin of the scaling
53                if (mode != 'effect') { // Set default origin and restore for show/hide
54                        options.origin = origin || ['middle','center'];
55                        options.restore = true;
56                }
57                var original = {height: el.height(), width: el.width()}; // Save original
58                el.from = o.options.from || (mode == 'show' ? {height: 0, width: 0} : original); // Default from state
59
60                // Adjust
61                var factor = { // Set scaling factor
62                        y: direction != 'horizontal' ? (percent / 100) : 1,
63                        x: direction != 'vertical' ? (percent / 100) : 1
64                };
65                el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state
66
67                if (o.options.fade) { // Fade option to support puff
68                        if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};
69                        if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};
70                };
71
72                // Animation
73                options.from = el.from; options.to = el.to; options.mode = mode;
74
75                // Animate
76                el.effect('size', options, o.duration, o.callback);
77                el.dequeue();
78        });
79
80};
81
82$.effects.size = function(o) {
83
84        return this.queue(function() {
85
86                // Create element
87                var el = $(this), props = ['position','top','bottom','left','right','width','height','overflow','opacity'];
88                var props1 = ['position','top','bottom','left','right','overflow','opacity']; // Always restore
89                var props2 = ['width','height','overflow']; // Copy for children
90                var cProps = ['fontSize'];
91                var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];
92                var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];
93
94                // Set options
95                var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
96                var restore = o.options.restore || false; // Default restore
97                var scale = o.options.scale || 'both'; // Default scale mode
98                var origin = o.options.origin; // The origin of the sizing
99                var original = {height: el.height(), width: el.width()}; // Save original
100                el.from = o.options.from || original; // Default from state
101                el.to = o.options.to || original; // Default to state
102                // Adjust
103                if (origin) { // Calculate baseline shifts
104                        var baseline = $.effects.getBaseline(origin, original);
105                        el.from.top = (original.height - el.from.height) * baseline.y;
106                        el.from.left = (original.width - el.from.width) * baseline.x;
107                        el.to.top = (original.height - el.to.height) * baseline.y;
108                        el.to.left = (original.width - el.to.width) * baseline.x;
109                };
110                var factor = { // Set scaling factor
111                        from: {y: el.from.height / original.height, x: el.from.width / original.width},
112                        to: {y: el.to.height / original.height, x: el.to.width / original.width}
113                };
114                if (scale == 'box' || scale == 'both') { // Scale the css box
115                        if (factor.from.y != factor.to.y) { // Vertical props scaling
116                                props = props.concat(vProps);
117                                el.from = $.effects.setTransition(el, vProps, factor.from.y, el.from);
118                                el.to = $.effects.setTransition(el, vProps, factor.to.y, el.to);
119                        };
120                        if (factor.from.x != factor.to.x) { // Horizontal props scaling
121                                props = props.concat(hProps);
122                                el.from = $.effects.setTransition(el, hProps, factor.from.x, el.from);
123                                el.to = $.effects.setTransition(el, hProps, factor.to.x, el.to);
124                        };
125                };
126                if (scale == 'content' || scale == 'both') { // Scale the content
127                        if (factor.from.y != factor.to.y) { // Vertical props scaling
128                                props = props.concat(cProps);
129                                el.from = $.effects.setTransition(el, cProps, factor.from.y, el.from);
130                                el.to = $.effects.setTransition(el, cProps, factor.to.y, el.to);
131                        };
132                };
133                $.effects.save(el, restore ? props : props1); el.show(); // Save & Show
134                $.effects.createWrapper(el); // Create Wrapper
135                el.css('overflow','hidden').css(el.from); // Shift
136
137                // Animate
138                if (scale == 'content' || scale == 'both') { // Scale the children
139                        vProps = vProps.concat(['marginTop','marginBottom']).concat(cProps); // Add margins/font-size
140                        hProps = hProps.concat(['marginLeft','marginRight']); // Add margins
141                        props2 = props.concat(vProps).concat(hProps); // Concat
142                        el.find("*[width]").each(function(){
143                                child = $(this);
144                                if (restore) $.effects.save(child, props2);
145                                var c_original = {height: child.height(), width: child.width()}; // Save original
146                                child.from = {height: c_original.height * factor.from.y, width: c_original.width * factor.from.x};
147                                child.to = {height: c_original.height * factor.to.y, width: c_original.width * factor.to.x};
148                                if (factor.from.y != factor.to.y) { // Vertical props scaling
149                                        child.from = $.effects.setTransition(child, vProps, factor.from.y, child.from);
150                                        child.to = $.effects.setTransition(child, vProps, factor.to.y, child.to);
151                                };
152                                if (factor.from.x != factor.to.x) { // Horizontal props scaling
153                                        child.from = $.effects.setTransition(child, hProps, factor.from.x, child.from);
154                                        child.to = $.effects.setTransition(child, hProps, factor.to.x, child.to);
155                                };
156                                child.css(child.from); // Shift children
157                                child.animate(child.to, o.duration, o.options.easing, function(){
158                                        if (restore) $.effects.restore(child, props2); // Restore children
159                                }); // Animate children
160                        });
161                };
162
163                // Animate
164                el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
165                        if (el.to.opacity === 0) {
166                                el.css('opacity', el.from.opacity);
167                        }
168                        if(mode == 'hide') el.hide(); // Hide
169                        $.effects.restore(el, restore ? props : props1); $.effects.removeWrapper(el); // Restore
170                        if(o.callback) o.callback.apply(this, arguments); // Callback
171                        el.dequeue();
172                }});
173
174        });
175
176};
177
178})(jQuery);
Note: See TracBrowser for help on using the repository browser.