2013-05-08 12:06:54 +00:00
|
|
|
/*!
|
|
|
|
* jQuery UI Effects Size @VERSION
|
|
|
|
* http://jqueryui.com
|
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2013-05-08 12:06:54 +00:00
|
|
|
* Released under the MIT license.
|
|
|
|
* http://jquery.org/license
|
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Size Effect
|
|
|
|
//>>group: Effects
|
|
|
|
//>>description: Resize an element to a specified width and height.
|
|
|
|
//>>docs: http://api.jqueryui.com/size-effect/
|
|
|
|
//>>demos: http://jqueryui.com/effect/
|
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
( function( factory ) {
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-18 14:39:12 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./effect"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2015-03-18 14:39:12 +00:00
|
|
|
}( function( $ ) {
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
return $.effects.define( "size", function( options, done ) {
|
2013-05-08 12:06:54 +00:00
|
|
|
|
|
|
|
// Create element
|
2012-12-26 13:35:42 +00:00
|
|
|
var baseline, factor, temp,
|
|
|
|
element = $( this ),
|
2013-05-08 12:06:54 +00:00
|
|
|
|
|
|
|
// Copy for children
|
|
|
|
cProps = [ "fontSize" ],
|
|
|
|
vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
|
|
|
|
hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
|
|
|
|
|
|
|
|
// Set options
|
2012-12-26 13:35:42 +00:00
|
|
|
mode = options.mode,
|
|
|
|
restore = mode !== "effect",
|
|
|
|
scale = options.scale || "both",
|
|
|
|
origin = options.origin || [ "middle", "center" ],
|
|
|
|
position = element.css( "position" ),
|
|
|
|
pos = element.position(),
|
|
|
|
original = $.effects.scaledDimensions( element ),
|
|
|
|
from = options.from || original,
|
|
|
|
to = options.to || $.effects.scaledDimensions( element, 0 );
|
|
|
|
|
|
|
|
$.effects.createPlaceholder( element );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
|
|
|
if ( mode === "show" ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
temp = from;
|
|
|
|
from = to;
|
|
|
|
to = temp;
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set scaling factor
|
|
|
|
factor = {
|
|
|
|
from: {
|
2012-12-26 13:35:42 +00:00
|
|
|
y: from.height / original.height,
|
|
|
|
x: from.width / original.width
|
2013-05-08 12:06:54 +00:00
|
|
|
},
|
|
|
|
to: {
|
2012-12-26 13:35:42 +00:00
|
|
|
y: to.height / original.height,
|
|
|
|
x: to.width / original.width
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Scale the css box
|
|
|
|
if ( scale === "box" || scale === "both" ) {
|
|
|
|
|
|
|
|
// Vertical props scaling
|
|
|
|
if ( factor.from.y !== factor.to.y ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
from = $.effects.setTransition( element, vProps, factor.from.y, from );
|
|
|
|
to = $.effects.setTransition( element, vProps, factor.to.y, to );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Horizontal props scaling
|
|
|
|
if ( factor.from.x !== factor.to.x ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
from = $.effects.setTransition( element, hProps, factor.from.x, from );
|
|
|
|
to = $.effects.setTransition( element, hProps, factor.to.x, to );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scale the content
|
|
|
|
if ( scale === "content" || scale === "both" ) {
|
|
|
|
|
|
|
|
// Vertical props scaling
|
|
|
|
if ( factor.from.y !== factor.to.y ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
from = $.effects.setTransition( element, cProps, factor.from.y, from );
|
|
|
|
to = $.effects.setTransition( element, cProps, factor.to.y, to );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
// Adjust the position properties based on the provided origin points
|
|
|
|
if ( origin ) {
|
2013-05-08 12:06:54 +00:00
|
|
|
baseline = $.effects.getBaseline( origin, original );
|
2012-12-26 13:35:42 +00:00
|
|
|
from.top = ( original.outerHeight - from.outerHeight ) * baseline.y + pos.top;
|
|
|
|
from.left = ( original.outerWidth - from.outerWidth ) * baseline.x + pos.left;
|
|
|
|
to.top = ( original.outerHeight - to.outerHeight ) * baseline.y + pos.top;
|
|
|
|
to.left = ( original.outerWidth - to.outerWidth ) * baseline.x + pos.left;
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
2012-12-26 13:35:42 +00:00
|
|
|
element.css( from );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
// Animate the children if desired
|
|
|
|
if ( scale === "content" || scale === "both" ) {
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
vProps = vProps.concat( [ "marginTop", "marginBottom" ] ).concat( cProps );
|
|
|
|
hProps = hProps.concat( [ "marginLeft", "marginRight" ] );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
// Only animate children with width attributes specified
|
|
|
|
// TODO: is this right? should we include anything with css width specified as well
|
|
|
|
element.find( "*[width]" ).each( function() {
|
2013-05-08 12:06:54 +00:00
|
|
|
var child = $( this ),
|
2012-12-26 13:35:42 +00:00
|
|
|
childOriginal = $.effects.scaledDimensions( child ),
|
|
|
|
childFrom = {
|
|
|
|
height: childOriginal.height * factor.from.y,
|
|
|
|
width: childOriginal.width * factor.from.x,
|
|
|
|
outerHeight: childOriginal.outerHeight * factor.from.y,
|
|
|
|
outerWidth: childOriginal.outerWidth * factor.from.x
|
|
|
|
},
|
|
|
|
childTo = {
|
|
|
|
height: childOriginal.height * factor.to.y,
|
|
|
|
width: childOriginal.width * factor.to.x,
|
|
|
|
outerHeight: childOriginal.height * factor.to.y,
|
|
|
|
outerWidth: childOriginal.width * factor.to.x
|
2013-05-08 12:06:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Vertical props scaling
|
|
|
|
if ( factor.from.y !== factor.to.y ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
childFrom = $.effects.setTransition( child, vProps, factor.from.y, childFrom );
|
|
|
|
childTo = $.effects.setTransition( child, vProps, factor.to.y, childTo );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Horizontal props scaling
|
|
|
|
if ( factor.from.x !== factor.to.x ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
childFrom = $.effects.setTransition( child, hProps, factor.from.x, childFrom );
|
|
|
|
childTo = $.effects.setTransition( child, hProps, factor.to.x, childTo );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( restore ) {
|
|
|
|
$.effects.saveStyle( child );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Animate children
|
2012-12-26 13:35:42 +00:00
|
|
|
child.css( childFrom );
|
|
|
|
child.animate( childTo, options.duration, options.easing, function() {
|
2013-05-08 12:06:54 +00:00
|
|
|
|
|
|
|
// Restore children
|
|
|
|
if ( restore ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
$.effects.restoreStyle( child );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
|
|
|
} );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Animate
|
2012-12-26 13:35:42 +00:00
|
|
|
element.animate( to, {
|
2013-05-08 12:06:54 +00:00
|
|
|
queue: false,
|
2012-12-26 13:35:42 +00:00
|
|
|
duration: options.duration,
|
|
|
|
easing: options.easing,
|
2013-05-08 12:06:54 +00:00
|
|
|
complete: function() {
|
2012-12-26 13:35:42 +00:00
|
|
|
|
|
|
|
var offset = element.offset();
|
|
|
|
|
|
|
|
if ( to.opacity === 0 ) {
|
|
|
|
element.css( "opacity", from.opacity );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
2012-12-26 13:35:42 +00:00
|
|
|
|
2013-05-08 12:06:54 +00:00
|
|
|
if ( !restore ) {
|
2012-12-26 13:35:42 +00:00
|
|
|
element
|
|
|
|
.css( "position", position === "static" ? "relative" : position )
|
|
|
|
.offset( offset );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2012-12-26 13:35:42 +00:00
|
|
|
// Need to save style here so that automatic style restoration
|
|
|
|
// doesn't restore to the original styles from before the animation.
|
|
|
|
$.effects.saveStyle( element );
|
2013-05-08 12:06:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
}
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
} );
|
2013-05-08 12:06:54 +00:00
|
|
|
|
2015-03-18 14:39:12 +00:00
|
|
|
} ) );
|