Skip to content

Commit ab627e0

Browse files
committed
Effects.*: DRY the complete callback execution into the 'done' callback passed into an effect
1 parent 65a6c46 commit ab627e0

14 files changed

+49
-83
lines changed

ui/jquery.effects.blind.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
var rvertical = /up|down|vertical/,
1616
rpositivemotion = /up|left|vertical|horizontal/;
1717

18-
$.effects.effect.blind = function( o, next ) {
18+
$.effects.effect.blind = function( o, done ) {
1919
// Create element
2020
var el = $( this ),
2121
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -70,10 +70,7 @@ $.effects.effect.blind = function( o, next ) {
7070
}
7171
$.effects.restore( el, props );
7272
$.effects.removeWrapper( el );
73-
if ( $.isFunction( o.complete ) ) {
74-
o.complete.apply( el[ 0 ], arguments );
75-
}
76-
next();
73+
done();
7774
}
7875
});
7976

ui/jquery.effects.bounce.js

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

15-
$.effects.effect.bounce = function( o, next ) {
15+
$.effects.effect.bounce = function( o, done ) {
1616
var el = $( this ),
1717
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
1818

@@ -91,24 +91,21 @@ $.effects.effect.bounce = function( o, next ) {
9191
el.animate( upAnim, speed, easing );
9292
}
9393

94-
el.queue( function( next ) {
94+
el.queue(function() {
9595
if ( hide ) {
9696
el.hide();
9797
}
9898
$.effects.restore( el, props );
9999
$.effects.removeWrapper( el );
100-
if ( o.complete ) {
101-
o.complete.apply( el[ 0 ] );
102-
}
103-
next();
100+
done();
104101
});
105102

106103
// inject all the animations we just queued to be first in line (after "inprogress")
107104
if ( queuelen > 1) {
108105
queue.splice.apply( queue,
109106
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
110107
}
111-
next();
108+
el.dequeue();
112109

113110
};
114111

ui/jquery.effects.clip.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.clip = function( o, next ) {
15+
$.effects.effect.clip = function( o, done ) {
1616
// Create element
1717
var el = $( this ),
1818
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -57,10 +57,7 @@ $.effects.effect.clip = function( o, next ) {
5757
}
5858
$.effects.restore( el, props );
5959
$.effects.removeWrapper( el );
60-
if ( $.isFunction( o.complete ) ) {
61-
o.complete.apply( el[ 0 ], arguments );
62-
}
63-
el.dequeue();
60+
done();
6461
}
6562
});
6663

ui/jquery.effects.core.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,19 @@ $.fn.extend({
556556
}
557557

558558
function run( next ) {
559-
effectMethod.call( this, args, $.isFunction( next ) ? next : $.noop );
559+
var elem = this,
560+
complete = args.complete;
561+
562+
function done() {
563+
if ( $.isFunction( complete ) ) {
564+
complete.call( elem );
565+
}
566+
if ( $.isFunction( next ) ) {
567+
next();
568+
}
569+
}
570+
571+
effectMethod.call( elem, args, done );
560572
}
561573

562574
// TODO: remove this check in 2.0, effectMethod will always be true

ui/jquery.effects.drop.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.drop = function( o, next ) {
15+
$.effects.effect.drop = function( o, done ) {
1616

1717
var el = $( this ),
1818
props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
@@ -54,8 +54,7 @@ $.effects.effect.drop = function( o, next ) {
5454
mode == "hide" && el.hide();
5555
$.effects.restore( el, props );
5656
$.effects.removeWrapper( el );
57-
$.isFunction( o.complete ) && o.complete.apply( this, arguments );
58-
next();
57+
done();
5958
}
6059
});
6160

ui/jquery.effects.explode.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.explode = function( o, next ) {
15+
$.effects.effect.explode = function( o, done ) {
1616

1717
var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
1818
cells = rows,
@@ -89,10 +89,7 @@ $.effects.effect.explode = function( o, next ) {
8989
if ( !show ) {
9090
el.hide();
9191
}
92-
if ( $.isFunction( o.complete ) ) {
93-
o.complete.apply( el[ 0 ] );
94-
}
95-
next();
92+
done();
9693
}
9794
};
9895

ui/jquery.effects.fade.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.fade = function( o, next ) {
15+
$.effects.effect.fade = function( o, done ) {
1616
var el = $( this ),
1717
mode = $.effects.setMode( el, o.mode || "toggle" ),
1818
hide = mode === "hide";
@@ -28,10 +28,7 @@ $.effects.effect.fade = function( o, next ) {
2828
if ( hide ) {
2929
el.hide();
3030
}
31-
if ( o.complete ) {
32-
o.complete.call( this );
33-
}
34-
next();
31+
done();
3532
}
3633
});
3734
};

ui/jquery.effects.fold.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.fold = function( o, next ) {
15+
$.effects.effect.fold = function( o, done ) {
1616

1717
// Create element
1818
var el = $( this ),
@@ -66,10 +66,7 @@ $.effects.effect.fold = function( o, next ) {
6666
}
6767
$.effects.restore( el, props );
6868
$.effects.removeWrapper( el );
69-
if ( $.isFunction( o.complete ) ) {
70-
o.complete.apply( el[ 0 ], arguments );
71-
}
72-
next();
69+
done();
7370
});
7471

7572
};

ui/jquery.effects.highlight.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.highlight = function( o, next ) {
15+
$.effects.effect.highlight = function( o, done ) {
1616
var elem = $( this ),
1717
props = [ "backgroundImage", "backgroundColor", "opacity" ],
1818
mode = $.effects.setMode( elem, o.mode || "show" ),
@@ -41,10 +41,7 @@ $.effects.effect.highlight = function( o, next ) {
4141
elem.hide();
4242
}
4343
$.effects.restore( elem, props );
44-
if ( $.isFunction( o.complete) ) {
45-
o.complete.apply( this, arguments );
46-
}
47-
next();
44+
done();
4845
}
4946
});
5047
};

ui/jquery.effects.pulsate.js

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

15-
$.effects.effect.pulsate = function( o, next ) {
15+
$.effects.effect.pulsate = function( o, done ) {
1616
var elem = $( this ),
1717
mode = $.effects.setMode( elem, o.mode || "show" ),
1818
show = mode === "show",
@@ -44,22 +44,19 @@ $.effects.effect.pulsate = function( o, next ) {
4444
opacity: animateTo
4545
}, duration, o.easing);
4646

47-
elem.queue( function( next ) {
47+
elem.queue(function() {
4848
if ( hide ) {
4949
elem.hide();
5050
}
51-
if ( o.complete ) {
52-
o.complete.apply( this );
53-
}
54-
next();
51+
done();
5552
});
5653

5754
// We just queued up "anims" animations, we need to put them next in the queue
5855
if ( queuelen > 1 ) {
5956
queue.splice.apply( queue,
6057
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
6158
}
62-
next();
59+
elem.dequeue();
6360
};
6461

6562
})(jQuery);

ui/jquery.effects.scale.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
function compFunction( el, complete, next ) {
16-
return function() {
17-
if ( $.isFunction( complete ) ) {
18-
complete.apply( el );
19-
}
20-
next();
21-
};
22-
};
23-
24-
$.effects.effect.puff = function( o, next ) {
15+
$.effects.effect.puff = function( o, done ) {
2516
var elem = $( this ),
2617
mode = $.effects.setMode( elem, o.mode || "hide" ),
2718
hide = mode === "hide",
@@ -37,7 +28,7 @@ $.effects.effect.puff = function( o, next ) {
3728
queue: false,
3829
fade: true,
3930
mode: mode,
40-
complete: compFunction( this, o.complete, next ),
31+
complete: done,
4132
percent: hide ? percent : 100,
4233
from: hide
4334
? original
@@ -50,7 +41,7 @@ $.effects.effect.puff = function( o, next ) {
5041
elem.effect( o );
5142
};
5243

53-
$.effects.effect.scale = function( o, next ) {
44+
$.effects.effect.scale = function( o, done ) {
5445

5546
// Create element
5647
var el = $( this ),
@@ -73,7 +64,7 @@ $.effects.effect.scale = function( o, next ) {
7364
// We are going to pass this effect to the size effect:
7465
options.effect = "size";
7566
options.queue = false;
76-
options.complete = compFunction( this, options.complete, next );
67+
options.complete = done;
7768

7869
// Set default origin and restore for show/hide
7970
if ( mode != "effect" ) {
@@ -105,7 +96,7 @@ $.effects.effect.scale = function( o, next ) {
10596

10697
};
10798

108-
$.effects.effect.size = function( o, next ) {
99+
$.effects.effect.size = function( o, done ) {
109100

110101
// Create element
111102
var el = $( this ),
@@ -302,10 +293,7 @@ $.effects.effect.size = function( o, next ) {
302293
}
303294

304295
$.effects.removeWrapper( el );
305-
if ( $.isFunction( o.complete ) ) {
306-
o.complete.apply( this, arguments );
307-
}
308-
next();
296+
done();
309297
}
310298
});
311299

ui/jquery.effects.shake.js

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

15-
$.effects.effect.shake = function( o, next ) {
15+
$.effects.effect.shake = function( o, done ) {
1616

1717
var el = $( this ),
1818
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -53,24 +53,21 @@ $.effects.effect.shake = function( o, next ) {
5353
el
5454
.animate( animation1, speed, o.easing )
5555
.animate( animation, speed / 2, o.easing )
56-
.queue( function( next ) {
56+
.queue(function() {
5757
if ( mode === "hide" ) {
5858
el.hide();
5959
}
6060
$.effects.restore( el, props );
6161
$.effects.removeWrapper( el );
62-
if ( $.isFunction( o.complete ) ) {
63-
o.complete.apply( this, arguments );
64-
}
65-
next();
62+
done();
6663
});
6764

6865
// inject all the animations we just queued to be first in line (after "inprogress")
6966
if ( queuelen > 1) {
7067
queue.splice.apply( queue,
7168
[ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
7269
}
73-
next();
70+
el.dequeue();
7471

7572
};
7673

ui/jquery.effects.slide.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.slide = function( o, next ) {
15+
$.effects.effect.slide = function( o, done ) {
1616

1717
// Create element
1818
var el = $( this ),
@@ -58,10 +58,7 @@ $.effects.effect.slide = function( o, next ) {
5858
}
5959
$.effects.restore( el, props );
6060
$.effects.removeWrapper( el );
61-
if ( $.isFunction( o.complete ) ) {
62-
o.complete.apply( this, arguments );
63-
}
64-
next();
61+
done();
6562
}
6663
});
6764

ui/jquery.effects.transfer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
(function( $, undefined ) {
1414

15-
$.effects.effect.transfer = function( o, next ) {
15+
$.effects.effect.transfer = function( o, done ) {
1616
var elem = $( this ),
1717
target = $( o.to ),
1818
targetFixed = target.css( "position" ) === "fixed",
@@ -39,10 +39,7 @@ $.effects.effect.transfer = function( o, next ) {
3939
})
4040
.animate( animation, o.duration, o.easing, function() {
4141
transfer.remove();
42-
if ( $.isFunction( o.complete ) ) {
43-
o.complete.apply( elem[0], arguments );
44-
}
45-
next();
42+
done();
4643
});
4744
};
4845

0 commit comments

Comments
 (0)