root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / attributes / attr.js @ 0aee3c58
1 |
define([ |
---|---|
2 |
"../core",
|
3 |
"../var/rnotwhite",
|
4 |
"../var/strundefined",
|
5 |
"../core/access",
|
6 |
"./support",
|
7 |
"./val",
|
8 |
"../selector"
|
9 |
], function( jQuery, rnotwhite, strundefined, access, support ) {
|
10 |
|
11 |
var nodeHook, boolHook,
|
12 |
attrHandle = jQuery.expr.attrHandle, |
13 |
ruseDefault = /^(?:checked|selected)$/i,
|
14 |
getSetAttribute = support.getSetAttribute, |
15 |
getSetInput = support.input; |
16 |
|
17 |
jQuery.fn.extend({ |
18 |
attr: function( name, value ) { |
19 |
return access( this, jQuery.attr, name, value, arguments.length > 1 ); |
20 |
}, |
21 |
|
22 |
removeAttr: function( name ) { |
23 |
return this.each(function() { |
24 |
jQuery.removeAttr( this, name );
|
25 |
}); |
26 |
} |
27 |
}); |
28 |
|
29 |
jQuery.extend({ |
30 |
attr: function( elem, name, value ) { |
31 |
var hooks, ret,
|
32 |
nType = elem.nodeType; |
33 |
|
34 |
// don't get/set attributes on text, comment and attribute nodes
|
35 |
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { |
36 |
return;
|
37 |
} |
38 |
|
39 |
// Fallback to prop when attributes are not supported
|
40 |
if ( typeof elem.getAttribute === strundefined ) { |
41 |
return jQuery.prop( elem, name, value );
|
42 |
} |
43 |
|
44 |
// All attributes are lowercase
|
45 |
// Grab necessary hook if one is defined
|
46 |
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { |
47 |
name = name.toLowerCase(); |
48 |
hooks = jQuery.attrHooks[ name ] || |
49 |
( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook ); |
50 |
} |
51 |
|
52 |
if ( value !== undefined ) { |
53 |
|
54 |
if ( value === null ) { |
55 |
jQuery.removeAttr( elem, name ); |
56 |
|
57 |
} else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { |
58 |
return ret;
|
59 |
|
60 |
} else {
|
61 |
elem.setAttribute( name, value + "" );
|
62 |
return value;
|
63 |
} |
64 |
|
65 |
} else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { |
66 |
return ret;
|
67 |
|
68 |
} else {
|
69 |
ret = jQuery.find.attr( elem, name ); |
70 |
|
71 |
// Non-existent attributes return null, we normalize to undefined
|
72 |
return ret == null ? |
73 |
undefined :
|
74 |
ret; |
75 |
} |
76 |
}, |
77 |
|
78 |
removeAttr: function( elem, value ) { |
79 |
var name, propName,
|
80 |
i = 0,
|
81 |
attrNames = value && value.match( rnotwhite ); |
82 |
|
83 |
if ( attrNames && elem.nodeType === 1 ) { |
84 |
while ( (name = attrNames[i++]) ) {
|
85 |
propName = jQuery.propFix[ name ] || name; |
86 |
|
87 |
// Boolean attributes get special treatment (#10870)
|
88 |
if ( jQuery.expr.match.bool.test( name ) ) {
|
89 |
// Set corresponding property to false
|
90 |
if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) {
|
91 |
elem[ propName ] = false;
|
92 |
// Support: IE<9
|
93 |
// Also clear defaultChecked/defaultSelected (if appropriate)
|
94 |
} else {
|
95 |
elem[ jQuery.camelCase( "default-" + name ) ] =
|
96 |
elem[ propName ] = false;
|
97 |
} |
98 |
|
99 |
// See #9699 for explanation of this approach (setting first, then removal)
|
100 |
} else {
|
101 |
jQuery.attr( elem, name, "" );
|
102 |
} |
103 |
|
104 |
elem.removeAttribute( getSetAttribute ? name : propName ); |
105 |
} |
106 |
} |
107 |
}, |
108 |
|
109 |
attrHooks: {
|
110 |
type: {
|
111 |
set: function( elem, value ) { |
112 |
if ( !support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { |
113 |
// Setting the type on a radio button after the value resets the value in IE6-9
|
114 |
// Reset value to default in case type is set after value during creation
|
115 |
var val = elem.value;
|
116 |
elem.setAttribute( "type", value );
|
117 |
if ( val ) {
|
118 |
elem.value = val; |
119 |
} |
120 |
return value;
|
121 |
} |
122 |
} |
123 |
} |
124 |
} |
125 |
}); |
126 |
|
127 |
// Hook for boolean attributes
|
128 |
boolHook = { |
129 |
set: function( elem, value, name ) { |
130 |
if ( value === false ) { |
131 |
// Remove boolean attributes when set to false
|
132 |
jQuery.removeAttr( elem, name ); |
133 |
} else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { |
134 |
// IE<8 needs the *property* name
|
135 |
elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name ); |
136 |
|
137 |
// Use defaultChecked and defaultSelected for oldIE
|
138 |
} else {
|
139 |
elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true; |
140 |
} |
141 |
|
142 |
return name;
|
143 |
} |
144 |
}; |
145 |
|
146 |
// Retrieve booleans specially
|
147 |
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { |
148 |
|
149 |
var getter = attrHandle[ name ] || jQuery.find.attr;
|
150 |
|
151 |
attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ? |
152 |
function( elem, name, isXML ) {
|
153 |
var ret, handle;
|
154 |
if ( !isXML ) {
|
155 |
// Avoid an infinite loop by temporarily removing this function from the getter
|
156 |
handle = attrHandle[ name ]; |
157 |
attrHandle[ name ] = ret; |
158 |
ret = getter( elem, name, isXML ) != null ?
|
159 |
name.toLowerCase() : |
160 |
null;
|
161 |
attrHandle[ name ] = handle; |
162 |
} |
163 |
return ret;
|
164 |
} : |
165 |
function( elem, name, isXML ) {
|
166 |
if ( !isXML ) {
|
167 |
return elem[ jQuery.camelCase( "default-" + name ) ] ? |
168 |
name.toLowerCase() : |
169 |
null;
|
170 |
} |
171 |
}; |
172 |
}); |
173 |
|
174 |
// fix oldIE attroperties
|
175 |
if ( !getSetInput || !getSetAttribute ) {
|
176 |
jQuery.attrHooks.value = { |
177 |
set: function( elem, value, name ) { |
178 |
if ( jQuery.nodeName( elem, "input" ) ) { |
179 |
// Does not return so that setAttribute is also used
|
180 |
elem.defaultValue = value; |
181 |
} else {
|
182 |
// Use nodeHook if defined (#1954); otherwise setAttribute is fine
|
183 |
return nodeHook && nodeHook.set( elem, value, name );
|
184 |
} |
185 |
} |
186 |
}; |
187 |
} |
188 |
|
189 |
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
190 |
if ( !getSetAttribute ) {
|
191 |
|
192 |
// Use this for any attribute in IE6/7
|
193 |
// This fixes almost every IE6/7 issue
|
194 |
nodeHook = { |
195 |
set: function( elem, value, name ) { |
196 |
// Set the existing or create a new attribute node
|
197 |
var ret = elem.getAttributeNode( name );
|
198 |
if ( !ret ) {
|
199 |
elem.setAttributeNode( |
200 |
(ret = elem.ownerDocument.createAttribute( name )) |
201 |
); |
202 |
} |
203 |
|
204 |
ret.value = value += "";
|
205 |
|
206 |
// Break association with cloned elements by also using setAttribute (#9646)
|
207 |
if ( name === "value" || value === elem.getAttribute( name ) ) { |
208 |
return value;
|
209 |
} |
210 |
} |
211 |
}; |
212 |
|
213 |
// Some attributes are constructed with empty-string values when not defined
|
214 |
attrHandle.id = attrHandle.name = attrHandle.coords =
|
215 |
function( elem, name, isXML ) {
|
216 |
var ret;
|
217 |
if ( !isXML ) {
|
218 |
return (ret = elem.getAttributeNode( name )) && ret.value !== "" ? |
219 |
ret.value : |
220 |
null;
|
221 |
} |
222 |
}; |
223 |
|
224 |
// Fixing value retrieval on a button requires this module
|
225 |
jQuery.valHooks.button = { |
226 |
get: function( elem, name ) { |
227 |
var ret = elem.getAttributeNode( name );
|
228 |
if ( ret && ret.specified ) {
|
229 |
return ret.value;
|
230 |
} |
231 |
}, |
232 |
set: nodeHook.set
|
233 |
}; |
234 |
|
235 |
// Set contenteditable to false on removals(#10429)
|
236 |
// Setting to empty string throws an error as an invalid value
|
237 |
jQuery.attrHooks.contenteditable = { |
238 |
set: function( elem, value, name ) { |
239 |
nodeHook.set( elem, value === "" ? false : value, name ); |
240 |
} |
241 |
}; |
242 |
|
243 |
// Set width and height to auto instead of 0 on empty string( Bug #8150 )
|
244 |
// This is for removals
|
245 |
jQuery.each([ "width", "height" ], function( i, name ) { |
246 |
jQuery.attrHooks[ name ] = { |
247 |
set: function( elem, value ) { |
248 |
if ( value === "" ) { |
249 |
elem.setAttribute( name, "auto" );
|
250 |
return value;
|
251 |
} |
252 |
} |
253 |
}; |
254 |
}); |
255 |
} |
256 |
|
257 |
if ( !support.style ) {
|
258 |
jQuery.attrHooks.style = { |
259 |
get: function( elem ) { |
260 |
// Return undefined in the case of empty string
|
261 |
// Note: IE uppercases css property names, but if we were to .toLowerCase()
|
262 |
// .cssText, that would destroy case senstitivity in URL's, like in "background"
|
263 |
return elem.style.cssText || undefined; |
264 |
}, |
265 |
set: function( elem, value ) { |
266 |
return ( elem.style.cssText = value + "" ); |
267 |
} |
268 |
}; |
269 |
} |
270 |
|
271 |
}); |