You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.7 KiB

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