external library initial commit
[dwaf.git] / externals / jquery-ui-1.8 / ui / jquery.effects.scale.js
blob17b97995da83740ca4497310a99a386547393be3
1 /*\r
2  * jQuery UI Effects Scale 1.8\r
3  *\r
4  * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)\r
5  * Dual licensed under the MIT (MIT-LICENSE.txt)\r
6  * and GPL (GPL-LICENSE.txt) licenses.\r
7  *\r
8  * http://docs.jquery.com/UI/Effects/Scale\r
9  *\r
10  * Depends:\r
11  *      jquery.effects.core.js\r
12  */\r
13 (function($) {\r
15 $.effects.puff = function(o) {\r
16         return this.queue(function() {\r
17                 var elem = $(this),\r
18                         mode = $.effects.setMode(elem, o.options.mode || 'hide'),\r
19                         percent = parseInt(o.options.percent, 10) || 150,\r
20                         factor = percent / 100,\r
21                         original = { height: elem.height(), width: elem.width() };\r
23                 $.extend(o.options, {\r
24                         fade: true,\r
25                         mode: mode,\r
26                         percent: mode == 'hide' ? percent : 100,\r
27                         from: mode == 'hide'\r
28                                 ? original\r
29                                 : {\r
30                                         height: original.height * factor,\r
31                                         width: original.width * factor\r
32                                 }\r
33                 });\r
35                 elem.effect('scale', o.options, o.duration, o.callback);\r
36                 elem.dequeue();\r
37         });\r
38 };\r
40 $.effects.scale = function(o) {\r
42         return this.queue(function() {\r
44                 // Create element\r
45                 var el = $(this);\r
47                 // Set options\r
48                 var options = $.extend(true, {}, o.options);\r
49                 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode\r
50                 var percent = parseInt(o.options.percent,10) || (parseInt(o.options.percent,10) == 0 ? 0 : (mode == 'hide' ? 0 : 100)); // Set default scaling percent\r
51                 var direction = o.options.direction || 'both'; // Set default axis\r
52                 var origin = o.options.origin; // The origin of the scaling\r
53                 if (mode != 'effect') { // Set default origin and restore for show/hide\r
54                         options.origin = origin || ['middle','center'];\r
55                         options.restore = true;\r
56                 }\r
57                 var original = {height: el.height(), width: el.width()}; // Save original\r
58                 el.from = o.options.from || (mode == 'show' ? {height: 0, width: 0} : original); // Default from state\r
60                 // Adjust\r
61                 var factor = { // Set scaling factor\r
62                         y: direction != 'horizontal' ? (percent / 100) : 1,\r
63                         x: direction != 'vertical' ? (percent / 100) : 1\r
64                 };\r
65                 el.to = {height: original.height * factor.y, width: original.width * factor.x}; // Set to state\r
67                 if (o.options.fade) { // Fade option to support puff\r
68                         if (mode == 'show') {el.from.opacity = 0; el.to.opacity = 1;};\r
69                         if (mode == 'hide') {el.from.opacity = 1; el.to.opacity = 0;};\r
70                 };\r
72                 // Animation\r
73                 options.from = el.from; options.to = el.to; options.mode = mode;\r
75                 // Animate\r
76                 el.effect('size', options, o.duration, o.callback);\r
77                 el.dequeue();\r
78         });\r
80 };\r
82 $.effects.size = function(o) {\r
84         return this.queue(function() {\r
86                 // Create element\r
87                 var el = $(this), props = ['position','top','left','width','height','overflow','opacity'];\r
88                 var props1 = ['position','top','left','overflow','opacity']; // Always restore\r
89                 var props2 = ['width','height','overflow']; // Copy for children\r
90                 var cProps = ['fontSize'];\r
91                 var vProps = ['borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'];\r
92                 var hProps = ['borderLeftWidth', 'borderRightWidth', 'paddingLeft', 'paddingRight'];\r
94                 // Set options\r
95                 var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode\r
96                 var restore = o.options.restore || false; // Default restore\r
97                 var scale = o.options.scale || 'both'; // Default scale mode\r
98                 var origin = o.options.origin; // The origin of the sizing\r
99                 var original = {height: el.height(), width: el.width()}; // Save original\r
100                 el.from = o.options.from || original; // Default from state\r
101                 el.to = o.options.to || original; // Default to state\r
102                 // Adjust\r
103                 if (origin) { // Calculate baseline shifts\r
104                         var baseline = $.effects.getBaseline(origin, original);\r
105                         el.from.top = (original.height - el.from.height) * baseline.y;\r
106                         el.from.left = (original.width - el.from.width) * baseline.x;\r
107                         el.to.top = (original.height - el.to.height) * baseline.y;\r
108                         el.to.left = (original.width - el.to.width) * baseline.x;\r
109                 };\r
110                 var factor = { // Set scaling factor\r
111                         from: {y: el.from.height / original.height, x: el.from.width / original.width},\r
112                         to: {y: el.to.height / original.height, x: el.to.width / original.width}\r
113                 };\r
114                 if (scale == 'box' || scale == 'both') { // Scale the css box\r
115                         if (factor.from.y != factor.to.y) { // Vertical props scaling\r
116                                 props = props.concat(vProps);\r
117                                 el.from = $.effects.setTransition(el, vProps, factor.from.y, el.from);\r
118                                 el.to = $.effects.setTransition(el, vProps, factor.to.y, el.to);\r
119                         };\r
120                         if (factor.from.x != factor.to.x) { // Horizontal props scaling\r
121                                 props = props.concat(hProps);\r
122                                 el.from = $.effects.setTransition(el, hProps, factor.from.x, el.from);\r
123                                 el.to = $.effects.setTransition(el, hProps, factor.to.x, el.to);\r
124                         };\r
125                 };\r
126                 if (scale == 'content' || scale == 'both') { // Scale the content\r
127                         if (factor.from.y != factor.to.y) { // Vertical props scaling\r
128                                 props = props.concat(cProps);\r
129                                 el.from = $.effects.setTransition(el, cProps, factor.from.y, el.from);\r
130                                 el.to = $.effects.setTransition(el, cProps, factor.to.y, el.to);\r
131                         };\r
132                 };\r
133                 $.effects.save(el, restore ? props : props1); el.show(); // Save & Show\r
134                 $.effects.createWrapper(el); // Create Wrapper\r
135                 el.css('overflow','hidden').css(el.from); // Shift\r
137                 // Animate\r
138                 if (scale == 'content' || scale == 'both') { // Scale the children\r
139                         vProps = vProps.concat(['marginTop','marginBottom']).concat(cProps); // Add margins/font-size\r
140                         hProps = hProps.concat(['marginLeft','marginRight']); // Add margins\r
141                         props2 = props.concat(vProps).concat(hProps); // Concat\r
142                         el.find("*[width]").each(function(){\r
143                                 child = $(this);\r
144                                 if (restore) $.effects.save(child, props2);\r
145                                 var c_original = {height: child.height(), width: child.width()}; // Save original\r
146                                 child.from = {height: c_original.height * factor.from.y, width: c_original.width * factor.from.x};\r
147                                 child.to = {height: c_original.height * factor.to.y, width: c_original.width * factor.to.x};\r
148                                 if (factor.from.y != factor.to.y) { // Vertical props scaling\r
149                                         child.from = $.effects.setTransition(child, vProps, factor.from.y, child.from);\r
150                                         child.to = $.effects.setTransition(child, vProps, factor.to.y, child.to);\r
151                                 };\r
152                                 if (factor.from.x != factor.to.x) { // Horizontal props scaling\r
153                                         child.from = $.effects.setTransition(child, hProps, factor.from.x, child.from);\r
154                                         child.to = $.effects.setTransition(child, hProps, factor.to.x, child.to);\r
155                                 };\r
156                                 child.css(child.from); // Shift children\r
157                                 child.animate(child.to, o.duration, o.options.easing, function(){\r
158                                         if (restore) $.effects.restore(child, props2); // Restore children\r
159                                 }); // Animate children\r
160                         });\r
161                 };\r
163                 // Animate\r
164                 el.animate(el.to, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {\r
165                         if (el.to.opacity === 0) {\r
166                                 el.css('opacity', el.from.opacity);\r
167                         }\r
168                         if(mode == 'hide') el.hide(); // Hide\r
169                         $.effects.restore(el, restore ? props : props1); $.effects.removeWrapper(el); // Restore\r
170                         if(o.callback) o.callback.apply(this, arguments); // Callback\r
171                         el.dequeue();\r
172                 }});\r
174         });\r
176 };\r
178 })(jQuery);\r