jquery-ui/ui/jquery.ui.effect-scale.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

/*!
* jQuery UI Effects Scale @VERSION
2012-07-04 13:08:08 +00:00
* http://jqueryui.com
*
2013-01-10 13:52:20 +00:00
* Copyright 2013 jQuery Foundation and other contributors
2012-08-09 14:13:24 +00:00
* Released under the MIT license.
* http://jquery.org/license
*
2012-09-26 23:06:20 +00:00
* http://api.jqueryui.com/scale-effect/
*
* Depends:
2012-06-15 16:47:12 +00:00
* jquery.ui.effect.js
* jquery.ui.effect-size.js
*/
(function( $, undefined ) {
$.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
})(jQuery);