1 | /*!
|
---|
2 | * Bootstrap button.js v5.1.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
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 |
|
---|
12 | const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
---|
13 |
|
---|
14 | const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
---|
15 | const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * --------------------------------------------------------------------------
|
---|
19 | * Bootstrap (v5.1.3): util/index.js
|
---|
20 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
21 | * --------------------------------------------------------------------------
|
---|
22 | */
|
---|
23 |
|
---|
24 | const getjQuery = () => {
|
---|
25 | const {
|
---|
26 | jQuery
|
---|
27 | } = window;
|
---|
28 |
|
---|
29 | if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
---|
30 | return jQuery;
|
---|
31 | }
|
---|
32 |
|
---|
33 | return null;
|
---|
34 | };
|
---|
35 |
|
---|
36 | const DOMContentLoadedCallbacks = [];
|
---|
37 |
|
---|
38 | const onDOMContentLoaded = callback => {
|
---|
39 | if (document.readyState === 'loading') {
|
---|
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);
|
---|
48 | } else {
|
---|
49 | callback();
|
---|
50 | }
|
---|
51 | };
|
---|
52 |
|
---|
53 | const defineJQueryPlugin = plugin => {
|
---|
54 | onDOMContentLoaded(() => {
|
---|
55 | const $ = getjQuery();
|
---|
56 | /* istanbul ignore if */
|
---|
57 |
|
---|
58 | if ($) {
|
---|
59 | const name = plugin.NAME;
|
---|
60 | const JQUERY_NO_CONFLICT = $.fn[name];
|
---|
61 | $.fn[name] = plugin.jQueryInterface;
|
---|
62 | $.fn[name].Constructor = plugin;
|
---|
63 |
|
---|
64 | $.fn[name].noConflict = () => {
|
---|
65 | $.fn[name] = JQUERY_NO_CONFLICT;
|
---|
66 | return plugin.jQueryInterface;
|
---|
67 | };
|
---|
68 | }
|
---|
69 | });
|
---|
70 | };
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * --------------------------------------------------------------------------
|
---|
74 | * Bootstrap (v5.1.3): button.js
|
---|
75 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
76 | * --------------------------------------------------------------------------
|
---|
77 | */
|
---|
78 | /**
|
---|
79 | * ------------------------------------------------------------------------
|
---|
80 | * Constants
|
---|
81 | * ------------------------------------------------------------------------
|
---|
82 | */
|
---|
83 |
|
---|
84 | const NAME = 'button';
|
---|
85 | const DATA_KEY = 'bs.button';
|
---|
86 | const EVENT_KEY = `.${DATA_KEY}`;
|
---|
87 | const DATA_API_KEY = '.data-api';
|
---|
88 | const CLASS_NAME_ACTIVE = 'active';
|
---|
89 | const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]';
|
---|
90 | const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
|
---|
91 | /**
|
---|
92 | * ------------------------------------------------------------------------
|
---|
93 | * Class Definition
|
---|
94 | * ------------------------------------------------------------------------
|
---|
95 | */
|
---|
96 |
|
---|
97 | class Button extends BaseComponent__default.default {
|
---|
98 | // Getters
|
---|
99 | static get NAME() {
|
---|
100 | return NAME;
|
---|
101 | } // Public
|
---|
102 |
|
---|
103 |
|
---|
104 | toggle() {
|
---|
105 | // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
|
---|
106 | this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE));
|
---|
107 | } // Static
|
---|
108 |
|
---|
109 |
|
---|
110 | static jQueryInterface(config) {
|
---|
111 | return this.each(function () {
|
---|
112 | const data = Button.getOrCreateInstance(this);
|
---|
113 |
|
---|
114 | if (config === 'toggle') {
|
---|
115 | data[config]();
|
---|
116 | }
|
---|
117 | });
|
---|
118 | }
|
---|
119 |
|
---|
120 | }
|
---|
121 | /**
|
---|
122 | * ------------------------------------------------------------------------
|
---|
123 | * Data Api implementation
|
---|
124 | * ------------------------------------------------------------------------
|
---|
125 | */
|
---|
126 |
|
---|
127 |
|
---|
128 | EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
|
---|
129 | event.preventDefault();
|
---|
130 | const button = event.target.closest(SELECTOR_DATA_TOGGLE);
|
---|
131 | const data = Button.getOrCreateInstance(button);
|
---|
132 | data.toggle();
|
---|
133 | });
|
---|
134 | /**
|
---|
135 | * ------------------------------------------------------------------------
|
---|
136 | * jQuery
|
---|
137 | * ------------------------------------------------------------------------
|
---|
138 | * add .Button to jQuery only if jQuery is present
|
---|
139 | */
|
---|
140 |
|
---|
141 | defineJQueryPlugin(Button);
|
---|
142 |
|
---|
143 | return Button;
|
---|
144 |
|
---|
145 | }));
|
---|
146 | //# sourceMappingURL=button.js.map
|
---|