|
define( [ |
|
"../core", |
|
"../core/access", |
|
"./support", |
|
"../var/rnotwhite", |
|
"../selector" |
|
], function( jQuery, access, support, rnotwhite ) { |
|
|
|
var boolHook, |
|
attrHandle = jQuery.expr.attrHandle; |
|
|
|
jQuery.fn.extend( { |
|
attr: function( name, value ) { |
|
return access( this, jQuery.attr, name, value, arguments.length > 1 ); |
|
}, |
|
|
|
removeAttr: function( name ) { |
|
return this.each( function() { |
|
jQuery.removeAttr( this, name ); |
|
} ); |
|
} |
|
} ); |
|
|
|
jQuery.extend( { |
|
attr: function( elem, name, value ) { |
|
var ret, hooks, |
|
nType = elem.nodeType; |
|
|
|
|
|
if ( nType === 3 || nType === 8 || nType === 2 ) { |
|
return; |
|
} |
|
|
|
|
|
if ( typeof elem.getAttribute === "undefined" ) { |
|
return jQuery.prop( elem, name, value ); |
|
} |
|
|
|
|
|
|
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { |
|
name = name.toLowerCase(); |
|
hooks = jQuery.attrHooks[ name ] || |
|
( jQuery.expr.match.bool.test( name ) ? boolHook : undefined ); |
|
} |
|
|
|
if ( value !== undefined ) { |
|
if ( value === null ) { |
|
jQuery.removeAttr( elem, name ); |
|
return; |
|
} |
|
|
|
if ( hooks && "set" in hooks && |
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) { |
|
return ret; |
|
} |
|
|
|
elem.setAttribute( name, value + "" ); |
|
return value; |
|
} |
|
|
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { |
|
return ret; |
|
} |
|
|
|
ret = jQuery.find.attr( elem, name ); |
|
|
|
|
|
return ret == null ? undefined : ret; |
|
}, |
|
|
|
attrHooks: { |
|
type: { |
|
set: function( elem, value ) { |
|
if ( !support.radioValue && value === "radio" && |
|
jQuery.nodeName( elem, "input" ) ) { |
|
var val = elem.value; |
|
elem.setAttribute( "type", value ); |
|
if ( val ) { |
|
elem.value = val; |
|
} |
|
return value; |
|
} |
|
} |
|
} |
|
}, |
|
|
|
removeAttr: function( elem, value ) { |
|
var name, propName, |
|
i = 0, |
|
attrNames = value && value.match( rnotwhite ); |
|
|
|
if ( attrNames && elem.nodeType === 1 ) { |
|
while ( ( name = attrNames[ i++ ] ) ) { |
|
propName = jQuery.propFix[ name ] || name; |
|
|
|
|
|
if ( jQuery.expr.match.bool.test( name ) ) { |
|
|
|
|
|
elem[ propName ] = false; |
|
} |
|
|
|
elem.removeAttribute( name ); |
|
} |
|
} |
|
} |
|
} ); |
|
|
|
|
|
boolHook = { |
|
set: function( elem, value, name ) { |
|
if ( value === 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; |
|
if ( !isXML ) { |
|
|
|
|
|
handle = attrHandle[ name ]; |
|
attrHandle[ name ] = ret; |
|
ret = getter( elem, name, isXML ) != null ? |
|
name.toLowerCase() : |
|
null; |
|
attrHandle[ name ] = handle; |
|
} |
|
return ret; |
|
}; |
|
} ); |
|
|
|
} ); |
|
|