external library initial commit
[dwaf.git] / externals / jquery-ui-1.8 / ui / jquery.effects.bounce.js
blobf37528ac2e820d906116f6a7c7d39a3ebabcdc31
1 /*\r
2  * jQuery UI Effects Bounce 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/Bounce\r
9  *\r
10  * Depends:\r
11  *      jquery.effects.core.js\r
12  */\r
13 (function($) {\r
15 $.effects.bounce = 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 || 'effect'); // Set Mode\r
24                 var direction = o.options.direction || 'up'; // Default direction\r
25                 var distance = o.options.distance || 20; // Default distance\r
26                 var times = o.options.times || 5; // Default # of times\r
27                 var speed = o.duration || 250; // Default speed per bounce\r
28                 if (/show|hide/.test(mode)) props.push('opacity'); // Avoid touching opacity to prevent clearType and PNG issues in IE\r
30                 // Adjust\r
31                 $.effects.save(el, props); el.show(); // Save & Show\r
32                 $.effects.createWrapper(el); // Create Wrapper\r
33                 var ref = (direction == 'up' || direction == 'down') ? 'top' : 'left';\r
34                 var motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg';\r
35                 var distance = o.options.distance || (ref == 'top' ? el.outerHeight({margin:true}) / 3 : el.outerWidth({margin:true}) / 3);\r
36                 if (mode == 'show') el.css('opacity', 0).css(ref, motion == 'pos' ? -distance : distance); // Shift\r
37                 if (mode == 'hide') distance = distance / (times * 2);\r
38                 if (mode != 'hide') times--;\r
40                 // Animate\r
41                 if (mode == 'show') { // Show Bounce\r
42                         var animation = {opacity: 1};\r
43                         animation[ref] = (motion == 'pos' ? '+=' : '-=') + distance;\r
44                         el.animate(animation, speed / 2, o.options.easing);\r
45                         distance = distance / 2;\r
46                         times--;\r
47                 };\r
48                 for (var i = 0; i < times; i++) { // Bounces\r
49                         var animation1 = {}, animation2 = {};\r
50                         animation1[ref] = (motion == 'pos' ? '-=' : '+=') + distance;\r
51                         animation2[ref] = (motion == 'pos' ? '+=' : '-=') + distance;\r
52                         el.animate(animation1, speed / 2, o.options.easing).animate(animation2, speed / 2, o.options.easing);\r
53                         distance = (mode == 'hide') ? distance * 2 : distance / 2;\r
54                 };\r
55                 if (mode == 'hide') { // Last Bounce\r
56                         var animation = {opacity: 0};\r
57                         animation[ref] = (motion == 'pos' ? '-=' : '+=')  + distance;\r
58                         el.animate(animation, speed / 2, o.options.easing, function(){\r
59                                 el.hide(); // Hide\r
60                                 $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore\r
61                                 if(o.callback) o.callback.apply(this, arguments); // Callback\r
62                         });\r
63                 } else {\r
64                         var animation1 = {}, animation2 = {};\r
65                         animation1[ref] = (motion == 'pos' ? '-=' : '+=') + distance;\r
66                         animation2[ref] = (motion == 'pos' ? '+=' : '-=') + distance;\r
67                         el.animate(animation1, speed / 2, o.options.easing).animate(animation2, speed / 2, o.options.easing, function(){\r
68                                 $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore\r
69                                 if(o.callback) o.callback.apply(this, arguments); // Callback\r
70                         });\r
71                 };\r
72                 el.queue('fx', function() { el.dequeue(); });\r
73                 el.dequeue();\r
74         });\r
76 };\r
78 })(jQuery);\r