UPDATE 4.4.0.0
[phpmyadmin.git] / js / jquery / src / jquery-ui / effect-bounce.js
blobd89ea0475854f7f5f4ebc26153a04489fd5e490c
1 /*!
2  * jQuery UI Effects Bounce 1.11.2
3  * http://jqueryui.com
4  *
5  * Copyright 2014 jQuery Foundation and other contributors
6  * Released under the MIT license.
7  * http://jquery.org/license
8  *
9  * http://api.jqueryui.com/bounce-effect/
10  */
11 (function( factory ) {
12         if ( typeof define === "function" && define.amd ) {
14                 // AMD. Register as an anonymous module.
15                 define([
16                         "jquery",
17                         "./effect"
18                 ], factory );
19         } else {
21                 // Browser globals
22                 factory( jQuery );
23         }
24 }(function( $ ) {
26 return $.effects.effect.bounce = function( o, done ) {
27         var el = $( this ),
28                 props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
30                 // defaults:
31                 mode = $.effects.setMode( el, o.mode || "effect" ),
32                 hide = mode === "hide",
33                 show = mode === "show",
34                 direction = o.direction || "up",
35                 distance = o.distance,
36                 times = o.times || 5,
38                 // number of internal animations
39                 anims = times * 2 + ( show || hide ? 1 : 0 ),
40                 speed = o.duration / anims,
41                 easing = o.easing,
43                 // utility:
44                 ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
45                 motion = ( direction === "up" || direction === "left" ),
46                 i,
47                 upAnim,
48                 downAnim,
50                 // we will need to re-assemble the queue to stack our animations in place
51                 queue = el.queue(),
52                 queuelen = queue.length;
54         // Avoid touching opacity to prevent clearType and PNG issues in IE
55         if ( show || hide ) {
56                 props.push( "opacity" );
57         }
59         $.effects.save( el, props );
60         el.show();
61         $.effects.createWrapper( el ); // Create Wrapper
63         // default distance for the BIGGEST bounce is the outer Distance / 3
64         if ( !distance ) {
65                 distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
66         }
68         if ( show ) {
69                 downAnim = { opacity: 1 };
70                 downAnim[ ref ] = 0;
72                 // if we are showing, force opacity 0 and set the initial position
73                 // then do the "first" animation
74                 el.css( "opacity", 0 )
75                         .css( ref, motion ? -distance * 2 : distance * 2 )
76                         .animate( downAnim, speed, easing );
77         }
79         // start at the smallest distance if we are hiding
80         if ( hide ) {
81                 distance = distance / Math.pow( 2, times - 1 );
82         }
84         downAnim = {};
85         downAnim[ ref ] = 0;
86         // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
87         for ( i = 0; i < times; i++ ) {
88                 upAnim = {};
89                 upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
91                 el.animate( upAnim, speed, easing )
92                         .animate( downAnim, speed, easing );
94                 distance = hide ? distance * 2 : distance / 2;
95         }
97         // Last Bounce when Hiding
98         if ( hide ) {
99                 upAnim = { opacity: 0 };
100                 upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
102                 el.animate( upAnim, speed, easing );
103         }
105         el.queue(function() {
106                 if ( hide ) {
107                         el.hide();
108                 }
109                 $.effects.restore( el, props );
110                 $.effects.removeWrapper( el );
111                 done();
112         });
114         // inject all the animations we just queued to be first in line (after "inprogress")
115         if ( queuelen > 1) {
116                 queue.splice.apply( queue,
117                         [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
118         }
119         el.dequeue();
123 }));