From 372e04e78e81cc8eb868c5fc97f271a695569aa5 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 21 Jan 2013 16:14:56 -0500 Subject: [PATCH] Treat an element as hidden if either offsetWidth or offsetHeight is 0. Fixes #13132, #10406. --- src/css.js | 2 +- test/unit/css.js | 83 +++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/css.js b/src/css.js index e2dcb5018..c64fdb3a5 100644 --- a/src/css.js +++ b/src/css.js @@ -532,7 +532,7 @@ jQuery(function() { if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { - return elem.offsetWidth === 0 && elem.offsetHeight === 0; + return elem.offsetWidth === 0 || elem.offsetHeight === 0; }; jQuery.expr.filters.visible = function( elem ) { diff --git a/test/unit/css.js b/test/unit/css.js index 8513913ee..d1cf33304 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -3,22 +3,14 @@ if ( jQuery.css ) { module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { - expect( 45 ); + expect( 40 ); equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"" ); - ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" ); - jQuery("#nothiddendiv").css({ display: "none" }); - ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" ); var $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" }); notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" ); notEqual( $child.css("height"), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" ); - jQuery("#nothiddendiv").css({"display": "block"}); - ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); - ok( jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an error in IE."); - ok( jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an error in IE."); - var div = jQuery( "
" ); // These should be "auto" (or some better value) @@ -203,13 +195,7 @@ test("css() explicit and relative values", function() { }); test("css(String, Object)", function() { - expect(22); - - ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); - jQuery("#nothiddendiv").css("display", "none"); - ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden"); - jQuery("#nothiddendiv").css("display", "block"); - ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); + expect( 19 ); jQuery("#nothiddendiv").css("top", "-1em"); ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." ); @@ -638,19 +624,6 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); }); -test(":visible selector works properly on table elements (bug #4512)", function () { - expect(1); - - jQuery("#table").html("cellcell"); - equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible"); -}); - -test(":visible selector works properly on children with a hidden parent (bug #4512)", function () { - expect(1); - jQuery("#table").css("display", "none").html("cellcell"); - equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible"); -}); - test("internal ref to elem.runtimeStyle (bug #7608)", function () { expect(1); var result = true; @@ -870,17 +843,47 @@ test( "cssHooks - expand", function() { test( "css opacity consistency across browsers (#12685)", function() { expect( 4 ); - var fixture = jQuery("#qunit-fixture"), - style = jQuery("").appendTo(fixture), - el = jQuery("
").appendTo(fixture); - - equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" ); - el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685"); - equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" ); - el.css( "opacity", 0.3 ); - equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" ); - el.css( "opacity", "" ); - equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" ); + var fixture = jQuery("#qunit-fixture"), + style = jQuery("").appendTo(fixture), + el = jQuery("
").appendTo(fixture); + + equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" ); + el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685"); + equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" ); + el.css( "opacity", 0.3 ); + equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" ); + el.css( "opacity", "" ); + equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" ); +}); + +test( ":visible/:hidden selectors", function() { + expect( 13 ); + + ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" ); + jQuery("#nothiddendiv").css({ display: "none" }); + ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" ); + jQuery("#nothiddendiv").css({"display": "block"}); + ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); + ok( jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an error in IE."); + ok( jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an error in IE."); + + ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); + jQuery("#nothiddendiv").css("display", "none"); + ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden"); + jQuery("#nothiddendiv").css("display", "block"); + ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); + + ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" ); + var $newDiv = jQuery("
").appendTo("#qunit-fixture"); + equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" ); + var $br = jQuery("
").appendTo("#qunit-fixture"); + ok( !$br.is(":visible"), "br element not visible (#10406)"); + + var $table = jQuery("#table"); + $table.html("cellcell"); + equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements"); + $table.css("display", "none").html("cellcell"); + equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)"); }); asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() { -- 2.39.5