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.

63 lines
2.1 KiB

5 months ago
  1. /*!
  2. * Bootstrap data.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() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Data = factory());
  10. })(this, (function () { 'use strict';
  11. /**
  12. * --------------------------------------------------------------------------
  13. * Bootstrap dom/data.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. /**
  18. * Constants
  19. */
  20. const elementMap = new Map();
  21. const data = {
  22. set(element, key, instance) {
  23. if (!elementMap.has(element)) {
  24. elementMap.set(element, new Map());
  25. }
  26. const instanceMap = elementMap.get(element);
  27. // make it clear we only want one instance per element
  28. // can be removed later when multiple key/instances are fine to be used
  29. if (!instanceMap.has(key) && instanceMap.size !== 0) {
  30. // eslint-disable-next-line no-console
  31. console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
  32. return;
  33. }
  34. instanceMap.set(key, instance);
  35. },
  36. get(element, key) {
  37. if (elementMap.has(element)) {
  38. return elementMap.get(element).get(key) || null;
  39. }
  40. return null;
  41. },
  42. remove(element, key) {
  43. if (!elementMap.has(element)) {
  44. return;
  45. }
  46. const instanceMap = elementMap.get(element);
  47. instanceMap.delete(key);
  48. // free up element references if there are no instances left for an element
  49. if (instanceMap.size === 0) {
  50. elementMap.delete(element);
  51. }
  52. }
  53. };
  54. return data;
  55. }));
  56. //# sourceMappingURL=data.js.map