]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add `isShown` method and reuse it
authorGeoSot <geo.sotis@gmail.com>
Thu, 10 Jun 2021 14:51:01 +0000 (17:51 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Thu, 22 Jul 2021 14:54:48 +0000 (17:54 +0300)
js/src/dropdown.js

index 681369b484ea80ceeb7ff983916c1dfa0ec61a6d..d9bd903c18667076240e4a84cb93c23b2834a0cf 100644 (file)
@@ -11,12 +11,12 @@ import {
   defineJQueryPlugin,
   getElement,
   getElementFromSelector,
+  getNextActiveElement,
   isDisabled,
   isElement,
-  isVisible,
   isRTL,
+  isVisible,
   noop,
-  getNextActiveElement,
   typeCheckConfig
 } from './util/index'
 import EventHandler from './dom/event-handler'
@@ -128,7 +128,7 @@ class Dropdown extends BaseComponent {
       return
     }
 
-    const isActive = this._element.classList.contains(CLASS_NAME_SHOW)
+    const isActive = this._isShown()
 
     if (isActive) {
       this.hide()
@@ -139,7 +139,7 @@ class Dropdown extends BaseComponent {
   }
 
   show() {
-    if (isDisabled(this._element) || this._menu.classList.contains(CLASS_NAME_SHOW)) {
+    if (isDisabled(this._element) || this._isShown(this._menu)) {
       return
     }
 
@@ -201,7 +201,7 @@ class Dropdown extends BaseComponent {
   }
 
   hide() {
-    if (isDisabled(this._element) || !this._menu.classList.contains(CLASS_NAME_SHOW)) {
+    if (isDisabled(this._element) || !this._isShown(this._menu)) {
       return
     }
 
@@ -279,6 +279,10 @@ class Dropdown extends BaseComponent {
     return config
   }
 
+  _isShown(element = this._element) {
+    return element.classList.contains(CLASS_NAME_SHOW)
+  }
+
   _getMenuElement() {
     return SelectorEngine.next(this._element, SELECTOR_MENU)[0]
   }
@@ -398,7 +402,7 @@ class Dropdown extends BaseComponent {
         continue
       }
 
-      if (!context._element.classList.contains(CLASS_NAME_SHOW)) {
+      if (!context._isShown()) {
         continue
       }