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