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.

69 lines
2.2 KiB

  1. /*!
  2. * Bootstrap data.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() :
  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 (v5.1.3): dom/data.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. /**
  18. * ------------------------------------------------------------------------
  19. * Constants
  20. * ------------------------------------------------------------------------
  21. */
  22. const elementMap = new Map();
  23. const data = {
  24. set(element, key, instance) {
  25. if (!elementMap.has(element)) {
  26. elementMap.set(element, new Map());
  27. }
  28. const instanceMap = elementMap.get(element); // make it clear we only want one instance per element
  29. // can be removed later when multiple key/instances are fine to be used
  30. if (!instanceMap.has(key) && instanceMap.size !== 0) {
  31. // eslint-disable-next-line no-console
  32. console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
  33. return;
  34. }
  35. instanceMap.set(key, instance);
  36. },
  37. get(element, key) {
  38. if (elementMap.has(element)) {
  39. return elementMap.get(element).get(key) || null;
  40. }
  41. return null;
  42. },
  43. remove(element, key) {
  44. if (!elementMap.has(element)) {
  45. return;
  46. }
  47. const instanceMap = elementMap.get(element);
  48. instanceMap.delete(key); // 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