2 * jQuery UI Effects Shake 1.11.4
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
9 * http://api.jqueryui.com/shake-effect/
11 (function( factory
) {
12 if ( typeof define
=== "function" && define
.amd
) {
14 // AMD. Register as an anonymous module.
26 return $.effects
.effect
.shake = function( o
, done
) {
29 props
= [ "position", "top", "bottom", "left", "right", "height", "width" ],
30 mode
= $.effects
.setMode( el
, o
.mode
|| "effect" ),
31 direction
= o
.direction
|| "left",
32 distance
= o
.distance
|| 20,
34 anims
= times
* 2 + 1,
35 speed
= Math
.round( o
.duration
/ anims
),
36 ref
= (direction
=== "up" || direction
=== "down") ? "top" : "left",
37 positiveMotion
= (direction
=== "up" || direction
=== "left"),
43 // we will need to re-assemble the queue to stack our animations in place
45 queuelen
= queue
.length
;
47 $.effects
.save( el
, props
);
49 $.effects
.createWrapper( el
);
52 animation
[ ref
] = ( positiveMotion
? "-=" : "+=" ) + distance
;
53 animation1
[ ref
] = ( positiveMotion
? "+=" : "-=" ) + distance
* 2;
54 animation2
[ ref
] = ( positiveMotion
? "-=" : "+=" ) + distance
* 2;
57 el
.animate( animation
, speed
, o
.easing
);
60 for ( i
= 1; i
< times
; i
++ ) {
61 el
.animate( animation1
, speed
, o
.easing
).animate( animation2
, speed
, o
.easing
);
64 .animate( animation1
, speed
, o
.easing
)
65 .animate( animation
, speed
/ 2, o
.easing
)
67 if ( mode
=== "hide" ) {
70 $.effects
.restore( el
, props
);
71 $.effects
.removeWrapper( el
);
75 // inject all the animations we just queued to be first in line (after "inprogress")
77 queue
.splice
.apply( queue
,
78 [ 1, 0 ].concat( queue
.splice( queuelen
, anims
+ 1 ) ) );