2 * jQuery UI Effects Scale 1.9.0
5 * Copyright 2012 jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/scale-effect/
14 (function( $, undefined ) {
16 $.effects
.effect
.puff = function( o
, done
) {
18 mode
= $.effects
.setMode( elem
, o
.mode
|| "hide" ),
19 hide
= mode
=== "hide",
20 percent
= parseInt( o
.percent
, 10 ) || 150,
21 factor
= percent
/ 100,
23 height
: elem
.height(),
33 percent
: hide
? percent
: 100,
37 height
: original
.height
* factor
,
38 width
: original
.width
* factor
45 $.effects
.effect
.scale = function( o
, done
) {
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",
58 outerHeight
: el
.outerHeight(),
59 outerWidth
: el
.outerWidth()
62 y
: direction
!== "horizontal" ? (percent
/ 100) : 1,
63 x
: direction
!== "vertical" ? (percent
/ 100) : 1
66 // We are going to pass this effect to the size effect:
67 options
.effect
= "size";
68 options
.queue
= false;
69 options
.complete
= done
;
71 // Set default origin and restore for show/hide
72 if ( mode
!== "effect" ) {
73 options
.origin
= origin
|| ["middle","center"];
74 options
.restore
= true;
77 options
.from = o
.from || ( mode
=== "show" ? { height
: 0, width
: 0 } : original
);
79 height
: original
.height
* factor
.y
,
80 width
: original
.width
* factor
.x
,
81 outerHeight
: original
.outerHeight
* factor
.y
,
82 outerWidth
: original
.outerWidth
* factor
.x
85 // Fade option to support puff
87 if ( mode
=== "show" ) {
88 options
.from.opacity
= 0;
89 options
.to
.opacity
= 1;
91 if ( mode
=== "hide" ) {
92 options
.from.opacity
= 1;
93 options
.to
.opacity
= 0;
102 $.effects
.effect
.size = function( o
, done
) {
106 props
= [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
109 props1
= [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
112 props2
= [ "width", "height", "overflow" ],
113 cProps
= [ "fontSize" ],
114 vProps
= [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
115 hProps
= [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
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" );
125 if ( mode
=== "show" ) {
131 outerHeight
: el
.outerHeight(),
132 outerWidth
: el
.outerWidth()
135 el
.from = o
.from || original
;
136 el
.to
= o
.to
|| original
;
138 // Set scaling factor
141 y
: el
.from.height
/ original
.height
,
142 x
: el
.from.width
/ original
.width
145 y
: el
.to
.height
/ original
.height
,
146 x
: el
.to
.width
/ original
.width
151 if ( scale
=== "box" || scale
=== "both" ) {
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
);
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
);
169 if ( scale
=== "content" || scale
=== "both" ) {
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
);
179 $.effects
.save( el
, restore
? props
: props1
);
181 $.effects
.createWrapper( el
);
182 el
.css( "overflow", "hidden" ).css( el
.from );
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
;
192 el
.css( el
.from ); // set top & left
195 if ( scale
=== "content" || scale
=== "both" ) { // Scale the children
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
);
202 el
.find( "*[width]" ).each( function(){
203 var child
= $( this ),
205 height
: child
.height(),
209 $.effects
.save(child
, props2
);
213 height
: c_original
.height
* factor
.from.y
,
214 width
: c_original
.width
* factor
.from.x
217 height
: c_original
.height
* factor
.to
.y
,
218 width
: c_original
.width
* factor
.to
.x
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
);
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
);
234 child
.css( child
.from );
235 child
.animate( child
.to
, o
.duration
, o
.easing
, function() {
239 $.effects
.restore( child
, props2
);
248 duration
: o
.duration
,
250 complete: function() {
251 if ( el
.to
.opacity
=== 0 ) {
252 el
.css( "opacity", el
.from.opacity
);
254 if( mode
=== "hide" ) {
257 $.effects
.restore( el
, restore
? props
: props1
);
260 // we need to calculate our new positioning based on the scaling
261 if ( position
=== "static" ) {
263 position
: "relative",
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
;
273 // if original was "auto", recalculate the new value from wrapper
274 if ( str
=== "auto" ) {
278 return val
+ toRef
+ "px";
284 $.effects
.removeWrapper( el
);