commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / jquery / jquery-ui-1.9.0 / development-bundle / ui / jquery.ui.effect-scale.js
1 /*!
2 * jQuery UI Effects Scale 1.9.0
3 * http://jqueryui.com
4 *
5 * Copyright 2012 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
8 *
9 * http://api.jqueryui.com/scale-effect/
10 *
11 * Depends:
12 * jquery.ui.effect.js
13 */
14 (function( $, undefined ) {
15
16 $.effects.effect.puff = function( o, done ) {
17 var elem = $( this ),
18 mode = $.effects.setMode( elem, o.mode || "hide" ),
19 hide = mode === "hide",
20 percent = parseInt( o.percent, 10 ) || 150,
21 factor = percent / 100,
22 original = {
23 height: elem.height(),
24 width: elem.width()
25 };
26
27 $.extend( o, {
28 effect: "scale",
29 queue: false,
30 fade: true,
31 mode: mode,
32 complete: done,
33 percent: hide ? percent : 100,
34 from: hide ?
35 original :
36 {
37 height: original.height * factor,
38 width: original.width * factor
39 }
40 });
41
42 elem.effect( o );
43 };
44
45 $.effects.effect.scale = function( o, done ) {
46
47 // Create element
48 var el = $( this ),
49 options = $.extend( true, {}, o ),
50 mode = $.effects.setMode( el, o.mode || "effect" ),
51 percent = parseInt( o.percent, 10 ) ||
52 ( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ),
53 direction = o.direction || "both",
54 origin = o.origin,
55 original = {
56 height: el.height(),
57 width: el.width(),
58 outerHeight: el.outerHeight(),
59 outerWidth: el.outerWidth()
60 },
61 factor = {
62 y: direction !== "horizontal" ? (percent / 100) : 1,
63 x: direction !== "vertical" ? (percent / 100) : 1
64 };
65
66 // We are going to pass this effect to the size effect:
67 options.effect = "size";
68 options.queue = false;
69 options.complete = done;
70
71 // Set default origin and restore for show/hide
72 if ( mode !== "effect" ) {
73 options.origin = origin || ["middle","center"];
74 options.restore = true;
75 }
76
77 options.from = o.from || ( mode === "show" ? { height: 0, width: 0 } : original );
78 options.to = {
79 height: original.height * factor.y,
80 width: original.width * factor.x,
81 outerHeight: original.outerHeight * factor.y,
82 outerWidth: original.outerWidth * factor.x
83 };
84
85 // Fade option to support puff
86 if ( options.fade ) {
87 if ( mode === "show" ) {
88 options.from.opacity = 0;
89 options.to.opacity = 1;
90 }
91 if ( mode === "hide" ) {
92 options.from.opacity = 1;
93 options.to.opacity = 0;
94 }
95 }
96
97 // Animate
98 el.effect( options );
99
100 };
101
102 $.effects.effect.size = function( o, done ) {
103
104 // Create element
105 var el = $( this ),
106 props = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
107
108 // Always restore
109 props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
110
111 // Copy for children
112 props2 = [ "width", "height", "overflow" ],
113 cProps = [ "fontSize" ],
114 vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
115 hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
116
117 // Set options
118 mode = $.effects.setMode( el, o.mode || "effect" ),
119 restore = o.restore || mode !== "effect",
120 scale = o.scale || "both",
121 origin = o.origin || [ "middle", "center" ],
122 original, baseline, factor,
123 position = el.css( "position" );
124
125 if ( mode === "show" ) {
126 el.show();
127 }
128 original = {
129 height: el.height(),
130 width: el.width(),
131 outerHeight: el.outerHeight(),
132 outerWidth: el.outerWidth()
133 };
134
135 el.from = o.from || original;
136 el.to = o.to || original;
137
138 // Set scaling factor
139 factor = {
140 from: {
141 y: el.from.height / original.height,
142 x: el.from.width / original.width
143 },
144 to: {
145 y: el.to.height / original.height,
146 x: el.to.width / original.width
147 }
148 };
149
150 // Scale the css box
151 if ( scale === "box" || scale === "both" ) {
152
153 // Vertical props scaling
154 if ( factor.from.y !== factor.to.y ) {
155 props = props.concat( vProps );
156 el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from );
157 el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to );
158 }
159
160 // Horizontal props scaling
161 if ( factor.from.x !== factor.to.x ) {
162 props = props.concat( hProps );
163 el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from );
164 el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to );
165 }
166 }
167
168 // Scale the content
169 if ( scale === "content" || scale === "both" ) {
170
171 // Vertical props scaling
172 if ( factor.from.y !== factor.to.y ) {
173 props = props.concat( cProps );
174 el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from );
175 el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to );
176 }
177 }
178
179 $.effects.save( el, restore ? props : props1 );
180 el.show();
181 $.effects.createWrapper( el );
182 el.css( "overflow", "hidden" ).css( el.from );
183
184 // Adjust
185 if (origin) { // Calculate baseline shifts
186 baseline = $.effects.getBaseline( origin, original );
187 el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y;
188 el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x;
189 el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y;
190 el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x;
191 }
192 el.css( el.from ); // set top & left
193
194 // Animate
195 if ( scale === "content" || scale === "both" ) { // Scale the children
196
197 // Add margins/font-size
198 vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps);
199 hProps = hProps.concat([ "marginLeft", "marginRight" ]);
200 props2 = props.concat(vProps).concat(hProps);
201
202 el.find( "*[width]" ).each( function(){
203 var child = $( this ),
204 c_original = {
205 height: child.height(),
206 width: child.width()
207 };
208 if (restore) {
209 $.effects.save(child, props2);
210 }
211
212 child.from = {
213 height: c_original.height * factor.from.y,
214 width: c_original.width * factor.from.x
215 };
216 child.to = {
217 height: c_original.height * factor.to.y,
218 width: c_original.width * factor.to.x
219 };
220
221 // Vertical props scaling
222 if ( factor.from.y !== factor.to.y ) {
223 child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from );
224 child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to );
225 }
226
227 // Horizontal props scaling
228 if ( factor.from.x !== factor.to.x ) {
229 child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from );
230 child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to );
231 }
232
233 // Animate children
234 child.css( child.from );
235 child.animate( child.to, o.duration, o.easing, function() {
236
237 // Restore children
238 if ( restore ) {
239 $.effects.restore( child, props2 );
240 }
241 });
242 });
243 }
244
245 // Animate
246 el.animate( el.to, {
247 queue: false,
248 duration: o.duration,
249 easing: o.easing,
250 complete: function() {
251 if ( el.to.opacity === 0 ) {
252 el.css( "opacity", el.from.opacity );
253 }
254 if( mode === "hide" ) {
255 el.hide();
256 }
257 $.effects.restore( el, restore ? props : props1 );
258 if ( !restore ) {
259
260 // we need to calculate our new positioning based on the scaling
261 if ( position === "static" ) {
262 el.css({
263 position: "relative",
264 top: el.to.top,
265 left: el.to.left
266 });
267 } else {
268 $.each([ "top", "left" ], function( idx, pos ) {
269 el.css( pos, function( _, str ) {
270 var val = parseInt( str, 10 ),
271 toRef = idx ? el.to.left : el.to.top;
272
273 // if original was "auto", recalculate the new value from wrapper
274 if ( str === "auto" ) {
275 return toRef + "px";
276 }
277
278 return val + toRef + "px";
279 });
280 });
281 }
282 }
283
284 $.effects.removeWrapper( el );
285 done();
286 }
287 });
288
289 };
290
291 })(jQuery);