2 * jQuery UI Effects Scale 1.8.24
4 * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
8 * http://docs.jquery.com/UI/Effects/Scale
11 * jquery.effects.core.js
13 (function( $, undefined ) {
15 $.effects.puff = function(o) {
16 return this.queue(function() {
18 mode = $.effects.setMode(elem, o.options.mode || 'hide'),
19 percent = parseInt(o.options.percent, 10) || 150,
20 factor = percent / 100,
21 original = { height: elem.height(), width: elem.width() };
26 percent: mode == 'hide' ? percent : 100,
30 height: original.height * factor,
31 width: original.width * factor
35 elem.effect('scale', o.options, o.duration, o.callback);
40 $.effects.scale = function(o) {
42 return this.queue(function() {
48 var options = $.extend(true, {}, o.options);
49 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
50 var percent = parseInt(o.options.percent,10) || (parseInt(o.options.percent,10) == 0 ? 0 : (mode == 'hide' ? 0 : 100)); // Set default scaling percent
51 var direction = o.options.direction || 'both'; // Set default axis
52 var origin = o.options.origin; // The origin of the scaling
53 if (mode != 'effect') { // Set default origin and restore for show/hide
54 options.origin = origin || ['middle','center'];
55 options.restore = true;
57 var original = {height: el.height(), width: el.width()}; // Save original
58 el.from = o.options.from || (mode == 'show' ? {height: 0, width: 0} : original); // Default from state
61 var factor = { // Set scaling factor
62 y: direction != 'horizontal' ? (percent / 100) : 1,
63 x: direction != 'vertical' ? (percent / 100) : 1
65 el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state
67 if (o.options.fade) { // Fade option to support puff
68 if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};
69 if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};
73 options.from = el.from; options.to = el.to; options.mode = mode;
76 el.effect('size', options, o.duration, o.callback);
82 $.effects.size = function(o) {
84 return this.queue(function() {
87 var el = $(this), props = ['position','top','bottom','left','right','width','height','overflow','opacity'];
88 var props1 = ['position','top','bottom','left','right','overflow','opacity']; // Always restore
89 var props2 = ['width','height','overflow']; // Copy for children
90 var cProps = ['fontSize'];
91 var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];
92 var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];
95 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
96 var restore = o.options.restore || false; // Default restore
97 var scale = o.options.scale || 'both'; // Default scale mode
98 var origin = o.options.origin; // The origin of the sizing
99 var original = {height: el.height(), width: el.width()}; // Save original
100 el.from = o.options.from || original; // Default from state
101 el.to = o.options.to || original; // Default to state
103 if (origin) { // Calculate baseline shifts
104 var baseline = $.effects.getBaseline(origin, original);
105 el.from.top = (original.height - el.from.height) * baseline.y;
106 el.from.left = (original.width - el.from.width) * baseline.x;
107 el.to.top = (original.height - el.to.height) * baseline.y;
108 el.to.left = (original.width - el.to.width) * baseline.x;
110 var factor = { // Set scaling factor
111 from: {y: el.from.height / original.height, x: el.from.width / original.width},
112 to: {y: el.to.height / original.height, x: el.to.width / original.width}
114 if (scale == 'box' || scale == 'both') { // Scale the css box
115 if (factor.from.y != factor.to.y) { // Vertical props scaling
116 props = props.concat(vProps);
117 el.from = $.effects.setTransition(el, vProps, factor.from.y, el.from);
118 el.to = $.effects.setTransition(el, vProps, factor.to.y, el.to);
120 if (factor.from.x != factor.to.x) { // Horizontal props scaling
121 props = props.concat(hProps);
122 el.from = $.effects.setTransition(el, hProps, factor.from.x, el.from);
123 el.to = $.effects.setTransition(el, hProps, factor.to.x, el.to);
126 if (scale == 'content' || scale == 'both') { // Scale the content
127 if (factor.from.y != factor.to.y) { // Vertical props scaling
128 props = props.concat(cProps);
129 el.from = $.effects.setTransition(el, cProps, factor.from.y, el.from);
130 el.to = $.effects.setTransition(el, cProps, factor.to.y, el.to);
133 $.effects.save(el, restore ? props : props1); el.show(); // Save & Show
134 $.effects.createWrapper(el); // Create Wrapper
135 el.css('overflow','hidden').css(el.from); // Shift
138 if (scale == 'content' || scale == 'both') { // Scale the children
139 vProps = vProps.concat(['marginTop','marginBottom']).concat(cProps); // Add margins/font-size
140 hProps = hProps.concat(['marginLeft','marginRight']); // Add margins
141 props2 = props.concat(vProps).concat(hProps); // Concat
142 el.find("*[width]").each(function(){
144 if (restore) $.effects.save(child, props2);
145 var c_original = {height: child.height(), width: child.width()}; // Save original
146 child.from = {height: c_original.height * factor.from.y, width: c_original.width * factor.from.x};
147 child.to = {height: c_original.height * factor.to.y, width: c_original.width * factor.to.x};
148 if (factor.from.y != factor.to.y) { // Vertical props scaling
149 child.from = $.effects.setTransition(child, vProps, factor.from.y, child.from);
150 child.to = $.effects.setTransition(child, vProps, factor.to.y, child.to);
152 if (factor.from.x != factor.to.x) { // Horizontal props scaling
153 child.from = $.effects.setTransition(child, hProps, factor.from.x, child.from);
154 child.to = $.effects.setTransition(child, hProps, factor.to.x, child.to);
156 child.css(child.from); // Shift children
157 child.animate(child.to, o.duration, o.options.easing, function(){
158 if (restore) $.effects.restore(child, props2); // Restore children
159 }); // Animate children
164 el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
165 if (el.to.opacity === 0) {
166 el.css('opacity', el.from.opacity);
168 if(mode == 'hide') el.hide(); // Hide
169 $.effects.restore(el, restore ? props : props1); $.effects.removeWrapper(el); // Restore
170 if(o.callback) o.callback.apply(this, arguments); // Callback