[d565449] | 1 | /*!
|
---|
| 2 | * Bootstrap button.js v5.3.3 (https://getbootstrap.com/)
|
---|
| 3 | * Copyright 2011-2024 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('./base-component.js'), require('./dom/event-handler.js'), require('./util/index.js')) :
|
---|
| 8 | typeof define === 'function' && define.amd ? define(['./base-component', './dom/event-handler', './util/index'], factory) :
|
---|
| 9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.BaseComponent, global.EventHandler, global.Index));
|
---|
| 10 | })(this, (function (BaseComponent, EventHandler, index_js) { 'use strict';
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * --------------------------------------------------------------------------
|
---|
| 14 | * Bootstrap button.js
|
---|
| 15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
| 16 | * --------------------------------------------------------------------------
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Constants
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | const NAME = 'button';
|
---|
| 25 | const DATA_KEY = 'bs.button';
|
---|
| 26 | const EVENT_KEY = `.${DATA_KEY}`;
|
---|
| 27 | const DATA_API_KEY = '.data-api';
|
---|
| 28 | const CLASS_NAME_ACTIVE = 'active';
|
---|
| 29 | const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]';
|
---|
| 30 | const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Class definition
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | class Button extends BaseComponent {
|
---|
| 37 | // Getters
|
---|
| 38 | static get NAME() {
|
---|
| 39 | return NAME;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | // Public
|
---|
| 43 | toggle() {
|
---|
| 44 | // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
|
---|
| 45 | this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE));
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | // Static
|
---|
| 49 | static jQueryInterface(config) {
|
---|
| 50 | return this.each(function () {
|
---|
| 51 | const data = Button.getOrCreateInstance(this);
|
---|
| 52 | if (config === 'toggle') {
|
---|
| 53 | data[config]();
|
---|
| 54 | }
|
---|
| 55 | });
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Data API implementation
|
---|
| 61 | */
|
---|
| 62 |
|
---|
| 63 | EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
|
---|
| 64 | event.preventDefault();
|
---|
| 65 | const button = event.target.closest(SELECTOR_DATA_TOGGLE);
|
---|
| 66 | const data = Button.getOrCreateInstance(button);
|
---|
| 67 | data.toggle();
|
---|
| 68 | });
|
---|
| 69 |
|
---|
| 70 | /**
|
---|
| 71 | * jQuery
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | index_js.defineJQueryPlugin(Button);
|
---|
| 75 |
|
---|
| 76 | return Button;
|
---|
| 77 |
|
---|
| 78 | }));
|
---|
| 79 | //# sourceMappingURL=button.js.map
|
---|