From 9f88fa9165e73b879d0c955fdf81fdd681d2d192 Mon Sep 17 00:00:00 2001 From: timmywil Date: Sun, 13 Mar 2011 15:44:51 -0400 Subject: [PATCH] Full test suite now passes in all browsers! There are probably some tweaks we can make to shorten and simplify. - removeAttr now only uses setAttribute if camelCase setAttribute is not supported + Might want to rename jQuery.support.getSetAttribute - tabIndex is a special case now for hooks where undefined should be returned. + Should we be checking if hooks returns undefined? undefined might be the desired return value in future hooks. As of now, tabIndex is the only one that needs it, but the test suite will still pass if we don't check if hooks are undefined. --- src/attributes.js | 16 +++++++++------- src/support.js | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index ad75a001..64b61261 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -313,7 +313,7 @@ jQuery.extend({ } else { - if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem )) !== undefined ) { + if ( hooks && "get" in hooks && notxml && ((ret = hooks.get( elem )) !== undefined || name === "tabIndex") ) { return ret; } else { @@ -325,11 +325,13 @@ jQuery.extend({ } }, - // removeAttribute returns boolean in IE6/7 - // set property to null in that case + // removeAttribute returns boolean in IE + // set property to null if getSetAttribute not supported (IE6-7) removeAttr: function( elem, name ) { - if ( typeof elem.removeAttribute( name ) === "boolean" ) { - elem.setAttribute( name, null ); + name = jQuery.attrFix[ name ] || name; + if ( typeof elem.removeAttribute( name ) === "boolean" && !jQuery.support.getSetAttribute ) { + // Setting className to null sets a class of "null" + name === "className" ? elem.className = "" : elem.setAttribute( name, null ); } }, @@ -399,7 +401,7 @@ if ( !jQuery.support.getSetAttribute ) { frameborder: "frameBorder" }); - // Action attribute in ie6/7 returns form object + // Action attribute in ie6/7 returns form objects jQuery.attrHooks.action = jQuery.extend( jQuery.attrHooks.action, { get: function( elem ) { return elem.nodeName === "FORM" ? elem.getAttributeNode("action").nodeValue : elem.getAttribute("action"); @@ -414,7 +416,7 @@ if ( !jQuery.support.getSetAttribute ) { // Remove certain attrs if set to false jQuery.each([ "selected", "checked", "readonly", "disabled" ], function( i, name ) { name = jQuery.attrFix[ name ] || name; - + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { set: function( elem, value ) { if ( !value ) { // '', undefined, false, null will remove attr diff --git a/src/support.js b/src/support.js index 8e86c46c..b227293d 100644 --- a/src/support.js +++ b/src/support.js @@ -58,7 +58,8 @@ // Make sure that a selected-by-default option has a working selected property. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, - + + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", // Will be defined later