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.

79 lines
2.4 KiB

5 months ago
  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. * Bootstrap button.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. /**
  18. * Constants
  19. */
  20. const NAME = 'button';
  21. const DATA_KEY = 'bs.button';
  22. const EVENT_KEY = `.${DATA_KEY}`;
  23. const DATA_API_KEY = '.data-api';
  24. const CLASS_NAME_ACTIVE = 'active';
  25. const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]';
  26. const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
  27. /**
  28. * Class definition
  29. */
  30. class Button extends BaseComponent {
  31. // Getters
  32. static get NAME() {
  33. return NAME;
  34. }
  35. // Public
  36. toggle() {
  37. // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
  38. this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE));
  39. }
  40. // Static
  41. static jQueryInterface(config) {
  42. return this.each(function () {
  43. const data = Button.getOrCreateInstance(this);
  44. if (config === 'toggle') {
  45. data[config]();
  46. }
  47. });
  48. }
  49. }
  50. /**
  51. * Data API implementation
  52. */
  53. EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
  54. event.preventDefault();
  55. const button = event.target.closest(SELECTOR_DATA_TOGGLE);
  56. const data = Button.getOrCreateInstance(button);
  57. data.toggle();
  58. });
  59. /**
  60. * jQuery
  61. */
  62. index_js.defineJQueryPlugin(Button);
  63. return Button;
  64. }));
  65. //# sourceMappingURL=button.js.map