topical media & game development
lib-jquery-style-custom-development-bundle-ui-effects.scale.js / js
/*
* jQuery UI Effects Scale 1.7.1
*
* Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* http://docs.jquery.com/UI/Effects/Scale
*
* Depends:
* effects.core.js
*/
(function(.effects.puff = function(o) {
return this.queue(function() {
// Create element
var el = this;
// Set options
var options = .effects.setMode(el, o.options.mode || 'hide'); // Set Mode
var percent = parseInt(o.options.percent,10) || 150; // Set default puff percent
options.fade = true; // It's not a puff if it doesn't fade! :)
var original = {height: el.height(), width: el.width()}; // Save original
// Adjust
var factor = percent / 100;
el.from = (mode == 'hide') ? original : {height: original.height * factor, width: original.width * factor};
// Animation
options.from = el.from;
options.percent = (mode == 'hide') ? percent : 100;
options.mode = mode;
// Animate
el.effect('scale', options, o.duration, o.callback);
el.dequeue();
});
};
.extend(true, {}, o.options);
var mode = .effects.size = function(o) {
return this.queue(function() {
// Create element
var el = this, props = ['position','top','left','width','height','overflow','opacity'];
var props1 = ['position','top','left','overflow','opacity']; // Always restore
var props2 = ['width','height','overflow']; // Copy for children
var cProps = ['fontSize'];
var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];
var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];
// Set options
var mode = .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;
};
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.to.y, el.to);
};
if (factor.from.x != factor.to.x) { // Horizontal props scaling
props = props.concat(hProps);
el.from = .effects.setTransition(el, hProps, factor.to.x, el.to);
};
};
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.to.y, el.to);
};
};
.effects.createWrapper(el); // Create Wrapper
el.css('overflow','hidden').css(el.from); // Shift
// 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.setTransition(child, vProps, factor.from.y, child.from);
child.to = .effects.setTransition(child, hProps, factor.from.x, child.from);
child.to = .effects.restore(child, props2); // Restore children
}); // Animate children
});
};
// Animate
el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
if(mode == 'hide') el.hide(); // Hide
.effects.removeWrapper(el); // Restore
if(o.callback) o.callback.apply(this, arguments); // Callback
el.dequeue();
}});
});
};
})(jQuery);
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.