-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (37 loc) · 916 Bytes
/
index.js
File metadata and controls
44 lines (37 loc) · 916 Bytes
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
/*
** Fallback for older IE without get/setAttribute
*/
function fetch(el, attr) {
var attrs = el.attributes;
for(var i = 0; i < attrs.length; i++) {
if (attr[i] !== undefined) {
if(attr[i].nodeName === attr) {
return attr[i];
}
}
}
return null;
}
function Attr(el) {
this.el = el;
}
Attr.prototype.get = function(attr) {
return (this.el.getAttribute && this.el.getAttribute(attr))
|| (fetch(this.el, attr) === null ? null : fetch(this.el, attr).value);
};
Attr.prototype.set = function(attr, val) {
if(this.el.setAttribute) {
this.el.setAttribute(attr, val);
} else {
fetch(this.el, attr).value = val;
}
return this;
};
Attr.prototype.has = function(attr) {
return (this.el.hasAttribute && this.el.hasAttribute(attr))
|| fetch(this.el, attr) !== null;
};
module.exports = function(el) {
return new Attr(el);
};
module.exports.Attr = Attr;