blob: 530986d99ec2402cb511346ce5df766c88361d52 (
plain)
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
|
import Element from './Element.js'
import {extend} from './tools.js'
extend(Element, {
// Store data values on svg nodes
data (a, v, r) {
if (typeof a === 'object') {
for (v in a) {
this.data(v, a[v])
}
} else if (arguments.length < 2) {
try {
return JSON.parse(this.attr('data-' + a))
} catch (e) {
return this.attr('data-' + a)
}
} else {
this.attr('data-' + a,
v === null ? null
: r === true || typeof v === 'string' || typeof v === 'number' ? v
: JSON.stringify(v)
)
}
return this
}
})
|