diff options
Diffstat (limited to 'src/attributes')
-rw-r--r-- | src/attributes/attr.js | 57 | ||||
-rw-r--r-- | src/attributes/prop.js | 2 | ||||
-rw-r--r-- | src/attributes/val.js | 2 |
3 files changed, 25 insertions, 36 deletions
diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 49d5e2550..afa4f5775 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -9,9 +9,6 @@ define( [ "use strict"; -var boolHook, - attrHandle = jQuery.expr.attrHandle; - jQuery.fn.extend( { attr: function( name, value ) { return access( this, jQuery.attr, name, value, arguments.length > 1 ); @@ -42,8 +39,7 @@ jQuery.extend( { // Attribute hooks are determined by the lowercase version // Grab necessary hook if one is defined if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { - hooks = jQuery.attrHooks[ name.toLowerCase() ] || - ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined ); + hooks = jQuery.attrHooks[ name.toLowerCase() ]; } if ( value !== undefined ) { @@ -65,7 +61,7 @@ jQuery.extend( { return ret; } - ret = jQuery.find.attr( elem, name ); + ret = elem.getAttribute( name ); // Non-existent attributes return null, we normalize to undefined return ret == null ? undefined : ret; @@ -105,38 +101,31 @@ jQuery.extend( { } } ); -// Hooks for boolean attributes -boolHook = { - set: function( elem, value, name ) { - if ( value === false ) { - - // Remove boolean attributes when set to false - jQuery.removeAttr( elem, name ); - } else { - elem.setAttribute( name, name ); - } - return name; - } -}; - jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) { - var getter = attrHandle[ name ] || jQuery.find.attr; - - attrHandle[ name ] = function( elem, name, isXML ) { - var ret, handle, - lowercaseName = name.toLowerCase(); + jQuery.attrHooks[ name ] = { + get: function( elem ) { + var ret, + isXML = jQuery.isXMLDoc( elem ), + lowercaseName = name.toLowerCase(); + + if ( !isXML ) { + ret = elem.getAttribute( name ) != null ? + lowercaseName : + null; + } + return ret; + }, - if ( !isXML ) { + set: function( elem, value, name ) { + if ( value === false ) { - // Avoid an infinite loop by temporarily removing this function from the getter - handle = attrHandle[ lowercaseName ]; - attrHandle[ lowercaseName ] = ret; - ret = getter( elem, name, isXML ) != null ? - lowercaseName : - null; - attrHandle[ lowercaseName ] = handle; + // Remove boolean attributes when set to false + jQuery.removeAttr( elem, name ); + } else { + elem.setAttribute( name, name ); + } + return name; } - return ret; }; } ); diff --git a/src/attributes/prop.js b/src/attributes/prop.js index 71358aa92..651d9e215 100644 --- a/src/attributes/prop.js +++ b/src/attributes/prop.js @@ -64,7 +64,7 @@ jQuery.extend( { // correct value when it hasn't been explicitly set // https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ // Use proper attribute retrieval(#12072) - var tabindex = jQuery.find.attr( elem, "tabindex" ); + var tabindex = elem.getAttribute( "tabindex" ); if ( tabindex ) { return parseInt( tabindex, 10 ); diff --git a/src/attributes/val.js b/src/attributes/val.js index f7d6cf190..02559ffaa 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -84,7 +84,7 @@ jQuery.extend( { option: { get: function( elem ) { - var val = jQuery.find.attr( elem, "value" ); + var val = elem.getAttribute( "value" ); return val != null ? val : |