From 08227506f23072c538b9af6db564c366681bf8a0 Mon Sep 17 00:00:00 2001 From: Johann-S <johann.servoire@gmail.com> Date: Wed, 13 Feb 2019 20:25:08 +0100 Subject: [PATCH] use only dataset to get data attributes --- js/src/dom/manipulator.js | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index b531a55868..5210f8b2c6 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -37,30 +37,12 @@ const Manipulator = { }, getDataAttributes(element) { - if (typeof element === 'undefined' || element === null) { + if (!element) { return {} } - let attributes - if (Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'dataset')) { - attributes = { - ...element.dataset - } - } else { - attributes = {} - for (let i = 0; i < element.attributes.length; i++) { - const attribute = element.attributes[i] - - if (attribute.nodeName.indexOf('data-') !== -1) { - // remove 'data-' part of the attribute name - const attributeName = attribute - .nodeName - .substring('data-'.length) - .replace(/-./g, (str) => str.charAt(1).toUpperCase()) - - attributes[attributeName] = attribute.nodeValue - } - } + const attributes = { + ...element.dataset } Object.keys(attributes) -- GitLab