Skip to content

Commit

Permalink
Merge branch 'main' into bubble-click-events
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjhol authored Mar 18, 2021
2 parents d5e67c6 + 26d8955 commit b5f3d91
Show file tree
Hide file tree
Showing 23 changed files with 826 additions and 260 deletions.
4 changes: 2 additions & 2 deletions .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"path": "./dist/js/bootstrap.bundle.min.js",
"maxSize": "22.5 kB"
"maxSize": "22.75 kB"
},
{
"path": "./dist/js/bootstrap.esm.js",
Expand All @@ -54,7 +54,7 @@
},
{
"path": "./dist/js/bootstrap.min.js",
"maxSize": "16.25 kB"
"maxSize": "16.5 kB"
}
],
"ci": {
Expand Down
4 changes: 2 additions & 2 deletions build/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const bsPlugins = {
Collapse: path.resolve(__dirname, '../js/src/collapse.js'),
Dropdown: path.resolve(__dirname, '../js/src/dropdown.js'),
Modal: path.resolve(__dirname, '../js/src/modal.js'),
OffCanvas: path.resolve(__dirname, '../js/src/offcanvas.js'),
Offcanvas: path.resolve(__dirname, '../js/src/offcanvas.js'),
Popover: path.resolve(__dirname, '../js/src/popover.js'),
ScrollSpy: path.resolve(__dirname, '../js/src/scrollspy.js'),
Tab: path.resolve(__dirname, '../js/src/tab.js'),
Expand Down Expand Up @@ -72,7 +72,7 @@ const getConfigByPluginKey = pluginKey => {
}
}

if (pluginKey === 'Alert' || pluginKey === 'Tab' || pluginKey === 'OffCanvas') {
if (pluginKey === 'Alert' || pluginKey === 'Tab' || pluginKey === 'Offcanvas') {
return defaultPluginConfig
}

Expand Down
4 changes: 2 additions & 2 deletions js/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Carousel from './src/carousel'
import Collapse from './src/collapse'
import Dropdown from './src/dropdown'
import Modal from './src/modal'
import OffCanvas from './src/offcanvas'
import Offcanvas from './src/offcanvas'
import Popover from './src/popover'
import ScrollSpy from './src/scrollspy'
import Tab from './src/tab'
Expand All @@ -25,7 +25,7 @@ export {
Collapse,
Dropdown,
Modal,
OffCanvas,
Offcanvas,
Popover,
ScrollSpy,
Tab,
Expand Down
4 changes: 2 additions & 2 deletions js/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Carousel from './src/carousel'
import Collapse from './src/collapse'
import Dropdown from './src/dropdown'
import Modal from './src/modal'
import OffCanvas from './src/offcanvas'
import Offcanvas from './src/offcanvas'
import Popover from './src/popover'
import ScrollSpy from './src/scrollspy'
import Tab from './src/tab'
Expand All @@ -25,7 +25,7 @@ export default {
Collapse,
Dropdown,
Modal,
OffCanvas,
Offcanvas,
Popover,
ScrollSpy,
Tab,
Expand Down
95 changes: 50 additions & 45 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
emulateTransitionEnd,
getElementFromSelector,
getTransitionDurationFromElement,
isVisible,
isRTL,
isVisible,
reflow,
triggerTransitionEnd,
typeCheckConfig
Expand Down Expand Up @@ -56,8 +56,8 @@ const DefaultType = {
touch: 'boolean'
}

const DIRECTION_NEXT = 'next'
const DIRECTION_PREV = 'prev'
const ORDER_NEXT = 'next'
const ORDER_PREV = 'prev'
const DIRECTION_LEFT = 'left'
const DIRECTION_RIGHT = 'right'

Expand Down Expand Up @@ -137,7 +137,7 @@ class Carousel extends BaseComponent {

next() {
if (!this._isSliding) {
this._slide(DIRECTION_NEXT)
this._slide(ORDER_NEXT)
}
}

Expand All @@ -151,7 +151,7 @@ class Carousel extends BaseComponent {

prev() {
if (!this._isSliding) {
this._slide(DIRECTION_PREV)
this._slide(ORDER_PREV)
}
}

Expand Down Expand Up @@ -208,11 +208,11 @@ class Carousel extends BaseComponent {
return
}

const direction = index > activeIndex ?
DIRECTION_NEXT :
DIRECTION_PREV
const order = index > activeIndex ?
ORDER_NEXT :
ORDER_PREV

this._slide(direction, this._items[index])
this._slide(order, this._items[index])
}

dispose() {
Expand Down Expand Up @@ -251,23 +251,11 @@ class Carousel extends BaseComponent {

this.touchDeltaX = 0

// swipe left
if (direction > 0) {
if (isRTL()) {
this.next()
} else {
this.prev()
}
if (!direction) {
return
}

// swipe right
if (direction < 0) {
if (isRTL()) {
this.prev()
} else {
this.next()
}
}
this._slide(direction > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT)
}

_addEventListeners() {
Expand Down Expand Up @@ -350,18 +338,10 @@ class Carousel extends BaseComponent {

if (event.key === ARROW_LEFT_KEY) {
event.preventDefault()
if (isRTL()) {
this.next()
} else {
this.prev()
}
this._slide(DIRECTION_LEFT)
} else if (event.key === ARROW_RIGHT_KEY) {
event.preventDefault()
if (isRTL()) {
this.prev()
} else {
this.next()
}
this._slide(DIRECTION_RIGHT)
}
}

Expand All @@ -373,19 +353,18 @@ class Carousel extends BaseComponent {
return this._items.indexOf(element)
}

_getItemByDirection(direction, activeElement) {
const isNextDirection = direction === DIRECTION_NEXT
const isPrevDirection = direction === DIRECTION_PREV
_getItemByOrder(order, activeElement) {
const isNext = order === ORDER_NEXT
const isPrev = order === ORDER_PREV
const activeIndex = this._getItemIndex(activeElement)
const lastItemIndex = this._items.length - 1
const isGoingToWrap = (isPrevDirection && activeIndex === 0) ||
(isNextDirection && activeIndex === lastItemIndex)
const isGoingToWrap = (isPrev && activeIndex === 0) || (isNext && activeIndex === lastItemIndex)

if (isGoingToWrap && !this._config.wrap) {
return activeElement
}

const delta = direction === DIRECTION_PREV ? -1 : 1
const delta = isPrev ? -1 : 1
const itemIndex = (activeIndex + delta) % this._items.length

return itemIndex === -1 ?
Expand Down Expand Up @@ -441,17 +420,19 @@ class Carousel extends BaseComponent {
}
}

_slide(direction, element) {
_slide(directionOrOrder, element) {
const order = this._directionToOrder(directionOrOrder)
const activeElement = SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
const activeElementIndex = this._getItemIndex(activeElement)
const nextElement = element || (activeElement && this._getItemByDirection(direction, activeElement))
const nextElement = element || this._getItemByOrder(order, activeElement)

const nextElementIndex = this._getItemIndex(nextElement)
const isCycling = Boolean(this._interval)

const directionalClassName = direction === DIRECTION_NEXT ? CLASS_NAME_START : CLASS_NAME_END
const orderClassName = direction === DIRECTION_NEXT ? CLASS_NAME_NEXT : CLASS_NAME_PREV
const eventDirectionName = direction === DIRECTION_NEXT ? DIRECTION_LEFT : DIRECTION_RIGHT
const isNext = order === ORDER_NEXT
const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END
const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV
const eventDirectionName = this._orderToDirection(order)

if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
this._isSliding = false
Expand Down Expand Up @@ -524,6 +505,30 @@ class Carousel extends BaseComponent {
}
}

_directionToOrder(direction) {
if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
return direction
}

if (isRTL()) {
return direction === DIRECTION_RIGHT ? ORDER_PREV : ORDER_NEXT
}

return direction === DIRECTION_RIGHT ? ORDER_NEXT : ORDER_PREV
}

_orderToDirection(order) {
if (![ORDER_NEXT, ORDER_PREV].includes(order)) {
return order
}

if (isRTL()) {
return order === ORDER_NEXT ? DIRECTION_LEFT : DIRECTION_RIGHT
}

return order === ORDER_NEXT ? DIRECTION_RIGHT : DIRECTION_LEFT
}

// Static

static carouselInterface(element, config) {
Expand Down
Loading

0 comments on commit b5f3d91

Please sign in to comment.