forked from vuejs/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattr.js
49 lines (43 loc) · 1.02 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
// xlink
var xlinkNS = 'http://www.w3.org/1999/xlink'
var xlinkRE = /^xlink:/
module.exports = {
priority: 850,
update: function (value) {
if (this.arg) {
this.setAttr(this.arg, value)
} else if (typeof value === 'object') {
this.objectHandler(value)
}
},
objectHandler: function (value) {
// cache object attrs so that only changed attrs
// are actually updated.
var cache = this.cache || (this.cache = {})
var attr, val
for (attr in cache) {
if (!(attr in value)) {
this.setAttr(attr, null)
delete cache[attr]
}
}
for (attr in value) {
val = value[attr]
if (val !== cache[attr]) {
cache[attr] = val
this.setAttr(attr, val)
}
}
},
setAttr: function (attr, value) {
if (value || value === 0) {
if (xlinkRE.test(attr)) {
this.el.setAttributeNS(xlinkNS, attr, value)
} else {
this.el.setAttribute(attr, value)
}
} else {
this.el.removeAttribute(attr)
}
}
}