aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes.js
diff options
context:
space:
mode:
authortimmywil <timmywillisn@gmail.com>2011-08-04 16:34:59 -0400
committertimmywil <timmywillisn@gmail.com>2011-08-04 18:16:15 -0400
commit8c2cb49917fc1082abac0a26298b992dcd6a5b6e (patch)
tree64e02c4fbc99e75fcf0f29390ba5d70fd85c6723 /src/attributes.js
parentfd4ee2a39752cc40e35fbcb1bfd48634ffe4bfd4 (diff)
downloadjquery-8c2cb49917fc1082abac0a26298b992dcd6a5b6e.tar.gz
jquery-8c2cb49917fc1082abac0a26298b992dcd6a5b6e.zip
Now using getAttributeNode in all attribute cases in IE6/7, which normalizes attribute behaviors across browsers, is less hacky, and shortens the attribute code. Fixes #9980.
Diffstat (limited to 'src/attributes.js')
-rw-r--r--src/attributes.js41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/attributes.js b/src/attributes.js
index df87e23b4..9a35c045b 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -8,7 +8,7 @@ var rclass = /[\n\t\r]/g,
rclickable = /^a(?:rea)?$/i,
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
rinvalidChar = /\:|^on/,
- formHook, boolHook;
+ nodeHook, boolHook;
jQuery.fn.extend({
attr: function( name, value ) {
@@ -326,14 +326,11 @@ jQuery.extend({
if ( !hooks ) {
// Use boolHook for boolean attributes
if ( rboolean.test( name ) ) {
-
hooks = boolHook;
- // Use formHook for forms and if the name contains certain characters
- } else if ( formHook && name !== "className" &&
- (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) {
-
- hooks = formHook;
+ // Use nodeHook if available( IE6/7 )
+ } else if ( nodeHook ) {
+ hooks = nodeHook;
}
}
}
@@ -406,19 +403,19 @@ jQuery.extend({
}
},
// Use the value property for back compat
- // Use the formHook for button elements in IE6/7 (#1954)
+ // Use the nodeHook for button elements in IE6/7 (#1954)
value: {
get: function( elem, name ) {
- if ( formHook && jQuery.nodeName( elem, "button" ) ) {
- return formHook.get( elem, name );
+ if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
+ return nodeHook.get( elem, name );
}
return name in elem ?
elem.value :
null;
},
set: function( elem, value, name ) {
- if ( formHook && jQuery.nodeName( elem, "button" ) ) {
- return formHook.set( elem, value, name );
+ if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
+ return nodeHook.set( elem, value, name );
}
// Does not return so that setAttribute is also used
elem.value = value;
@@ -481,7 +478,7 @@ jQuery.extend({
get: function( elem ) {
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
- var attributeNode = elem.getAttributeNode("tabIndex");
+ var attributeNode = elem.getAttributeNode("tabindex");
return attributeNode && attributeNode.specified ?
parseInt( attributeNode.value, 10 ) :
@@ -528,12 +525,10 @@ boolHook = {
// IE6/7 do not support getting/setting some attributes with get/setAttribute
if ( !jQuery.support.getSetAttribute ) {
-
- // propFix is more comprehensive and contains all fixes
- jQuery.attrFix = jQuery.propFix;
- // Use this for any attribute on a form in IE6/7
- formHook = jQuery.attrHooks.name = jQuery.attrHooks.title = jQuery.valHooks.button = {
+ // Use this for any attribute in IE6/7
+ // This fixes almost every IE6/7 issue
+ nodeHook = jQuery.valHooks.button = {
get: function( elem, name ) {
var ret;
ret = elem.getAttributeNode( name );
@@ -543,13 +538,13 @@ if ( !jQuery.support.getSetAttribute ) {
undefined;
},
set: function( elem, value, name ) {
- // Check form objects in IE (multiple bugs related)
- // Only use nodeValue if the attribute node exists on the form
+ // Set the existing or create a new attribute node
var ret = elem.getAttributeNode( name );
- if ( ret ) {
- ret.nodeValue = value;
- return value;
+ if ( !ret ) {
+ ret = document.createAttribute( name );
+ elem.setAttributeNode( ret );
}
+ return (ret.nodeValue = value + "");
}
};