From 5fc2281fcc83783b86647a5a86380b9ac21e7f79 Mon Sep 17 00:00:00 2001 From: timmywil Date: Fri, 1 Apr 2011 21:13:01 -0400 Subject: [PATCH] - Added a hook to swap display none for width and height in browsers that do not sufficiently support get/setAttribute --- src/attributes.js | 14 ++++++++++++++ src/manipulation.js | 3 ++- test/unit/attributes.js | 12 ++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index f03985590..f29c340a3 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -446,6 +446,20 @@ if ( !jQuery.support.getSetAttribute ) { return value; } }; + + // Retrieving the width/height attributes on an + // element with display: none returns 0 in ie6/7 (#5413) + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + get: function( elem ) { + var ret; + jQuery.swap( elem, { visibility: "hidden", display: "block" }, function() { + ret = elem.getAttribute( name ); + }); + return ret; + } + }); + }); } // Remove certain attrs if set to false diff --git a/src/manipulation.js b/src/manipulation.js index 81a55cb89..758cdbae0 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -549,7 +549,8 @@ jQuery.extend({ // Return the cloned set return clone; -}, + }, + clean: function( elems, context, fragment, scripts ) { context = context || document; diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 262f3499e..a73b51fc5 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -75,7 +75,7 @@ test("prop(String, Object)", function() { }); test("attr(String)", function() { - expect(28); + expect(30); equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' ); equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' ); @@ -125,12 +125,16 @@ test("attr(String)", function() { optgroup.appendChild( option ); select.appendChild( optgroup ); - ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); - ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); - + var $img = jQuery('').appendTo('body'); + equals( $img.attr('width'), "215", "Retrieve width attribute an an element with display:none." ); + equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." ); + // Check for style support ok( !!~jQuery('#dl').attr('style').indexOf('absolute'), 'Check style attribute getter' ); ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('absolute'), 'Check style setter' ); + + ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); + ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); }); if ( !isLocal ) { -- 2.39.5