2 * jQuery UI Effects Size 1.11.4
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/size-effect/
11 (function( factory
) {
12 if ( typeof define
=== "function" && define
.amd
) {
14 // AMD. Register as an anonymous module.
26 return $.effects
.effect
.size = function( o
, done
) {
29 var original
, baseline
, factor
,
31 props0
= [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
34 props1
= [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
37 props2
= [ "width", "height", "overflow" ],
38 cProps
= [ "fontSize" ],
39 vProps
= [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
40 hProps
= [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
43 mode
= $.effects
.setMode( el
, o
.mode
|| "effect" ),
44 restore
= o
.restore
|| mode
!== "effect",
45 scale
= o
.scale
|| "both",
46 origin
= o
.origin
|| [ "middle", "center" ],
47 position
= el
.css( "position" ),
48 props
= restore
? props0
: props1
,
56 if ( mode
=== "show" ) {
62 outerHeight
: el
.outerHeight(),
63 outerWidth
: el
.outerWidth()
66 if ( o
.mode
=== "toggle" && mode
=== "show" ) {
67 el
.from = o
.to
|| zero
;
68 el
.to
= o
.from || original
;
70 el
.from = o
.from || ( mode
=== "show" ? zero
: original
);
71 el
.to
= o
.to
|| ( mode
=== "hide" ? zero
: original
);
77 y
: el
.from.height
/ original
.height
,
78 x
: el
.from.width
/ original
.width
81 y
: el
.to
.height
/ original
.height
,
82 x
: el
.to
.width
/ original
.width
87 if ( scale
=== "box" || scale
=== "both" ) {
89 // Vertical props scaling
90 if ( factor
.from.y
!== factor
.to
.y
) {
91 props
= props
.concat( vProps
);
92 el
.from = $.effects
.setTransition( el
, vProps
, factor
.from.y
, el
.from );
93 el
.to
= $.effects
.setTransition( el
, vProps
, factor
.to
.y
, el
.to
);
96 // Horizontal props scaling
97 if ( factor
.from.x
!== factor
.to
.x
) {
98 props
= props
.concat( hProps
);
99 el
.from = $.effects
.setTransition( el
, hProps
, factor
.from.x
, el
.from );
100 el
.to
= $.effects
.setTransition( el
, hProps
, factor
.to
.x
, el
.to
);
105 if ( scale
=== "content" || scale
=== "both" ) {
107 // Vertical props scaling
108 if ( factor
.from.y
!== factor
.to
.y
) {
109 props
= props
.concat( cProps
).concat( props2
);
110 el
.from = $.effects
.setTransition( el
, cProps
, factor
.from.y
, el
.from );
111 el
.to
= $.effects
.setTransition( el
, cProps
, factor
.to
.y
, el
.to
);
115 $.effects
.save( el
, props
);
117 $.effects
.createWrapper( el
);
118 el
.css( "overflow", "hidden" ).css( el
.from );
121 if (origin
) { // Calculate baseline shifts
122 baseline
= $.effects
.getBaseline( origin
, original
);
123 el
.from.top
= ( original
.outerHeight
- el
.outerHeight() ) * baseline
.y
;
124 el
.from.left
= ( original
.outerWidth
- el
.outerWidth() ) * baseline
.x
;
125 el
.to
.top
= ( original
.outerHeight
- el
.to
.outerHeight
) * baseline
.y
;
126 el
.to
.left
= ( original
.outerWidth
- el
.to
.outerWidth
) * baseline
.x
;
128 el
.css( el
.from ); // set top & left
131 if ( scale
=== "content" || scale
=== "both" ) { // Scale the children
133 // Add margins/font-size
134 vProps
= vProps
.concat([ "marginTop", "marginBottom" ]).concat(cProps
);
135 hProps
= hProps
.concat([ "marginLeft", "marginRight" ]);
136 props2
= props0
.concat(vProps
).concat(hProps
);
138 el
.find( "*[width]" ).each( function() {
139 var child
= $( this ),
141 height
: child
.height(),
142 width
: child
.width(),
143 outerHeight
: child
.outerHeight(),
144 outerWidth
: child
.outerWidth()
147 $.effects
.save(child
, props2
);
151 height
: c_original
.height
* factor
.from.y
,
152 width
: c_original
.width
* factor
.from.x
,
153 outerHeight
: c_original
.outerHeight
* factor
.from.y
,
154 outerWidth
: c_original
.outerWidth
* factor
.from.x
157 height
: c_original
.height
* factor
.to
.y
,
158 width
: c_original
.width
* factor
.to
.x
,
159 outerHeight
: c_original
.height
* factor
.to
.y
,
160 outerWidth
: c_original
.width
* factor
.to
.x
163 // Vertical props scaling
164 if ( factor
.from.y
!== factor
.to
.y
) {
165 child
.from = $.effects
.setTransition( child
, vProps
, factor
.from.y
, child
.from );
166 child
.to
= $.effects
.setTransition( child
, vProps
, factor
.to
.y
, child
.to
);
169 // Horizontal props scaling
170 if ( factor
.from.x
!== factor
.to
.x
) {
171 child
.from = $.effects
.setTransition( child
, hProps
, factor
.from.x
, child
.from );
172 child
.to
= $.effects
.setTransition( child
, hProps
, factor
.to
.x
, child
.to
);
176 child
.css( child
.from );
177 child
.animate( child
.to
, o
.duration
, o
.easing
, function() {
181 $.effects
.restore( child
, props2
);
190 duration
: o
.duration
,
192 complete: function() {
193 if ( el
.to
.opacity
=== 0 ) {
194 el
.css( "opacity", el
.from.opacity
);
196 if ( mode
=== "hide" ) {
199 $.effects
.restore( el
, props
);
202 // we need to calculate our new positioning based on the scaling
203 if ( position
=== "static" ) {
205 position
: "relative",
210 $.each([ "top", "left" ], function( idx
, pos
) {
211 el
.css( pos
, function( _
, str
) {
212 var val
= parseInt( str
, 10 ),
213 toRef
= idx
? el
.to
.left
: el
.to
.top
;
215 // if original was "auto", recalculate the new value from wrapper
216 if ( str
=== "auto" ) {
220 return val
+ toRef
+ "px";
226 $.effects
.removeWrapper( el
);