bootstrap 5.0.0 → 5.1.1

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/assets/javascripts/bootstrap/alert.js +77 -106
  4. data/assets/javascripts/bootstrap/base-component.js +126 -7
  5. data/assets/javascripts/bootstrap/button.js +24 -24
  6. data/assets/javascripts/bootstrap/carousel.js +115 -128
  7. data/assets/javascripts/bootstrap/collapse.js +119 -176
  8. data/assets/javascripts/bootstrap/dom/data.js +2 -2
  9. data/assets/javascripts/bootstrap/dom/event-handler.js +3 -4
  10. data/assets/javascripts/bootstrap/dom/manipulator.js +4 -4
  11. data/assets/javascripts/bootstrap/dom/selector-engine.js +47 -5
  12. data/assets/javascripts/bootstrap/dropdown.js +142 -130
  13. data/assets/javascripts/bootstrap/modal.js +376 -171
  14. data/assets/javascripts/bootstrap/offcanvas.js +328 -133
  15. data/assets/javascripts/bootstrap/popover.js +27 -59
  16. data/assets/javascripts/bootstrap/scrollspy.js +51 -56
  17. data/assets/javascripts/bootstrap/tab.js +39 -66
  18. data/assets/javascripts/bootstrap/toast.js +175 -86
  19. data/assets/javascripts/bootstrap/tooltip.js +141 -185
  20. data/assets/javascripts/bootstrap-sprockets.js +6 -6
  21. data/assets/javascripts/bootstrap.js +1031 -1026
  22. data/assets/javascripts/bootstrap.min.js +2 -2
  23. data/assets/stylesheets/_bootstrap-grid.scss +3 -1
  24. data/assets/stylesheets/_bootstrap-reboot.scss +2 -4
  25. data/assets/stylesheets/_bootstrap.scss +2 -1
  26. data/assets/stylesheets/bootstrap/_card.scss +7 -6
  27. data/assets/stylesheets/bootstrap/_carousel.scss +2 -2
  28. data/assets/stylesheets/bootstrap/_dropdown.scss +4 -4
  29. data/assets/stylesheets/bootstrap/_functions.scss +100 -3
  30. data/assets/stylesheets/bootstrap/_grid.scss +11 -0
  31. data/assets/stylesheets/bootstrap/_helpers.scss +2 -0
  32. data/assets/stylesheets/bootstrap/_images.scss +1 -1
  33. data/assets/stylesheets/bootstrap/_list-group.scss +5 -5
  34. data/assets/stylesheets/bootstrap/_mixins.scss +1 -0
  35. data/assets/stylesheets/bootstrap/_modal.scss +7 -26
  36. data/assets/stylesheets/bootstrap/_navbar.scss +30 -1
  37. data/assets/stylesheets/bootstrap/_offcanvas.scss +8 -2
  38. data/assets/stylesheets/bootstrap/_placeholders.scss +51 -0
  39. data/assets/stylesheets/bootstrap/_popover.scss +10 -10
  40. data/assets/stylesheets/bootstrap/_reboot.scss +12 -8
  41. data/assets/stylesheets/bootstrap/_root.scss +40 -2
  42. data/assets/stylesheets/bootstrap/_tables.scss +1 -0
  43. data/assets/stylesheets/bootstrap/_toasts.scss +3 -3
  44. data/assets/stylesheets/bootstrap/_tooltip.scss +4 -4
  45. data/assets/stylesheets/bootstrap/_transitions.scss +6 -0
  46. data/assets/stylesheets/bootstrap/_utilities.scss +44 -8
  47. data/assets/stylesheets/bootstrap/_variables.scss +200 -25
  48. data/assets/stylesheets/bootstrap/bootstrap-utilities.scss +1 -1
  49. data/assets/stylesheets/bootstrap/forms/_floating-labels.scss +3 -1
  50. data/assets/stylesheets/bootstrap/forms/_form-check.scss +1 -1
  51. data/assets/stylesheets/bootstrap/forms/_form-control.scss +6 -6
  52. data/assets/stylesheets/bootstrap/forms/_form-range.scss +1 -1
  53. data/assets/stylesheets/bootstrap/forms/_form-select.scss +3 -0
  54. data/assets/stylesheets/bootstrap/helpers/_stacks.scss +15 -0
  55. data/assets/stylesheets/bootstrap/helpers/_vr.scss +8 -0
  56. data/assets/stylesheets/bootstrap/mixins/_backdrop.scss +14 -0
  57. data/assets/stylesheets/bootstrap/mixins/_buttons.scss +1 -1
  58. data/assets/stylesheets/bootstrap/mixins/_forms.scss +8 -1
  59. data/assets/stylesheets/bootstrap/mixins/_grid.scss +33 -8
  60. data/assets/stylesheets/bootstrap/mixins/_utilities.scss +27 -6
  61. data/assets/stylesheets/bootstrap/vendor/_rfs.scss +55 -13
  62. data/bootstrap.gemspec +3 -3
  63. data/lib/bootstrap/version.rb +2 -2
  64. data/tasks/updater/js.rb +6 -2
  65. metadata +12 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab3cae7213a21110421a1bff463a4f8bccfdc085ce03953a9add6330fcc52f6f
