]> source.dussan.org Git - jquery-ui.git/commitdiff
Effects.core: Check Visibility vs 'hide' and 'show' modes, finish immediately if...
authorCorey Frang <gnarf@gnarf.net>
Thu, 23 Jun 2011 12:22:34 +0000 (07:22 -0500)
committerCorey Frang <gnarf@gnarf.net>
Thu, 23 Jun 2011 12:22:34 +0000 (07:22 -0500)
tests/unit/effects/effects_core.js
ui/jquery.effects.core.js

index fd6b4d37853da7ab980fd6e5362208681107bffb..f78aea304c1bc8672863b81c82d427f9838eb20b 100644 (file)
@@ -19,6 +19,18 @@ var minDuration = 15,
 
 module( "effects.core" );
 
+test( "Immediate Return Conditions", function() {
+       var hidden = $( "div.hidden" ),
+               count = 0;
+       expect( 6 );
+       hidden.hide( "blind", function() {
+               equal( ++count, 1, "Hide on hidden returned immediately" );
+       }).show().show( "blind", function() {
+               equal( ++count, 2, "Show on shown returned immediately" );
+       });
+       equal( ++count, 3, "Both Functions worked properly" );
+});
+
 $.each( $.effects.effect, function( effect ) {
        if ( effect === "transfer" ) {
                return;
index 330ddd83cd2a1fb0ed7ec27235178d9812f2fe78..b08cd6cf4615a9f07241891bc5ca271c0b147966 100644 (file)
@@ -556,19 +556,26 @@ $.fn.extend({
                }
 
                function run( next ) {
-                       var elem = this,
-                               complete = args.complete;
+                       var elem = $( this ),
+                               complete = args.complete,
+                               mode = args.mode;
 
                        function done() {
                                if ( $.isFunction( complete ) ) {
-                                       complete.call( elem );
+                                       complete.call( elem[0] );
                                }
                                if ( $.isFunction( next ) ) {
                                        next();
                                }
                        }
 
-                       effectMethod.call( elem, args, done );
+                       // if the element is hiddden and mode is hide,
+                       // or element is visible and mode is show
+                       if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
+                               done();
+                       } else {
+                               effectMethod.call( elem[0], args, done );
+                       }
                }
 
                // TODO: remove this check in 2.0, effectMethod will always be true