]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Carousel: cleanup jQueryInterface
authorGeoSot <geo.sotis@gmail.com>
Tue, 1 Mar 2022 22:57:28 +0000 (00:57 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 9 Mar 2022 15:25:47 +0000 (17:25 +0200)
Drop chained else ifs and unused variable.

Since we were checking for `typeof config === 'string'` in both places, action was never `_config.slide`.

js/src/carousel.js

index ea258527da51cbf6e29043158da3a4c215c4415d..afe02f5b7b8f2a26d266984531e836c0fe116475 100644 (file)
@@ -442,17 +442,21 @@ class Carousel extends BaseComponent {
         }
       }
 
-      const action = typeof config === 'string' ? config : _config.slide
-
       if (typeof config === 'number') {
         data.to(config)
-      } else if (typeof action === 'string') {
-        if (typeof data[action] === 'undefined') {
-          throw new TypeError(`No method named "${action}"`)
+        return
+      }
+
+      if (typeof config === 'string') {
+        if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
+          throw new TypeError(`No method named "${config}"`)
         }
 
-        data[action]()
-      } else if (_config.interval && _config.ride) {
+        data[config]()
+        return
+      }
+
+      if (_config.interval && _config.ride) {
         data.pause()
         data.cycle()
       }