Blame view

bower_components/jquery/src/attributes/attr.js 3.24 KB
c5169e0e   Renato De Donato   a new hope
1
  define([
74249687   Luigi Serra   Cross browser con...
2
  	"../core",
c5169e0e   Renato De Donato   a new hope
3
4
  	"../var/rnotwhite",
  	"../var/strundefined",
74249687   Luigi Serra   Cross browser con...
5
6
  	"../core/access",
  	"./support",
74249687   Luigi Serra   Cross browser con...
7
  	"../selector"
c5169e0e   Renato De Donato   a new hope
8
  ], function( jQuery, rnotwhite, strundefined, access, support ) {
74249687   Luigi Serra   Cross browser con...
9
  
c5169e0e   Renato De Donato   a new hope
10
  var nodeHook, boolHook,
74249687   Luigi Serra   Cross browser con...
11
12
  	attrHandle = jQuery.expr.attrHandle;
  
c5169e0e   Renato De Donato   a new hope
13
  jQuery.fn.extend({
74249687   Luigi Serra   Cross browser con...
14
15
16
17
18
  	attr: function( name, value ) {
  		return access( this, jQuery.attr, name, value, arguments.length > 1 );
  	},
  
  	removeAttr: function( name ) {
c5169e0e   Renato De Donato   a new hope
19
  		return this.each(function() {
74249687   Luigi Serra   Cross browser con...
20
  			jQuery.removeAttr( this, name );
c5169e0e   Renato De Donato   a new hope
21
  		});
74249687   Luigi Serra   Cross browser con...
22
  	}
c5169e0e   Renato De Donato   a new hope
23
  });
74249687   Luigi Serra   Cross browser con...
24
  
c5169e0e   Renato De Donato   a new hope
25
  jQuery.extend({
74249687   Luigi Serra   Cross browser con...
26
  	attr: function( elem, name, value ) {
c5169e0e   Renato De Donato   a new hope
27
  		var hooks, ret,
74249687   Luigi Serra   Cross browser con...
28
29
  			nType = elem.nodeType;
  
c5169e0e   Renato De Donato   a new hope
30
31
  		// don't get/set attributes on text, comment and attribute nodes
  		if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
74249687   Luigi Serra   Cross browser con...
32
33
34
35
  			return;
  		}
  
  		// Fallback to prop when attributes are not supported
c5169e0e   Renato De Donato   a new hope
36
  		if ( typeof elem.getAttribute === strundefined ) {
74249687   Luigi Serra   Cross browser con...
37
38
39
40
41
42
43
44
  			return jQuery.prop( elem, name, value );
  		}
  
  		// All attributes are lowercase
  		// Grab necessary hook if one is defined
  		if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
  			name = name.toLowerCase();
  			hooks = jQuery.attrHooks[ name ] ||
c5169e0e   Renato De Donato   a new hope
45
  				( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
74249687   Luigi Serra   Cross browser con...
46
47
48
  		}
  
  		if ( value !== undefined ) {
c5169e0e   Renato De Donato   a new hope
49
  
74249687   Luigi Serra   Cross browser con...
50
51
  			if ( value === null ) {
  				jQuery.removeAttr( elem, name );
74249687   Luigi Serra   Cross browser con...
52
  
c5169e0e   Renato De Donato   a new hope
53
  			} else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
74249687   Luigi Serra   Cross browser con...
54
  				return ret;
74249687   Luigi Serra   Cross browser con...
55
  
c5169e0e   Renato De Donato   a new hope
56
57
58
59
  			} else {
  				elem.setAttribute( name, value + "" );
  				return value;
  			}
a1a3bc73   Luigi Serra   graphs updates
60
  
c5169e0e   Renato De Donato   a new hope
61
  		} else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
74249687   Luigi Serra   Cross browser con...
62
  			return ret;
a1a3bc73   Luigi Serra   graphs updates
63
  
c5169e0e   Renato De Donato   a new hope
64
65
  		} else {
  			ret = jQuery.find.attr( elem, name );
74249687   Luigi Serra   Cross browser con...
66
  
c5169e0e   Renato De Donato   a new hope
67
68
69
70
  			// Non-existent attributes return null, we normalize to undefined
  			return ret == null ?
  				undefined :
  				ret;
74249687   Luigi Serra   Cross browser con...
71
72
73
74
75
76
77
78
79
  		}
  	},
  
  	removeAttr: function( elem, value ) {
  		var name, propName,
  			i = 0,
  			attrNames = value && value.match( rnotwhite );
  
  		if ( attrNames && elem.nodeType === 1 ) {
c5169e0e   Renato De Donato   a new hope
80
  			while ( (name = attrNames[i++]) ) {
74249687   Luigi Serra   Cross browser con...
81
82
83
84
  				propName = jQuery.propFix[ name ] || name;
  
  				// Boolean attributes get special treatment (#10870)
  				if ( jQuery.expr.match.bool.test( name ) ) {
74249687   Luigi Serra   Cross browser con...
85
86
87
88
89
90
91
  					// Set corresponding property to false
  					elem[ propName ] = false;
  				}
  
  				elem.removeAttribute( name );
  			}
  		}
c5169e0e   Renato De Donato   a new hope
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  	},
  
  	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;
  				}
  			}
  		}
74249687   Luigi Serra   Cross browser con...
108
  	}
c5169e0e   Renato De Donato   a new hope
109
  });
74249687   Luigi Serra   Cross browser con...
110
111
112
113
114
  
  // Hooks for boolean attributes
  boolHook = {
  	set: function( elem, value, name ) {
  		if ( value === false ) {
74249687   Luigi Serra   Cross browser con...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  			// 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;
  		if ( !isXML ) {
74249687   Luigi Serra   Cross browser con...
129
130
131
132
133
134
135
136
137
138
  			// Avoid an infinite loop by temporarily removing this function from the getter
  			handle = attrHandle[ name ];
  			attrHandle[ name ] = ret;
  			ret = getter( elem, name, isXML ) != null ?
  				name.toLowerCase() :
  				null;
  			attrHandle[ name ] = handle;
  		}
  		return ret;
  	};
c5169e0e   Renato De Donato   a new hope
139
  });
74249687   Luigi Serra   Cross browser con...
140
  
c5169e0e   Renato De Donato   a new hope
141
  });