]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
streamline `_getConfig` & interface
authorGeoSot <geo.sotis@gmail.com>
Wed, 9 Jun 2021 22:08:07 +0000 (01:08 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Thu, 29 Jul 2021 13:30:02 +0000 (16:30 +0300)
js/src/collapse.js

index 22bd31f9b3979bd53456665d479e364fbbdda25f..a8651fc0a90788c034f83be5b97cff36e80484c2 100644 (file)
@@ -259,6 +259,7 @@ class Collapse extends BaseComponent {
   _getConfig(config) {
     config = {
       ...Default,
+      ...Manipulator.getDataAttributes(this._element),
       ...config
     }
     config.toggle = Boolean(config.toggle) // Coerce string values
@@ -311,20 +312,12 @@ class Collapse extends BaseComponent {
   // Static
 
   static collapseInterface(element, config) {
-    let data = Collapse.getInstance(element)
-    const _config = {
-      ...Default,
-      ...Manipulator.getDataAttributes(element),
-      ...(typeof config === 'object' && config ? config : {})
-    }
-
-    if (!data && _config.toggle && typeof config === 'string' && /show|hide/.test(config)) {
+    const _config = {}
+    if (typeof config === 'string' && /show|hide/.test(config)) {
       _config.toggle = false
     }
 
-    if (!data) {
-      data = new Collapse(element, _config)
-    }
+    const data = Collapse.getOrCreateInstance(element, _config)
 
     if (typeof config === 'string') {
       if (typeof data[config] === 'undefined') {