]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Get only bs prefixed data attributes
authorRohit Sharma <rohit2sharma95@gmail.com>
Wed, 11 Nov 2020 06:37:04 +0000 (12:07 +0530)
committerXhmikosR <xhmikosr@gmail.com>
Sat, 14 Nov 2020 05:09:15 +0000 (07:09 +0200)
js/src/dom/manipulator.js
js/tests/unit/dom/manipulator.spec.js

index 04b9543c8a34af925d06fd01788ae9f1287e9161..faab54b5ef7177a5bde54ddc1956761774cea335 100644 (file)
@@ -43,16 +43,14 @@ const Manipulator = {
       return {}
     }
 
-    const attributes = {
-      ...element.dataset
-    }
+    const attributes = {}
 
-    Object.keys(attributes)
+    Object.keys(element.dataset)
       .filter(key => key.startsWith('bs'))
       .forEach(key => {
         let pureKey = key.replace(/^bs/, '')
         pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length)
-        attributes[pureKey] = normalizeData(attributes[key])
+        attributes[pureKey] = normalizeData(element.dataset[key])
       })
 
     return attributes
index 747e8bfd74d6d73273babf5651603051d1c4669b..4f5ef715e8fdd26860b4b6b859d06dfc534d2732 100644 (file)
@@ -60,32 +60,16 @@ describe('Manipulator', () => {
       expect().nothing()
     })
 
-    it('should get all data attributes, without bs prefixed as well', () => {
-      fixtureEl.innerHTML = '<div data-bs-toggle="tabs" data-bs-target="#element" data-another="value"></div>'
+    it('should get only bs prefixed data attributes without bs namespace', () => {
+      fixtureEl.innerHTML = '<div data-bs-toggle="tabs" data-bs-target="#element" data-another="value" data-target-bs="#element" data-in-bs-out="in-between"></div>'
 
       const div = fixtureEl.querySelector('div')
 
       expect(Manipulator.getDataAttributes(div)).toEqual({
-        bsToggle: 'tabs',
-        bsTarget: '#element',
-        another: 'value',
         toggle: 'tabs',
         target: '#element'
       })
     })
-
-    it('should remove just prefixed bs keyword from the attributes and override original attribute with bs prefixed', () => {
-      fixtureEl.innerHTML = '<div data-bs-toggle="tabs" data-toggle="override" data-target-bs="#element" data-in-bs-out="in-between"></div>'
-
-      const div = fixtureEl.querySelector('div')
-
-      expect(Manipulator.getDataAttributes(div)).toEqual({
-        bsToggle: 'tabs',
-        targetBs: '#element',
-        inBsOut: 'in-between',
-        toggle: 'tabs'
-      })
-    })
   })
 
   describe('getDataAttribute', () => {