Skip to content

Commit 1eada21

Browse files
committed
effects.*: Updating fade, pulsate, scale, shake to pass units
1 parent ec5aeb1 commit 1eada21

File tree

4 files changed

+58
-36
lines changed

4 files changed

+58
-36
lines changed

ui/jquery.effects.fade.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313
(function( $, undefined ) {
1414

1515
$.effects.effect.fade = function( o ) {
16-
return this.queue( function() {
16+
return this.queue( function( next ) {
1717
var el = $( this ),
18-
mode = $.effects.setMode( el, o.mode || 'hide' );
18+
mode = $.effects.setMode( el, o.mode || 'toggle' ),
19+
hide = mode === "hide";
1920

21+
el.show();
2022
el.animate({
21-
opacity: mode
23+
opacity: hide ? 0 : 1
2224
}, {
2325
queue: false,
2426
duration: o.duration,
2527
easing: o.easing,
2628
complete: function() {
27-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
28-
el.dequeue();
29+
if ( hide ) {
30+
el.hide();
31+
}
32+
if ( o.complete ) {
33+
o.complete.call( this );
34+
}
35+
next();
2936
}
3037
});
3138
});

ui/jquery.effects.pulsate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ $.effects.effect.pulsate = function( o ) {
1616
return this.queue( function( next ) {
1717
var elem = $( this ),
1818
mode = $.effects.setMode( elem, o.mode || "show" ),
19-
show = mode === "show" || !elem.is( ":visible" ),
20-
showhide = ( show || mode === "hide" ),
19+
show = mode === "show",
20+
hide = mode === "hide",
2121

2222
// showing or hiding leaves of the "last" animation
23-
anims = ( ( o.times || 5 ) * 2 ) - ( showhide ? 1 : 0 ),
23+
anims = ( ( o.times || 5 ) * 2 ) - ( show || hide ? 1 : 0 ),
2424
duration = o.duration / anims,
2525
animateTo = 0,
2626
queue = elem.queue(),
2727
queuelen = queue.length,
2828
i;
2929

30-
if ( show ) {
30+
if ( show || !elem.is(':visible')) {
3131
elem.css( "opacity", 0 ).show();
3232
animateTo = 1;
3333
}
@@ -42,7 +42,7 @@ $.effects.effect.pulsate = function( o ) {
4242
elem.animate({
4343
opacity: animateTo
4444
}, duration, o.easing, function() {
45-
if ( animateTo === 0 ) {
45+
if ( hide ) {
4646
elem.hide();
4747
}
4848
if ( o.complete ) {

ui/jquery.effects.scale.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $.effects.effect.puff = function( o ) {
2525

2626
$.extend(o, {
2727
effect: 'scale',
28+
queue: false,
2829
fade: true,
2930
mode: mode,
3031
percent: mode == 'hide' ? percent : 100,
@@ -36,13 +37,13 @@ $.effects.effect.puff = function( o ) {
3637
}
3738
});
3839

39-
elem.effect( o ).dequeue();
40+
elem.effect( o );
4041
});
4142
};
4243

4344
$.effects.effect.scale = function( o ) {
4445

45-
return this.queue( function() {
46+
return this[ o.queue === false ? "each" : "queue" ]( function() {
4647

4748
// Create element
4849
var el = $( this ),
@@ -62,6 +63,7 @@ $.effects.effect.scale = function( o ) {
6263

6364
// We are going to pass this effect to the size effect:
6465
options.effect = "size";
66+
options.queue = false;
6567

6668
// Set default origin and restore for show/hide
6769
if ( mode != 'effect' ) {
@@ -87,14 +89,14 @@ $.effects.effect.scale = function( o ) {
8789
};
8890

8991
// Animate
90-
el.effect(options).dequeue();
92+
el.effect(options);
9193
});
9294

9395
};
9496

9597
$.effects.effect.size = function( o ) {
9698

97-
return this.queue( function() {
99+
return this[ o.queue === false ? "each" : "queue" ]( function() {
98100
// Create element
99101
var el = $( this ),
100102
props = [ 'position', 'top', 'bottom', 'left', 'right', 'width', 'height', 'overflow', 'opacity' ],

ui/jquery.effects.shake.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,59 @@ $.effects.effect.shake = function( o ) {
1717
return this.queue( function() {
1818

1919
var el = $( this ),
20-
props = [ 'position', 'top', 'bottom', 'left', 'right' ],
21-
mode = $.effects.setMode( el, o.mode || 'effect' ),
22-
direction = o.direction || 'left',
20+
props = [ "position", "top", "bottom", "left", "right" ],
21+
mode = $.effects.setMode( el, o.mode || "effect" ),
22+
direction = o.direction || "left",
2323
distance = o.distance || 20,
2424
times = o.times || 3,
25-
speed = o.duration || 140,
26-
ref = (direction == 'up' || direction == 'down') ? 'top' : 'left',
27-
motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg',
25+
anims = times * 2 + 1,
26+
speed = o.duration,
27+
ref = (direction == "up" || direction == "down") ? "top" : "left",
28+
motion = (direction == "up" || direction == "left") ? "pos" : "neg",
2829
animation = {},
2930
animation1 = {},
3031
animation2 = {},
31-
i;
32+
i,
3233

33-
// Adjust
34-
$.effects.save( el, props );
35-
el.show();
36-
$.effects.createWrapper( el ); // Create Wrapper
34+
// we will need to re-assemble the queue to stack our animations in place
35+
queue = el.queue(),
36+
queuelen = queue.length;
37+
38+
39+
$.effects.save( el, props );
40+
el.show();
41+
$.effects.createWrapper( el );
3742

3843
// Animation
39-
animation[ ref ] = ( motion == 'pos' ? '-=' : '+=' ) + distance;
40-
animation1[ ref ] = ( motion == 'pos' ? '+=' : '-=' ) + distance * 2;
41-
animation2[ ref ] = ( motion == 'pos' ? '-=' : '+=' ) + distance * 2;
44+
animation[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance;
45+
animation1[ ref ] = ( motion == "pos" ? "+=" : "-=" ) + distance * 2;
46+
animation2[ ref ] = ( motion == "pos" ? "-=" : "+=" ) + distance * 2;
4247

4348
// Animate
4449
el.animate( animation, speed, o.easing );
4550

4651
// Shakes
47-
for ( i = 1; i < times; i++ ) {
52+
for ( i = 1; i < times; i++ ) {
4853
el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing );
4954
};
5055
el
5156
.animate( animation1, speed, o.easing )
52-
.animate( animation, speed / 2, o.easing, function() {
53-
57+
.animate( animation, speed / 2, o.easing, function() {
58+
if ( mode === "hide" ) {
59+
el.hide();
60+
}
5461
// Last shake
55-
$.effects.restore( el, props );
56-
$.effects.removeWrapper( el );
57-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
58-
})
59-
.dequeue();
62+
$.effects.restore( el, props );
63+
$.effects.removeWrapper( el );
64+
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
65+
});
66+
67+
// inject all the animations we just queued to be first in line (after "inprogress")
68+
if ( queuelen > 1) {
69+
queue.splice.apply( queue,
70+
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
71+
}
72+
el.dequeue();
6073
});
6174

6275
};

0 commit comments

Comments
 (0)