Commit ed898c62 authored by Dave Methvin's avatar Dave Methvin

Fix #12148. Let .toggle() call the public .hide() for punching.

There is a slightly shorter way to do this but it's not Closure-friendly.
parent 5119b252
...@@ -43,8 +43,7 @@ function vendorPropName( style, name ) { ...@@ -43,8 +43,7 @@ function vendorPropName( style, name ) {
return origName; return origName;
} }
function isHidden( elem, el ) { function isHidden( elem ) {
elem = el || elem;
return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem ); return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem );
} }
...@@ -111,16 +110,19 @@ jQuery.fn.extend({ ...@@ -111,16 +110,19 @@ jQuery.fn.extend({
hide: function() { hide: function() {
return showHide( this ); return showHide( this );
}, },
toggle: function( fn, fn2 ) { toggle: function( state, fn2 ) {
var bool = typeof fn === "boolean"; var bool = typeof state === "boolean";
if ( jQuery.isFunction( fn ) && jQuery.isFunction( fn2 ) ) { if ( jQuery.isFunction( state ) && jQuery.isFunction( fn2 ) ) {
return eventsToggle.apply( this, arguments ); return eventsToggle.apply( this, arguments );
} }
return this.each(function() { return this.each(function() {
var state = bool ? fn : jQuery( this ).is(":hidden"); if ( bool ? state : isHidden( this ) ) {
showHide([ this ], state ); jQuery( this ).show();
} else {
jQuery( this ).hide();
}
}); });
} }
}); });
......
...@@ -561,7 +561,7 @@ test( "show() resolves correct default display, detached nodes (#10006)", functi ...@@ -561,7 +561,7 @@ test( "show() resolves correct default display, detached nodes (#10006)", functi
}); });
test("toggle()", function() { test("toggle()", function() {
expect(6); expect(7);
var x = jQuery("#foo"); var x = jQuery("#foo");
ok( x.is(":visible"), "is visible" ); ok( x.is(":visible"), "is visible" );
x.toggle(); x.toggle();
...@@ -575,6 +575,17 @@ test("toggle()", function() { ...@@ -575,6 +575,17 @@ test("toggle()", function() {
ok( x.is(":hidden"), "is hidden" ); ok( x.is(":hidden"), "is hidden" );
x.toggle(true); x.toggle(true);
ok( x.is(":visible"), "is visible again" ); ok( x.is(":visible"), "is visible again" );
// Ensure hide() is called when toggled (#12148)
var oldHide = jQuery.fn.hide;
jQuery.fn.hide = function() {
ok( true, name + " method called on toggle" );
return oldHide.apply( this, arguments );
};
x.toggle( name === "show" );
jQuery.fn.hide = oldHide;
}); });
test("hide hidden elements (bug #7141)", function() { test("hide hidden elements (bug #7141)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment