diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-26 10:52:11 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-26 10:52:11 +1000 |
commit | bba5002cc8985b9729119bfcadc2de58f4e198a1 (patch) | |
tree | 8fe8a01ff7bfcaedcd2bf36d558d31f4c0e226c9 /src | |
parent | 77c20c30bde7941f1489ce47d8aea439ec1b8e5f (diff) | |
download | svg.js-bba5002cc8985b9729119bfcadc2de58f4e198a1.tar.gz svg.js-bba5002cc8985b9729119bfcadc2de58f4e198a1.zip |
added tests for data.js and memory.js, enhanced data function to work like css and attr
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/optional/data.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/modules/optional/data.js b/src/modules/optional/data.js index 4c163c0..3a642c0 100644 --- a/src/modules/optional/data.js +++ b/src/modules/optional/data.js @@ -1,8 +1,19 @@ import { registerMethods } from '../../utils/methods.js' +import { isNumber } from '../core/regex.js' +import { filter, map } from '../../utils/utils.js' // Store data values on svg nodes export function data (a, v, r) { - if (typeof a === 'object') { + if (a == null) { + // get an object of attributes + return this.data(map(filter(this.node.attributes, (el) => el.nodeName.indexOf('data-') === 0), (el) => el.nodeName.slice(5))) + } else if (a instanceof Array) { + const data = {} + for (const key of a) { + data[key] = this.data(key) + } + return data + } else if (typeof a === 'object') { for (v in a) { this.data(v, a[v]) } |