4
- data.tar.gz: f5e9f214138024c8adafcc459b934119657f9a0989b83c43dacf783ddd01a8a6
3
+ metadata.gz: b01026d318b10329a0807b13b6468916ce5222500fca7d405495ce2de3455b8d
4
+ data.tar.gz: 194572fec23701c2836ede69479cb76eef1d4360da970c4f14a85a324d69c6d4
5
5
  SHA512:
6
- metadata.gz: a54dd7911c5a617cce35d57e7e8543859cd891e82fa919a85e74a7242337c6258175c7cacf09957b016d24a77957d85731a9373e948a9cfd1e85311513b05184
7
- data.tar.gz: 63aac9f119c570a9826c14f6e1fefdf1c472bdd3befeac525c1d86c75a01e73e36c85bb238916ba09968b12541472c6f8727f3ca701366c7a72c161a32ff8c18
6
+ metadata.gz: acfaf27f3e1c37ffb46653dfe31ccc4118b3af7333697144e8caf09eb1d547fb38964d84ac81267c66002d0e7e4331a6c8050d6badcf49e110bfe2c81809ffce
7
+ data.tar.gz: d16647e78c6c10f02ea79b6f4c9b9da567ca67f7d5d9944d60df37b7230a1c0d2232e8d02d2c098f8fabe935909d2ed4de709d8fbe23ed8a7dd8d51e90e23eb2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bootstrap Ruby Gem [![Build Status](https://travis-ci.org/twbs/bootstrap-rubygem.svg?branch=master)](https://travis-ci.org/twbs/bootstrap-rubygem) [![Gem](https://img.shields.io/gem/v/bootstrap.svg)](https://rubygems.org/gems/bootstrap)
2
2
 
3
- [Bootstrap 4][bootstrap-home] ruby gem for Ruby on Rails (*Sprockets*) and Hanami (formerly Lotus).
3
+ [Bootstrap 5][bootstrap-home] ruby gem for Ruby on Rails (*Sprockets*) and Hanami (formerly Lotus).
4
4
 
5
5
  For Sass versions of Bootstrap 3 and 2 see [bootstrap-sass](https://github.com/twbs/bootstrap-sass) instead.
6
6
 
@@ -20,7 +20,7 @@ Please see the appropriate guide for your environment of choice:
20
20
  Add `bootstrap` to your Gemfile:
21
21
 
22
22
  ```ruby
23
- gem 'bootstrap', '~> 5.0.0'
23
+ gem 'bootstrap', '~> 5.1.1'
24
24
  ```
25
25
 
26
26
  Ensure that `sprockets-rails` is at least v2.3.2.
@@ -1,28 +1,25 @@
1
1
  /*!
2
- * Bootstrap alert.js v5.0.0 (https://getbootstrap.com/)
2
+ * Bootstrap alert.js v5.1.1 (https://getbootstrap.com/)
3
3
  * Copyright 2011-2021 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('./dom/data.js'), require('./dom/event-handler.js'), require('./base-component.js')) :
8
- typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './base-component'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.Data, global.EventHandler, global.Base));
10
- }(this, (function (Data, EventHandler, BaseComponent) { 'use strict';
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) :
8
+ typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.EventHandler, global.Base));
10
+ }(this, (function (EventHandler, BaseComponent) { 'use strict';
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
- var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
15
14
  var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
16
15
  var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
17
16
 
18
17
  /**
19
18
  * --------------------------------------------------------------------------
20
- * Bootstrap (v5.0.0): util/index.js
19
+ * Bootstrap (v5.1.1): util/index.js
21
20
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
22
21
  * --------------------------------------------------------------------------
23
22
  */
24
- const MILLISECONDS_MULTIPLIER = 1000;
25
- const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
26
23
 
27
24
  const getSelector = element => {
28
25
  let selector = element.getAttribute('data-bs-target');
@@ -53,49 +50,20 @@
53
50
  return selector ? document.querySelector(selector) : null;
54
51
  };
55
52
 
56
- const getTransitionDurationFromElement = element => {
57
- if (!element) {
58
- return 0;
59
- } // Get transition-duration of the element
60
-
61
-
62
- let {
63
- transitionDuration,
64
- transitionDelay
65
- } = window.getComputedStyle(element);
66
- const floatTransitionDuration = Number.parseFloat(transitionDuration);
67
- const floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
68
-
69
- if (!floatTransitionDuration && !floatTransitionDelay) {
70
- return 0;
71
- } // If multiple durations are defined, take the first
72
-
73
-
74
- transitionDuration = transitionDuration.split(',')[0];
75
- transitionDelay = transitionDelay.split(',')[0];
76
- return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
77
- };
78
-
79
- const triggerTransitionEnd = element => {
80
- element.dispatchEvent(new Event(TRANSITION_END));
81
- };
53
+ const isDisabled = element => {
54
+ if (!element || element.nodeType !== Node.ELEMENT_NODE) {
55
+ return true;
56
+ }
82
57
 
83
- const emulateTransitionEnd = (element, duration) => {
84
- let called = false;
85
- const durationPadding = 5;
86
- const emulatedDuration = duration + durationPadding;
58
+ if (element.classList.contains('disabled')) {
59
+ return true;
60
+ }
87
61
 
88
- function listener() {
89
- called = true;
90
- element.removeEventListener(TRANSITION_END, listener);
62
+ if (typeof element.disabled !== 'undefined') {
63
+ return element.disabled;
91
64
  }
92
65
 
93
- element.addEventListener(TRANSITION_END, listener);
94
- setTimeout(() => {
95
- if (!called) {
96
- triggerTransitionEnd(element);
97
- }
98
- }, emulatedDuration);
66
+ return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
99
67
  };
100
68
 
101
69
  const getjQuery = () => {
@@ -110,20 +78,30 @@
110
78
  return null;
111
79
  };
112
80
 
81
+ const DOMContentLoadedCallbacks = [];
82
+
113
83
  const onDOMContentLoaded = callback => {
114
84
  if (document.readyState === 'loading') {
115
- document.addEventListener('DOMContentLoaded', callback);
85
+ // add listener on the first call when the document is in loading state
86
+ if (!DOMContentLoadedCallbacks.length) {
87
+ document.addEventListener('DOMContentLoaded', () => {
88
+ DOMContentLoadedCallbacks.forEach(callback => callback());
89
+ });
90
+ }
91
+
92
+ DOMContentLoadedCallbacks.push(callback);
116
93
  } else {
117
94
  callback();
118
95
  }
119
96
  };
120
97
 
121
- const defineJQueryPlugin = (name, plugin) => {
98
+ const defineJQueryPlugin = plugin => {
122
99
  onDOMContentLoaded(() => {
123
100
  const $ = getjQuery();
124
101
  /* istanbul ignore if */
125
102
 
126
103
  if ($) {
104
+ const name = plugin.NAME;
127
105
  const JQUERY_NO_CONFLICT = $.fn[name];
128
106
  $.fn[name] = plugin.jQueryInterface;
129
107
  $.fn[name].Constructor = plugin;
@@ -138,7 +116,33 @@
138
116
 
139
117
  /**
140
118
  * --------------------------------------------------------------------------
141
- * Bootstrap (v5.0.0): alert.js
119
+ * Bootstrap (v5.1.1): util/component-functions.js
120
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
121
+ * --------------------------------------------------------------------------
122
+ */
123
+
124
+ const enableDismissTrigger = (component, method = 'hide') => {
125
+ const clickEvent = `click.dismiss${component.EVENT_KEY}`;
126
+ const name = component.NAME;
127
+ EventHandler__default['default'].on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
128
+ if (['A', 'AREA'].includes(this.tagName)) {
129
+ event.preventDefault();
130
+ }
131
+
132
+ if (isDisabled(this)) {
133
+ return;
134
+ }
135
+
136
+ const target = getElementFromSelector(this) || this.closest(`.${name}`);
137
+ const instance = component.getOrCreateInstance(target); // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
138
+
139
+ instance[method]();
140
+ });
141
+ };
142
+
143
+ /**
144
+ * --------------------------------------------------------------------------
145
+ * Bootstrap (v5.1.1): alert.js
142
146
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
143
147
  * --------------------------------------------------------------------------
144
148
  */
@@ -151,12 +155,8 @@
151
155
  const NAME = 'alert';
152
156
  const DATA_KEY = 'bs.alert';
153
157
  const EVENT_KEY = `.${DATA_KEY}`;
154
- const DATA_API_KEY = '.data-api';
155
- const SELECTOR_DISMISS = '[data-bs-dismiss="alert"]';
156
158
  const EVENT_CLOSE = `close${EVENT_KEY}`;
157
159
  const EVENT_CLOSED = `closed${EVENT_KEY}`;
158
- const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
159
- const CLASS_NAME_ALERT = 'alert';
160
160
  const CLASS_NAME_FADE = 'fade';
161
161
  const CLASS_NAME_SHOW = 'show';
162
162
  /**
@@ -167,77 +167,48 @@
167
167
 
168
168
  class Alert extends BaseComponent__default['default'] {
169
169
  // Getters
170
- static get DATA_KEY() {
171
- return DATA_KEY;
170
+ static get NAME() {
171
+ return NAME;
172
172
  } // Public
173
173
 
174
174
 
175
- close(element) {
176
- const rootElement = element ? this._getRootElement(element) : this._element;
177
-
178
- const customEvent = this._triggerCloseEvent(rootElement);
175
+ close() {
176
+ const closeEvent = EventHandler__default['default'].trigger(this._element, EVENT_CLOSE);
179
177
 
180
- if (customEvent === null || customEvent.defaultPrevented) {
178
+ if (closeEvent.defaultPrevented) {
181
179
  return;
182
180
  }
183
181
 
184
- this._removeElement(rootElement);
185
- } // Private
186
-
187
-
188
- _getRootElement(element) {
189
- return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`);
190
- }
191
-
192
- _triggerCloseEvent(element) {
193
- return EventHandler__default['default'].trigger(element, EVENT_CLOSE);
194
- }
182
+ this._element.classList.remove(CLASS_NAME_SHOW);
195
183
 
196
- _removeElement(element) {
197
- element.classList.remove(CLASS_NAME_SHOW);
184
+ const isAnimated = this._element.classList.contains(CLASS_NAME_FADE);
198
185
 
199
- if (!element.classList.contains(CLASS_NAME_FADE)) {
200
- this._destroyElement(element);
201
-
202
- return;
203
- }
186
+ this._queueCallback(() => this._destroyElement(), this._element, isAnimated);
187
+ } // Private
204
188
 
205
- const transitionDuration = getTransitionDurationFromElement(element);
206
- EventHandler__default['default'].one(element, 'transitionend', () => this._destroyElement(element));
207
- emulateTransitionEnd(element, transitionDuration);
208
- }
209
189
 
210
- _destroyElement(element) {
211
- if (element.parentNode) {
212
- element.parentNode.removeChild(element);
213
- }
190
+ _destroyElement() {
191
+ this._element.remove();
214
192
 
215
- EventHandler__default['default'].trigger(element, EVENT_CLOSED);
193
+ EventHandler__default['default'].trigger(this._element, EVENT_CLOSED);
194
+ this.dispose();
216
195
  } // Static
217
196
 
218
197
 
219
198
  static jQueryInterface(config) {
220
199
  return this.each(function () {
221
- let data = Data__default['default'].get(this, DATA_KEY);
200
+ const data = Alert.getOrCreateInstance(this);
222
201
 
223
- if (!data) {
224
- data = new Alert(this);
202
+ if (typeof config !== 'string') {
203
+ return;
225
204
  }
226
205
 
227
- if (config === 'close') {
228
- data[config](this);
206
+ if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
207
+ throw new TypeError(`No method named "${config}"`);
229
208
  }
230
- });
231
- }
232
209
 
233
- static handleDismiss(alertInstance) {
234
- return function (event) {
235
- if (event) {
236
- event.preventDefault();
237
- }
238
-
239
- alertInstance.close(this);
240
- };
210
+ data[config](this);
211
+ });
241
212
  }
242
213
 
243
214
  }
@@ -248,7 +219,7 @@
248
219
  */
249
220
 
250
221
 
251
- EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()));
222
+ enableDismissTrigger(Alert, 'close');
252
223
  /**
253
224
  * ------------------------------------------------------------------------
254
225
  * jQuery
@@ -256,7 +227,7 @@
256
227
  * add .Alert to jQuery only if jQuery is present
257
228
  */
258
229
 
259
- defineJQueryPlugin(NAME, Alert);
230
+ defineJQueryPlugin(Alert);
260
231
 
261
232
  return Alert;
262
233
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Bootstrap base-component.js v5.0.0 (https://getbootstrap.com/)
2
+ * Bootstrap base-component.js v5.1.1 (https://getbootstrap.com/)
3
3
  * Copyright 2011-2021 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
  */
@@ -16,7 +16,104 @@
16
16
 
17
17
  /**
18
18
  * --------------------------------------------------------------------------
19
- * Bootstrap (v5.0.0): base-component.js
19
+ * Bootstrap (v5.1.1): util/index.js
20
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
21
+ * --------------------------------------------------------------------------
22
+ */
23
+ const MILLISECONDS_MULTIPLIER = 1000;
24
+ const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
25
+
26
+ const getTransitionDurationFromElement = element => {
27
+ if (!element) {
28
+ return 0;
29
+ } // Get transition-duration of the element
30
+
31
+
32
+ let {
33
+ transitionDuration,
34
+ transitionDelay
35
+ } = window.getComputedStyle(element);
36
+ const floatTransitionDuration = Number.parseFloat(transitionDuration);
37
+ const floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
38
+
39
+ if (!floatTransitionDuration && !floatTransitionDelay) {
40
+ return 0;
41
+ } // If multiple durations are defined, take the first
42
+
43
+
44
+ transitionDuration = transitionDuration.split(',')[0];
45
+ transitionDelay = transitionDelay.split(',')[0];
46
+ return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
47
+ };
48
+
49
+ const triggerTransitionEnd = element => {
50
+ element.dispatchEvent(new Event(TRANSITION_END));
51
+ };
52
+
53
+ const isElement = obj => {
54
+ if (!obj || typeof obj !== 'object') {
55
+ return false;
56
+ }
57
+
58
+ if (typeof obj.jquery !== 'undefined') {
59
+ obj = obj[0];
60
+ }
61
+
62
+ return typeof obj.nodeType !== 'undefined';
63
+ };
64
+
65
+ const getElement = obj => {
66
+ if (isElement(obj)) {
67
+ // it's a jQuery object or a node element
68
+ return obj.jquery ? obj[0] : obj;
69
+ }
70
+
71
+ if (typeof obj === 'string' && obj.length > 0) {
72
+ return document.querySelector(obj);
73
+ }
74
+
75
+ return null;
76
+ };
77
+
78
+ const execute = callback => {
79
+ if (typeof callback === 'function') {
80
+ callback();
81
+ }
82
+ };
83
+
84
+ const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
85
+ if (!waitForTransition) {
86
+ execute(callback);
87
+ return;
88
+ }
89
+
90
+ const durationPadding = 5;
91
+ const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
92
+ let called = false;
93
+
94
+ const handler = ({
95
+ target
96
+ }) => {
97
+ if (target !== transitionElement) {
98
+ return;
99
+ }
100
+
101
+ called = true;
102
+ transitionElement.removeEventListener(TRANSITION_END, handler);
103
+ execute(callback);
104
+ };
105
+
106
+ transitionElement.addEventListener(TRANSITION_END, handler);
107
+ setTimeout(() => {
108
+ if (!called) {
109
+ triggerTransitionEnd(transitionElement);
110
+ }
111
+ }, emulatedDuration);
112
+ };
113
+
114
+ /**
115
+ * --------------------------------------------------------------------------
116
+ * Bootstrap (v5.1.1): base-component.js
20
117
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
21
118
  * --------------------------------------------------------------------------
22
119
  */
@@ -26,11 +123,11 @@
26
123
  * ------------------------------------------------------------------------
27
124
  */
28
125
 
29
- const VERSION = '5.0.0';
126
+ const VERSION = '5.1.1';
30
127
 
31
128
  class BaseComponent {
32
129
  constructor(element) {
33
- element = typeof element === 'string' ? document.querySelector(element) : element;
130
+ element = getElement(element);
34
131
 
35
132
  if (!element) {
36
133
  return;
@@ -42,20 +139,42 @@
42
139
 
43
140
  dispose() {
44
141
  Data__default['default'].remove(this._element, this.constructor.DATA_KEY);
45
- EventHandler__default['default'].off(this._element, `.${this.constructor.DATA_KEY}`);
46
- this._element = null;
142
+ EventHandler__default['default'].off(this._element, this.constructor.EVENT_KEY);
143
+ Object.getOwnPropertyNames(this).forEach(propertyName => {
144
+ this[propertyName] = null;
145
+ });
146
+ }
147
+
148
+ _queueCallback(callback, element, isAnimated = true) {
149
+ executeAfterTransition(callback, element, isAnimated);
47
150
  }
48
151
  /** Static */
49
152
 
50
153
 
51
154
  static getInstance(element) {
52
- return Data__default['default'].get(element, this.DATA_KEY);
155
+ return Data__default['default'].get(getElement(element), this.DATA_KEY);
156
+ }
157
+
158
+ static getOrCreateInstance(element, config = {}) {
159
+ return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null);
53
160
  }
54
161
 
55
162
  static get VERSION() {
56
163
  return VERSION;
57
164
  }
58
165
 
166
+ static get NAME() {
167
+ throw new Error('You have to implement the static method "NAME", for each component!');
168
+ }
169
+
170
+ static get DATA_KEY() {
171
+ return `bs.${this.NAME}`;
172
+ }
173
+
174
+ static get EVENT_KEY() {
175
+ return `.${this.DATA_KEY}`;
176
+ }
177
+
59
178
  }
60
179
 
61
180
  return BaseComponent;
@@ -1,23 +1,22 @@
1
1
  /*!
2
- * Bootstrap button.js v5.0.0 (https://getbootstrap.com/)
2
+ * Bootstrap button.js v5.1.1 (https://getbootstrap.com/)
3
3
  * Copyright 2011-2021 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('./dom/data.js'), require('./dom/event-handler.js'), require('./base-component.js')) :
8
- typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './base-component'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.Data, global.EventHandler, global.Base));
10
- }(this, (function (Data, EventHandler, BaseComponent) { 'use strict';
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) :
8
+ typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.EventHandler, global.Base));
10
+ }(this, (function (EventHandler, BaseComponent) { 'use strict';
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
- var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
15
14
  var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
16
15
  var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
17
16
 
18
17
  /**
19
18
  * --------------------------------------------------------------------------
20
- * Bootstrap (v5.0.0): util/index.js
19
+ * Bootstrap (v5.1.1): util/index.js
21
20
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
22
21
  * --------------------------------------------------------------------------
23
22
  */
@@ -34,20 +33,30 @@
34
33
  return null;
35
34
  };
36
35
 
36
+ const DOMContentLoadedCallbacks = [];
37
+
37
38
  const onDOMContentLoaded = callback => {
38
39
  if (document.readyState === 'loading') {
39
- document.addEventListener('DOMContentLoaded', callback);
40
+ // add listener on the first call when the document is in loading state
41
+ if (!DOMContentLoadedCallbacks.length) {
42
+ document.addEventListener('DOMContentLoaded', () => {
43
+ DOMContentLoadedCallbacks.forEach(callback => callback());
44
+ });
45
+ }
46
+
47
+ DOMContentLoadedCallbacks.push(callback);
40
48
  } else {
41
49
  callback();
42
50
  }
43
51
  };
44
52
 
45
- const defineJQueryPlugin = (name, plugin) => {
53
+ const defineJQueryPlugin = plugin => {
46
54
  onDOMContentLoaded(() => {
47
55
  const $ = getjQuery();
48
56
  /* istanbul ignore if */
49
57
 
50
58
  if ($) {
59
+ const name = plugin.NAME;
51
60
  const JQUERY_NO_CONFLICT = $.fn[name];
52
61
  $.fn[name] = plugin.jQueryInterface;
53
62
  $.fn[name].Constructor = plugin;
@@ -62,7 +71,7 @@
62
71
 
63
72
  /**
64
73
  * --------------------------------------------------------------------------
65
- * Bootstrap (v5.0.0): button.js
74
+ * Bootstrap (v5.1.1): button.js
66
75
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
67
76
  * --------------------------------------------------------------------------
68
77
  */
@@ -87,8 +96,8 @@
87
96
 
88
97
  class Button extends BaseComponent__default['default'] {
89
98
  // Getters
90
- static get DATA_KEY() {
91
- return DATA_KEY;
99
+ static get NAME() {
100
+ return NAME;
92
101
  } // Public
93
102
 
94
103
 
@@ -100,11 +109,7 @@
100
109
 
101
110
  static jQueryInterface(config) {
102
111
  return this.each(function () {
103
- let data = Data__default['default'].get(this, DATA_KEY);
104
-
105
- if (!data) {
106
- data = new Button(this);
107
- }
112
+ const data = Button.getOrCreateInstance(this);
108
113
 
109
114
  if (config === 'toggle') {
110
115
  data[config]();
@@ -123,12 +128,7 @@
123
128
  EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
124
129
  event.preventDefault();
125
130
  const button = event.target.closest(SELECTOR_DATA_TOGGLE);
126
- let data = Data__default['default'].get(button, DATA_KEY);
127
-
128
- if (!data) {
129
- data = new Button(button);
130
- }
131
-
131
+ const data = Button.getOrCreateInstance(button);
132
132
  data.toggle();
133
133
  });
134
134
  /**
@@ -138,7 +138,7 @@
138
138
  * add .Button to jQuery only if jQuery is present
139
139
  */
140
140
 
141
- defineJQueryPlugin(NAME, Button);
141
+ defineJQueryPlugin(Button);
142
142
 
143
143
  return Button;
144
144