Skip to content

Commit b546f31

Browse files
committed
Merge remote branch 'gnarf37/ticket-7067'
2 parents 1a97410 + 126d46c commit b546f31

File tree

3 files changed

+121
-90
lines changed

3 files changed

+121
-90
lines changed

tests/visual/effects.all.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ $(function() {
1414

1515
$(el).bind("click", function() {
1616

17-
$(this).addClass("current").hide(n, o, duration, function() {
18-
var self = this;
19-
window.setTimeout(function() {
20-
$(self).show(n, o, duration, function() { $(this).removeClass("current"); });
21-
}, wait);
22-
});
17+
$(this).addClass("current")
18+
// delaying the initial animation makes sure that the queue stays in tact
19+
.delay( 10 )
20+
.hide( n, o, duration )
21+
.delay( wait )
22+
.show( n, o, duration, function() {
23+
$( this ).removeClass("current");
24+
});
2325
});
2426

2527
};

ui/jquery.effects.bounce.js

Lines changed: 82 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,107 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
var rshowhide = /show|hide/;
16-
1715
$.effects.effect.bounce = function(o) {
1816

19-
return this.queue(function() {
20-
21-
// Create element
17+
return this.queue( function( next ) {
2218
var el = $( this ),
23-
props = [ 'position', 'top', 'bottom', 'left', 'right' ],
19+
props = [ "position", "top", "bottom", "left", "right" ],
20+
2421
// defaults:
25-
mode = $.effects.setMode( el, o.mode || 'effect' ),
26-
direction = o.direction || 'up',
27-
distance = o.distance || 20,
28-
times = o.times || 5,
29-
speed = (o.duration || 250),
22+
mode = $.effects.setMode( el, o.mode || "effect" ),
23+
hide = mode === "hide",
24+
show = mode === "show",
25+
direction = o.direction || "up",
26+
distance = o.distance,
27+
times = o.times || 5,
28+
29+
// number of internal animations
30+
anims = times * 2 + ( show || hide ? 1 : 0 ),
31+
speed = o.duration / anims,
32+
easing = o.easing,
33+
3034
// utility:
31-
ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
32-
motion = ( direction == 'up' || direction == 'left' ), // true is positive
33-
i, animation, animation1, animation2;
34-
35+
ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
36+
motion = ( direction === "up" || direction === "left" ),
37+
i,
38+
upAnim,
39+
downAnim,
40+
41+
// we will need to re-assemble the queue to stack our animations in place
42+
queue = el.queue(),
43+
queuelen = queue.length;
44+
3545
// Avoid touching opacity to prevent clearType and PNG issues in IE
36-
if ( rshowhide.test( mode ) ) {
37-
props.push( 'opacity' );
46+
if ( show || hide ) {
47+
props.push( "opacity" );
3848
}
3949

4050
$.effects.save( el, props );
4151
el.show();
4252
$.effects.createWrapper( el ); // Create Wrapper
4353

54+
// default distance for the BIGGEST bounce is the outer Distance / 3
4455
if ( !distance ) {
45-
distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3;
56+
distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
4657
}
47-
if ( mode == 'show' ) el.css( 'opacity', 0 ).css( ref, motion ? -distance : distance ); // Shift
48-
if ( mode == 'hide' ) distance = distance / (times * 2);
49-
if ( mode != 'hide' ) times--;
50-
51-
// Animate
52-
if ( mode == 'show' ) {
53-
animation = {
54-
opacity: 1
55-
};
56-
animation[ ref ] = ( motion ? '+=' : '-=' ) + distance;
57-
el.animate( animation, speed / 2, o.easing);
58-
distance = distance / 2;
59-
times--;
60-
};
61-
62-
// Bounces
63-
for (i = 0; i < times; i++) {
64-
animation1 = {};
65-
animation2 = {};
66-
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
67-
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
68-
el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing );
69-
distance = ( mode == 'hide' ) ? distance * 2 : distance / 2;
58+
59+
if ( show ) {
60+
downAnim = { opacity: 1 };
61+
downAnim[ ref ] = 0;
62+
63+
// if we are showing, force opacity 0 and set the initial position
64+
// then do the "first" animation
65+
el.css( "opacity", 0 )
66+
.css( ref, motion ? -distance*2 : distance*2 )
67+
.animate( downAnim, speed, easing );
68+
}
69+
70+
// start at the smallest distance if we are hiding
71+
if ( hide ) {
72+
distance = distance / Math.pow( 2, times - 1 );
7073
}
7174

72-
// Last Bounce
73-
if ( mode == 'hide' ) {
74-
animation = {
75-
opacity: 0
76-
};
77-
animation[ ref ] = ( motion ? '-=' : '+=' ) + distance;
78-
el.animate( animation, speed / 2, o.easing, function(){
75+
downAnim = {};
76+
downAnim[ ref ] = 0;
77+
// Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
78+
for ( i = 0; i < times; i++ ) {
79+
upAnim = {};
80+
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
81+
82+
// add the finish callback to the last animation if we aren't hiding
83+
el.animate( upAnim, speed, easing )
84+
.animate( downAnim, speed, easing,
85+
( ( i === times - 1 ) && !hide ) ? finish : undefined );
86+
87+
distance = hide ? distance * 2 : distance / 2;
88+
}
89+
90+
// Last Bounce when Hiding
91+
if ( hide ) {
92+
upAnim = { opacity: 0 };
93+
upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
94+
95+
el.animate( upAnim, speed, easing, function(){
7996
el.hide();
80-
$.effects.restore( el, props );
81-
$.effects.removeWrapper( el );
82-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
97+
finish();
8398
});
84-
} else {
85-
animation1 = {};
86-
animation2 = {};
87-
animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
88-
animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
89-
el
90-
.animate( animation1, speed / 2, o.easing )
91-
.animate( animation2, speed / 2, o.easing, function() {
92-
$.effects.restore( el, props );
93-
$.effects.removeWrapper( el );
94-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
95-
});
9699
}
97-
el.dequeue();
100+
101+
function finish() {
102+
$.effects.restore( el, props );
103+
$.effects.removeWrapper( el );
104+
if ( o.complete ) {
105+
o.complete.apply( el[ 0 ] );
106+
}
107+
}
108+
109+
// inject all the animations we just queued to be first in line (after "inprogress")
110+
if ( queuelen > 1) {
111+
queue.splice.apply( queue,
112+
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
113+
}
114+
next();
115+
98116
});
99117

100118
};

ui/jquery.effects.pulsate.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,50 @@
1313
(function( $, undefined ) {
1414

1515
$.effects.effect.pulsate = function( o ) {
16-
return this.queue( function() {
16+
return this.queue( function( next ) {
1717
var elem = $( this ),
18-
mode = $.effects.setMode( elem, o.mode || 'show' ),
19-
times = ( ( o.times || 5 ) * 2 ) - 1,
20-
duration = o.duration / 2,
21-
isVisible = elem.is( ':visible' ),
18+
mode = $.effects.setMode( elem, o.mode || "effect" ),
19+
show = mode === "show" || elem.is( ":hidden" ),
20+
showhide = ( show || mode === "hide" ),
21+
22+
// showing or hiding adds an extra "half" animation
23+
anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),
24+
duration = o.duration / anims,
2225
animateTo = 0,
26+
queue = elem.queue(),
27+
queuelen = queue.length,
2328
i;
2429

25-
if ( !isVisible ) {
26-
elem.css('opacity', 0).show();
30+
if ( show ) {
31+
elem.css( "opacity", 0 ).show();
2732
animateTo = 1;
2833
}
2934

30-
if ( ( mode == 'hide' && isVisible ) || ( mode == 'show' && !isVisible ) ) {
31-
times--;
32-
}
33-
34-
for ( i = 0; i < times; i++ ) {
35-
elem.animate({
36-
opacity: animateTo
35+
// anims - 1 opacity "toggles"
36+
for ( i = 1; i < anims; i++ ) {
37+
elem.animate({
38+
opacity: animateTo
3739
}, duration, o.easing );
38-
animateTo = ( animateTo + 1 ) % 2;
40+
animateTo = 1 - animateTo;
3941
}
4042

41-
elem.animate({
42-
opacity: animateTo
43+
elem.animate({
44+
opacity: animateTo
4345
}, duration, o.easing, function() {
44-
if (animateTo == 0) {
46+
if ( animateTo === 0 ) {
4547
elem.hide();
4648
}
47-
(o.complete && o.complete.apply(this, arguments));
48-
}).dequeue();
49+
if ( o.complete ) {
50+
o.complete.apply( this );
51+
}
52+
});
53+
54+
// We just queued up "anims" animations, we need to put them next in the queue
55+
if ( queuelen > 1) {
56+
queue.splice.apply( queue,
57+
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
58+
}
59+
next();
4960
});
5061
};
5162

0 commit comments

Comments
 (0)