From bba5002cc8985b9729119bfcadc2de58f4e198a1 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Sun, 26 Apr 2020 10:52:11 +1000 Subject: added tests for data.js and memory.js, enhanced data function to work like css and attr --- src/modules/optional/data.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') 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]) } -- cgit v1.2.3