return origName;
}
-function isHidden( elem, el ) {
- elem = el || elem;
+function isHidden( elem ) {
return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem );
}
hide: function() {
return showHide( this );
},
- toggle: function( fn, fn2 ) {
- var bool = typeof fn === "boolean";
+ toggle: function( state, fn2 ) {
+ 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 this.each(function() {
- var state = bool ? fn : jQuery( this ).is(":hidden");
- showHide([ this ], state );
+ if ( bool ? state : isHidden( this ) ) {
+ jQuery( this ).show();
+ } else {
+ jQuery( this ).hide();
+ }
});
}
});
});
test("toggle()", function() {
- expect(6);
+ expect(7);
var x = jQuery("#foo");
ok( x.is(":visible"), "is visible" );
x.toggle();
ok( x.is(":hidden"), "is hidden" );
x.toggle(true);
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() {