external library initial commit
[dwaf.git] / externals / jquery-ui-1.8 / ui / jquery.effects.fold.js
blobe3902d667cba16f92b3fb3531e8d62f1c16891f4
1 /*\r
2  * jQuery UI Effects Fold 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/Fold\r
9  *\r
10  * Depends:\r
11  *      jquery.effects.core.js\r
12  */\r
13 (function($) {\r
15 $.effects.fold = function(o) {\r
17         return this.queue(function() {\r
19                 // Create element\r
20                 var el = $(this), props = ['position','top','left'];\r
22                 // Set options\r
23                 var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode\r
24                 var size = o.options.size || 15; // Default fold size\r
25                 var horizFirst = !(!o.options.horizFirst); // Ensure a boolean value\r
26                 var duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2;\r
28                 // Adjust\r
29                 $.effects.save(el, props); el.show(); // Save & Show\r
30                 var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper\r
31                 var widthFirst = ((mode == 'show') != horizFirst);\r
32                 var ref = widthFirst ? ['width', 'height'] : ['height', 'width'];\r
33                 var distance = widthFirst ? [wrapper.width(), wrapper.height()] : [wrapper.height(), wrapper.width()];\r
34                 var percent = /([0-9]+)%/.exec(size);\r
35                 if(percent) size = parseInt(percent[1],10) / 100 * distance[mode == 'hide' ? 0 : 1];\r
36                 if(mode == 'show') wrapper.css(horizFirst ? {height: 0, width: size} : {height: size, width: 0}); // Shift\r
38                 // Animation\r
39                 var animation1 = {}, animation2 = {};\r
40                 animation1[ref[0]] = mode == 'show' ? distance[0] : size;\r
41                 animation2[ref[1]] = mode == 'show' ? distance[1] : 0;\r
43                 // Animate\r
44                 wrapper.animate(animation1, duration, o.options.easing)\r
45                 .animate(animation2, duration, o.options.easing, function() {\r
46                         if(mode == 'hide') el.hide(); // Hide\r
47                         $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore\r
48                         if(o.callback) o.callback.apply(el[0], arguments); // Callback\r
49                         el.dequeue();\r
50                 });\r
52         });\r
54 };\r
56 })(jQuery);\r