PageRenderTime 62ms CodeModel.GetById 14ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 0ms

/application/static/libs/adminlte/bower_components/jquery-ui/ui/effect-size.js

https://bitbucket.org/tin_gimranoff/docstar
JavaScript | 233 lines | 169 code | 32 blank | 32 comment | 35 complexity | 6fe768670979842da1d1a3a9549d0e54 MD5 | raw file
  1/*!
  2 * jQuery UI Effects Size 1.11.4
  3 * http://jqueryui.com
  4 *
  5 * Copyright jQuery Foundation and other contributors
  6 * Released under the MIT license.
  7 * http://jquery.org/license
  8 *
  9 * http://api.jqueryui.com/size-effect/
 10 */
 11(function( factory ) {
 12	if ( typeof define === "function" && define.amd ) {
 13
 14		// AMD. Register as an anonymous module.
 15		define([
 16			"jquery",
 17			"./effect"
 18		], factory );
 19	} else {
 20
 21		// Browser globals
 22		factory( jQuery );
 23	}
 24}(function( $ ) {
 25
 26return $.effects.effect.size = function( o, done ) {
 27
 28	// Create element
 29	var original, baseline, factor,
 30		el = $( this ),
 31		props0 = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
 32
 33		// Always restore
 34		props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
 35
 36		// Copy for children
 37		props2 = [ "width", "height", "overflow" ],
 38		cProps = [ "fontSize" ],
 39		vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
 40		hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
 41
 42		// Set options
 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,
 49		zero = {
 50			height: 0,
 51			width: 0,
 52			outerHeight: 0,
 53			outerWidth: 0
 54		};
 55
 56	if ( mode === "show" ) {
 57		el.show();
 58	}
 59	original = {
 60		height: el.height(),
 61		width: el.width(),
 62		outerHeight: el.outerHeight(),
 63		outerWidth: el.outerWidth()
 64	};
 65
 66	if ( o.mode === "toggle" && mode === "show" ) {
 67		el.from = o.to || zero;
 68		el.to = o.from || original;
 69	} else {
 70		el.from = o.from || ( mode === "show" ? zero : original );
 71		el.to = o.to || ( mode === "hide" ? zero : original );
 72	}
 73
 74	// Set scaling factor
 75	factor = {
 76		from: {
 77			y: el.from.height / original.height,
 78			x: el.from.width / original.width
 79		},
 80		to: {
 81			y: el.to.height / original.height,
 82			x: el.to.width / original.width
 83		}
 84	};
 85
 86	// Scale the css box
 87	if ( scale === "box" || scale === "both" ) {
 88
 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 );
 94		}
 95
 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 );
101		}
102	}
103
104	// Scale the content
105	if ( scale === "content" || scale === "both" ) {
106
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 );
112		}
113	}
114
115	$.effects.save( el, props );
116	el.show();
117	$.effects.createWrapper( el );
118	el.css( "overflow", "hidden" ).css( el.from );
119
120	// Adjust
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;
127	}
128	el.css( el.from ); // set top & left
129
130	// Animate
131	if ( scale === "content" || scale === "both" ) { // Scale the children
132
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);
137
138		el.find( "*[width]" ).each( function() {
139			var child = $( this ),
140				c_original = {
141					height: child.height(),
142					width: child.width(),
143					outerHeight: child.outerHeight(),
144					outerWidth: child.outerWidth()
145				};
146			if (restore) {
147				$.effects.save(child, props2);
148			}
149
150			child.from = {
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
155			};
156			child.to = {
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
161			};
162
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 );
167			}
168
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 );
173			}
174
175			// Animate children
176			child.css( child.from );
177			child.animate( child.to, o.duration, o.easing, function() {
178
179				// Restore children
180				if ( restore ) {
181					$.effects.restore( child, props2 );
182				}
183			});
184		});
185	}
186
187	// Animate
188	el.animate( el.to, {
189		queue: false,
190		duration: o.duration,
191		easing: o.easing,
192		complete: function() {
193			if ( el.to.opacity === 0 ) {
194				el.css( "opacity", el.from.opacity );
195			}
196			if ( mode === "hide" ) {
197				el.hide();
198			}
199			$.effects.restore( el, props );
200			if ( !restore ) {
201
202				// we need to calculate our new positioning based on the scaling
203				if ( position === "static" ) {
204					el.css({
205						position: "relative",
206						top: el.to.top,
207						left: el.to.left
208					});
209				} else {
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;
214
215							// if original was "auto", recalculate the new value from wrapper
216							if ( str === "auto" ) {
217								return toRef + "px";
218							}
219
220							return val + toRef + "px";
221						});
222					});
223				}
224			}
225
226			$.effects.removeWrapper( el );
227			done();
228		}
229	});
230
231};
232
233}));