bootstrap 5.2.3 → 5.3.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/assets/javascripts/bootstrap/alert.js +21 -32
- data/assets/javascripts/bootstrap/base-component.js +21 -38
- data/assets/javascripts/bootstrap/button.js +18 -22
- data/assets/javascripts/bootstrap/carousel.js +51 -135
- data/assets/javascripts/bootstrap/collapse.js +39 -102
- data/assets/javascripts/bootstrap/dom/data.js +8 -12
- data/assets/javascripts/bootstrap/dom/event-handler.js +18 -66
- data/assets/javascripts/bootstrap/dom/manipulator.js +4 -17
- data/assets/javascripts/bootstrap/dom/selector-engine.js +41 -24
- data/assets/javascripts/bootstrap/dropdown.js +73 -145
- data/assets/javascripts/bootstrap/modal.js +52 -133
- data/assets/javascripts/bootstrap/offcanvas.js +49 -102
- data/assets/javascripts/bootstrap/popover.js +22 -29
- data/assets/javascripts/bootstrap/scrollspy.js +51 -89
- data/assets/javascripts/bootstrap/tab.js +51 -109
- data/assets/javascripts/bootstrap/toast.js +30 -73
- data/assets/javascripts/bootstrap/tooltip.js +74 -177
- data/assets/javascripts/bootstrap/util/backdrop.js +27 -54
- data/assets/javascripts/bootstrap/util/component-functions.js +13 -19
- data/assets/javascripts/bootstrap/util/config.js +14 -27
- data/assets/javascripts/bootstrap/util/focustrap.js +19 -36
- data/assets/javascripts/bootstrap/util/index.js +42 -111
- data/assets/javascripts/bootstrap/util/sanitizer.js +13 -19
- data/assets/javascripts/bootstrap/util/scrollbar.js +23 -50
- data/assets/javascripts/bootstrap/util/swipe.js +26 -48
- data/assets/javascripts/bootstrap/util/template-factory.js +24 -52
- data/assets/javascripts/bootstrap-sprockets.js +1 -1
- data/assets/javascripts/bootstrap.js +626 -1406
- data/assets/javascripts/bootstrap.min.js +3 -3
- data/assets/stylesheets/_bootstrap-grid.scss +1 -3
- data/assets/stylesheets/_bootstrap-reboot.scss +1 -0
- data/assets/stylesheets/_bootstrap.scss +1 -0
- data/assets/stylesheets/bootstrap/_accordion.scss +9 -0
- data/assets/stylesheets/bootstrap/_alert.scss +8 -11
- data/assets/stylesheets/bootstrap/_button-group.scss +2 -2
- data/assets/stylesheets/bootstrap/_buttons.scss +3 -3
- data/assets/stylesheets/bootstrap/_card.scss +5 -0
- data/assets/stylesheets/bootstrap/_carousel.scss +20 -2
- data/assets/stylesheets/bootstrap/_close.scss +32 -9
- data/assets/stylesheets/bootstrap/_dropdown.scss +1 -0
- data/assets/stylesheets/bootstrap/_functions.scss +1 -1
- data/assets/stylesheets/bootstrap/_grid.scss +6 -0
- data/assets/stylesheets/bootstrap/_helpers.scss +2 -0
- data/assets/stylesheets/bootstrap/_list-group.scss +12 -7
- data/assets/stylesheets/bootstrap/_maps.scss +120 -0
- data/assets/stylesheets/bootstrap/_mixins.scss +1 -2
- data/assets/stylesheets/bootstrap/_nav.scss +40 -3
- data/assets/stylesheets/bootstrap/_navbar.scss +13 -3
- data/assets/stylesheets/bootstrap/_offcanvas.scss +4 -2
- data/assets/stylesheets/bootstrap/_pagination.scss +1 -1
- data/assets/stylesheets/bootstrap/_progress.scss +10 -1
- data/assets/stylesheets/bootstrap/_reboot.scss +3 -3
- data/assets/stylesheets/bootstrap/_root.scss +125 -10
- data/assets/stylesheets/bootstrap/_tables.scss +1 -1
- data/assets/stylesheets/bootstrap/_tooltip.scss +4 -5
- data/assets/stylesheets/bootstrap/_utilities.scss +172 -13
- data/assets/stylesheets/bootstrap/_variables-dark.scss +85 -0
- data/assets/stylesheets/bootstrap/_variables.scss +260 -151
- data/assets/stylesheets/bootstrap/bootstrap-utilities.scss +1 -0
- data/assets/stylesheets/bootstrap/forms/_floating-labels.scss +21 -3
- data/assets/stylesheets/bootstrap/forms/_form-check.scss +24 -11
- data/assets/stylesheets/bootstrap/forms/_form-control.scss +23 -3
- data/assets/stylesheets/bootstrap/forms/_form-select.scss +11 -2
- data/assets/stylesheets/bootstrap/forms/_input-group.scss +1 -1
- data/assets/stylesheets/bootstrap/helpers/_colored-links.scss +22 -2
- data/assets/stylesheets/bootstrap/helpers/_focus-ring.scss +5 -0
- data/assets/stylesheets/bootstrap/helpers/_icon-link.scss +25 -0
- data/assets/stylesheets/bootstrap/mixins/_alert.scss +4 -1
- data/assets/stylesheets/bootstrap/mixins/_banner.scss +2 -4
- data/assets/stylesheets/bootstrap/mixins/_caret.scss +30 -25
- data/assets/stylesheets/bootstrap/mixins/_color-mode.scss +21 -0
- data/assets/stylesheets/bootstrap/mixins/_forms.scss +8 -7
- data/assets/stylesheets/bootstrap/mixins/_list-group.scss +2 -0
- data/assets/stylesheets/bootstrap/mixins/_utilities.scss +1 -1
- data/assets/stylesheets/bootstrap/mixins/_visually-hidden.scss +5 -1
- data/assets/stylesheets/bootstrap/vendor/_rfs.scss +23 -29
- data/bootstrap.gemspec +1 -1
- data/lib/bootstrap/version.rb +2 -2
- data/tasks/updater/js.rb +1 -1
- data/tasks/updater/scss.rb +1 -1
- metadata +10 -6
@@ -1,26 +1,21 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap collapse.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap collapse.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./
|
8
|
-
typeof define === 'function' && define.amd ? define(['./
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.
|
10
|
-
})(this, (function (
|
11
|
-
|
12
|
-
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
13
|
-
|
14
|
-
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
15
|
-
const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
16
|
-
const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./base-component.js'), require('./dom/event-handler.js'), require('./dom/selector-engine.js'), require('./util/index.js')) :
|
8
|
+
typeof define === 'function' && define.amd ? define(['./base-component', './dom/event-handler', './dom/selector-engine', './util/index'], factory) :
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Collapse = factory(global.BaseComponent, global.EventHandler, global.SelectorEngine, global.Index));
|
10
|
+
})(this, (function (BaseComponent, EventHandler, SelectorEngine, index_js) { 'use strict';
|
17
11
|
|
18
12
|
/**
|
19
13
|
* --------------------------------------------------------------------------
|
20
|
-
* Bootstrap
|
14
|
+
* Bootstrap collapse.js
|
21
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
22
16
|
* --------------------------------------------------------------------------
|
23
17
|
*/
|
18
|
+
|
24
19
|
/**
|
25
20
|
* Constants
|
26
21
|
*/
|
@@ -52,51 +47,45 @@
|
|
52
47
|
parent: '(null|element)',
|
53
48
|
toggle: 'boolean'
|
54
49
|
};
|
50
|
+
|
55
51
|
/**
|
56
52
|
* Class definition
|
57
53
|
*/
|
58
54
|
|
59
|
-
class Collapse extends
|
55
|
+
class Collapse extends BaseComponent {
|
60
56
|
constructor(element, config) {
|
61
57
|
super(element, config);
|
62
58
|
this._isTransitioning = false;
|
63
59
|
this._triggerArray = [];
|
64
|
-
const toggleList =
|
65
|
-
|
60
|
+
const toggleList = SelectorEngine.find(SELECTOR_DATA_TOGGLE);
|
66
61
|
for (const elem of toggleList) {
|
67
|
-
const selector =
|
68
|
-
const filterElement =
|
69
|
-
|
62
|
+
const selector = SelectorEngine.getSelectorFromElement(elem);
|
63
|
+
const filterElement = SelectorEngine.find(selector).filter(foundElement => foundElement === this._element);
|
70
64
|
if (selector !== null && filterElement.length) {
|
71
65
|
this._triggerArray.push(elem);
|
72
66
|
}
|
73
67
|
}
|
74
|
-
|
75
68
|
this._initializeChildren();
|
76
|
-
|
77
69
|
if (!this._config.parent) {
|
78
70
|
this._addAriaAndCollapsedClass(this._triggerArray, this._isShown());
|
79
71
|
}
|
80
|
-
|
81
72
|
if (this._config.toggle) {
|
82
73
|
this.toggle();
|
83
74
|
}
|
84
|
-
}
|
85
|
-
|
75
|
+
}
|
86
76
|
|
77
|
+
// Getters
|
87
78
|
static get Default() {
|
88
79
|
return Default;
|
89
80
|
}
|
90
|
-
|
91
81
|
static get DefaultType() {
|
92
82
|
return DefaultType;
|
93
83
|
}
|
94
|
-
|
95
84
|
static get NAME() {
|
96
85
|
return NAME;
|
97
|
-
}
|
98
|
-
|
86
|
+
}
|
99
87
|
|
88
|
+
// Public
|
100
89
|
toggle() {
|
101
90
|
if (this._isShown()) {
|
102
91
|
this.hide();
|
@@ -104,206 +93,154 @@
|
|
104
93
|
this.show();
|
105
94
|
}
|
106
95
|
}
|
107
|
-
|
108
96
|
show() {
|
109
97
|
if (this._isTransitioning || this._isShown()) {
|
110
98
|
return;
|
111
99
|
}
|
100
|
+
let activeChildren = [];
|
112
101
|
|
113
|
-
|
114
|
-
|
102
|
+
// find active children
|
115
103
|
if (this._config.parent) {
|
116
104
|
activeChildren = this._getFirstLevelChildren(SELECTOR_ACTIVES).filter(element => element !== this._element).map(element => Collapse.getOrCreateInstance(element, {
|
117
105
|
toggle: false
|
118
106
|
}));
|
119
107
|
}
|
120
|
-
|
121
108
|
if (activeChildren.length && activeChildren[0]._isTransitioning) {
|
122
109
|
return;
|
123
110
|
}
|
124
|
-
|
125
|
-
const startEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW);
|
126
|
-
|
111
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_SHOW);
|
127
112
|
if (startEvent.defaultPrevented) {
|
128
113
|
return;
|
129
114
|
}
|
130
|
-
|
131
115
|
for (const activeInstance of activeChildren) {
|
132
116
|
activeInstance.hide();
|
133
117
|
}
|
134
|
-
|
135
118
|
const dimension = this._getDimension();
|
136
|
-
|
137
119
|
this._element.classList.remove(CLASS_NAME_COLLAPSE);
|
138
|
-
|
139
120
|
this._element.classList.add(CLASS_NAME_COLLAPSING);
|
140
|
-
|
141
121
|
this._element.style[dimension] = 0;
|
142
|
-
|
143
122
|
this._addAriaAndCollapsedClass(this._triggerArray, true);
|
144
|
-
|
145
123
|
this._isTransitioning = true;
|
146
|
-
|
147
124
|
const complete = () => {
|
148
125
|
this._isTransitioning = false;
|
149
|
-
|
150
126
|
this._element.classList.remove(CLASS_NAME_COLLAPSING);
|
151
|
-
|
152
127
|
this._element.classList.add(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
|
153
|
-
|
154
128
|
this._element.style[dimension] = '';
|
155
|
-
|
129
|
+
EventHandler.trigger(this._element, EVENT_SHOWN);
|
156
130
|
};
|
157
|
-
|
158
131
|
const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1);
|
159
132
|
const scrollSize = `scroll${capitalizedDimension}`;
|
160
|
-
|
161
133
|
this._queueCallback(complete, this._element, true);
|
162
|
-
|
163
134
|
this._element.style[dimension] = `${this._element[scrollSize]}px`;
|
164
135
|
}
|
165
|
-
|
166
136
|
hide() {
|
167
137
|
if (this._isTransitioning || !this._isShown()) {
|
168
138
|
return;
|
169
139
|
}
|
170
|
-
|
171
|
-
const startEvent = EventHandler__default.default.trigger(this._element, EVENT_HIDE);
|
172
|
-
|
140
|
+
const startEvent = EventHandler.trigger(this._element, EVENT_HIDE);
|
173
141
|
if (startEvent.defaultPrevented) {
|
174
142
|
return;
|
175
143
|
}
|
176
|
-
|
177
144
|
const dimension = this._getDimension();
|
178
|
-
|
179
145
|
this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px`;
|
180
|
-
|
181
|
-
|
146
|
+
index_js.reflow(this._element);
|
182
147
|
this._element.classList.add(CLASS_NAME_COLLAPSING);
|
183
|
-
|
184
148
|
this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW);
|
185
|
-
|
186
149
|
for (const trigger of this._triggerArray) {
|
187
|
-
const element =
|
188
|
-
|
150
|
+
const element = SelectorEngine.getElementFromSelector(trigger);
|
189
151
|
if (element && !this._isShown(element)) {
|
190
152
|
this._addAriaAndCollapsedClass([trigger], false);
|
191
153
|
}
|
192
154
|
}
|
193
|
-
|
194
155
|
this._isTransitioning = true;
|
195
|
-
|
196
156
|
const complete = () => {
|
197
157
|
this._isTransitioning = false;
|
198
|
-
|
199
158
|
this._element.classList.remove(CLASS_NAME_COLLAPSING);
|
200
|
-
|
201
159
|
this._element.classList.add(CLASS_NAME_COLLAPSE);
|
202
|
-
|
203
|
-
EventHandler__default.default.trigger(this._element, EVENT_HIDDEN);
|
160
|
+
EventHandler.trigger(this._element, EVENT_HIDDEN);
|
204
161
|
};
|
205
|
-
|
206
162
|
this._element.style[dimension] = '';
|
207
|
-
|
208
163
|
this._queueCallback(complete, this._element, true);
|
209
164
|
}
|
210
|
-
|
211
165
|
_isShown(element = this._element) {
|
212
166
|
return element.classList.contains(CLASS_NAME_SHOW);
|
213
|
-
}
|
214
|
-
|
167
|
+
}
|
215
168
|
|
169
|
+
// Private
|
216
170
|
_configAfterMerge(config) {
|
217
171
|
config.toggle = Boolean(config.toggle); // Coerce string values
|
218
|
-
|
219
|
-
config.parent = index.getElement(config.parent);
|
172
|
+
config.parent = index_js.getElement(config.parent);
|
220
173
|
return config;
|
221
174
|
}
|
222
|
-
|
223
175
|
_getDimension() {
|
224
176
|
return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT;
|
225
177
|
}
|
226
|
-
|
227
178
|
_initializeChildren() {
|
228
179
|
if (!this._config.parent) {
|
229
180
|
return;
|
230
181
|
}
|
231
|
-
|
232
182
|
const children = this._getFirstLevelChildren(SELECTOR_DATA_TOGGLE);
|
233
|
-
|
234
183
|
for (const element of children) {
|
235
|
-
const selected =
|
236
|
-
|
184
|
+
const selected = SelectorEngine.getElementFromSelector(element);
|
237
185
|
if (selected) {
|
238
186
|
this._addAriaAndCollapsedClass([element], this._isShown(selected));
|
239
187
|
}
|
240
188
|
}
|
241
189
|
}
|
242
|
-
|
243
190
|
_getFirstLevelChildren(selector) {
|
244
|
-
const children =
|
245
|
-
|
246
|
-
return
|
191
|
+
const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent);
|
192
|
+
// remove children if greater depth
|
193
|
+
return SelectorEngine.find(selector, this._config.parent).filter(element => !children.includes(element));
|
247
194
|
}
|
248
|
-
|
249
195
|
_addAriaAndCollapsedClass(triggerArray, isOpen) {
|
250
196
|
if (!triggerArray.length) {
|
251
197
|
return;
|
252
198
|
}
|
253
|
-
|
254
199
|
for (const element of triggerArray) {
|
255
200
|
element.classList.toggle(CLASS_NAME_COLLAPSED, !isOpen);
|
256
201
|
element.setAttribute('aria-expanded', isOpen);
|
257
202
|
}
|
258
|
-
}
|
259
|
-
|
203
|
+
}
|
260
204
|
|
205
|
+
// Static
|
261
206
|
static jQueryInterface(config) {
|
262
207
|
const _config = {};
|
263
|
-
|
264
208
|
if (typeof config === 'string' && /show|hide/.test(config)) {
|
265
209
|
_config.toggle = false;
|
266
210
|
}
|
267
|
-
|
268
211
|
return this.each(function () {
|
269
212
|
const data = Collapse.getOrCreateInstance(this, _config);
|
270
|
-
|
271
213
|
if (typeof config === 'string') {
|
272
214
|
if (typeof data[config] === 'undefined') {
|
273
215
|
throw new TypeError(`No method named "${config}"`);
|
274
216
|
}
|
275
|
-
|
276
217
|
data[config]();
|
277
218
|
}
|
278
219
|
});
|
279
220
|
}
|
280
|
-
|
281
221
|
}
|
222
|
+
|
282
223
|
/**
|
283
224
|
* Data API implementation
|
284
225
|
*/
|
285
226
|
|
286
|
-
|
287
|
-
EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
227
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
288
228
|
// preventDefault only for <a> elements (which change the URL) not inside the collapsible element
|
289
229
|
if (event.target.tagName === 'A' || event.delegateTarget && event.delegateTarget.tagName === 'A') {
|
290
230
|
event.preventDefault();
|
291
231
|
}
|
292
|
-
|
293
|
-
const selector = index.getSelectorFromElement(this);
|
294
|
-
const selectorElements = SelectorEngine__default.default.find(selector);
|
295
|
-
|
296
|
-
for (const element of selectorElements) {
|
232
|
+
for (const element of SelectorEngine.getMultipleElementsFromSelector(this)) {
|
297
233
|
Collapse.getOrCreateInstance(element, {
|
298
234
|
toggle: false
|
299
235
|
}).toggle();
|
300
236
|
}
|
301
237
|
});
|
238
|
+
|
302
239
|
/**
|
303
240
|
* jQuery
|
304
241
|
*/
|
305
242
|
|
306
|
-
|
243
|
+
index_js.defineJQueryPlugin(Collapse);
|
307
244
|
|
308
245
|
return Collapse;
|
309
246
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap data.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap data.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
/**
|
13
13
|
* --------------------------------------------------------------------------
|
14
|
-
* Bootstrap
|
14
|
+
* Bootstrap dom/data.js
|
15
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
16
16
|
* --------------------------------------------------------------------------
|
17
17
|
*/
|
@@ -19,46 +19,42 @@
|
|
19
19
|
/**
|
20
20
|
* Constants
|
21
21
|
*/
|
22
|
+
|
22
23
|
const elementMap = new Map();
|
23
24
|
const data = {
|
24
25
|
set(element, key, instance) {
|
25
26
|
if (!elementMap.has(element)) {
|
26
27
|
elementMap.set(element, new Map());
|
27
28
|
}
|
29
|
+
const instanceMap = elementMap.get(element);
|
28
30
|
|
29
|
-
|
31
|
+
// make it clear we only want one instance per element
|
30
32
|
// can be removed later when multiple key/instances are fine to be used
|
31
|
-
|
32
33
|
if (!instanceMap.has(key) && instanceMap.size !== 0) {
|
33
34
|
// eslint-disable-next-line no-console
|
34
35
|
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
|
35
36
|
return;
|
36
37
|
}
|
37
|
-
|
38
38
|
instanceMap.set(key, instance);
|
39
39
|
},
|
40
|
-
|
41
40
|
get(element, key) {
|
42
41
|
if (elementMap.has(element)) {
|
43
42
|
return elementMap.get(element).get(key) || null;
|
44
43
|
}
|
45
|
-
|
46
44
|
return null;
|
47
45
|
},
|
48
|
-
|
49
46
|
remove(element, key) {
|
50
47
|
if (!elementMap.has(element)) {
|
51
48
|
return;
|
52
49
|
}
|
53
|
-
|
54
50
|
const instanceMap = elementMap.get(element);
|
55
|
-
instanceMap.delete(key);
|
51
|
+
instanceMap.delete(key);
|
56
52
|
|
53
|
+
// free up element references if there are no instances left for an element
|
57
54
|
if (instanceMap.size === 0) {
|
58
55
|
elementMap.delete(element);
|
59
56
|
}
|
60
57
|
}
|
61
|
-
|
62
58
|
};
|
63
59
|
|
64
60
|
return data;
|
@@ -1,20 +1,21 @@
|
|
1
1
|
/*!
|
2
|
-
* Bootstrap event-handler.js v5.
|
3
|
-
* Copyright 2011-
|
2
|
+
* Bootstrap event-handler.js v5.3.0-alpha3 (https://getbootstrap.com/)
|
3
|
+
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
4
4
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
5
|
*/
|
6
6
|
(function (global, factory) {
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../util/index')) :
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../util/index.js')) :
|
8
8
|
typeof define === 'function' && define.amd ? define(['../util/index'], factory) :
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.EventHandler = factory(global.Index));
|
10
|
-
})(this, (function (
|
10
|
+
})(this, (function (index_js) { 'use strict';
|
11
11
|
|
12
12
|
/**
|
13
13
|
* --------------------------------------------------------------------------
|
14
|
-
* Bootstrap
|
14
|
+
* Bootstrap dom/event-handler.js
|
15
15
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
16
16
|
* --------------------------------------------------------------------------
|
17
17
|
*/
|
18
|
+
|
18
19
|
/**
|
19
20
|
* Constants
|
20
21
|
*/
|
@@ -23,13 +24,13 @@
|
|
23
24
|
const stripNameRegex = /\..*/;
|
24
25
|
const stripUidRegex = /::\d+$/;
|
25
26
|
const eventRegistry = {}; // Events storage
|
26
|
-
|
27
27
|
let uidEvent = 1;
|
28
28
|
const customEvents = {
|
29
29
|
mouseenter: 'mouseover',
|
30
30
|
mouseleave: 'mouseout'
|
31
31
|
};
|
32
32
|
const nativeEvents = new Set(['click', 'dblclick', 'mouseup', 'mousedown', 'contextmenu', 'mousewheel', 'DOMMouseScroll', 'mouseover', 'mouseout', 'mousemove', 'selectstart', 'selectend', 'keydown', 'keypress', 'keyup', 'orientationchange', 'touchstart', 'touchmove', 'touchend', 'touchcancel', 'pointerdown', 'pointermove', 'pointerup', 'pointerleave', 'pointercancel', 'gesturestart', 'gesturechange', 'gestureend', 'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout', 'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange', 'error', 'abort', 'scroll']);
|
33
|
+
|
33
34
|
/**
|
34
35
|
* Private methods
|
35
36
|
*/
|
@@ -37,32 +38,26 @@
|
|
37
38
|
function makeEventUid(element, uid) {
|
38
39
|
return uid && `${uid}::${uidEvent++}` || element.uidEvent || uidEvent++;
|
39
40
|
}
|
40
|
-
|
41
41
|
function getElementEvents(element) {
|
42
42
|
const uid = makeEventUid(element);
|
43
43
|
element.uidEvent = uid;
|
44
44
|
eventRegistry[uid] = eventRegistry[uid] || {};
|
45
45
|
return eventRegistry[uid];
|
46
46
|
}
|
47
|
-
|
48
47
|
function bootstrapHandler(element, fn) {
|
49
48
|
return function handler(event) {
|
50
49
|
hydrateObj(event, {
|
51
50
|
delegateTarget: element
|
52
51
|
});
|
53
|
-
|
54
52
|
if (handler.oneOff) {
|
55
53
|
EventHandler.off(element, event.type, fn);
|
56
54
|
}
|
57
|
-
|
58
55
|
return fn.apply(element, [event]);
|
59
56
|
};
|
60
57
|
}
|
61
|
-
|
62
58
|
function bootstrapDelegationHandler(element, selector, fn) {
|
63
59
|
return function handler(event) {
|
64
60
|
const domElements = element.querySelectorAll(selector);
|
65
|
-
|
66
61
|
for (let {
|
67
62
|
target
|
68
63
|
} = event; target && target !== this; target = target.parentNode) {
|
@@ -70,46 +65,38 @@
|
|
70
65
|
if (domElement !== target) {
|
71
66
|
continue;
|
72
67
|
}
|
73
|
-
|
74
68
|
hydrateObj(event, {
|
75
69
|
delegateTarget: target
|
76
70
|
});
|
77
|
-
|
78
71
|
if (handler.oneOff) {
|
79
72
|
EventHandler.off(element, event.type, selector, fn);
|
80
73
|
}
|
81
|
-
|
82
74
|
return fn.apply(target, [event]);
|
83
75
|
}
|
84
76
|
}
|
85
77
|
};
|
86
78
|
}
|
87
|
-
|
88
79
|
function findHandler(events, callable, delegationSelector = null) {
|
89
80
|
return Object.values(events).find(event => event.callable === callable && event.delegationSelector === delegationSelector);
|
90
81
|
}
|
91
|
-
|
92
82
|
function normalizeParameters(originalTypeEvent, handler, delegationFunction) {
|
93
|
-
const isDelegated = typeof handler === 'string';
|
94
|
-
|
83
|
+
const isDelegated = typeof handler === 'string';
|
84
|
+
// TODO: tooltip passes `false` instead of selector, so we need to check
|
95
85
|
const callable = isDelegated ? delegationFunction : handler || delegationFunction;
|
96
86
|
let typeEvent = getTypeEvent(originalTypeEvent);
|
97
|
-
|
98
87
|
if (!nativeEvents.has(typeEvent)) {
|
99
88
|
typeEvent = originalTypeEvent;
|
100
89
|
}
|
101
|
-
|
102
90
|
return [isDelegated, callable, typeEvent];
|
103
91
|
}
|
104
|
-
|
105
92
|
function addHandler(element, originalTypeEvent, handler, delegationFunction, oneOff) {
|
106
93
|
if (typeof originalTypeEvent !== 'string' || !element) {
|
107
94
|
return;
|
108
95
|
}
|
96
|
+
let [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction);
|
109
97
|
|
110
|
-
|
98
|
+
// in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position
|
111
99
|
// this prevents the handler from being dispatched the same way as mouseover or mouseout does
|
112
|
-
|
113
100
|
if (originalTypeEvent in customEvents) {
|
114
101
|
const wrapFunction = fn => {
|
115
102
|
return function (event) {
|
@@ -118,19 +105,15 @@
|
|
118
105
|
}
|
119
106
|
};
|
120
107
|
};
|
121
|
-
|
122
108
|
callable = wrapFunction(callable);
|
123
109
|
}
|
124
|
-
|
125
110
|
const events = getElementEvents(element);
|
126
111
|
const handlers = events[typeEvent] || (events[typeEvent] = {});
|
127
112
|
const previousFunction = findHandler(handlers, callable, isDelegated ? handler : null);
|
128
|
-
|
129
113
|
if (previousFunction) {
|
130
114
|
previousFunction.oneOff = previousFunction.oneOff && oneOff;
|
131
115
|
return;
|
132
116
|
}
|
133
|
-
|
134
117
|
const uid = makeEventUid(callable, originalTypeEvent.replace(namespaceRegex, ''));
|
135
118
|
const fn = isDelegated ? bootstrapDelegationHandler(element, handler, callable) : bootstrapHandler(element, callable);
|
136
119
|
fn.delegationSelector = isDelegated ? handler : null;
|
@@ -140,94 +123,74 @@
|
|
140
123
|
handlers[uid] = fn;
|
141
124
|
element.addEventListener(typeEvent, fn, isDelegated);
|
142
125
|
}
|
143
|
-
|
144
126
|
function removeHandler(element, events, typeEvent, handler, delegationSelector) {
|
145
127
|
const fn = findHandler(events[typeEvent], handler, delegationSelector);
|
146
|
-
|
147
128
|
if (!fn) {
|
148
129
|
return;
|
149
130
|
}
|
150
|
-
|
151
131
|
element.removeEventListener(typeEvent, fn, Boolean(delegationSelector));
|
152
132
|
delete events[typeEvent][fn.uidEvent];
|
153
133
|
}
|
154
|
-
|
155
134
|
function removeNamespacedHandlers(element, events, typeEvent, namespace) {
|
156
135
|
const storeElementEvent = events[typeEvent] || {};
|
157
|
-
|
158
|
-
for (const handlerKey of Object.keys(storeElementEvent)) {
|
136
|
+
for (const [handlerKey, event] of Object.entries(storeElementEvent)) {
|
159
137
|
if (handlerKey.includes(namespace)) {
|
160
|
-
const event = storeElementEvent[handlerKey];
|
161
138
|
removeHandler(element, events, typeEvent, event.callable, event.delegationSelector);
|
162
139
|
}
|
163
140
|
}
|
164
141
|
}
|
165
|
-
|
166
142
|
function getTypeEvent(event) {
|
167
143
|
// allow to get the native events from namespaced events ('click.bs.button' --> 'click')
|
168
144
|
event = event.replace(stripNameRegex, '');
|
169
145
|
return customEvents[event] || event;
|
170
146
|
}
|
171
|
-
|
172
147
|
const EventHandler = {
|
173
148
|
on(element, event, handler, delegationFunction) {
|
174
149
|
addHandler(element, event, handler, delegationFunction, false);
|
175
150
|
},
|
176
|
-
|
177
151
|
one(element, event, handler, delegationFunction) {
|
178
152
|
addHandler(element, event, handler, delegationFunction, true);
|
179
153
|
},
|
180
|
-
|
181
154
|
off(element, originalTypeEvent, handler, delegationFunction) {
|
182
155
|
if (typeof originalTypeEvent !== 'string' || !element) {
|
183
156
|
return;
|
184
157
|
}
|
185
|
-
|
186
158
|
const [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction);
|
187
159
|
const inNamespace = typeEvent !== originalTypeEvent;
|
188
160
|
const events = getElementEvents(element);
|
189
161
|
const storeElementEvent = events[typeEvent] || {};
|
190
162
|
const isNamespace = originalTypeEvent.startsWith('.');
|
191
|
-
|
192
163
|
if (typeof callable !== 'undefined') {
|
193
164
|
// Simplest case: handler is passed, remove that listener ONLY.
|
194
165
|
if (!Object.keys(storeElementEvent).length) {
|
195
166
|
return;
|
196
167
|
}
|
197
|
-
|
198
168
|
removeHandler(element, events, typeEvent, callable, isDelegated ? handler : null);
|
199
169
|
return;
|
200
170
|
}
|
201
|
-
|
202
171
|
if (isNamespace) {
|
203
172
|
for (const elementEvent of Object.keys(events)) {
|
204
173
|
removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1));
|
205
174
|
}
|
206
175
|
}
|
207
|
-
|
208
|
-
for (const keyHandlers of Object.keys(storeElementEvent)) {
|
176
|
+
for (const [keyHandlers, event] of Object.entries(storeElementEvent)) {
|
209
177
|
const handlerKey = keyHandlers.replace(stripUidRegex, '');
|
210
|
-
|
211
178
|
if (!inNamespace || originalTypeEvent.includes(handlerKey)) {
|
212
|
-
const event = storeElementEvent[keyHandlers];
|
213
179
|
removeHandler(element, events, typeEvent, event.callable, event.delegationSelector);
|
214
180
|
}
|
215
181
|
}
|
216
182
|
},
|
217
|
-
|
218
183
|
trigger(element, event, args) {
|
219
184
|
if (typeof event !== 'string' || !element) {
|
220
185
|
return null;
|
221
186
|
}
|
222
|
-
|
223
|
-
const $ = index.getjQuery();
|
187
|
+
const $ = index_js.getjQuery();
|
224
188
|
const typeEvent = getTypeEvent(event);
|
225
189
|
const inNamespace = event !== typeEvent;
|
226
190
|
let jQueryEvent = null;
|
227
191
|
let bubbles = true;
|
228
192
|
let nativeDispatch = true;
|
229
193
|
let defaultPrevented = false;
|
230
|
-
|
231
194
|
if (inNamespace && $) {
|
232
195
|
jQueryEvent = $.Event(event, args);
|
233
196
|
$(element).trigger(jQueryEvent);
|
@@ -235,46 +198,35 @@
|
|
235
198
|
nativeDispatch = !jQueryEvent.isImmediatePropagationStopped();
|
236
199
|
defaultPrevented = jQueryEvent.isDefaultPrevented();
|
237
200
|
}
|
238
|
-
|
239
|
-
let evt = new Event(event, {
|
201
|
+
const evt = hydrateObj(new Event(event, {
|
240
202
|
bubbles,
|
241
203
|
cancelable: true
|
242
|
-
});
|
243
|
-
evt = hydrateObj(evt, args);
|
244
|
-
|
204
|
+
}), args);
|
245
205
|
if (defaultPrevented) {
|
246
206
|
evt.preventDefault();
|
247
207
|
}
|
248
|
-
|
249
208
|
if (nativeDispatch) {
|
250
209
|
element.dispatchEvent(evt);
|
251
210
|
}
|
252
|
-
|
253
211
|
if (evt.defaultPrevented && jQueryEvent) {
|
254
212
|
jQueryEvent.preventDefault();
|
255
213
|
}
|
256
|
-
|
257
214
|
return evt;
|
258
215
|
}
|
259
|
-
|
260
216
|
};
|
261
|
-
|
262
|
-
|
263
|
-
for (const [key, value] of Object.entries(meta || {})) {
|
217
|
+
function hydrateObj(obj, meta = {}) {
|
218
|
+
for (const [key, value] of Object.entries(meta)) {
|
264
219
|
try {
|
265
220
|
obj[key] = value;
|
266
221
|
} catch (_unused) {
|
267
222
|
Object.defineProperty(obj, key, {
|
268
223
|
configurable: true,
|
269
|
-
|
270
224
|
get() {
|
271
225
|
return value;
|
272
226
|
}
|
273
|
-
|
274
227
|
});
|
275
228
|
}
|
276
229
|
}
|
277
|
-
|
278
230
|
return obj;
|
279
231
|
}
|
280
232
|
|