base-component.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*!
  2. * Bootstrap base-component.js v5.3.7 (https://getbootstrap.com/)
  3. * Copyright 2011-2025 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/data.js'), require('./dom/event-handler.js'), require('./util/config.js'), require('./util/index.js')) :
  8. typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './util/config', './util/index'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BaseComponent = factory(global.Data, global.EventHandler, global.Config, global.Index));
  10. })(this, (function (Data, EventHandler, Config, index_js) { 'use strict';
  11. /**
  12. * --------------------------------------------------------------------------
  13. * Bootstrap base-component.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. /**
  18. * Constants
  19. */
  20. const VERSION = '5.3.7';
  21. /**
  22. * Class definition
  23. */
  24. class BaseComponent extends Config {
  25. constructor(element, config) {
  26. super();
  27. element = index_js.getElement(element);
  28. if (!element) {
  29. return;
  30. }
  31. this._element = element;
  32. this._config = this._getConfig(config);
  33. Data.set(this._element, this.constructor.DATA_KEY, this);
  34. }
  35. // Public
  36. dispose() {
  37. Data.remove(this._element, this.constructor.DATA_KEY);
  38. EventHandler.off(this._element, this.constructor.EVENT_KEY);
  39. for (const propertyName of Object.getOwnPropertyNames(this)) {
  40. this[propertyName] = null;
  41. }
  42. }
  43. // Private
  44. _queueCallback(callback, element, isAnimated = true) {
  45. index_js.executeAfterTransition(callback, element, isAnimated);
  46. }
  47. _getConfig(config) {
  48. config = this._mergeConfigObj(config, this._element);
  49. config = this._configAfterMerge(config);
  50. this._typeCheckConfig(config);
  51. return config;
  52. }
  53. // Static
  54. static getInstance(element) {
  55. return Data.get(index_js.getElement(element), this.DATA_KEY);
  56. }
  57. static getOrCreateInstance(element, config = {}) {
  58. return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null);
  59. }
  60. static get VERSION() {
  61. return VERSION;
  62. }
  63. static get DATA_KEY() {
  64. return `bs.${this.NAME}`;
  65. }
  66. static get EVENT_KEY() {
  67. return `.${this.DATA_KEY}`;
  68. }
  69. static eventName(name) {
  70. return `${name}${this.EVENT_KEY}`;
  71. }
  72. }
  73. return BaseComponent;
  74. }));
  75. //# sourceMappingURL=base-component.js.map