]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/jquery/jquery.effects.custombounce.js
Release 6.5.3
[Github/sugarcrm.git] / include / javascript / jquery / jquery.effects.custombounce.js
1 /*!
2  * jQuery UI Effects Bounce 1.8.21
3  *
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
7  *
8  * http://docs.jquery.com/UI/Effects/Bounce
9  *
10  * Depends:
11  *      jquery.effects.core.js
12  */
13 (function( $, undefined ) {
14
15     $.effects.custombounce = function(o) {
16
17         return this.queue(function() {
18
19             // Create element
20             var el = $(this), props = ['position','top','bottom','left','right'];
21             // Set options
22             var mode = $.effects.setMode(el, o.options.mode || 'effect'); // Set Mode
23             var direction = o.options.direction || 'up'; // Default direction
24             var gravity = (o.options.gravity == "undefined") ? true : o.options.gravity ; // Default direction
25             var distance = o.options.distance || 20; // Default distance
26             var times = o.options.times || 5; // Default # of times
27             var speed = o.duration || 250; // Default speed per bounce
28             if (/show|hide/.test(mode)) props.push('opacity'); // Avoid touching opacity to prevent clearType and PNG issues in IE
29
30             // Adjust
31             $.effects.save(el, props); el.show(); // Save & Show
32             $.effects.createWrapper(el); // Create Wrapper
33             var ref ,ref2, motion;
34
35             if(direction == 'up' || direction == 'down') {
36                 ref = 'top';
37             } else if(direction == 'up right' || direction == 'down right' || direction == 'up left' || direction == 'down left') {
38                 ref = 'top';
39                 ref2 = 'left';
40             }  else {
41                 ref = 'left';
42             }
43
44             var motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg';
45
46             if (direction == "up" || direction == "left") {
47                  motion = "pos";
48             } else {
49                  motion = "neg";
50             }
51             var distance = o.options.distance || (ref == 'top' ? el.outerHeight({margin:true}) / 3 : el.outerWidth({margin:true}) / 3);
52             if (mode == 'show') el.css('opacity', 0).css(ref, motion == 'pos' ? -distance : distance); // Shift
53             if (mode == 'hide') distance = distance / (times * 2);
54             if (mode != 'hide') times--;
55
56             // Animate
57             if (mode == 'show') { // Show Bounce
58                 var animation = {opacity: 1};
59                 animation[ref] = (motion == 'pos' ? '+=' : '-=') + distance;
60                 el.animate(animation, speed / 2, o.options.easing);
61                 distance = distance / 2;
62                 times--;
63             };
64             for (var i = 0; i < times; i++) { // Bounces
65                 var animation1 = {}, animation2 = {};
66
67                 animation1[ref] = (motion == 'pos' ? '-=' : '+=') + distance;
68                 animation2[ref] = (motion == 'pos' ? '+=' : '-=') + distance;
69                 if(ref2 != "undefined") {
70                     if(!rtl) {
71                         if(direction == "up right" || direction == "down left")   {
72                             animation1[ref2] = (motion == 'pos' ? '-=' : '+=') + distance;
73                             animation2[ref2] = (motion == 'pos' ? '+=' : '-=') + distance;
74                         } else {
75                             animation1[ref2] = (motion == 'pos' ? '+=' : '-=') + distance;
76                             animation2[ref2] = (motion == 'pos' ? '-=' : '+=') + distance;
77                         }
78                     } else {
79                         if(direction == "down right" || direction == "up left")   {
80                             animation1[ref2] = (motion == 'pos' ? '-=' : '+=') + distance;
81                             animation2[ref2] = (motion == 'pos' ? '+=' : '-=') + distance;
82                         } else {
83                             animation1[ref2] = (motion == 'pos' ? '+=' : '-=') + distance;
84                             animation2[ref2] = (motion == 'pos' ? '-=' : '+=') + distance;
85                         }
86                     }
87
88                 }
89                 el.animate(animation1, speed / 2, o.options.easing).animate(animation2, speed / 2, o.options.easing);
90                 if(gravity) {
91                     distance = (mode == 'hide') ? distance * 2 : distance / 2;
92                 }
93
94 //                console.log(distance)
95             };
96             if (mode == 'hide') { // Last Bounce
97                 var animation = {opacity: 0};
98                 animation[ref] = (motion == 'pos' ? '-=' : '+=')  + distance;
99                 el.animate(animation, speed / 2, o.options.easing, function(){
100                     el.hide(); // Hide
101                     $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
102                     if(o.callback) o.callback.apply(this, arguments); // Callback
103                 });
104             } else {
105                 var animation1 = {}, animation2 = {};
106                 animation1[ref] = (motion == 'pos' ? '-=' : '+=') + distance;
107                 animation2[ref] = (motion == 'pos' ? '+=' : '-=') + distance;
108                 if(ref2 != "undefined") {
109                     animation1[ref2] = (motion == 'pos' ? '+=' : '-=') + distance;
110                     animation2[ref2] = (motion == 'pos' ? '-=' : '+=') + distance;
111                 }
112                 el.animate(animation1, speed / 2, o.options.easing).animate(animation2, speed / 2, o.options.easing, function(){
113                     $.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
114                     if(o.callback) o.callback.apply(this, arguments); // Callback
115                 });
116             };
117             el.queue('fx', function() { el.dequeue(); });
118             el.dequeue();
119         });
120
121     };
122
123 })(jQuery);