2015-08-16 06:59:58 +00:00
|
|
|
define( [
|
2015-10-18 19:09:59 +00:00
|
|
|
"../core",
|
2015-10-09 19:52:29 +00:00
|
|
|
"../data/var/dataPriv",
|
2016-01-20 18:20:58 +00:00
|
|
|
"../css/var/isHiddenWithinTree"
|
|
|
|
], function( jQuery, dataPriv, isHiddenWithinTree ) {
|
2015-04-02 20:57:33 +00:00
|
|
|
|
2016-01-11 07:26:55 +00:00
|
|
|
var defaultDisplayMap = {};
|
|
|
|
|
|
|
|
function getDefaultDisplay( elem ) {
|
|
|
|
var temp,
|
|
|
|
doc = elem.ownerDocument,
|
|
|
|
nodeName = elem.nodeName,
|
|
|
|
display = defaultDisplayMap[ nodeName ];
|
|
|
|
|
|
|
|
if ( display ) {
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = doc.body.appendChild( doc.createElement( nodeName ) ),
|
|
|
|
display = jQuery.css( temp, "display" );
|
|
|
|
|
|
|
|
temp.parentNode.removeChild( temp );
|
|
|
|
|
|
|
|
if ( display === "none" ) {
|
|
|
|
display = "block";
|
|
|
|
}
|
|
|
|
defaultDisplayMap[ nodeName ] = display;
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2015-04-02 20:57:33 +00:00
|
|
|
function showHide( elements, show ) {
|
|
|
|
var display, elem,
|
|
|
|
values = [],
|
|
|
|
index = 0,
|
|
|
|
length = elements.length;
|
|
|
|
|
|
|
|
// Determine new display value for elements that need to change
|
|
|
|
for ( ; index < length; index++ ) {
|
|
|
|
elem = elements[ index ];
|
|
|
|
if ( !elem.style ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
display = elem.style.display;
|
|
|
|
if ( show ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2016-01-11 07:26:55 +00:00
|
|
|
// Since we force visibility upon cascade-hidden elements, an immediate (and slow)
|
|
|
|
// check is required in this first loop unless we have a nonempty display value (either
|
|
|
|
// inline or about-to-be-restored)
|
|
|
|
if ( display === "none" ) {
|
|
|
|
values[ index ] = dataPriv.get( elem, "display" ) || null;
|
|
|
|
if ( !values[ index ] ) {
|
|
|
|
elem.style.display = "";
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 20:27:17 +00:00
|
|
|
if ( elem.style.display === "" && jQuery.css( elem, "display" ) === "none" &&
|
|
|
|
|
|
|
|
// Support: Firefox <=42 - 43
|
|
|
|
// Don't set inline display on disconnected elements with computed display: none
|
|
|
|
jQuery.contains( elem.ownerDocument, elem ) ) {
|
|
|
|
|
2016-01-11 07:26:55 +00:00
|
|
|
values[ index ] = getDefaultDisplay( elem );
|
2015-04-02 20:57:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( display !== "none" ) {
|
|
|
|
values[ index ] = "none";
|
|
|
|
|
2016-01-11 07:26:55 +00:00
|
|
|
// Remember what we're overwriting
|
2015-04-02 20:57:33 +00:00
|
|
|
dataPriv.set( elem, "display", display );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 07:26:55 +00:00
|
|
|
// Set the display of the elements in a second loop to avoid constant reflow
|
2015-04-02 20:57:33 +00:00
|
|
|
for ( index = 0; index < length; index++ ) {
|
|
|
|
if ( values[ index ] != null ) {
|
|
|
|
elements[ index ].style.display = values[ index ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
2015-10-09 19:52:29 +00:00
|
|
|
jQuery.fn.extend( {
|
|
|
|
show: function() {
|
|
|
|
return showHide( this, true );
|
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
return showHide( this );
|
|
|
|
},
|
|
|
|
toggle: function( state ) {
|
|
|
|
if ( typeof state === "boolean" ) {
|
|
|
|
return state ? this.show() : this.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.each( function() {
|
2016-01-20 18:20:58 +00:00
|
|
|
if ( isHiddenWithinTree( this ) ) {
|
2015-10-09 19:52:29 +00:00
|
|
|
jQuery( this ).show();
|
|
|
|
} else {
|
|
|
|
jQuery( this ).hide();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
2015-04-02 20:57:33 +00:00
|
|
|
|
2015-11-10 17:44:35 +00:00
|
|
|
return showHide;
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|