]> source.dussan.org Git - jquery-ui.git/commitdiff
Effects.*: DRY the complete callback execution into the 'done' callback passed into...
authorgnarf <gnarf@gnarf.net>
Tue, 21 Jun 2011 06:11:46 +0000 (01:11 -0500)
committergnarf <gnarf@gnarf.net>
Tue, 21 Jun 2011 06:18:19 +0000 (01:18 -0500)
14 files changed:
ui/jquery.effects.blind.js
ui/jquery.effects.bounce.js
ui/jquery.effects.clip.js
ui/jquery.effects.core.js
ui/jquery.effects.drop.js
ui/jquery.effects.explode.js
ui/jquery.effects.fade.js
ui/jquery.effects.fold.js
ui/jquery.effects.highlight.js
ui/jquery.effects.pulsate.js
ui/jquery.effects.scale.js
ui/jquery.effects.shake.js
ui/jquery.effects.slide.js
ui/jquery.effects.transfer.js

index 09d6a9e57e693714359cb8d41dbb331568921480..5f86bed7b25c8476334fa98a974c675d97e2f901 100644 (file)
@@ -15,7 +15,7 @@
 var rvertical = /up|down|vertical/,
        rpositivemotion = /up|left|vertical|horizontal/;
 
-$.effects.effect.blind = function( o, next ) {
+$.effects.effect.blind = function( o, done ) {
        // Create element
        var el = $( this ),
                props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -70,10 +70,7 @@ $.effects.effect.blind = function( o, next ) {
                        }
                        $.effects.restore( el, props );
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( el[ 0 ], arguments );
-                       }
-                       next();
+                       done();
                }
        });
 
