bootstrap-italia 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.EN.md +1 -1
- package/README.md +1 -1
- package/dist/bootstrap-italia.esm.js +1 -1
- package/dist/css/bootstrap-italia.min.css +9 -1
- package/dist/css/bootstrap-italia.min.css.map +1 -1
- package/dist/js/bootstrap-italia.bundle.min.js +19 -23
- package/dist/js/bootstrap-italia.min.js +18 -2
- package/dist/plugins/accept-overlay.js +19 -9
- package/dist/plugins/accept-overlay.js.map +1 -1
- package/dist/plugins/accordion.js +19 -24
- package/dist/plugins/accordion.js.map +1 -1
- package/dist/plugins/alert.js +67 -2
- package/dist/plugins/alert.js.map +1 -1
- package/dist/plugins/{backToTop.js → back-to-top.js} +14 -5
- package/dist/plugins/back-to-top.js.map +1 -0
- package/dist/plugins/base-component.js +91 -0
- package/dist/plugins/base-component.js.map +1 -0
- package/dist/plugins/button.js +58 -2
- package/dist/plugins/button.js.map +1 -1
- package/dist/plugins/carousel-bi.js +19 -9
- package/dist/plugins/carousel-bi.js.map +1 -1
- package/dist/plugins/carousel.js +445 -2
- package/dist/plugins/carousel.js.map +1 -1
- package/dist/plugins/collapse.js +273 -2
- package/dist/plugins/collapse.js.map +1 -1
- package/dist/plugins/cookiebar.js +39 -52
- package/dist/plugins/cookiebar.js.map +1 -1
- package/dist/plugins/dimmer.js +19 -8
- package/dist/plugins/dimmer.js.map +1 -1
- package/dist/plugins/dom/data.js +61 -0
- package/dist/plugins/dom/data.js.map +1 -0
- package/dist/plugins/dom/event-handler.js +296 -0
- package/dist/plugins/dom/event-handler.js.map +1 -0
- package/dist/plugins/dom/manipulator.js +76 -0
- package/dist/plugins/dom/manipulator.js.map +1 -0
- package/dist/plugins/dom/selector-engine.js +82 -0
- package/dist/plugins/dom/selector-engine.js.map +1 -0
- package/dist/plugins/dropdown.js +433 -2
- package/dist/plugins/dropdown.js.map +1 -1
- package/dist/plugins/fonts-loader.js +9 -1
- package/dist/plugins/fonts-loader.js.map +1 -1
- package/dist/plugins/form-validate.js +22 -8
- package/dist/plugins/form-validate.js.map +1 -1
- package/dist/plugins/forward.js +21 -18
- package/dist/plugins/forward.js.map +1 -1
- package/dist/plugins/header-sticky.js +11 -2
- package/dist/plugins/header-sticky.js.map +1 -1
- package/dist/plugins/history-back.js +17 -17
- package/dist/plugins/history-back.js.map +1 -1
- package/dist/plugins/init.js +9 -0
- package/dist/plugins/init.js.map +1 -1
- package/dist/plugins/input-label.js +14 -3
- package/dist/plugins/input-label.js.map +1 -1
- package/dist/plugins/input-number.js +13 -4
- package/dist/plugins/input-number.js.map +1 -1
- package/dist/plugins/input-password.js +48 -37
- package/dist/plugins/input-password.js.map +1 -1
- package/dist/plugins/input-search-autocomplete.js +9 -11
- package/dist/plugins/input-search-autocomplete.js.map +1 -1
- package/dist/plugins/input.js +12 -3
- package/dist/plugins/input.js.map +1 -1
- package/dist/plugins/list.js +23 -12
- package/dist/plugins/list.js.map +1 -1
- package/dist/plugins/masonry.js +29 -29
- package/dist/plugins/masonry.js.map +1 -1
- package/dist/plugins/modal.js +358 -2
- package/dist/plugins/modal.js.map +1 -1
- package/dist/plugins/navbar-collapsible.js +55 -45
- package/dist/plugins/navbar-collapsible.js.map +1 -1
- package/dist/plugins/navscroll.js +16 -23
- package/dist/plugins/navscroll.js.map +1 -1
- package/dist/plugins/notification.js +34 -23
- package/dist/plugins/notification.js.map +1 -1
- package/dist/plugins/offcanvas.js +259 -2
- package/dist/plugins/offcanvas.js.map +1 -1
- package/dist/plugins/popover.js +76 -2
- package/dist/plugins/popover.js.map +1 -1
- package/dist/plugins/progress-donut.js +19 -12
- package/dist/plugins/progress-donut.js.map +1 -1
- package/dist/plugins/scrollspy.js +273 -2
- package/dist/plugins/scrollspy.js.map +1 -1
- package/dist/plugins/select-autocomplete.js +10 -1
- package/dist/plugins/select-autocomplete.js.map +1 -1
- package/dist/plugins/sticky.js +21 -18
- package/dist/plugins/sticky.js.map +1 -1
- package/dist/plugins/tab.js +244 -27
- package/dist/plugins/tab.js.map +1 -1
- package/dist/plugins/toast.js +203 -2
- package/dist/plugins/toast.js.map +1 -1
- package/dist/plugins/tooltip.js +602 -2
- package/dist/plugins/tooltip.js.map +1 -1
- package/dist/plugins/track-focus.js +8 -0
- package/dist/plugins/track-focus.js.map +1 -1
- package/dist/plugins/transfer.js +11 -16
- package/dist/plugins/transfer.js.map +1 -1
- package/dist/plugins/upload-dragdrop.js +13 -4
- package/dist/plugins/upload-dragdrop.js.map +1 -1
- package/dist/plugins/util/backdrop.js +155 -0
- package/dist/plugins/util/backdrop.js.map +1 -0
- package/dist/plugins/util/component-functions.js +38 -0
- package/dist/plugins/util/component-functions.js.map +1 -0
- package/dist/plugins/util/config.js +70 -0
- package/dist/plugins/util/config.js.map +1 -0
- package/dist/plugins/util/cookies.js +8 -0
- package/dist/plugins/util/cookies.js.map +1 -1
- package/dist/plugins/util/device.js +0 -3
- package/dist/plugins/util/device.js.map +1 -1
- package/dist/plugins/util/dom.js +8 -0
- package/dist/plugins/util/dom.js.map +1 -1
- package/dist/plugins/util/focustrap.js +121 -0
- package/dist/plugins/util/focustrap.js.map +1 -0
- package/dist/plugins/util/index.js +280 -0
- package/dist/plugins/util/index.js.map +1 -0
- package/dist/plugins/util/observer.js +8 -0
- package/dist/plugins/util/observer.js.map +1 -1
- package/dist/plugins/util/on-document-scroll.js +20 -9
- package/dist/plugins/util/on-document-scroll.js.map +1 -1
- package/dist/plugins/util/pageScroll.js +8 -0
- package/dist/plugins/util/pageScroll.js.map +1 -1
- package/dist/plugins/util/sanitizer.js +115 -0
- package/dist/plugins/util/sanitizer.js.map +1 -0
- package/dist/plugins/util/scrollbar.js +120 -0
- package/dist/plugins/util/scrollbar.js.map +1 -0
- package/dist/plugins/util/swipe.js +150 -0
- package/dist/plugins/util/swipe.js.map +1 -0
- package/dist/plugins/util/template-factory.js +166 -0
- package/dist/plugins/util/template-factory.js.map +1 -0
- package/dist/plugins/util/tween.js +10 -1
- package/dist/plugins/util/tween.js.map +1 -1
- package/dist/plugins/util/youtube-video.js +12 -21
- package/dist/plugins/util/youtube-video.js.map +1 -1
- package/dist/plugins/videoplayer.js +19 -8
- package/dist/plugins/videoplayer.js.map +1 -1
- package/dist/version.js +10 -3
- package/dist/version.js.map +1 -1
- package/package.json +6 -7
- package/src/js/bootstrap-italia.entry.js +8 -0
- package/src/js/bootstrap-italia.esm.js +9 -1
- package/src/js/icons.js +8 -0
- package/src/js/load-plugin.js +8 -0
- package/src/js/plugins/accept-overlay.js +18 -10
- package/src/js/plugins/accordion.js +16 -22
- package/src/js/plugins/alert.js +66 -2
- package/src/js/plugins/{backToTop.js → back-to-top.js} +12 -4
- package/src/js/plugins/base-component.js +89 -0
- package/src/js/plugins/button.js +57 -2
- package/src/js/plugins/carousel-bi.js +18 -9
- package/src/js/plugins/carousel.js +444 -2
- package/src/js/plugins/collapse.js +272 -2
- package/src/js/plugins/cookiebar.js +37 -60
- package/src/js/plugins/dimmer.js +18 -8
- package/src/js/plugins/dom/data.js +58 -0
- package/src/js/plugins/dom/event-handler.js +301 -0
- package/src/js/plugins/dom/manipulator.js +75 -0
- package/src/js/plugins/dom/selector-engine.js +80 -0
- package/src/js/plugins/dropdown.js +432 -2
- package/src/js/plugins/fonts-loader.js +9 -1
- package/src/js/plugins/form-validate.js +21 -8
- package/src/js/plugins/form.js +11 -3
- package/src/js/plugins/forward.js +18 -16
- package/src/js/plugins/header-sticky.js +10 -2
- package/src/js/plugins/history-back.js +14 -14
- package/src/js/plugins/init.js +8 -0
- package/src/js/plugins/input-label.js +13 -3
- package/src/js/plugins/input-number.js +12 -4
- package/src/js/plugins/input-password.js +46 -36
- package/src/js/plugins/input-search-autocomplete.js +9 -13
- package/src/js/plugins/input.js +11 -3
- package/src/js/plugins/list.js +22 -12
- package/src/js/plugins/masonry.js +26 -27
- package/src/js/plugins/modal.js +357 -2
- package/src/js/plugins/navbar-collapsible.js +55 -53
- package/src/js/plugins/navscroll.js +16 -23
- package/src/js/plugins/notification.js +33 -23
- package/src/js/plugins/offcanvas.js +258 -2
- package/src/js/plugins/popover.js +75 -2
- package/src/js/plugins/progress-donut.js +17 -13
- package/src/js/plugins/scrollspy.js +272 -2
- package/src/js/plugins/select-autocomplete.js +9 -1
- package/src/js/plugins/sticky.js +21 -23
- package/src/js/plugins/tab.js +243 -27
- package/src/js/plugins/toast.js +206 -2
- package/src/js/plugins/tooltip.js +601 -2
- package/src/js/plugins/track-focus.js +8 -0
- package/src/js/plugins/transfer.js +12 -24
- package/src/js/plugins/upload-dragdrop.js +12 -4
- package/src/js/plugins/util/backdrop.js +153 -0
- package/src/js/plugins/util/component-functions.js +36 -0
- package/src/js/plugins/util/config.js +68 -0
- package/src/js/plugins/util/cookies.js +8 -0
- package/src/js/plugins/util/device.js +0 -3
- package/src/js/plugins/util/dom.js +8 -0
- package/src/js/plugins/util/focustrap.js +119 -0
- package/src/js/plugins/util/index.js +317 -0
- package/src/js/plugins/util/observer.js +8 -0
- package/src/js/plugins/util/on-document-scroll.js +19 -9
- package/src/js/plugins/util/pageScroll.js +8 -0
- package/src/js/plugins/util/sanitizer.js +112 -0
- package/src/js/plugins/util/scrollbar.js +118 -0
- package/src/js/plugins/util/swipe.js +148 -0
- package/src/js/plugins/util/template-factory.js +164 -0
- package/src/js/plugins/util/tween.js +9 -1
- package/src/js/plugins/util/youtube-video.js +12 -21
- package/src/js/plugins/videoplayer.js +18 -8
- package/src/js/version.js +10 -3
- package/src/scss/base/_containers.scss +41 -0
- package/src/scss/base/_functions.scss +373 -0
- package/src/scss/base/_helpers.scss +10 -0
- package/src/scss/base/_maps.scss +54 -0
- package/src/scss/base/_mixins.scss +44 -0
- package/src/scss/base/_reboot.scss +590 -0
- package/src/scss/base/_root.scss +73 -0
- package/src/scss/base/_transitions.scss +27 -0
- package/src/scss/base/_utilities.scss +742 -0
- package/src/scss/base/_variables.scss +2123 -0
- package/src/scss/base/_version.scss +3 -0
- package/src/scss/base/helpers/_clearfix.scss +3 -0
- package/src/scss/base/helpers/_color-bg.scss +10 -0
- package/src/scss/base/helpers/_colored-links.scss +16 -0
- package/src/scss/base/helpers/_position.scss +36 -0
- package/src/scss/base/helpers/_ratio.scss +26 -0
- package/src/scss/base/helpers/_stacks.scss +15 -0
- package/src/scss/base/helpers/_stretched-link.scss +15 -0
- package/src/scss/base/helpers/_text-truncation.scss +7 -0
- package/src/scss/base/helpers/_visually-hidden.scss +8 -0
- package/src/scss/base/helpers/_vr.scss +8 -0
- package/src/scss/base/mixins/_alert.scss +15 -0
- package/src/scss/base/mixins/_backdrop.scss +18 -0
- package/src/scss/base/mixins/_banner.scss +11 -0
- package/src/scss/base/mixins/_border-radius.scss +77 -0
- package/src/scss/base/mixins/_box-shadow.scss +18 -0
- package/src/scss/base/mixins/_breakpoints.scss +127 -0
- package/src/scss/base/mixins/_buttons.scss +141 -0
- package/src/scss/base/mixins/_caret.scss +64 -0
- package/src/scss/base/mixins/_clearfix.scss +9 -0
- package/src/scss/base/mixins/_color-scheme.scss +7 -0
- package/src/scss/base/mixins/_container.scss +11 -0
- package/src/scss/base/mixins/_deprecate.scss +10 -0
- package/src/scss/base/mixins/_forms.scss +152 -0
- package/src/scss/base/mixins/_gradients.scss +47 -0
- package/src/scss/base/mixins/_grid.scss +151 -0
- package/src/scss/base/mixins/_image.scss +15 -0
- package/src/scss/base/mixins/_list-group.scss +24 -0
- package/src/scss/base/mixins/_lists.scss +7 -0
- package/src/scss/base/mixins/_pagination.scss +10 -0
- package/src/scss/base/mixins/_reset-text.scss +17 -0
- package/src/scss/base/mixins/_resize.scss +6 -0
- package/src/scss/base/mixins/_table-variants.scss +24 -0
- package/src/scss/base/mixins/_text-truncate.scss +8 -0
- package/src/scss/base/mixins/_transition.scss +26 -0
- package/src/scss/base/mixins/_utilities.scss +96 -0
- package/src/scss/base/mixins/_visually-hidden.scss +29 -0
- package/src/scss/base/utilities/_api.scss +45 -0
- package/src/scss/base/vendor/_rfs.scss +337 -0
- package/src/scss/bootstrap-italia.scss +137 -156
- package/src/scss/components/_accordion.scss +297 -0
- package/src/scss/{custom → components}/_avatar.scss +75 -35
- package/src/scss/components/_badge.scss +60 -0
- package/src/scss/components/_breadcrumb.scss +95 -0
- package/src/scss/components/_button-group.scss +143 -0
- package/src/scss/components/_buttons.scss +467 -0
- package/src/scss/{custom → components}/_card.scss +228 -0
- package/src/scss/{custom → components}/_carousel.scss +225 -3
- package/src/scss/components/_dropdown.scss +480 -0
- package/src/scss/{custom → components}/_grid.scss +33 -0
- package/src/scss/{custom → components}/_gridlist.scss +7 -0
- package/src/scss/{custom → components}/_hero.scss +23 -57
- package/src/scss/components/_images.scss +48 -0
- package/src/scss/{custom → components}/_linklist.scss +0 -1
- package/src/scss/components/_list-group.scss +190 -0
- package/src/scss/components/_modal.scss +475 -0
- package/src/scss/components/_nav.scss +169 -0
- package/src/scss/components/_navbar.scss +273 -0
- package/src/scss/components/_offcanvas.scss +144 -0
- package/src/scss/components/_pagination.scss +108 -0
- package/src/scss/components/_placeholders.scss +51 -0
- package/src/scss/components/_popover.scss +298 -0
- package/src/scss/components/_progress-bars.scss +126 -0
- package/src/scss/{custom → components}/_steppers.scss +2 -2
- package/src/scss/{custom → components}/_tab.scss +3 -7
- package/src/scss/components/_tables.scss +171 -0
- package/src/scss/components/_toasts.scss +73 -0
- package/src/scss/{custom → components}/_toolbar.scss +19 -12
- package/src/scss/components/_tooltip.scss +139 -0
- package/src/scss/{custom → components}/_type.scss +92 -0
- package/src/scss/forms/_accessible-autocomplete.scss +188 -0
- package/src/scss/forms/_floating-labels.scss +75 -0
- package/src/scss/forms/_form-check.scss +175 -0
- package/src/scss/forms/_form-control.scss +201 -0
- package/src/scss/forms/_form-range.scss +95 -0
- package/src/scss/{custom → forms}/_form-select.scss +72 -0
- package/src/scss/forms/_form-text.scss +11 -0
- package/src/scss/{custom → forms}/_forms.scss +8 -12
- package/src/scss/forms/_input-group.scss +129 -0
- package/src/scss/forms/_labels.scss +36 -0
- package/src/scss/forms/_validation.scss +12 -0
- package/src/scss/utilities/icons.scss +5 -5
- package/types/index.d.ts +4 -1
- package/types/plugins/video.ts +33 -0
- package/dist/plugins/backToTop.js.map +0 -1
- package/src/scss/_functions.scss +0 -38
- package/src/scss/_variables.scss +0 -639
- package/src/scss/custom/_accessible-autocomplete.scss +0 -30
- package/src/scss/custom/_accordion.scss +0 -176
- package/src/scss/custom/_badge.scss +0 -29
- package/src/scss/custom/_breadcrumb.scss +0 -51
- package/src/scss/custom/_buttons.scss +0 -235
- package/src/scss/custom/_componente-base.scss +0 -6
- package/src/scss/custom/_dropdown.scss +0 -248
- package/src/scss/custom/_form-datepicker.scss +0 -604
- package/src/scss/custom/_images.scss +0 -10
- package/src/scss/custom/_modal.scss +0 -248
- package/src/scss/custom/_popover.scss +0 -106
- package/src/scss/custom/_progress-bars.scss +0 -70
- package/src/scss/custom/_tables.scss +0 -11
- package/src/scss/custom/_timepicker.scss +0 -252
- package/src/scss/custom/_tooltip.scss +0 -33
- package/src/scss/custom/_version.scss +0 -3
- package/src/scss/custom/mixins/_buttons.scss +0 -67
- package/src/scss/utilities/colors_vars.scss +0 -426
- /package/src/scss/{custom → base}/mixins/_text-emphasis.scss +0 -0
- /package/src/scss/{custom → components}/_accept-overlay.scss +0 -0
- /package/src/scss/{custom → components}/_affix.scss +0 -0
- /package/src/scss/{custom → components}/_alert.scss +0 -0
- /package/src/scss/{custom → components}/_anchor.scss +0 -0
- /package/src/scss/{custom → components}/_back-to-top.scss +0 -0
- /package/src/scss/{custom → components}/_bottomnav.scss +0 -0
- /package/src/scss/{custom → components}/_calendar.scss +0 -0
- /package/src/scss/{custom → components}/_callout.scss +0 -0
- /package/src/scss/{custom → components}/_chips.scss +0 -0
- /package/src/scss/{custom → components}/_code.scss +0 -0
- /package/src/scss/{custom → components}/_cookiebar.scss +0 -0
- /package/src/scss/{custom → components}/_dimmer.scss +0 -0
- /package/src/scss/{custom → components}/_figcaption.scss +0 -0
- /package/src/scss/{custom → components}/_font.scss +0 -0
- /package/src/scss/{custom → components}/_footer.scss +0 -0
- /package/src/scss/{custom → components}/_forward.scss +0 -0
- /package/src/scss/{custom → components}/_header.scss +0 -0
- /package/src/scss/{custom → components}/_headercenter.scss +0 -0
- /package/src/scss/{custom → components}/_headercentertheme.scss +0 -0
- /package/src/scss/{custom → components}/_headernavbar.scss +0 -0
- /package/src/scss/{custom → components}/_headernavbartheme.scss +0 -0
- /package/src/scss/{custom → components}/_headerslim.scss +0 -0
- /package/src/scss/{custom → components}/_headerslimtheme.scss +0 -0
- /package/src/scss/{custom → components}/_imgresponsive.scss +0 -0
- /package/src/scss/{custom → components}/_list.scss +0 -0
- /package/src/scss/{custom → components}/_map.scss +0 -0
- /package/src/scss/{custom → components}/_masonry-loader.scss +0 -0
- /package/src/scss/{custom → components}/_megamenu.scss +0 -0
- /package/src/scss/{custom → components}/_navigation.scss +0 -0
- /package/src/scss/{custom → components}/_navigationtheme.scss +0 -0
- /package/src/scss/{custom → components}/_navscroll.scss +0 -0
- /package/src/scss/{custom → components}/_navscrolltheme.scss +0 -0
- /package/src/scss/{custom → components}/_notifications.scss +0 -0
- /package/src/scss/{custom → components}/_overlay-panel.scss +0 -0
- /package/src/scss/{custom → components}/_page-scroll.scss +0 -0
- /package/src/scss/{custom → components}/_pager.scss +0 -0
- /package/src/scss/{custom → components}/_point-list.scss +0 -0
- /package/src/scss/{custom → components}/_print.scss +0 -0
- /package/src/scss/{custom → components}/_progress-donuts.scss +0 -0
- /package/src/scss/{custom → components}/_progress-spinners.scss +0 -0
- /package/src/scss/{custom → components}/_rating-list.scss +0 -0
- /package/src/scss/{custom → components}/_rating.scss +0 -0
- /package/src/scss/{custom → components}/_sections.scss +0 -0
- /package/src/scss/{custom → components}/_sidebar.scss +0 -0
- /package/src/scss/{custom → components}/_sidebarthemes.scss +0 -0
- /package/src/scss/{custom → components}/_skiplinks.scss +0 -0
- /package/src/scss/{custom → components}/_sticky.scss +0 -0
- /package/src/scss/{custom → components}/_thumbnav.scss +0 -0
- /package/src/scss/{custom → components}/_timeline.scss +0 -0
- /package/src/scss/{custom → components}/_videoplayer.scss +0 -0
- /package/src/scss/{custom → forms}/_autocomplete.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-file.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-number.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-upload.scss +0 -0
- /package/src/scss/{custom → forms}/_form-password.scss +0 -0
- /package/src/scss/{custom → forms}/_form-toggles.scss +0 -0
- /package/src/scss/{custom → forms}/_form-transfer.scss +0 -0
- /package/src/scss/{custom → forms}/_just-validate.scss +0 -0
- /package/types/plugins/{backToTop.d.ts → back-to-top.d.ts} +0 -0
|
@@ -1,5 +1,447 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
4
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
5
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
6
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
7
|
+
* Bootstrap (v5.2.3): carousel.js
|
|
8
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
9
|
+
* --------------------------------------------------------------------------
|
|
10
|
+
*/
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
import { getElementFromSelector, getNextActiveElement, isRTL, isVisible, reflow, triggerTransitionEnd } from './util/index'
|
|
13
|
+
import EventHandler from './dom/event-handler'
|
|
14
|
+
import Manipulator from './dom/manipulator'
|
|
15
|
+
import SelectorEngine from './dom/selector-engine'
|
|
16
|
+
import Swipe from './util/swipe'
|
|
17
|
+
import BaseComponent from './base-component'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Constants
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const NAME = 'carousel'
|
|
24
|
+
const DATA_KEY = 'bs.carousel'
|
|
25
|
+
const EVENT_KEY = `.${DATA_KEY}`
|
|
26
|
+
const DATA_API_KEY = '.data-api'
|
|
27
|
+
|
|
28
|
+
const ARROW_LEFT_KEY = 'ArrowLeft'
|
|
29
|
+
const ARROW_RIGHT_KEY = 'ArrowRight'
|
|
30
|
+
const TOUCHEVENT_COMPAT_WAIT = 500 // Time for mouse compat events to fire after touch
|
|
31
|
+
|
|
32
|
+
const ORDER_NEXT = 'next'
|
|
33
|
+
const ORDER_PREV = 'prev'
|
|
34
|
+
const DIRECTION_LEFT = 'left'
|
|
35
|
+
const DIRECTION_RIGHT = 'right'
|
|
36
|
+
|
|
37
|
+
const EVENT_SLIDE = `slide${EVENT_KEY}`
|
|
38
|
+
const EVENT_SLID = `slid${EVENT_KEY}`
|
|
39
|
+
const EVENT_KEYDOWN = `keydown${EVENT_KEY}`
|
|
40
|
+
const EVENT_MOUSEENTER = `mouseenter${EVENT_KEY}`
|
|
41
|
+
const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`
|
|
42
|
+
const EVENT_DRAG_START = `dragstart${EVENT_KEY}`
|
|
43
|
+
const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`
|
|
44
|
+
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
|
45
|
+
|
|
46
|
+
const CLASS_NAME_CAROUSEL = 'carousel'
|
|
47
|
+
const CLASS_NAME_ACTIVE = 'active'
|
|
48
|
+
const CLASS_NAME_SLIDE = 'slide'
|
|
49
|
+
const CLASS_NAME_END = 'carousel-item-end'
|
|
50
|
+
const CLASS_NAME_START = 'carousel-item-start'
|
|
51
|
+
const CLASS_NAME_NEXT = 'carousel-item-next'
|
|
52
|
+
const CLASS_NAME_PREV = 'carousel-item-prev'
|
|
53
|
+
|
|
54
|
+
const SELECTOR_ACTIVE = '.active'
|
|
55
|
+
const SELECTOR_ITEM = '.carousel-item'
|
|
56
|
+
const SELECTOR_ACTIVE_ITEM = SELECTOR_ACTIVE + SELECTOR_ITEM
|
|
57
|
+
const SELECTOR_ITEM_IMG = '.carousel-item img'
|
|
58
|
+
const SELECTOR_INDICATORS = '.carousel-indicators'
|
|
59
|
+
const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]'
|
|
60
|
+
const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]'
|
|
61
|
+
|
|
62
|
+
const KEY_TO_DIRECTION = {
|
|
63
|
+
[ARROW_LEFT_KEY]: DIRECTION_RIGHT,
|
|
64
|
+
[ARROW_RIGHT_KEY]: DIRECTION_LEFT,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Default = {
|
|
68
|
+
interval: 5000,
|
|
69
|
+
keyboard: true,
|
|
70
|
+
pause: 'hover',
|
|
71
|
+
ride: false,
|
|
72
|
+
touch: true,
|
|
73
|
+
wrap: true,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const DefaultType = {
|
|
77
|
+
interval: '(number|boolean)', // TODO:v6 remove boolean support
|
|
78
|
+
keyboard: 'boolean',
|
|
79
|
+
pause: '(string|boolean)',
|
|
80
|
+
ride: '(boolean|string)',
|
|
81
|
+
touch: 'boolean',
|
|
82
|
+
wrap: 'boolean',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Class definition
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
class Carousel extends BaseComponent {
|
|
90
|
+
constructor(element, config) {
|
|
91
|
+
super(element, config)
|
|
92
|
+
|
|
93
|
+
this._interval = null
|
|
94
|
+
this._activeElement = null
|
|
95
|
+
this._isSliding = false
|
|
96
|
+
this.touchTimeout = null
|
|
97
|
+
this._swipeHelper = null
|
|
98
|
+
|
|
99
|
+
this._indicatorsElement = SelectorEngine.findOne(SELECTOR_INDICATORS, this._element)
|
|
100
|
+
this._addEventListeners()
|
|
101
|
+
|
|
102
|
+
if (this._config.ride === CLASS_NAME_CAROUSEL) {
|
|
103
|
+
this.cycle()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Getters
|
|
108
|
+
static get Default() {
|
|
109
|
+
return Default
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static get DefaultType() {
|
|
113
|
+
return DefaultType
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static get NAME() {
|
|
117
|
+
return NAME
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Public
|
|
121
|
+
next() {
|
|
122
|
+
this._slide(ORDER_NEXT)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
nextWhenVisible() {
|
|
126
|
+
// FIXME TODO use `document.visibilityState`
|
|
127
|
+
// Don't call next when the page isn't visible
|
|
128
|
+
// or the carousel or its parent isn't visible
|
|
129
|
+
if (!document.hidden && isVisible(this._element)) {
|
|
130
|
+
this.next()
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
prev() {
|
|
135
|
+
this._slide(ORDER_PREV)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
pause() {
|
|
139
|
+
if (this._isSliding) {
|
|
140
|
+
triggerTransitionEnd(this._element)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this._clearInterval()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
cycle() {
|
|
147
|
+
this._clearInterval()
|
|
148
|
+
this._updateInterval()
|
|
149
|
+
|
|
150
|
+
this._interval = setInterval(() => this.nextWhenVisible(), this._config.interval)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_maybeEnableCycle() {
|
|
154
|
+
if (!this._config.ride) {
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this._isSliding) {
|
|
159
|
+
EventHandler.one(this._element, EVENT_SLID, () => this.cycle())
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.cycle()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
to(index) {
|
|
167
|
+
const items = this._getItems()
|
|
168
|
+
if (index > items.length - 1 || index < 0) {
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (this._isSliding) {
|
|
173
|
+
EventHandler.one(this._element, EVENT_SLID, () => this.to(index))
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const activeIndex = this._getItemIndex(this._getActive())
|
|
178
|
+
if (activeIndex === index) {
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV
|
|
183
|
+
|
|
184
|
+
this._slide(order, items[index])
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
dispose() {
|
|
188
|
+
if (this._swipeHelper) {
|
|
189
|
+
this._swipeHelper.dispose()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
super.dispose()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Private
|
|
196
|
+
_configAfterMerge(config) {
|
|
197
|
+
config.defaultInterval = config.interval
|
|
198
|
+
return config
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_addEventListeners() {
|
|
202
|
+
if (this._config.keyboard) {
|
|
203
|
+
EventHandler.on(this._element, EVENT_KEYDOWN, (event) => this._keydown(event))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (this._config.pause === 'hover') {
|
|
207
|
+
EventHandler.on(this._element, EVENT_MOUSEENTER, () => this.pause())
|
|
208
|
+
EventHandler.on(this._element, EVENT_MOUSELEAVE, () => this._maybeEnableCycle())
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (this._config.touch && Swipe.isSupported()) {
|
|
212
|
+
this._addTouchEventListeners()
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_addTouchEventListeners() {
|
|
217
|
+
for (const img of SelectorEngine.find(SELECTOR_ITEM_IMG, this._element)) {
|
|
218
|
+
EventHandler.on(img, EVENT_DRAG_START, (event) => event.preventDefault())
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const endCallBack = () => {
|
|
222
|
+
if (this._config.pause !== 'hover') {
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// If it's a touch-enabled device, mouseenter/leave are fired as
|
|
227
|
+
// part of the mouse compatibility events on first tap - the carousel
|
|
228
|
+
// would stop cycling until user tapped out of it;
|
|
229
|
+
// here, we listen for touchend, explicitly pause the carousel
|
|
230
|
+
// (as if it's the second time we tap on it, mouseenter compat event
|
|
231
|
+
// is NOT fired) and after a timeout (to allow for mouse compatibility
|
|
232
|
+
// events to fire) we explicitly restart cycling
|
|
233
|
+
|
|
234
|
+
this.pause()
|
|
235
|
+
if (this.touchTimeout) {
|
|
236
|
+
clearTimeout(this.touchTimeout)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
this.touchTimeout = setTimeout(() => this._maybeEnableCycle(), TOUCHEVENT_COMPAT_WAIT + this._config.interval)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const swipeConfig = {
|
|
243
|
+
leftCallback: () => this._slide(this._directionToOrder(DIRECTION_LEFT)),
|
|
244
|
+
rightCallback: () => this._slide(this._directionToOrder(DIRECTION_RIGHT)),
|
|
245
|
+
endCallback: endCallBack,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this._swipeHelper = new Swipe(this._element, swipeConfig)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_keydown(event) {
|
|
252
|
+
if (/input|textarea/i.test(event.target.tagName)) {
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const direction = KEY_TO_DIRECTION[event.key]
|
|
257
|
+
if (direction) {
|
|
258
|
+
event.preventDefault()
|
|
259
|
+
this._slide(this._directionToOrder(direction))
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_getItemIndex(element) {
|
|
264
|
+
return this._getItems().indexOf(element)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_setActiveIndicatorElement(index) {
|
|
268
|
+
if (!this._indicatorsElement) {
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const activeIndicator = SelectorEngine.findOne(SELECTOR_ACTIVE, this._indicatorsElement)
|
|
273
|
+
|
|
274
|
+
activeIndicator.classList.remove(CLASS_NAME_ACTIVE)
|
|
275
|
+
activeIndicator.removeAttribute('aria-current')
|
|
276
|
+
|
|
277
|
+
const newActiveIndicator = SelectorEngine.findOne(`[data-bs-slide-to="${index}"]`, this._indicatorsElement)
|
|
278
|
+
|
|
279
|
+
if (newActiveIndicator) {
|
|
280
|
+
newActiveIndicator.classList.add(CLASS_NAME_ACTIVE)
|
|
281
|
+
newActiveIndicator.setAttribute('aria-current', 'true')
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
_updateInterval() {
|
|
286
|
+
const element = this._activeElement || this._getActive()
|
|
287
|
+
|
|
288
|
+
if (!element) {
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10)
|
|
293
|
+
|
|
294
|
+
this._config.interval = elementInterval || this._config.defaultInterval
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
_slide(order, element = null) {
|
|
298
|
+
if (this._isSliding) {
|
|
299
|
+
return
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const activeElement = this._getActive()
|
|
303
|
+
const isNext = order === ORDER_NEXT
|
|
304
|
+
const nextElement = element || getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
|
|
305
|
+
|
|
306
|
+
if (nextElement === activeElement) {
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const nextElementIndex = this._getItemIndex(nextElement)
|
|
311
|
+
|
|
312
|
+
const triggerEvent = (eventName) => {
|
|
313
|
+
return EventHandler.trigger(this._element, eventName, {
|
|
314
|
+
relatedTarget: nextElement,
|
|
315
|
+
direction: this._orderToDirection(order),
|
|
316
|
+
from: this._getItemIndex(activeElement),
|
|
317
|
+
to: nextElementIndex,
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const slideEvent = triggerEvent(EVENT_SLIDE)
|
|
322
|
+
|
|
323
|
+
if (slideEvent.defaultPrevented) {
|
|
324
|
+
return
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!activeElement || !nextElement) {
|
|
328
|
+
// Some weirdness is happening, so we bail
|
|
329
|
+
// todo: change tests that use empty divs to avoid this check
|
|
330
|
+
return
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const isCycling = Boolean(this._interval)
|
|
334
|
+
this.pause()
|
|
335
|
+
|
|
336
|
+
this._isSliding = true
|
|
337
|
+
|
|
338
|
+
this._setActiveIndicatorElement(nextElementIndex)
|
|
339
|
+
this._activeElement = nextElement
|
|
340
|
+
|
|
341
|
+
const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END
|
|
342
|
+
const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV
|
|
343
|
+
|
|
344
|
+
nextElement.classList.add(orderClassName)
|
|
345
|
+
|
|
346
|
+
reflow(nextElement)
|
|
347
|
+
|
|
348
|
+
activeElement.classList.add(directionalClassName)
|
|
349
|
+
nextElement.classList.add(directionalClassName)
|
|
350
|
+
|
|
351
|
+
const completeCallBack = () => {
|
|
352
|
+
nextElement.classList.remove(directionalClassName, orderClassName)
|
|
353
|
+
nextElement.classList.add(CLASS_NAME_ACTIVE)
|
|
354
|
+
|
|
355
|
+
activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName)
|
|
356
|
+
|
|
357
|
+
this._isSliding = false
|
|
358
|
+
|
|
359
|
+
triggerEvent(EVENT_SLID)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this._queueCallback(completeCallBack, activeElement, this._isAnimated())
|
|
363
|
+
|
|
364
|
+
if (isCycling) {
|
|
365
|
+
this.cycle()
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
_isAnimated() {
|
|
370
|
+
return this._element.classList.contains(CLASS_NAME_SLIDE)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
_getActive() {
|
|
374
|
+
return SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
_getItems() {
|
|
378
|
+
return SelectorEngine.find(SELECTOR_ITEM, this._element)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
_clearInterval() {
|
|
382
|
+
if (this._interval) {
|
|
383
|
+
clearInterval(this._interval)
|
|
384
|
+
this._interval = null
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
_directionToOrder(direction) {
|
|
389
|
+
if (isRTL()) {
|
|
390
|
+
return direction === DIRECTION_LEFT ? ORDER_PREV : ORDER_NEXT
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return direction === DIRECTION_LEFT ? ORDER_NEXT : ORDER_PREV
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
_orderToDirection(order) {
|
|
397
|
+
if (isRTL()) {
|
|
398
|
+
return order === ORDER_PREV ? DIRECTION_LEFT : DIRECTION_RIGHT
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return order === ORDER_PREV ? DIRECTION_RIGHT : DIRECTION_LEFT
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Data API implementation
|
|
407
|
+
*/
|
|
408
|
+
|
|
409
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
410
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, function (event) {
|
|
411
|
+
const target = getElementFromSelector(this)
|
|
412
|
+
|
|
413
|
+
if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
|
|
414
|
+
return
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
event.preventDefault()
|
|
418
|
+
|
|
419
|
+
const carousel = Carousel.getOrCreateInstance(target)
|
|
420
|
+
const slideIndex = this.getAttribute('data-bs-slide-to')
|
|
421
|
+
|
|
422
|
+
if (slideIndex) {
|
|
423
|
+
carousel.to(slideIndex)
|
|
424
|
+
carousel._maybeEnableCycle()
|
|
425
|
+
return
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (Manipulator.getDataAttribute(this, 'slide') === 'next') {
|
|
429
|
+
carousel.next()
|
|
430
|
+
carousel._maybeEnableCycle()
|
|
431
|
+
return
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
carousel.prev()
|
|
435
|
+
carousel._maybeEnableCycle()
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
|
439
|
+
const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)
|
|
440
|
+
|
|
441
|
+
for (const carousel of carousels) {
|
|
442
|
+
Carousel.getOrCreateInstance(carousel)
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
}
|
|
4
446
|
|
|
5
447
|
export default Carousel
|
|
@@ -1,5 +1,275 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
4
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
5
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
6
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
7
|
+
* Bootstrap (v5.2.3): collapse.js
|
|
8
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
9
|
+
* --------------------------------------------------------------------------
|
|
10
|
+
*/
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
import { getElement, getElementFromSelector, getSelectorFromElement, reflow } from './util/index'
|
|
13
|
+
import EventHandler from './dom/event-handler'
|
|
14
|
+
import SelectorEngine from './dom/selector-engine'
|
|
15
|
+
import BaseComponent from './base-component'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constants
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const NAME = 'collapse'
|
|
22
|
+
const DATA_KEY = 'bs.collapse'
|
|
23
|
+
const EVENT_KEY = `.${DATA_KEY}`
|
|
24
|
+
const DATA_API_KEY = '.data-api'
|
|
25
|
+
|
|
26
|
+
const EVENT_SHOW = `show${EVENT_KEY}`
|
|
27
|
+
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
|
28
|
+
const EVENT_HIDE = `hide${EVENT_KEY}`
|
|
29
|
+
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
|
|
30
|
+
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
|
31
|
+
|
|
32
|
+
const CLASS_NAME_SHOW = 'show'
|
|
33
|
+
const CLASS_NAME_COLLAPSE = 'collapse'
|
|
34
|
+
const CLASS_NAME_COLLAPSING = 'collapsing'
|
|
35
|
+
const CLASS_NAME_COLLAPSED = 'collapsed'
|
|
36
|
+
const CLASS_NAME_DEEPER_CHILDREN = `:scope .${CLASS_NAME_COLLAPSE} .${CLASS_NAME_COLLAPSE}`
|
|
37
|
+
const CLASS_NAME_HORIZONTAL = 'collapse-horizontal'
|
|
38
|
+
|
|
39
|
+
const WIDTH = 'width'
|
|
40
|
+
const HEIGHT = 'height'
|
|
41
|
+
|
|
42
|
+
const SELECTOR_ACTIVES = '.collapse.show, .collapse.collapsing'
|
|
43
|
+
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="collapse"]'
|
|
44
|
+
|
|
45
|
+
const Default = {
|
|
46
|
+
parent: null,
|
|
47
|
+
toggle: true,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const DefaultType = {
|
|
51
|
+
parent: '(null|element)',
|
|
52
|
+
toggle: 'boolean',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Class definition
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
class Collapse extends BaseComponent {
|
|
60
|
+
constructor(element, config) {
|
|
61
|
+
super(element, config)
|
|
62
|
+
|
|
63
|
+
this._isTransitioning = false
|
|
64
|
+
this._triggerArray = []
|
|
65
|
+
|
|
66
|
+
const toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE)
|
|
67
|
+
|
|
68
|
+
for (const elem of toggleList) {
|
|
69
|
+
const selector = getSelectorFromElement(elem)
|
|
70
|
+
const filterElement = SelectorEngine.find(selector).filter((foundElement) => foundElement === this._element)
|
|
71
|
+
|
|
72
|
+
if (selector !== null && filterElement.length) {
|
|
73
|
+
this._triggerArray.push(elem)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this._initializeChildren()
|
|
78
|
+
|
|
79
|
+
if (!this._config.parent) {
|
|
80
|
+
this._addAriaAndCollapsedClass(this._triggerArray, this._isShown())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this._config.toggle) {
|
|
84
|
+
this.toggle()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Getters
|
|
89
|
+
static get Default() {
|
|
90
|
+
return Default
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static get DefaultType() {
|
|
94
|
+
return DefaultType
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static get NAME() {
|
|
98
|
+
return NAME
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Public
|
|
102
|
+
toggle() {
|
|
103
|
+
if (this._isShown()) {
|
|
104
|
+
this.hide()
|
|
105
|
+
} else {
|
|
106
|
+
this.show()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
show() {
|
|
111
|
+
if (this._isTransitioning || this._isShown()) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let activeChildren = []
|
|
116
|
+
|
|
117
|
+
// find active children
|
|
118
|
+
if (this._config.parent) {
|
|
119
|
+
activeChildren = this._getFirstLevelChildren(SELECTOR_ACTIVES)
|
|
120
|
+
.filter((element) => element !== this._element)
|
|
121
|
+
.map((element) => Collapse.getOrCreateInstance(element, { toggle: false }))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (activeChildren.length && activeChildren[0]._isTransitioning) {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_SHOW)
|
|
129
|
+
if (startEvent.defaultPrevented) {
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (const activeInstance of activeChildren) {
|
|
134
|
+
activeInstance.hide()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const dimension = this._getDimension()
|
|
138
|
+
|
|
139
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSE)
|
|
140
|
+
this._element.classList.add(CLASS_NAME_COLLAPSING)
|
|
141
|
+
|
|
142
|
+
this._element.style[dimension] = 0
|
|
143
|
+
|
|
144
|
+
this._addAriaAndCollapsedClass(this._triggerArray, true)
|
|
145
|
+
this._isTransitioning = true
|
|
146
|
+
|
|
147
|
+
const complete = () => {
|
|
148
|
+
this._isTransitioning = false
|
|
149
|
+
|
|
150
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSING)
|
|
151
|
+
this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
|
152
|
+
|
|
153
|
+
this._element.style[dimension] = ''
|
|
154
|
+
|
|
155
|
+
EventHandler.trigger(this._element, EVENT_SHOWN)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
|
|
159
|
+
const scrollSize = `scroll${capitalizedDimension}`
|
|
160
|
+
|
|
161
|
+
this._queueCallback(complete, this._element, true)
|
|
162
|
+
this._element.style[dimension] = `${this._element[scrollSize]}px`
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
hide() {
|
|
166
|
+
if (this._isTransitioning || !this._isShown()) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_HIDE)
|
|
171
|
+
if (startEvent.defaultPrevented) {
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const dimension = this._getDimension()
|
|
176
|
+
|
|
177
|
+
this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`
|
|
178
|
+
|
|
179
|
+
reflow(this._element)
|
|
180
|
+
|
|
181
|
+
this._element.classList.add(CLASS_NAME_COLLAPSING)
|
|
182
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
|
183
|
+
|
|
184
|
+
for (const trigger of this._triggerArray) {
|
|
185
|
+
const element = getElementFromSelector(trigger)
|
|
186
|
+
|
|
187
|
+
if (element && !this._isShown(element)) {
|
|
188
|
+
this._addAriaAndCollapsedClass([trigger], false)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this._isTransitioning = true
|
|
193
|
+
|
|
194
|
+
const complete = () => {
|
|
195
|
+
this._isTransitioning = false
|
|
196
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSING)
|
|
197
|
+
this._element.classList.add(CLASS_NAME_COLLAPSE)
|
|
198
|
+
EventHandler.trigger(this._element, EVENT_HIDDEN)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this._element.style[dimension] = ''
|
|
202
|
+
|
|
203
|
+
this._queueCallback(complete, this._element, true)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
_isShown(element = this._element) {
|
|
207
|
+
return element.classList.contains(CLASS_NAME_SHOW)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Private
|
|
211
|
+
_configAfterMerge(config) {
|
|
212
|
+
config.toggle = Boolean(config.toggle) // Coerce string values
|
|
213
|
+
config.parent = getElement(config.parent)
|
|
214
|
+
return config
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
_getDimension() {
|
|
218
|
+
return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_initializeChildren() {
|
|
222
|
+
if (!this._config.parent) {
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE)
|
|
227
|
+
|
|
228
|
+
for (const element of children) {
|
|
229
|
+
const selected = getElementFromSelector(element)
|
|
230
|
+
|
|
231
|
+
if (selected) {
|
|
232
|
+
this._addAriaAndCollapsedClass([element], this._isShown(selected))
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
_getFirstLevelChildren(selector) {
|
|
238
|
+
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
|
239
|
+
// remove children if greater depth
|
|
240
|
+
return SelectorEngine.find(selector, this._config.parent).filter((element) => !children.includes(element))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
|
244
|
+
if (!triggerArray.length) {
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
for (const element of triggerArray) {
|
|
249
|
+
element.classList.toggle(CLASS_NAME_COLLAPSED, !isOpen)
|
|
250
|
+
element.setAttribute('aria-expanded', isOpen)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Data API implementation
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
260
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
|
261
|
+
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
|
|
262
|
+
if (event.target.tagName === 'A' || (event.delegateTarget && event.delegateTarget.tagName === 'A')) {
|
|
263
|
+
event.preventDefault()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const selector = getSelectorFromElement(this)
|
|
267
|
+
const selectorElements = SelectorEngine.find(selector)
|
|
268
|
+
|
|
269
|
+
for (const element of selectorElements) {
|
|
270
|
+
Collapse.getOrCreateInstance(element, { toggle: false }).toggle()
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
}
|
|
4
274
|
|
|
5
275
|
export default Collapse
|