3 "../data/var/dataPriv",
4 "../css/var/isHiddenWithinTree"
5 ], function( jQuery, dataPriv, isHiddenWithinTree ) {
9 var defaultDisplayMap = {};
11 function getDefaultDisplay( elem ) {
13 doc = elem.ownerDocument,
14 nodeName = elem.nodeName,
15 display = defaultDisplayMap[ nodeName ];
21 temp = doc.body.appendChild( doc.createElement( nodeName ) );
22 display = jQuery.css( temp, "display" );
24 temp.parentNode.removeChild( temp );
26 if ( display === "none" ) {
29 defaultDisplayMap[ nodeName ] = display;
34 function showHide( elements, show ) {
38 length = elements.length;
40 // Determine new display value for elements that need to change
41 for ( ; index < length; index++ ) {
42 elem = elements[ index ];
47 display = elem.style.display;
50 // Since we force visibility upon cascade-hidden elements, an immediate (and slow)
51 // check is required in this first loop unless we have a nonempty display value (either
52 // inline or about-to-be-restored)
53 if ( display === "none" ) {
54 values[ index ] = dataPriv.get( elem, "display" ) || null;
55 if ( !values[ index ] ) {
56 elem.style.display = "";
59 if ( elem.style.display === "" && isHiddenWithinTree( elem ) ) {
60 values[ index ] = getDefaultDisplay( elem );
63 if ( display !== "none" ) {
64 values[ index ] = "none";
66 // Remember what we're overwriting
67 dataPriv.set( elem, "display", display );
72 // Set the display of the elements in a second loop to avoid constant reflow
73 for ( index = 0; index < length; index++ ) {
74 if ( values[ index ] != null ) {
75 elements[ index ].style.display = values[ index ];
84 return showHide( this, true );
87 return showHide( this );
89 toggle: function( state ) {
90 if ( typeof state === "boolean" ) {
91 return state ? this.show() : this.hide();
94 return this.each( function() {
95 if ( isHiddenWithinTree( this ) ) {
96 jQuery( this ).show();
98 jQuery( this ).hide();