diff options
author | timmywil <tim.willison@thisismedium.com> | 2011-04-09 17:25:06 -0400 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-04-09 17:25:06 -0400 |
commit | 3a1b4661f5b8249ce7a741084824ec5445c75719 (patch) | |
tree | 79513f4bc8a85726946a141406d2436826430cee /src/attributes.js | |
parent | 17afd80d485b4ca36145a40fd7ac8f81f7099f7c (diff) | |
download | jquery-3a1b4661f5b8249ce7a741084824ec5445c75719.tar.gz jquery-3a1b4661f5b8249ce7a741084824ec5445c75719.zip |
#8150 - When removing the width and height attributes in IE6/7, setting to "" actually sets to 0 instead of auto
- Having fixed this automatically with the use of removeAttribute in browsers that support it, this will fix it for IE6/7 as well.
- This has no effect on width/height styles set elsewhere( test added to removeAttr )
- With this addition, I need to call attr in removeAttr for IE6/7, which means boolean calls like .attr("checked", "") will no longer remove the attribute, which I think is fine. .attr("checked", false) will still remove. If I had left it, it would have gone in an infinite loop since setting to empty string is the only way to remove it in these browsers.
- The hrefNormalized hooks were returning null if they weren't present. Added the null check to the getter.
- Now that the style support fails in IE8 as well due to uppercasing everything, no need to have style included with the hrefNormalized hooks
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/attributes.js b/src/attributes.js index 15d4d50e0..b4330a86e 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -338,16 +338,11 @@ jQuery.extend({ name = jQuery.attrFix[ name ] || name; if ( jQuery.support.getSetAttribute ) { + // Use removeAttribute in browsers that support it elem.removeAttribute( name ); } else { - // Only style is a special case. - if ( name === "style" ) { - elem.style.cssText = ""; - } else { - elem.setAttribute( name, "" ); - // Attempt to remove completely with DOM level 1 - elem.removeAttributeNode( elem.getAttributeNode( name ) ); - } + jQuery.attr( elem, name, "" ); + elem.removeAttributeNode( elem.getAttributeNode( name ) ); } } }, @@ -448,15 +443,28 @@ if ( !jQuery.support.getSetAttribute ) { } } }; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }); + }); } // Remove certain attrs if set to false jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { set: function( elem, value ) { - if ( !value ) { + if ( value === false ) { jQuery.removeAttr( elem, name ); - return false; + return value; } } }); @@ -464,10 +472,11 @@ jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name // Some attributes require a special call on IE if ( !jQuery.support.hrefNormalized ) { - jQuery.each([ "href", "src", "style", "width", "height", "list" ], function( i, name ) { + jQuery.each([ "href", "src", "width", "height", "list" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { get: function( elem ) { - return elem.getAttribute( name, 2 ); + var ret = elem.getAttribute( name, 2 ); + return ret === null ? undefined : ret; } }); }); |