Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@gmail.com>2021-10-13 15:19:28 +0300
committerGitHub <noreply@github.com>2021-10-13 15:19:28 +0300
commite8f702666f285a3e69866ed1f8d29fa6eaaaeabb (patch)
tree944b2dc894f49f8278d41d096e4388e9ac83157b /js/src/carousel.js
parentdb44392bda22f3d5319d2880c992f76d27d2a60c (diff)
JS: minor refactoring (#35183)
* add missing comments * shorten block comments * reorder constants * reorder public/private methods * sort exports alphabetically in util/index.js * fix a couple of typos
Diffstat (limited to 'js/src/carousel.js')
-rw-r--r--js/src/carousel.js64
1 files changed, 26 insertions, 38 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index f28ee259b3..3589f22067 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -22,9 +22,7 @@ import Swipe from './util/swipe'
import BaseComponent from './base-component'
/**
- * ------------------------------------------------------------------------
* Constants
- * ------------------------------------------------------------------------
*/
const NAME = 'carousel'
@@ -36,34 +34,11 @@ const ARROW_LEFT_KEY = 'ArrowLeft'
const ARROW_RIGHT_KEY = 'ArrowRight'
const TOUCHEVENT_COMPAT_WAIT = 500 // Time for mouse compat events to fire after touch
-const Default = {
- interval: 5000,
- keyboard: true,
- slide: false,
- pause: 'hover',
- wrap: true,
- touch: true
-}
-
-const DefaultType = {
- interval: '(number|boolean)',
- keyboard: 'boolean',
- slide: '(boolean|string)',
- pause: '(string|boolean)',
- wrap: 'boolean',
- touch: 'boolean'
-}
-
const ORDER_NEXT = 'next'
const ORDER_PREV = 'prev'
const DIRECTION_LEFT = 'left'
const DIRECTION_RIGHT = 'right'
-const KEY_TO_DIRECTION = {
- [ARROW_LEFT_KEY]: DIRECTION_RIGHT,
- [ARROW_RIGHT_KEY]: DIRECTION_LEFT
-}
-
const EVENT_SLIDE = `slide${EVENT_KEY}`
const EVENT_SLID = `slid${EVENT_KEY}`
const EVENT_KEYDOWN = `keydown${EVENT_KEY}`
@@ -91,11 +66,33 @@ const SELECTOR_INDICATOR = '[data-bs-target]'
const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]'
const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]'
+const KEY_TO_DIRECTION = {
+ [ARROW_LEFT_KEY]: DIRECTION_RIGHT,
+ [ARROW_RIGHT_KEY]: DIRECTION_LEFT
+}
+
+const Default = {
+ interval: 5000,
+ keyboard: true,
+ slide: false,
+ pause: 'hover',
+ wrap: true,
+ touch: true
+}
+
+const DefaultType = {
+ interval: '(number|boolean)',
+ keyboard: 'boolean',
+ slide: '(boolean|string)',
+ pause: '(string|boolean)',
+ wrap: 'boolean',
+ touch: 'boolean'
+}
+
/**
- * ------------------------------------------------------------------------
- * Class Definition
- * ------------------------------------------------------------------------
+ * Class definition
*/
+
class Carousel extends BaseComponent {
constructor(element, config) {
super(element)
@@ -114,7 +111,6 @@ class Carousel extends BaseComponent {
}
// Getters
-
static get Default() {
return Default
}
@@ -124,7 +120,6 @@ class Carousel extends BaseComponent {
}
// Public
-
next() {
this._slide(ORDER_NEXT)
}
@@ -210,7 +205,6 @@ class Carousel extends BaseComponent {
}
// Private
-
_getConfig(config) {
config = {
...Default,
@@ -451,7 +445,6 @@ class Carousel extends BaseComponent {
}
// Static
-
static carouselInterface(element, config) {
const data = Carousel.getOrCreateInstance(element, config)
@@ -513,9 +506,7 @@ class Carousel extends BaseComponent {
}
/**
- * ------------------------------------------------------------------------
- * Data Api implementation
- * ------------------------------------------------------------------------
+ * Data API implementation
*/
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler)
@@ -529,10 +520,7 @@ EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
})
/**
- * ------------------------------------------------------------------------
* jQuery
- * ------------------------------------------------------------------------
- * add .Carousel to jQuery only if jQuery is present
*/
defineJQueryPlugin(Carousel)