]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Remove `Manipulator.toggleClass` (#31842)
authorXhmikosR <xhmikosr@gmail.com>
Mon, 5 Oct 2020 15:07:49 +0000 (18:07 +0300)
committerGitHub <noreply@github.com>
Mon, 5 Oct 2020 15:07:49 +0000 (18:07 +0300)
It's only used in one place so it makes more sense to remove it for the time being.

js/src/dom/manipulator.js
js/src/dropdown.js
js/tests/unit/dom/manipulator.spec.js

index a81354e7850868f26f35c3da9da31774ef98720a..750ee115e0fe50689c1c01e86a4997acd3b68665 100644 (file)
@@ -72,18 +72,6 @@ const Manipulator = {
       top: element.offsetTop,
       left: element.offsetLeft
     }
-  },
-
-  toggleClass(element, className) {
-    if (!element) {
-      return
-    }
-
-    if (element.classList.contains(className)) {
-      element.classList.remove(className)
-    } else {
-      element.classList.add(className)
-    }
   }
 }
 
index 37bdd1f2480795fea7b70fd25fc1bb0512ce0b27..28d8b7299230c69f0d864847f1306c300f9f8121 100644 (file)
@@ -197,8 +197,8 @@ class Dropdown {
     this._element.focus()
     this._element.setAttribute('aria-expanded', true)
 
-    Manipulator.toggleClass(this._menu, CLASS_NAME_SHOW)
-    Manipulator.toggleClass(this._element, CLASS_NAME_SHOW)
+    this._menu.classList.toggle(CLASS_NAME_SHOW)
+    this._element.classList.toggle(CLASS_NAME_SHOW)
     EventHandler.trigger(parent, EVENT_SHOWN, relatedTarget)
   }
 
@@ -222,8 +222,8 @@ class Dropdown {
       this._popper.destroy()
     }
 
-    Manipulator.toggleClass(this._menu, CLASS_NAME_SHOW)
-    Manipulator.toggleClass(this._element, CLASS_NAME_SHOW)
+    this._menu.classList.toggle(CLASS_NAME_SHOW)
+    this._element.classList.toggle(CLASS_NAME_SHOW)
     EventHandler.trigger(parent, EVENT_HIDDEN, relatedTarget)
   }
 
index eec3ced52b1ebb522e427254df776d3a29ccbd67..16750fd7415dc5f02ad4f2fbcb8910ea3767d2c5 100644 (file)
@@ -129,30 +129,4 @@ describe('Manipulator', () => {
       expect(position.left).toEqual(jasmine.any(Number))
     })
   })
-
-  describe('toggleClass', () => {
-    it('should not error out if element is null or undefined', () => {
-      Manipulator.toggleClass(null, 'test')
-      Manipulator.toggleClass(undefined, 'test')
-      expect().nothing()
-    })
-
-    it('should add class if it is missing', () => {
-      fixtureEl.innerHTML = '<div></div>'
-
-      const div = fixtureEl.querySelector('div')
-
-      Manipulator.toggleClass(div, 'test')
-      expect(div.classList.contains('test')).toEqual(true)
-    })
-
-    it('should remove class if it is set', () => {
-      fixtureEl.innerHTML = '<div class="test"></div>'
-
-      const div = fixtureEl.querySelector('div')
-
-      Manipulator.toggleClass(div, 'test')
-      expect(div.classList.contains('test')).toEqual(false)
-    })
-  })
 })