index 38171c32e53248e15d52db1c7ca80c580dc07677..41ee34f6459ce259c07d1e2790844d552d9834ce 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.bounce = function( o, next ) {
+$.effects.effect.bounce = function( o, done ) {
        var el = $( this ), 
                props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
 
@@ -91,16 +91,13 @@ $.effects.effect.bounce = function( o, next ) {
                el.animate( upAnim, speed, easing );
        }
        
-       el.queue( function( next ) {
+       el.queue(function() {
                if ( hide ) {
                        el.hide();
                }
                $.effects.restore( el, props );
                $.effects.removeWrapper( el );
-               if ( o.complete ) {
-                       o.complete.apply( el[ 0 ] );
-               }
-               next();
+               done();
        });
 
        // inject all the animations we just queued to be first in line (after "inprogress")
@@ -108,7 +105,7 @@ $.effects.effect.bounce = function( o, next ) {
                queue.splice.apply( queue,
                        [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
        }
-       next();
+       el.dequeue();
 
 };
 
index 8c5c76e8c37eb775b543c30474d2f59fd6e9088b..c6eecc6713d73760c880acfb643b66aecbf10e3e 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.clip = function( o, next ) {
+$.effects.effect.clip = function( o, done ) {
        // Create element
        var el = $( this ),
                props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -57,10 +57,7 @@ $.effects.effect.clip = function( o, next ) {
                        }
                        $.effects.restore( el, props );
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( el[ 0 ], arguments );
-                       }
-                       el.dequeue();
+                       done();
                }
        });
 
index 87fc5a074260ec334abb1bb73669c6f9d41722bb..330ddd83cd2a1fb0ed7ec27235178d9812f2fe78 100644 (file)
@@ -556,7 +556,19 @@ $.fn.extend({
                }
 
                function run( next ) {
-                       effectMethod.call( this, args, $.isFunction( next ) ? next : $.noop );
+                       var elem = this,
+                               complete = args.complete;
+
+                       function done() {
+                               if ( $.isFunction( complete ) ) {
+                                       complete.call( elem );
+                               }
+                               if ( $.isFunction( next ) ) {
+                                       next();
+                               }
+                       }
+
+                       effectMethod.call( elem, args, done );
                }
 
                // TODO: remove this check in 2.0, effectMethod will always be true
index 2fba49d92d320a6394e63c5a934483695d057914..2e7a6ec0f57e821c23d9eee5d288da0eb2a2b3f1 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.drop = function( o, next ) {
+$.effects.effect.drop = function( o, done ) {
 
        var el = $( this ), 
                props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
@@ -54,8 +54,7 @@ $.effects.effect.drop = function( o, next ) {
                        mode == "hide" && el.hide();
                        $.effects.restore( el, props ); 
                        $.effects.removeWrapper( el ); 
-                       $.isFunction( o.complete ) && o.complete.apply( this, arguments );
-                       next();
+                       done();
                }
        });
 
index 0deb2be9f13c2c8e1e30e5b53d1ebd26bd6fdc06..22f5060455c6f16d90e5a3a4efd7e6f7f43fd80c 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.explode = function( o, next ) {
+$.effects.effect.explode = function( o, done ) {
 
        var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
                cells = rows,
@@ -89,10 +89,7 @@ $.effects.effect.explode = function( o, next ) {
                if ( !show ) {
                        el.hide();
                }
-               if ( $.isFunction( o.complete ) ) {
-                       o.complete.apply( el[ 0 ] );
-               }
-               next();
+               done();
        }
 };
 
index 8f2d956dcec0f3475914afbbc2c79eb53dee87e0..9b79ad3bc5b7de1649c6728b7a70be8657bbc0a6 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.fade = function( o, next ) {
+$.effects.effect.fade = function( o, done ) {
        var el = $( this ),
                mode = $.effects.setMode( el, o.mode || "toggle" ),
                hide = mode === "hide";
@@ -28,10 +28,7 @@ $.effects.effect.fade = function( o, next ) {
                        if ( hide ) {
                                el.hide();
                        }
-                       if ( o.complete ) {
-                               o.complete.call( this );
-                       }
-                       next();
+                       done();
                }
        });
 };
index b2a02ba786cb0c8ed16c823b554be2b69ad4d15e..7c4f583c1cf7a8d14f0d0beb266a8d8b35b368e0 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.fold = function( o, next ) {
+$.effects.effect.fold = function( o, done ) {
 
        // Create element
        var el = $( this ),
@@ -66,10 +66,7 @@ $.effects.effect.fold = function( o, next ) {
                        }
                        $.effects.restore( el, props );
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( el[ 0 ], arguments );
-                       }
-                       next();
+                       done();
                });
 
 };
index 709e93a3c8db0d3702e9f221dc6593a7802e3518..edde845a300b543a2ebc1b40e592c52866296ff5 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.highlight = function( o, next ) {
+$.effects.effect.highlight = function( o, done ) {
        var elem = $( this ),
                props = [ "backgroundImage", "backgroundColor", "opacity" ],
                mode = $.effects.setMode( elem, o.mode || "show" ),
@@ -41,10 +41,7 @@ $.effects.effect.highlight = function( o, next ) {
                                        elem.hide();
                                }
                                $.effects.restore( elem, props );
-                               if ( $.isFunction( o.complete) ) {
-                                       o.complete.apply( this, arguments );
-                               }
-                               next();
+                               done();
                        }
                });
 };
