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.

84 lines
2.8 KiB

7 months ago
  1. /*!
  2. * Bootstrap base-component.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('./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.3';
  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. _queueCallback(callback, element, isAnimated = true) {
  44. index_js.executeAfterTransition(callback, element, isAnimated);
  45. }
  46. _getConfig(config) {
  47. config = this._mergeConfigObj(config, this._element);
  48. config = this._configAfterMerge(config);
  49. this._typeCheckConfig(config);
  50. return config;
  51. }
  52. // Static
  53. static getInstance(element) {
  54. return Data.get(index_js.getElement(element), this.DATA_KEY);
  55. }
  56. static getOrCreateInstance(element, config = {}) {
  57. return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null);
  58. }
  59. static get VERSION() {
  60. return VERSION;
  61. }
  62. static get DATA_KEY() {
  63. return `bs.${this.NAME}`;
  64. }
  65. static get EVENT_KEY() {
  66. return `.${this.DATA_KEY}`;
  67. }
  68. static eventName(name) {
  69. return `${name}${this.EVENT_KEY}`;
  70. }
  71. }
  72. return BaseComponent;
  73. }));
  74. //# sourceMappingURL=base-component.js.map