-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattr.js
51 lines (40 loc) · 1.2 KB
/
attr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;(function( myjs ){
myjs.attrHooks = {};
myjs.extend( myjs.fn, {
attr: function( name, value ){
var elem = this[0],
hooks,ret;
if( elem.nodeType !== 1 ){
return;
}
hooks = myjs.attrHooks[ name ];
if( value === undefined ){
if( hooks && ('get' in hooks) && (ret = hooks.get(elem)) !== null ){
return ret;
}else{
return elem.getAttribute( name );
}
}else{
elem.setAttribute( name, value );
}
return this;
}
});
if( !myjs.support.hrefNormalized){
myjs.each(['href','src'], function(i,name){
myjs.attrHooks[ name ] = {
get: function( elem ){
var ret = elem.getAttribute(name,2);
return ret === null ? undefined : ret;
}
}
})
}
if( !myjs.support.style ){
myjs.attrHooks.style = {
get: function( elem ){
return elem.style.cssText.toLowerCase() || undefined;
}
}
}
})( myjs );