Skip to content

Commit

Permalink
Fix ticket 10503
Browse files Browse the repository at this point in the history
Rewrote some unclear code, this might not be performant
  • Loading branch information
omni5cience committed Oct 31, 2011
1 parent 0191e98 commit 3fe7e2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
40 changes: 10 additions & 30 deletions src/effects.js
Expand Up @@ -25,39 +25,19 @@ jQuery.fn.extend({
} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
elem = this[i];

if ( elem.style ) {
display = elem.style.display;

// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
display = elem.style.display = "";
}

// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( display === "none" || ( display === "" && jQuery.css( elem, "display" ) === "none" ) ) {
jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
}
}
}

// Set the display of most of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
elem = this[i];

if ( elem.style ) {
display = elem.style.display;

if ( display === "" || display === "none" ) {
elem.style.display = jQuery._data(elem, "olddisplay") || "";
var cachedDisplay = jQuery._data(elem, "olddisplay"),
defaultsForElems = {};
if ( elem.style) {
if ( cachedDisplay ) {
elem.style.display = cachedDisplay;
} else {
if ( !defaultsForElems[elem.nodeName] ) {
defaultsForElems[elem.nodeName] = defaultDisplay(elem.nodeName);
}
elem.style.display = defaultsForElems[elem.nodeName];
}
}
}

return this;
}
},
Expand Down
7 changes: 6 additions & 1 deletion test/unit/effects.js
Expand Up @@ -6,7 +6,7 @@ test("sanity check", function() {
});

test("show()", function() {
expect(28);
expect(29);

var hiddendiv = jQuery("div.hidden");

Expand Down Expand Up @@ -93,6 +93,11 @@ test("show()", function() {
// Make sure that showing or hiding a text node doesn't cause an error
jQuery("<div>test</div> text <span>test</span>").show().remove();
jQuery("<div>test</div> text <span>test</span>").hide().remove();

// Make sure elements maintain their correct display type after hiding/showing
var span = jQuery("<span style='display:block;'>test</span>").hide().show();
equals( "block", span.css("display") );
span.remove();
});

test("show(Number) - other displays", function() {
Expand Down

0 comments on commit 3fe7e2d

Please sign in to comment.