index bc257f62433587fd0f5208f4ea7ad5fa8483b4d6..7d6e9328f208a94a8f577101a9f178c26c885106 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.pulsate = function( o, next ) {
+$.effects.effect.pulsate = function( o, done ) {
        var elem = $( this ),
                mode = $.effects.setMode( elem, o.mode || "show" ),
                show = mode === "show",
@@ -44,14 +44,11 @@ $.effects.effect.pulsate = function( o, next ) {
                opacity: animateTo
        }, duration, o.easing);
 
-       elem.queue( function( next ) {
+       elem.queue(function() {
                if ( hide ) {
                        elem.hide();
                }
-               if ( o.complete ) {
-                       o.complete.apply( this );
-               }
-               next();
+               done();
        });
 
        // We just queued up "anims" animations, we need to put them next in the queue
@@ -59,7 +56,7 @@ $.effects.effect.pulsate = function( o, next ) {
                queue.splice.apply( queue,
                        [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
        }
-       next();
+       elem.dequeue();
 };
 
 })(jQuery);
index 2642c6c1de5368ed8881da8445c316263471b686..000fdee28817aca3d564bd2d3aa50d69497061ab 100644 (file)
  */
 (function( $, undefined ) {
 
-function compFunction( el, complete, next ) {
-       return function() {
-               if ( $.isFunction( complete ) ) {
-                       complete.apply( el );
-               }
-               next();
-       };
-};
-
-$.effects.effect.puff = function( o, next ) {
+$.effects.effect.puff = function( o, done ) {
        var elem = $( this ),
                mode = $.effects.setMode( elem, o.mode || "hide" ),
                hide = mode === "hide",
@@ -37,7 +28,7 @@ $.effects.effect.puff = function( o, next ) {
                queue: false,
                fade: true,
                mode: mode,
-               complete: compFunction( this, o.complete, next ),
+               complete: done,
                percent: hide ? percent : 100,
                from: hide
                        ? original
@@ -50,7 +41,7 @@ $.effects.effect.puff = function( o, next ) {
        elem.effect( o );
 };
 
-$.effects.effect.scale = function( o, next ) {
+$.effects.effect.scale = function( o, done ) {
 
        // Create element
        var el = $( this ),
@@ -73,7 +64,7 @@ $.effects.effect.scale = function( o, next ) {
        // We are going to pass this effect to the size effect:
        options.effect = "size";
        options.queue = false;
-       options.complete = compFunction( this, options.complete, next );
+       options.complete = done;
 
        // Set default origin and restore for show/hide
        if ( mode != "effect" ) { 
@@ -105,7 +96,7 @@ $.effects.effect.scale = function( o, next ) {
 
 };
 
-$.effects.effect.size = function( o, next ) {
+$.effects.effect.size = function( o, done ) {
 
        // Create element
        var el = $( this ), 
@@ -302,10 +293,7 @@ $.effects.effect.size = function( o, next ) {
                        }
 
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( this, arguments );
-                       }
-                       next();
+                       done();
                }
        });
 
index 311edced05334c8f721fae594a3244523a07b94f..7d83a9bb8b4cd61869b681e3ce59808e48a7cfe8 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.shake = function( o, next ) {
+$.effects.effect.shake = function( o, done ) {
 
        var el = $( this ),
                props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
@@ -53,16 +53,13 @@ $.effects.effect.shake = function( o, next ) {
        el
                .animate( animation1, speed, o.easing )
                .animate( animation, speed / 2, o.easing )
-               .queue( function( next ) {
+               .queue(function() {
                        if ( mode === "hide" ) {
                                el.hide();
                        }
                        $.effects.restore( el, props );
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( this, arguments );
-                       }
-                       next();
+                       done();
                });
 
        // inject all the animations we just queued to be first in line (after "inprogress")
@@ -70,7 +67,7 @@ $.effects.effect.shake = function( o, next ) {
                queue.splice.apply( queue,
                        [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
        }
-       next();
+       el.dequeue();
 
 };
 
index 3be28d91bb985523c8b3fce36c47ceeff99c7815..de393c7792b05fe561028af9f8271bc82922171f 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.slide = function( o, next ) {
+$.effects.effect.slide = function( o, done ) {
 
        // Create element
        var el = $( this ),
@@ -58,10 +58,7 @@ $.effects.effect.slide = function( o, next ) {
                        }
                        $.effects.restore( el, props );
                        $.effects.removeWrapper( el );
-                       if ( $.isFunction( o.complete ) ) {
-                               o.complete.apply( this, arguments ); 
-                       }
-                       next();
+                       done();
                }
        });
 
index 0c840c35cb39b9c5587fb5362bcb7b6378d2476a..1fa2912284352cdb31e64cd372d29c4b221dab6c 100644 (file)
@@ -12,7 +12,7 @@
  */
 (function( $, undefined ) {
 
-$.effects.effect.transfer = function( o, next ) {
+$.effects.effect.transfer = function( o, done ) {
        var elem = $( this ),
                target = $( o.to ),
                targetFixed = target.css( "position" ) === "fixed",
@@ -39,10 +39,7 @@ $.effects.effect.transfer = function( o, next ) {
                        })
                        .animate( animation, o.duration, o.easing, function() {
                                transfer.remove();
-                               if ( $.isFunction( o.complete ) ) {
-                                       o.complete.apply( elem[0], arguments );
-                               }
-                               next();
+                               done();
                        });
 };