2008-06-06 20:08:52 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Effects Scale @VERSION
|
2008-06-06 20:08:52 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-20 04:10:34 +00:00
|
|
|
*
|
2008-06-06 20:08:52 +00:00
|
|
|
* http://docs.jquery.com/UI/Effects/Scale
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.effects.core.js
|
2008-06-06 20:08:52 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-06 19:47:31 +00:00
|
|
|
|
|
|
|
$.effects.puff = function(o) {
|
|
|
|
return this.queue(function() {
|
2009-06-15 02:21:44 +00:00
|
|
|
var elem = $(this),
|
|
|
|
mode = $.effects.setMode(elem, o.options.mode || 'hide'),
|
|
|
|
percent = parseInt(o.options.percent, 10) || 150,
|
|
|
|
factor = percent / 100,
|
|
|
|
original = { height: elem.height(), width: elem.width() };
|
|
|
|
|
|
|
|
$.extend(o.options, {
|
|
|
|
fade: true,
|
|
|
|
mode: mode,
|
|
|
|
percent: mode == 'hide' ? percent : 100,
|
|
|
|
from: mode == 'hide'
|
|
|
|
? original
|
|
|
|
: {
|
|
|
|
height: original.height * factor,
|
|
|
|
width: original.width * factor
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
elem.effect('scale', o.options, o.duration, o.callback);
|
|
|
|
elem.dequeue();
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$.effects.scale = function(o) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
return this.queue(function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Create element
|
|
|
|
var el = $(this);
|
|
|
|
|
|
|
|
// Set options
|
2008-06-26 14:24:36 +00:00
|
|
|
var options = $.extend(true, {}, o.options);
|
2008-06-06 19:47:31 +00:00
|
|
|
var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
|
2009-02-10 13:11:34 +00:00
|
|
|
var percent = parseInt(o.options.percent,10) || (parseInt(o.options.percent,10) == 0 ? 0 : (mode == 'hide' ? 0 : 100)); // Set default scaling percent
|
2008-06-06 19:47:31 +00:00
|
|
|
var direction = o.options.direction || 'both'; // Set default axis
|
|
|
|
var origin = o.options.origin; // The origin of the scaling
|
|
|
|
if (mode != 'effect') { // Set default origin and restore for show/hide
|
2008-06-26 15:58:38 +00:00
|
|
|
options.origin = origin || ['middle','center'];
|
2008-06-06 19:47:31 +00:00
|
|
|
options.restore = true;
|
|
|
|
}
|
|
|
|
var original = {height: el.height(), width: el.width()}; // Save original
|
|
|
|
el.from = o.options.from || (mode == 'show' ? {height: 0, width: 0} : original); // Default from state
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Adjust
|
|
|
|
var factor = { // Set scaling factor
|
|
|
|
y: direction != 'horizontal' ? (percent / 100) : 1,
|
|
|
|
x: direction != 'vertical' ? (percent / 100) : 1
|
|
|
|
};
|
|
|
|
el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
if (o.options.fade) { // Fade option to support puff
|
|
|
|
if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};
|
|
|
|
if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animation
|
|
|
|
options.from = el.from; options.to = el.to; options.mode = mode;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
|
|
|
el.effect('size', options, o.duration, o.callback);
|
|
|
|
el.dequeue();
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
2008-05-31 17:18:24 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
$.effects.size = function(o) {
|
|
|
|
|
|
|
|
return this.queue(function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Create element
|
2010-12-13 18:02:31 +00:00
|
|
|
var el = $(this), props = ['position','top','bottom','left','right','width','height','overflow','opacity'];
|
|
|
|
var props1 = ['position','top','bottom','left','right','overflow','opacity']; // Always restore
|
2008-06-06 19:47:31 +00:00
|
|
|
var props2 = ['width','height','overflow']; // Copy for children
|
|
|
|
var cProps = ['fontSize'];
|
|
|
|
var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];
|
|
|
|
var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Set options
|
|
|
|
var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
|
|
|
|
var restore = o.options.restore || false; // Default restore
|
|
|
|
var scale = o.options.scale || 'both'; // Default scale mode
|
2008-06-26 15:58:38 +00:00
|
|
|
var origin = o.options.origin; // The origin of the sizing
|
2008-06-06 19:47:31 +00:00
|
|
|
var original = {height: el.height(), width: el.width()}; // Save original
|
|
|
|
el.from = o.options.from || original; // Default from state
|
|
|
|
el.to = o.options.to || original; // Default to state
|
|
|
|
// Adjust
|
2008-06-26 15:58:38 +00:00
|
|
|
if (origin) { // Calculate baseline shifts
|
|
|
|
var baseline = $.effects.getBaseline(origin, original);
|
|
|
|
el.from.top = (original.height - el.from.height) * baseline.y;
|
|
|
|
el.from.left = (original.width - el.from.width) * baseline.x;
|
|
|
|
el.to.top = (original.height - el.to.height) * baseline.y;
|
|
|
|
el.to.left = (original.width - el.to.width) * baseline.x;
|
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
var factor = { // Set scaling factor
|
|
|
|
from: {y: el.from.height / original.height, x: el.from.width / original.width},
|
|
|
|
to: {y: el.to.height / original.height, x: el.to.width / original.width}
|
|
|
|
};
|
|
|
|
if (scale == 'box' || scale == 'both') { // Scale the css box
|
|
|
|
if (factor.from.y != factor.to.y) { // Vertical props scaling
|
|
|
|
props = props.concat(vProps);
|
|
|
|
el.from = $.effects.setTransition(el, vProps, factor.from.y, el.from);
|
|
|
|
el.to = $.effects.setTransition(el, vProps, factor.to.y, el.to);
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
if (factor.from.x != factor.to.x) { // Horizontal props scaling
|
|
|
|
props = props.concat(hProps);
|
|
|
|
el.from = $.effects.setTransition(el, hProps, factor.from.x, el.from);
|
|
|
|
el.to = $.effects.setTransition(el, hProps, factor.to.x, el.to);
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
if (scale == 'content' || scale == 'both') { // Scale the content
|
|
|
|
if (factor.from.y != factor.to.y) { // Vertical props scaling
|
|
|
|
props = props.concat(cProps);
|
|
|
|
el.from = $.effects.setTransition(el, cProps, factor.from.y, el.from);
|
|
|
|
el.to = $.effects.setTransition(el, cProps, factor.to.y, el.to);
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
$.effects.save(el, restore ? props : props1); el.show(); // Save & Show
|
|
|
|
$.effects.createWrapper(el); // Create Wrapper
|
|
|
|
el.css('overflow','hidden').css(el.from); // Shift
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
|
|
|
if (scale == 'content' || scale == 'both') { // Scale the children
|
|
|
|
vProps = vProps.concat(['marginTop','marginBottom']).concat(cProps); // Add margins/font-size
|
|
|
|
hProps = hProps.concat(['marginLeft','marginRight']); // Add margins
|
|
|
|
props2 = props.concat(vProps).concat(hProps); // Concat
|
|
|
|
el.find("*[width]").each(function(){
|
|
|
|
child = $(this);
|
|
|
|
if (restore) $.effects.save(child, props2);
|
|
|
|
var c_original = {height: child.height(), width: child.width()}; // Save original
|
|
|
|
child.from = {height: c_original.height * factor.from.y, width: c_original.width * factor.from.x};
|
|
|
|
child.to = {height: c_original.height * factor.to.y, width: c_original.width * factor.to.x};
|
2008-05-31 17:18:24 +00:00
|
|
|
if (factor.from.y != factor.to.y) { // Vertical props scaling
|
2008-06-06 19:47:31 +00:00
|
|
|
child.from = $.effects.setTransition(child, vProps, factor.from.y, child.from);
|
|
|
|
child.to = $.effects.setTransition(child, vProps, factor.to.y, child.to);
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
|
|
|
if (factor.from.x != factor.to.x) { // Horizontal props scaling
|
2008-06-06 19:47:31 +00:00
|
|
|
child.from = $.effects.setTransition(child, hProps, factor.from.x, child.from);
|
|
|
|
child.to = $.effects.setTransition(child, hProps, factor.to.x, child.to);
|
2008-05-31 17:18:24 +00:00
|
|
|
};
|
2008-06-06 19:47:31 +00:00
|
|
|
child.css(child.from); // Shift children
|
|
|
|
child.animate(child.to, o.duration, o.options.easing, function(){
|
|
|
|
if (restore) $.effects.restore(child, props2); // Restore children
|
|
|
|
}); // Animate children
|
|
|
|
});
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
// Animate
|
|
|
|
el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
|
2009-07-09 04:00:35 +00:00
|
|
|
if (el.to.opacity === 0) {
|
|
|
|
el.css('opacity', el.from.opacity);
|
|
|
|
}
|
2008-06-06 19:47:31 +00:00
|
|
|
if(mode == 'hide') el.hide(); // Hide
|
|
|
|
$.effects.restore(el, restore ? props : props1); $.effects.removeWrapper(el); // Restore
|
|
|
|
if(o.callback) o.callback.apply(this, arguments); // Callback
|
|
|
|
el.dequeue();
|
2008-09-20 03:23:42 +00:00
|
|
|
}});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
});
|
2008-05-31 17:18:24 +00:00
|
|
|
|
2008-06-06 19:47:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|