diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/button.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/button.js | 282 |
1 files changed, 97 insertions, 185 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/button.js b/vendor/twbs/bootstrap/js/dist/button.js index b91fd0731..f9755e3d4 100644 --- a/vendor/twbs/bootstrap/js/dist/button.js +++ b/vendor/twbs/bootstrap/js/dist/button.js @@ -1,156 +1,123 @@ /*! - * Bootstrap button.js v4.6.0 (https://getbootstrap.com/) + * Bootstrap button.js v5.1.3 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) : - typeof define === 'function' && define.amd ? define(['jquery'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.jQuery)); -}(this, (function ($) { 'use strict'; - - function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } - - var $__default = /*#__PURE__*/_interopDefaultLegacy($); - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) : + typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Button = factory(global.EventHandler, global.Base)); +})(this, (function (EventHandler, BaseComponent) { 'use strict'; + + const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e }; + + const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler); + const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent); + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + + const getjQuery = () => { + const { + jQuery + } = window; + + if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) { + return jQuery; } - } - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } + return null; + }; + + const DOMContentLoadedCallbacks = []; + + const onDOMContentLoaded = callback => { + if (document.readyState === 'loading') { + // add listener on the first call when the document is in loading state + if (!DOMContentLoadedCallbacks.length) { + document.addEventListener('DOMContentLoaded', () => { + DOMContentLoadedCallbacks.forEach(callback => callback()); + }); + } + + DOMContentLoadedCallbacks.push(callback); + } else { + callback(); + } + }; + const defineJQueryPlugin = plugin => { + onDOMContentLoaded(() => { + const $ = getjQuery(); + /* istanbul ignore if */ + + if ($) { + const name = plugin.NAME; + const JQUERY_NO_CONFLICT = $.fn[name]; + $.fn[name] = plugin.jQueryInterface; + $.fn[name].Constructor = plugin; + + $.fn[name].noConflict = () => { + $.fn[name] = JQUERY_NO_CONFLICT; + return plugin.jQueryInterface; + }; + } + }); + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): button.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ - var NAME = 'button'; - var VERSION = '4.6.0'; - var DATA_KEY = 'bs.button'; - var EVENT_KEY = "." + DATA_KEY; - var DATA_API_KEY = '.data-api'; - var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME]; - var CLASS_NAME_ACTIVE = 'active'; - var CLASS_NAME_BUTTON = 'btn'; - var CLASS_NAME_FOCUS = 'focus'; - var SELECTOR_DATA_TOGGLE_CARROT = '[data-toggle^="button"]'; - var SELECTOR_DATA_TOGGLES = '[data-toggle="buttons"]'; - var SELECTOR_DATA_TOGGLE = '[data-toggle="button"]'; - var SELECTOR_DATA_TOGGLES_BUTTONS = '[data-toggle="buttons"] .btn'; - var SELECTOR_INPUT = 'input:not([type="hidden"])'; - var SELECTOR_ACTIVE = '.active'; - var SELECTOR_BUTTON = '.btn'; - var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY; - var EVENT_FOCUS_BLUR_DATA_API = "focus" + EVENT_KEY + DATA_API_KEY + " " + ("blur" + EVENT_KEY + DATA_API_KEY); - var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY; + const NAME = 'button'; + const DATA_KEY = 'bs.button'; + const EVENT_KEY = `.${DATA_KEY}`; + const DATA_API_KEY = '.data-api'; + const CLASS_NAME_ACTIVE = 'active'; + const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]'; + const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`; /** * ------------------------------------------------------------------------ * Class Definition * ------------------------------------------------------------------------ */ - var Button = /*#__PURE__*/function () { - function Button(element) { - this._element = element; - this.shouldAvoidTriggerChange = false; - } // Getters - - - var _proto = Button.prototype; - - // Public - _proto.toggle = function toggle() { - var triggerChangeEvent = true; - var addAriaPressed = true; - var rootElement = $__default['default'](this._element).closest(SELECTOR_DATA_TOGGLES)[0]; - - if (rootElement) { - var input = this._element.querySelector(SELECTOR_INPUT); - - if (input) { - if (input.type === 'radio') { - if (input.checked && this._element.classList.contains(CLASS_NAME_ACTIVE)) { - triggerChangeEvent = false; - } else { - var activeElement = rootElement.querySelector(SELECTOR_ACTIVE); - - if (activeElement) { - $__default['default'](activeElement).removeClass(CLASS_NAME_ACTIVE); - } - } - } - - if (triggerChangeEvent) { - // if it's not a radio button or checkbox don't add a pointless/invalid checked property to the input - if (input.type === 'checkbox' || input.type === 'radio') { - input.checked = !this._element.classList.contains(CLASS_NAME_ACTIVE); - } - - if (!this.shouldAvoidTriggerChange) { - $__default['default'](input).trigger('change'); - } - } - - input.focus(); - addAriaPressed = false; - } - } + class Button extends BaseComponent__default.default { + // Getters + static get NAME() { + return NAME; + } // Public - if (!(this._element.hasAttribute('disabled') || this._element.classList.contains('disabled'))) { - if (addAriaPressed) { - this._element.setAttribute('aria-pressed', !this._element.classList.contains(CLASS_NAME_ACTIVE)); - } - - if (triggerChangeEvent) { - $__default['default'](this._element).toggleClass(CLASS_NAME_ACTIVE); - } - } - }; - _proto.dispose = function dispose() { - $__default['default'].removeData(this._element, DATA_KEY); - this._element = null; + toggle() { + // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method + this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE)); } // Static - ; - Button._jQueryInterface = function _jQueryInterface(config, avoidTriggerChange) { - return this.each(function () { - var $element = $__default['default'](this); - var data = $element.data(DATA_KEY); - - if (!data) { - data = new Button(this); - $element.data(DATA_KEY, data); - } - data.shouldAvoidTriggerChange = avoidTriggerChange; + static jQueryInterface(config) { + return this.each(function () { + const data = Button.getOrCreateInstance(this); if (config === 'toggle') { data[config](); } }); - }; - - _createClass(Button, null, [{ - key: "VERSION", - get: function get() { - return VERSION; - } - }]); + } - return Button; - }(); + } /** * ------------------------------------------------------------------------ * Data Api implementation @@ -158,77 +125,22 @@ */ - $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE_CARROT, function (event) { - var button = event.target; - var initialButton = button; - - if (!$__default['default'](button).hasClass(CLASS_NAME_BUTTON)) { - button = $__default['default'](button).closest(SELECTOR_BUTTON)[0]; - } - - if (!button || button.hasAttribute('disabled') || button.classList.contains('disabled')) { - event.preventDefault(); // work around Firefox bug #1540995 - } else { - var inputBtn = button.querySelector(SELECTOR_INPUT); - - if (inputBtn && (inputBtn.hasAttribute('disabled') || inputBtn.classList.contains('disabled'))) { - event.preventDefault(); // work around Firefox bug #1540995 - - return; - } - - if (initialButton.tagName === 'INPUT' || button.tagName !== 'LABEL') { - Button._jQueryInterface.call($__default['default'](button), 'toggle', initialButton.tagName === 'INPUT'); - } - } - }).on(EVENT_FOCUS_BLUR_DATA_API, SELECTOR_DATA_TOGGLE_CARROT, function (event) { - var button = $__default['default'](event.target).closest(SELECTOR_BUTTON)[0]; - $__default['default'](button).toggleClass(CLASS_NAME_FOCUS, /^focus(in)?$/.test(event.type)); - }); - $__default['default'](window).on(EVENT_LOAD_DATA_API, function () { - // ensure correct active class is set to match the controls' actual values/states - // find all checkboxes/readio buttons inside data-toggle groups - var buttons = [].slice.call(document.querySelectorAll(SELECTOR_DATA_TOGGLES_BUTTONS)); - - for (var i = 0, len = buttons.length; i < len; i++) { - var button = buttons[i]; - var input = button.querySelector(SELECTOR_INPUT); - - if (input.checked || input.hasAttribute('checked')) { - button.classList.add(CLASS_NAME_ACTIVE); - } else { - button.classList.remove(CLASS_NAME_ACTIVE); - } - } // find all button toggles - - - buttons = [].slice.call(document.querySelectorAll(SELECTOR_DATA_TOGGLE)); - - for (var _i = 0, _len = buttons.length; _i < _len; _i++) { - var _button = buttons[_i]; - - if (_button.getAttribute('aria-pressed') === 'true') { - _button.classList.add(CLASS_NAME_ACTIVE); - } else { - _button.classList.remove(CLASS_NAME_ACTIVE); - } - } + EventHandler__default.default.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => { + event.preventDefault(); + const button = event.target.closest(SELECTOR_DATA_TOGGLE); + const data = Button.getOrCreateInstance(button); + data.toggle(); }); /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ + * add .Button to jQuery only if jQuery is present */ - $__default['default'].fn[NAME] = Button._jQueryInterface; - $__default['default'].fn[NAME].Constructor = Button; - - $__default['default'].fn[NAME].noConflict = function () { - $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT; - return Button._jQueryInterface; - }; + defineJQueryPlugin(Button); return Button; -}))); +})); //# sourceMappingURL=button.js.map |