1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-10-03 00:31:55 +02:00

JS: minor refactoring

* shorten block comments
* reorder constants
This commit is contained in:
XhmikosR
2021-10-14 17:40:07 +03:00
parent 4f0187c891
commit fe73da982f
12 changed files with 186 additions and 321 deletions

View File

@@ -9,9 +9,7 @@ import $ from 'jquery'
import Util from './util'
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
const NAME = 'carousel'
@@ -25,23 +23,14 @@ const ARROW_RIGHT_KEYCODE = 39 // KeyboardEvent.which value for right arrow key
const TOUCHEVENT_COMPAT_WAIT = 500 // Time for mouse compat events to fire after touch
const SWIPE_THRESHOLD = 40
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 CLASS_NAME_CAROUSEL = 'carousel'
const CLASS_NAME_ACTIVE = 'active'
const CLASS_NAME_SLIDE = 'slide'
const CLASS_NAME_RIGHT = 'carousel-item-right'
const CLASS_NAME_LEFT = 'carousel-item-left'
const CLASS_NAME_NEXT = 'carousel-item-next'
const CLASS_NAME_PREV = 'carousel-item-prev'
const CLASS_NAME_POINTER_EVENT = 'pointer-event'
const DIRECTION_NEXT = 'next'
const DIRECTION_PREV = 'prev'
@@ -62,15 +51,6 @@ const EVENT_DRAG_START = `dragstart${EVENT_KEY}`
const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
const CLASS_NAME_CAROUSEL = 'carousel'
const CLASS_NAME_ACTIVE = 'active'
const CLASS_NAME_SLIDE = 'slide'
const CLASS_NAME_RIGHT = 'carousel-item-right'
const CLASS_NAME_LEFT = 'carousel-item-left'
const CLASS_NAME_NEXT = 'carousel-item-next'
const CLASS_NAME_PREV = 'carousel-item-prev'
const CLASS_NAME_POINTER_EVENT = 'pointer-event'
const SELECTOR_ACTIVE = '.active'
const SELECTOR_ACTIVE_ITEM = '.active.carousel-item'
const SELECTOR_ITEM = '.carousel-item'
@@ -80,16 +60,33 @@ const SELECTOR_INDICATORS = '.carousel-indicators'
const SELECTOR_DATA_SLIDE = '[data-slide], [data-slide-to]'
const SELECTOR_DATA_RIDE = '[data-ride="carousel"]'
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 PointerType = {
TOUCH: 'touch',
PEN: 'pen'
}
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
* Class definition
*/
class Carousel {
constructor(element, config) {
this._items = null
@@ -111,7 +108,6 @@ class Carousel {
}
// Getters
static get VERSION() {
return VERSION
}
@@ -121,7 +117,6 @@ class Carousel {
}
// Public
next() {
if (!this._isSliding) {
this._slide(DIRECTION_NEXT)
@@ -220,7 +215,6 @@ class Carousel {
}
// Private
_getConfig(config) {
config = {
...Default,
@@ -508,7 +502,6 @@ class Carousel {
}
// Static
static _jQueryInterface(config) {
return this.each(function () {
let data = $(this).data(DATA_KEY)
@@ -580,9 +573,7 @@ class Carousel {
}
/**
* ------------------------------------------------------------------------
* Data Api implementation
* ------------------------------------------------------------------------
* Data API implementation
*/
$(document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel._dataApiClickHandler)
@@ -596,9 +587,7 @@ $(window).on(EVENT_LOAD_DATA_API, () => {
})
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Carousel._jQueryInterface