jquery-ui/ui/effect-scale.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

/*!
* jQuery UI Effects Scale @VERSION
2012-07-04 13:08:08 +00:00
* http://jqueryui.com
*
2014-01-29 03:25:02 +00:00
* Copyright 2014 jQuery Foundation and other contributors
2012-08-09 14:13:24 +00:00
* Released under the MIT license.
* http://jquery.org/license
*/
//>>label: Scale Effect
//>>group: Effects
//>>description: Grows or shrinks an element and its content. Restores an element to its original size.
//>>docs: http://api.jqueryui.com/scale-effect/
//>>demos: http://jqueryui.com/effect/
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define([
"jquery",
"./effect",
"./effect-size"
], factory );
} else {
// Browser globals
factory( jQuery );
}
}(function( $ ) {
return $.effects.effect.scale = function( o, done ) {
// Create element
var el = $( this ),
options = $.extend( true, {}, o ),
mode = $.effects.setMode( el, o.mode || "effect" ),
2012-04-02 23:12:21 +00:00
percent = parseInt( o.percent, 10 ) ||
( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ),
direction = o.direction || "both",
origin = o.origin,
2012-04-19 01:57:51 +00:00
original = {
height: el.height(),
width: el.width(),
outerHeight: el.outerHeight(),
outerWidth: el.outerWidth()
},
factor = {
2012-04-02 23:12:21 +00:00
y: direction !== "horizontal" ? (percent / 100) : 1,
x: direction !== "vertical" ? (percent / 100) : 1
2012-04-19 01:57:51 +00:00
};
2011-03-07 00:34:18 +00:00
// We are going to pass this effect to the size effect:
options.effect = "size";
options.queue = false;
options.complete = done;
// Set default origin and restore for show/hide
2012-04-19 01:57:51 +00:00
if ( mode !== "effect" ) {
2013-10-16 18:43:09 +00:00
options.origin = origin || [ "middle", "center" ];
options.restore = true;
}
options.from = o.from || ( mode === "show" ? {
height: 0,
width: 0,
outerHeight: 0,
outerWidth: 0
} : original );
options.to = {
2012-04-19 01:57:51 +00:00
height: original.height * factor.y,
width: original.width * factor.x,
2012-04-19 01:57:51 +00:00
outerHeight: original.outerHeight * factor.y,
outerWidth: original.outerWidth * factor.x
2012-04-19 01:57:51 +00:00
};
2012-04-02 19:55:50 +00:00
// Fade option to support puff
if ( options.fade ) {
2012-04-02 23:12:21 +00:00
if ( mode === "show" ) {
2012-04-19 01:57:51 +00:00
options.from.opacity = 0;
options.to.opacity = 1;
}
2012-04-02 23:12:21 +00:00
if ( mode === "hide" ) {
2012-04-19 01:57:51 +00:00
options.from.opacity = 1;
options.to.opacity = 0;
}
2012-04-02 19:55:50 +00:00
}
2011-03-07 00:34:18 +00:00
// Animate
el.effect( options );
2011-03-07 00:34:18 +00:00
};
2011-03-07 00:34:18 +00:00
}));