mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-18 11:21:23 +02:00
use only dataset to get data attributes
This commit is contained in:
@@ -37,31 +37,13 @@ const Manipulator = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getDataAttributes(element) {
|
getDataAttributes(element) {
|
||||||
if (typeof element === 'undefined' || element === null) {
|
if (!element) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let attributes
|
const attributes = {
|
||||||
if (Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'dataset')) {
|
|
||||||
attributes = {
|
|
||||||
...element.dataset
|
...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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(attributes)
|
Object.keys(attributes)
|
||||||
.forEach((key) => {
|
.forEach((key) => {
|
||||||
|
Reference in New Issue
Block a user