publishing_platform_publishing_components 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/Rakefile +41 -0
- data/app/assets/builds/gemkeep +0 -0
- data/app/assets/config/publishing_platform_publishing_components_manifest.js +2 -0
- data/app/assets/images/publishing_platform_publishing_components/gemkeep +0 -0
- data/app/assets/stylesheets/publishing_platform_publishing_components/_all_components.scss +3 -0
- data/app/assets/stylesheets/publishing_platform_publishing_components/components/_attachment.scss +117 -0
- data/app/assets/stylesheets/publishing_platform_publishing_components/components/_summary-list.scss +169 -0
- data/app/controllers/publishing_platform_publishing_components/application_controller.rb +4 -0
- data/app/helpers/publishing_platform_publishing_components/application_helper.rb +4 -0
- data/app/models/publishing_platform_publishing_components/component_doc.rb +90 -0
- data/app/models/publishing_platform_publishing_components/component_docs.rb +57 -0
- data/app/models/publishing_platform_publishing_components/component_example.rb +104 -0
- data/app/models/publishing_platform_publishing_components/shared_accessibility_criteria.rb +37 -0
- data/app/views/publishing_platform_publishing_components/component_doc/_component_output.html.erb +15 -0
- data/app/views/publishing_platform_publishing_components/components/_attachment.html.erb +91 -0
- data/app/views/publishing_platform_publishing_components/components/_error_summary.html.erb +38 -0
- data/app/views/publishing_platform_publishing_components/components/_summary_list.html.erb +135 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_document.html.erb +3 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_external.html.erb +3 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_generic.html.erb +4 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_html.html.erb +3 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_pdf.html.erb +3 -0
- data/app/views/publishing_platform_publishing_components/components/attachment/_thumbnail_spreadsheet.html.erb +5 -0
- data/app/views/publishing_platform_publishing_components/components/docs/attachment.yml +104 -0
- data/app/views/publishing_platform_publishing_components/components/docs/error_summary.yml +51 -0
- data/app/views/publishing_platform_publishing_components/components/docs/summary_list.yml +137 -0
- data/config/initializers/assets.rb +24 -0
- data/config/routes.rb +2 -0
- data/lib/publishing_platform_publishing_components/config.rb +25 -0
- data/lib/publishing_platform_publishing_components/engine.rb +5 -0
- data/lib/publishing_platform_publishing_components/presenters/attachment_helper.rb +176 -0
- data/lib/publishing_platform_publishing_components/presenters/component_wrapper_helper.rb +290 -0
- data/lib/publishing_platform_publishing_components/presenters/shared_helper.rb +24 -0
- data/lib/publishing_platform_publishing_components/version.rb +3 -0
- data/lib/publishing_platform_publishing_components.rb +10 -0
- data/lib/tasks/publishing_platform_publishing_components_tasks.rake +4 -0
- data/node_modules/bootstrap/LICENSE +21 -0
- data/node_modules/bootstrap/README.md +246 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.css +4085 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.css +4084 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-grid.rtl.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.css +601 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.css +598 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-reboot.rtl.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.css +5406 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.css +5397 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap-utilities.rtl.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap.css +12048 -0
- data/node_modules/bootstrap/dist/css/bootstrap.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap.min.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap.rtl.css +12021 -0
- data/node_modules/bootstrap/dist/css/bootstrap.rtl.css.map +1 -0
- data/node_modules/bootstrap/dist/css/bootstrap.rtl.min.css +6 -0
- data/node_modules/bootstrap/dist/css/bootstrap.rtl.min.css.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.bundle.js +6312 -0
- data/node_modules/bootstrap/dist/js/bootstrap.bundle.js.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js +7 -0
- data/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.esm.js +4447 -0
- data/node_modules/bootstrap/dist/js/bootstrap.esm.js.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.esm.min.js +7 -0
- data/node_modules/bootstrap/dist/js/bootstrap.esm.min.js.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.js +4494 -0
- data/node_modules/bootstrap/dist/js/bootstrap.js.map +1 -0
- data/node_modules/bootstrap/dist/js/bootstrap.min.js +7 -0
- data/node_modules/bootstrap/dist/js/bootstrap.min.js.map +1 -0
- data/node_modules/bootstrap/js/dist/alert.js +90 -0
- data/node_modules/bootstrap/js/dist/alert.js.map +1 -0
- data/node_modules/bootstrap/js/dist/base-component.js +86 -0
- data/node_modules/bootstrap/js/dist/base-component.js.map +1 -0
- data/node_modules/bootstrap/js/dist/button.js +79 -0
- data/node_modules/bootstrap/js/dist/button.js.map +1 -0
- data/node_modules/bootstrap/js/dist/carousel.js +388 -0
- data/node_modules/bootstrap/js/dist/carousel.js.map +1 -0
- data/node_modules/bootstrap/js/dist/collapse.js +249 -0
- data/node_modules/bootstrap/js/dist/collapse.js.map +1 -0
- data/node_modules/bootstrap/js/dist/dom/data.js +63 -0
- data/node_modules/bootstrap/js/dist/dom/data.js.map +1 -0
- data/node_modules/bootstrap/js/dist/dom/event-handler.js +237 -0
- data/node_modules/bootstrap/js/dist/dom/event-handler.js.map +1 -0
- data/node_modules/bootstrap/js/dist/dom/manipulator.js +72 -0
- data/node_modules/bootstrap/js/dist/dom/manipulator.js.map +1 -0
- data/node_modules/bootstrap/js/dist/dom/selector-engine.js +104 -0
- data/node_modules/bootstrap/js/dist/dom/selector-engine.js.map +1 -0
- data/node_modules/bootstrap/js/dist/dropdown.js +402 -0
- data/node_modules/bootstrap/js/dist/dropdown.js.map +1 -0
- data/node_modules/bootstrap/js/dist/modal.js +320 -0
- data/node_modules/bootstrap/js/dist/modal.js.map +1 -0
- data/node_modules/bootstrap/js/dist/offcanvas.js +246 -0
- data/node_modules/bootstrap/js/dist/offcanvas.js.map +1 -0
- data/node_modules/bootstrap/js/dist/popover.js +96 -0
- data/node_modules/bootstrap/js/dist/popover.js.map +1 -0
- data/node_modules/bootstrap/js/dist/scrollspy.js +275 -0
- data/node_modules/bootstrap/js/dist/scrollspy.js.map +1 -0
- data/node_modules/bootstrap/js/dist/tab.js +285 -0
- data/node_modules/bootstrap/js/dist/tab.js.map +1 -0
- data/node_modules/bootstrap/js/dist/toast.js +198 -0
- data/node_modules/bootstrap/js/dist/toast.js.map +1 -0
- data/node_modules/bootstrap/js/dist/tooltip.js +546 -0
- data/node_modules/bootstrap/js/dist/tooltip.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/backdrop.js +139 -0
- data/node_modules/bootstrap/js/dist/util/backdrop.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/component-functions.js +42 -0
- data/node_modules/bootstrap/js/dist/util/component-functions.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/config.js +68 -0
- data/node_modules/bootstrap/js/dist/util/config.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/focustrap.js +113 -0
- data/node_modules/bootstrap/js/dist/util/focustrap.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/index.js +281 -0
- data/node_modules/bootstrap/js/dist/util/index.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/sanitizer.js +113 -0
- data/node_modules/bootstrap/js/dist/util/sanitizer.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/scrollbar.js +113 -0
- data/node_modules/bootstrap/js/dist/util/scrollbar.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/swipe.js +135 -0
- data/node_modules/bootstrap/js/dist/util/swipe.js.map +1 -0
- data/node_modules/bootstrap/js/dist/util/template-factory.js +151 -0
- data/node_modules/bootstrap/js/dist/util/template-factory.js.map +1 -0
- data/node_modules/bootstrap/js/index.esm.js +19 -0
- data/node_modules/bootstrap/js/index.umd.js +34 -0
- data/node_modules/bootstrap/js/src/alert.js +87 -0
- data/node_modules/bootstrap/js/src/base-component.js +86 -0
- data/node_modules/bootstrap/js/src/button.js +72 -0
- data/node_modules/bootstrap/js/src/carousel.js +474 -0
- data/node_modules/bootstrap/js/src/collapse.js +297 -0
- data/node_modules/bootstrap/js/src/dom/data.js +55 -0
- data/node_modules/bootstrap/js/src/dom/event-handler.js +317 -0
- data/node_modules/bootstrap/js/src/dom/manipulator.js +71 -0
- data/node_modules/bootstrap/js/src/dom/selector-engine.js +126 -0
- data/node_modules/bootstrap/js/src/dropdown.js +455 -0
- data/node_modules/bootstrap/js/src/modal.js +378 -0
- data/node_modules/bootstrap/js/src/offcanvas.js +282 -0
- data/node_modules/bootstrap/js/src/popover.js +97 -0
- data/node_modules/bootstrap/js/src/scrollspy.js +296 -0
- data/node_modules/bootstrap/js/src/tab.js +315 -0
- data/node_modules/bootstrap/js/src/toast.js +224 -0
- data/node_modules/bootstrap/js/src/tooltip.js +633 -0
- data/node_modules/bootstrap/js/src/util/backdrop.js +151 -0
- data/node_modules/bootstrap/js/src/util/component-functions.js +35 -0
- data/node_modules/bootstrap/js/src/util/config.js +65 -0
- data/node_modules/bootstrap/js/src/util/focustrap.js +115 -0
- data/node_modules/bootstrap/js/src/util/index.js +306 -0
- data/node_modules/bootstrap/js/src/util/sanitizer.js +116 -0
- data/node_modules/bootstrap/js/src/util/scrollbar.js +114 -0
- data/node_modules/bootstrap/js/src/util/swipe.js +146 -0
- data/node_modules/bootstrap/js/src/util/template-factory.js +160 -0
- data/node_modules/bootstrap/package.json +210 -0
- data/node_modules/bootstrap/scss/_accordion.scss +153 -0
- data/node_modules/bootstrap/scss/_alert.scss +68 -0
- data/node_modules/bootstrap/scss/_badge.scss +38 -0
- data/node_modules/bootstrap/scss/_breadcrumb.scss +40 -0
- data/node_modules/bootstrap/scss/_button-group.scss +147 -0
- data/node_modules/bootstrap/scss/_buttons.scss +216 -0
- data/node_modules/bootstrap/scss/_card.scss +238 -0
- data/node_modules/bootstrap/scss/_carousel.scss +226 -0
- data/node_modules/bootstrap/scss/_close.scss +66 -0
- data/node_modules/bootstrap/scss/_containers.scss +41 -0
- data/node_modules/bootstrap/scss/_dropdown.scss +250 -0
- data/node_modules/bootstrap/scss/_forms.scss +9 -0
- data/node_modules/bootstrap/scss/_functions.scss +302 -0
- data/node_modules/bootstrap/scss/_grid.scss +39 -0
- data/node_modules/bootstrap/scss/_helpers.scss +12 -0
- data/node_modules/bootstrap/scss/_images.scss +42 -0
- data/node_modules/bootstrap/scss/_list-group.scss +199 -0
- data/node_modules/bootstrap/scss/_maps.scss +174 -0
- data/node_modules/bootstrap/scss/_mixins.scss +42 -0
- data/node_modules/bootstrap/scss/_modal.scss +240 -0
- data/node_modules/bootstrap/scss/_nav.scss +197 -0
- data/node_modules/bootstrap/scss/_navbar.scss +289 -0
- data/node_modules/bootstrap/scss/_offcanvas.scss +147 -0
- data/node_modules/bootstrap/scss/_pagination.scss +109 -0
- data/node_modules/bootstrap/scss/_placeholders.scss +51 -0
- data/node_modules/bootstrap/scss/_popover.scss +196 -0
- data/node_modules/bootstrap/scss/_progress.scss +68 -0
- data/node_modules/bootstrap/scss/_reboot.scss +617 -0
- data/node_modules/bootstrap/scss/_root.scss +187 -0
- data/node_modules/bootstrap/scss/_spinners.scss +86 -0
- data/node_modules/bootstrap/scss/_tables.scss +171 -0
- data/node_modules/bootstrap/scss/_toasts.scss +73 -0
- data/node_modules/bootstrap/scss/_tooltip.scss +119 -0
- data/node_modules/bootstrap/scss/_transitions.scss +27 -0
- data/node_modules/bootstrap/scss/_type.scss +106 -0
- data/node_modules/bootstrap/scss/_utilities.scss +806 -0
- data/node_modules/bootstrap/scss/_variables-dark.scss +102 -0
- data/node_modules/bootstrap/scss/_variables.scss +1753 -0
- data/node_modules/bootstrap/scss/bootstrap-grid.scss +62 -0
- data/node_modules/bootstrap/scss/bootstrap-reboot.scss +10 -0
- data/node_modules/bootstrap/scss/bootstrap-utilities.scss +19 -0
- data/node_modules/bootstrap/scss/bootstrap.scss +52 -0
- data/node_modules/bootstrap/scss/forms/_floating-labels.scss +97 -0
- data/node_modules/bootstrap/scss/forms/_form-check.scss +189 -0
- data/node_modules/bootstrap/scss/forms/_form-control.scss +214 -0
- data/node_modules/bootstrap/scss/forms/_form-range.scss +91 -0
- data/node_modules/bootstrap/scss/forms/_form-select.scss +80 -0
- data/node_modules/bootstrap/scss/forms/_form-text.scss +11 -0
- data/node_modules/bootstrap/scss/forms/_input-group.scss +132 -0
- data/node_modules/bootstrap/scss/forms/_labels.scss +36 -0
- data/node_modules/bootstrap/scss/forms/_validation.scss +12 -0
- data/node_modules/bootstrap/scss/helpers/_clearfix.scss +3 -0
- data/node_modules/bootstrap/scss/helpers/_color-bg.scss +7 -0
- data/node_modules/bootstrap/scss/helpers/_colored-links.scss +30 -0
- data/node_modules/bootstrap/scss/helpers/_focus-ring.scss +5 -0
- data/node_modules/bootstrap/scss/helpers/_icon-link.scss +25 -0
- data/node_modules/bootstrap/scss/helpers/_position.scss +36 -0
- data/node_modules/bootstrap/scss/helpers/_ratio.scss +26 -0
- data/node_modules/bootstrap/scss/helpers/_stacks.scss +15 -0
- data/node_modules/bootstrap/scss/helpers/_stretched-link.scss +15 -0
- data/node_modules/bootstrap/scss/helpers/_text-truncation.scss +7 -0
- data/node_modules/bootstrap/scss/helpers/_visually-hidden.scss +8 -0
- data/node_modules/bootstrap/scss/helpers/_vr.scss +8 -0
- data/node_modules/bootstrap/scss/mixins/_alert.scss +18 -0
- data/node_modules/bootstrap/scss/mixins/_backdrop.scss +14 -0
- data/node_modules/bootstrap/scss/mixins/_banner.scss +7 -0
- data/node_modules/bootstrap/scss/mixins/_border-radius.scss +78 -0
- data/node_modules/bootstrap/scss/mixins/_box-shadow.scss +24 -0
- data/node_modules/bootstrap/scss/mixins/_breakpoints.scss +127 -0
- data/node_modules/bootstrap/scss/mixins/_buttons.scss +70 -0
- data/node_modules/bootstrap/scss/mixins/_caret.scss +69 -0
- data/node_modules/bootstrap/scss/mixins/_clearfix.scss +9 -0
- data/node_modules/bootstrap/scss/mixins/_color-mode.scss +21 -0
- data/node_modules/bootstrap/scss/mixins/_color-scheme.scss +7 -0
- data/node_modules/bootstrap/scss/mixins/_container.scss +11 -0
- data/node_modules/bootstrap/scss/mixins/_deprecate.scss +10 -0
- data/node_modules/bootstrap/scss/mixins/_forms.scss +163 -0
- data/node_modules/bootstrap/scss/mixins/_gradients.scss +47 -0
- data/node_modules/bootstrap/scss/mixins/_grid.scss +151 -0
- data/node_modules/bootstrap/scss/mixins/_image.scss +16 -0
- data/node_modules/bootstrap/scss/mixins/_list-group.scss +26 -0
- data/node_modules/bootstrap/scss/mixins/_lists.scss +7 -0
- data/node_modules/bootstrap/scss/mixins/_pagination.scss +10 -0
- data/node_modules/bootstrap/scss/mixins/_reset-text.scss +17 -0
- data/node_modules/bootstrap/scss/mixins/_resize.scss +6 -0
- data/node_modules/bootstrap/scss/mixins/_table-variants.scss +24 -0
- data/node_modules/bootstrap/scss/mixins/_text-truncate.scss +8 -0
- data/node_modules/bootstrap/scss/mixins/_transition.scss +26 -0
- data/node_modules/bootstrap/scss/mixins/_utilities.scss +97 -0
- data/node_modules/bootstrap/scss/mixins/_visually-hidden.scss +38 -0
- data/node_modules/bootstrap/scss/utilities/_api.scss +47 -0
- data/node_modules/bootstrap/scss/vendor/_rfs.scss +348 -0
- metadata +448 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap collapse.js
|
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import BaseComponent from './base-component.js'
|
|
9
|
+
import EventHandler from './dom/event-handler.js'
|
|
10
|
+
import SelectorEngine from './dom/selector-engine.js'
|
|
11
|
+
import {
|
|
12
|
+
defineJQueryPlugin,
|
|
13
|
+
getElement,
|
|
14
|
+
reflow
|
|
15
|
+
} from './util/index.js'
|
|
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 = SelectorEngine.getSelectorFromElement(elem)
|
|
70
|
+
const filterElement = SelectorEngine.find(selector)
|
|
71
|
+
.filter(foundElement => foundElement === this._element)
|
|
72
|
+
|
|
73
|
+
if (selector !== null && filterElement.length) {
|
|
74
|
+
this._triggerArray.push(elem)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this._initializeChildren()
|
|
79
|
+
|
|
80
|
+
if (!this._config.parent) {
|
|
81
|
+
this._addAriaAndCollapsedClass(this._triggerArray, this._isShown())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this._config.toggle) {
|
|
85
|
+
this.toggle()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Getters
|
|
90
|
+
static get Default() {
|
|
91
|
+
return Default
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static get DefaultType() {
|
|
95
|
+
return DefaultType
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static get NAME() {
|
|
99
|
+
return NAME
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Public
|
|
103
|
+
toggle() {
|
|
104
|
+
if (this._isShown()) {
|
|
105
|
+
this.hide()
|
|
106
|
+
} else {
|
|
107
|
+
this.show()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
show() {
|
|
112
|
+
if (this._isTransitioning || this._isShown()) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let activeChildren = []
|
|
117
|
+
|
|
118
|
+
// find active children
|
|
119
|
+
if (this._config.parent) {
|
|
120
|
+
activeChildren = this._getFirstLevelChildren(SELECTOR_ACTIVES)
|
|
121
|
+
.filter(element => element !== this._element)
|
|
122
|
+
.map(element => Collapse.getOrCreateInstance(element, { toggle: false }))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (activeChildren.length && activeChildren[0]._isTransitioning) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_SHOW)
|
|
130
|
+
if (startEvent.defaultPrevented) {
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (const activeInstance of activeChildren) {
|
|
135
|
+
activeInstance.hide()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const dimension = this._getDimension()
|
|
139
|
+
|
|
140
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSE)
|
|
141
|
+
this._element.classList.add(CLASS_NAME_COLLAPSING)
|
|
142
|
+
|
|
143
|
+
this._element.style[dimension] = 0
|
|
144
|
+
|
|
145
|
+
this._addAriaAndCollapsedClass(this._triggerArray, true)
|
|
146
|
+
this._isTransitioning = true
|
|
147
|
+
|
|
148
|
+
const complete = () => {
|
|
149
|
+
this._isTransitioning = false
|
|
150
|
+
|
|
151
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSING)
|
|
152
|
+
this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
|
153
|
+
|
|
154
|
+
this._element.style[dimension] = ''
|
|
155
|
+
|
|
156
|
+
EventHandler.trigger(this._element, EVENT_SHOWN)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1)
|
|
160
|
+
const scrollSize = `scroll${capitalizedDimension}`
|
|
161
|
+
|
|
162
|
+
this._queueCallback(complete, this._element, true)
|
|
163
|
+
this._element.style[dimension] = `${this._element[scrollSize]}px`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
hide() {
|
|
167
|
+
if (this._isTransitioning || !this._isShown()) {
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_HIDE)
|
|
172
|
+
if (startEvent.defaultPrevented) {
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const dimension = this._getDimension()
|
|
177
|
+
|
|
178
|
+
this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`
|
|
179
|
+
|
|
180
|
+
reflow(this._element)
|
|
181
|
+
|
|
182
|
+
this._element.classList.add(CLASS_NAME_COLLAPSING)
|
|
183
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW)
|
|
184
|
+
|
|
185
|
+
for (const trigger of this._triggerArray) {
|
|
186
|
+
const element = SelectorEngine.getElementFromSelector(trigger)
|
|
187
|
+
|
|
188
|
+
if (element && !this._isShown(element)) {
|
|
189
|
+
this._addAriaAndCollapsedClass([trigger], false)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._isTransitioning = true
|
|
194
|
+
|
|
195
|
+
const complete = () => {
|
|
196
|
+
this._isTransitioning = false
|
|
197
|
+
this._element.classList.remove(CLASS_NAME_COLLAPSING)
|
|
198
|
+
this._element.classList.add(CLASS_NAME_COLLAPSE)
|
|
199
|
+
EventHandler.trigger(this._element, EVENT_HIDDEN)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
this._element.style[dimension] = ''
|
|
203
|
+
|
|
204
|
+
this._queueCallback(complete, this._element, true)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Private
|
|
208
|
+
_isShown(element = this._element) {
|
|
209
|
+
return element.classList.contains(CLASS_NAME_SHOW)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
_configAfterMerge(config) {
|
|
213
|
+
config.toggle = Boolean(config.toggle) // Coerce string values
|
|
214
|
+
config.parent = getElement(config.parent)
|
|
215
|
+
return config
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
_getDimension() {
|
|
219
|
+
return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_initializeChildren() {
|
|
223
|
+
if (!this._config.parent) {
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE)
|
|
228
|
+
|
|
229
|
+
for (const element of children) {
|
|
230
|
+
const selected = SelectorEngine.getElementFromSelector(element)
|
|
231
|
+
|
|
232
|
+
if (selected) {
|
|
233
|
+
this._addAriaAndCollapsedClass([element], this._isShown(selected))
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_getFirstLevelChildren(selector) {
|
|
239
|
+
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent)
|
|
240
|
+
// remove children if greater depth
|
|
241
|
+
return SelectorEngine.find(selector, this._config.parent).filter(element => !children.includes(element))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
|
245
|
+
if (!triggerArray.length) {
|
|
246
|
+
return
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (const element of triggerArray) {
|
|
250
|
+
element.classList.toggle(CLASS_NAME_COLLAPSED, !isOpen)
|
|
251
|
+
element.setAttribute('aria-expanded', isOpen)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Static
|
|
256
|
+
static jQueryInterface(config) {
|
|
257
|
+
const _config = {}
|
|
258
|
+
if (typeof config === 'string' && /show|hide/.test(config)) {
|
|
259
|
+
_config.toggle = false
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return this.each(function () {
|
|
263
|
+
const data = Collapse.getOrCreateInstance(this, _config)
|
|
264
|
+
|
|
265
|
+
if (typeof config === 'string') {
|
|
266
|
+
if (typeof data[config] === 'undefined') {
|
|
267
|
+
throw new TypeError(`No method named "${config}"`)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
data[config]()
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Data API implementation
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
|
281
|
+
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
|
|
282
|
+
if (event.target.tagName === 'A' || (event.delegateTarget && event.delegateTarget.tagName === 'A')) {
|
|
283
|
+
event.preventDefault()
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
for (const element of SelectorEngine.getMultipleElementsFromSelector(this)) {
|
|
287
|
+
Collapse.getOrCreateInstance(element, { toggle: false }).toggle()
|
|
288
|
+
}
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* jQuery
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
defineJQueryPlugin(Collapse)
|
|
296
|
+
|
|
297
|
+
export default Collapse
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap dom/data.js
|
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Constants
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const elementMap = new Map()
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
set(element, key, instance) {
|
|
16
|
+
if (!elementMap.has(element)) {
|
|
17
|
+
elementMap.set(element, new Map())
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const instanceMap = elementMap.get(element)
|
|
21
|
+
|
|
22
|
+
// make it clear we only want one instance per element
|
|
23
|
+
// can be removed later when multiple key/instances are fine to be used
|
|
24
|
+
if (!instanceMap.has(key) && instanceMap.size !== 0) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
instanceMap.set(key, instance)
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
get(element, key) {
|
|
34
|
+
if (elementMap.has(element)) {
|
|
35
|
+
return elementMap.get(element).get(key) || null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
remove(element, key) {
|
|
42
|
+
if (!elementMap.has(element)) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const instanceMap = elementMap.get(element)
|
|
47
|
+
|
|
48
|
+
instanceMap.delete(key)
|
|
49
|
+
|
|
50
|
+
// free up element references if there are no instances left for an element
|
|
51
|
+
if (instanceMap.size === 0) {
|
|
52
|
+
elementMap.delete(element)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap dom/event-handler.js
|
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
5
|
+
* --------------------------------------------------------------------------
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getjQuery } from '../util/index.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Constants
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
|
|
15
|
+
const stripNameRegex = /\..*/
|
|
16
|
+
const stripUidRegex = /::\d+$/
|
|
17
|
+
const eventRegistry = {} // Events storage
|
|
18
|
+
let uidEvent = 1
|
|
19
|
+
const customEvents = {
|
|
20
|
+
mouseenter: 'mouseover',
|
|
21
|
+
mouseleave: 'mouseout'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const nativeEvents = new Set([
|
|
25
|
+
'click',
|
|
26
|
+
'dblclick',
|
|
27
|
+
'mouseup',
|
|
28
|
+
'mousedown',
|
|
29
|
+
'contextmenu',
|
|
30
|
+
'mousewheel',
|
|
31
|
+
'DOMMouseScroll',
|
|
32
|
+
'mouseover',
|
|
33
|
+
'mouseout',
|
|
34
|
+
'mousemove',
|
|
35
|
+
'selectstart',
|
|
36
|
+
'selectend',
|
|
37
|
+
'keydown',
|
|
38
|
+
'keypress',
|
|
39
|
+
'keyup',
|
|
40
|
+
'orientationchange',
|
|
41
|
+
'touchstart',
|
|
42
|
+
'touchmove',
|
|
43
|
+
'touchend',
|
|
44
|
+
'touchcancel',
|
|
45
|
+
'pointerdown',
|
|
46
|
+
'pointermove',
|
|
47
|
+
'pointerup',
|
|
48
|
+
'pointerleave',
|
|
49
|
+
'pointercancel',
|
|
50
|
+
'gesturestart',
|
|
51
|
+
'gesturechange',
|
|
52
|
+
'gestureend',
|
|
53
|
+
'focus',
|
|
54
|
+
'blur',
|
|
55
|
+
'change',
|
|
56
|
+
'reset',
|
|
57
|
+
'select',
|
|
58
|
+
'submit',
|
|
59
|
+
'focusin',
|
|
60
|
+
'focusout',
|
|
61
|
+
'load',
|
|
62
|
+
'unload',
|
|
63
|
+
'beforeunload',
|
|
64
|
+
'resize',
|
|
65
|
+
'move',
|
|
66
|
+
'DOMContentLoaded',
|
|
67
|
+
'readystatechange',
|
|
68
|
+
'error',
|
|
69
|
+
'abort',
|
|
70
|
+
'scroll'
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Private methods
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
function makeEventUid(element, uid) {
|
|
78
|
+
return (uid && `${uid}::${uidEvent++}`) || element.uidEvent || uidEvent++
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getElementEvents(element) {
|
|
82
|
+
const uid = makeEventUid(element)
|
|
83
|
+
|
|
84
|
+
element.uidEvent = uid
|
|
85
|
+
eventRegistry[uid] = eventRegistry[uid] || {}
|
|
86
|
+
|
|
87
|
+
return eventRegistry[uid]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function bootstrapHandler(element, fn) {
|
|
91
|
+
return function handler(event) {
|
|
92
|
+
hydrateObj(event, { delegateTarget: element })
|
|
93
|
+
|
|
94
|
+
if (handler.oneOff) {
|
|
95
|
+
EventHandler.off(element, event.type, fn)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return fn.apply(element, [event])
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function bootstrapDelegationHandler(element, selector, fn) {
|
|
103
|
+
return function handler(event) {
|
|
104
|
+
const domElements = element.querySelectorAll(selector)
|
|
105
|
+
|
|
106
|
+
for (let { target } = event; target && target !== this; target = target.parentNode) {
|
|
107
|
+
for (const domElement of domElements) {
|
|
108
|
+
if (domElement !== target) {
|
|
109
|
+
continue
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
hydrateObj(event, { delegateTarget: target })
|
|
113
|
+
|
|
114
|
+
if (handler.oneOff) {
|
|
115
|
+
EventHandler.off(element, event.type, selector, fn)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return fn.apply(target, [event])
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function findHandler(events, callable, delegationSelector = null) {
|
|
125
|
+
return Object.values(events)
|
|
126
|
+
.find(event => event.callable === callable && event.delegationSelector === delegationSelector)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function normalizeParameters(originalTypeEvent, handler, delegationFunction) {
|
|
130
|
+
const isDelegated = typeof handler === 'string'
|
|
131
|
+
// TODO: tooltip passes `false` instead of selector, so we need to check
|
|
132
|
+
const callable = isDelegated ? delegationFunction : (handler || delegationFunction)
|
|
133
|
+
let typeEvent = getTypeEvent(originalTypeEvent)
|
|
134
|
+
|
|
135
|
+
if (!nativeEvents.has(typeEvent)) {
|
|
136
|
+
typeEvent = originalTypeEvent
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return [isDelegated, callable, typeEvent]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function addHandler(element, originalTypeEvent, handler, delegationFunction, oneOff) {
|
|
143
|
+
if (typeof originalTypeEvent !== 'string' || !element) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction)
|
|
148
|
+
|
|
149
|
+
// in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position
|
|
150
|
+
// this prevents the handler from being dispatched the same way as mouseover or mouseout does
|
|
151
|
+
if (originalTypeEvent in customEvents) {
|
|
152
|
+
const wrapFunction = fn => {
|
|
153
|
+
return function (event) {
|
|
154
|
+
if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget))) {
|
|
155
|
+
return fn.call(this, event)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
callable = wrapFunction(callable)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const events = getElementEvents(element)
|
|
164
|
+
const handlers = events[typeEvent] || (events[typeEvent] = {})
|
|
165
|
+
const previousFunction = findHandler(handlers, callable, isDelegated ? handler : null)
|
|
166
|
+
|
|
167
|
+
if (previousFunction) {
|
|
168
|
+
previousFunction.oneOff = previousFunction.oneOff && oneOff
|
|
169
|
+
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const uid = makeEventUid(callable, originalTypeEvent.replace(namespaceRegex, ''))
|
|
174
|
+
const fn = isDelegated ?
|
|
175
|
+
bootstrapDelegationHandler(element, handler, callable) :
|
|
176
|
+
bootstrapHandler(element, callable)
|
|
177
|
+
|
|
178
|
+
fn.delegationSelector = isDelegated ? handler : null
|
|
179
|
+
fn.callable = callable
|
|
180
|
+
fn.oneOff = oneOff
|
|
181
|
+
fn.uidEvent = uid
|
|
182
|
+
handlers[uid] = fn
|
|
183
|
+
|
|
184
|
+
element.addEventListener(typeEvent, fn, isDelegated)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function removeHandler(element, events, typeEvent, handler, delegationSelector) {
|
|
188
|
+
const fn = findHandler(events[typeEvent], handler, delegationSelector)
|
|
189
|
+
|
|
190
|
+
if (!fn) {
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
element.removeEventListener(typeEvent, fn, Boolean(delegationSelector))
|
|
195
|
+
delete events[typeEvent][fn.uidEvent]
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
|
199
|
+
const storeElementEvent = events[typeEvent] || {}
|
|
200
|
+
|
|
201
|
+
for (const [handlerKey, event] of Object.entries(storeElementEvent)) {
|
|
202
|
+
if (handlerKey.includes(namespace)) {
|
|
203
|
+
removeHandler(element, events, typeEvent, event.callable, event.delegationSelector)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getTypeEvent(event) {
|
|
209
|
+
// allow to get the native events from namespaced events ('click.bs.button' --> 'click')
|
|
210
|
+
event = event.replace(stripNameRegex, '')
|
|
211
|
+
return customEvents[event] || event
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const EventHandler = {
|
|
215
|
+
on(element, event, handler, delegationFunction) {
|
|
216
|
+
addHandler(element, event, handler, delegationFunction, false)
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
one(element, event, handler, delegationFunction) {
|
|
220
|
+
addHandler(element, event, handler, delegationFunction, true)
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
off(element, originalTypeEvent, handler, delegationFunction) {
|
|
224
|
+
if (typeof originalTypeEvent !== 'string' || !element) {
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction)
|
|
229
|
+
const inNamespace = typeEvent !== originalTypeEvent
|
|
230
|
+
const events = getElementEvents(element)
|
|
231
|
+
const storeElementEvent = events[typeEvent] || {}
|
|
232
|
+
const isNamespace = originalTypeEvent.startsWith('.')
|
|
233
|
+
|
|
234
|
+
if (typeof callable !== 'undefined') {
|
|
235
|
+
// Simplest case: handler is passed, remove that listener ONLY.
|
|
236
|
+
if (!Object.keys(storeElementEvent).length) {
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
removeHandler(element, events, typeEvent, callable, isDelegated ? handler : null)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (isNamespace) {
|
|
245
|
+
for (const elementEvent of Object.keys(events)) {
|
|
246
|
+
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1))
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
for (const [keyHandlers, event] of Object.entries(storeElementEvent)) {
|
|
251
|
+
const handlerKey = keyHandlers.replace(stripUidRegex, '')
|
|
252
|
+
|
|
253
|
+
if (!inNamespace || originalTypeEvent.includes(handlerKey)) {
|
|
254
|
+
removeHandler(element, events, typeEvent, event.callable, event.delegationSelector)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
trigger(element, event, args) {
|
|
260
|
+
if (typeof event !== 'string' || !element) {
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const $ = getjQuery()
|
|
265
|
+
const typeEvent = getTypeEvent(event)
|
|
266
|
+
const inNamespace = event !== typeEvent
|
|
267
|
+
|
|
268
|
+
let jQueryEvent = null
|
|
269
|
+
let bubbles = true
|
|
270
|
+
let nativeDispatch = true
|
|
271
|
+
let defaultPrevented = false
|
|
272
|
+
|
|
273
|
+
if (inNamespace && $) {
|
|
274
|
+
jQueryEvent = $.Event(event, args)
|
|
275
|
+
|
|
276
|
+
$(element).trigger(jQueryEvent)
|
|
277
|
+
bubbles = !jQueryEvent.isPropagationStopped()
|
|
278
|
+
nativeDispatch = !jQueryEvent.isImmediatePropagationStopped()
|
|
279
|
+
defaultPrevented = jQueryEvent.isDefaultPrevented()
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const evt = hydrateObj(new Event(event, { bubbles, cancelable: true }), args)
|
|
283
|
+
|
|
284
|
+
if (defaultPrevented) {
|
|
285
|
+
evt.preventDefault()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (nativeDispatch) {
|
|
289
|
+
element.dispatchEvent(evt)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (evt.defaultPrevented && jQueryEvent) {
|
|
293
|
+
jQueryEvent.preventDefault()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return evt
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function hydrateObj(obj, meta = {}) {
|
|
301
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
302
|
+
try {
|
|
303
|
+
obj[key] = value
|
|
304
|
+
} catch {
|
|
305
|
+
Object.defineProperty(obj, key, {
|
|
306
|
+
configurable: true,
|
|
307
|
+
get() {
|
|
308
|
+
return value
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return obj
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export default EventHandler
|