twbs--bootstrap/js/dist/dom/data.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-03-01 16:31:34 +00:00
/*!
* Bootstrap data.js v5.2.2 (https://getbootstrap.com/)
2022-05-13 06:07:23 +00:00
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 18:50:01 +00:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 16:31:34 +00:00
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
2020-09-14 15:12:06 +00:00
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Data = factory());
2021-10-05 15:50:18 +00:00
})(this, (function () { 'use strict';
2019-03-01 16:31:34 +00:00
/**
* --------------------------------------------------------------------------
* Bootstrap (v5.2.2): dom/data.js
2020-06-16 18:50:01 +00:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 16:31:34 +00:00
* --------------------------------------------------------------------------
*/
/**
* Constants
*/
2021-03-23 16:26:54 +00:00
const elementMap = new Map();
2021-10-05 15:50:18 +00:00
const data = {
2021-03-23 16:26:54 +00:00
set(element, key, instance) {
if (!elementMap.has(element)) {
elementMap.set(element, new Map());
}
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
const instanceMap = elementMap.get(element); // make it clear we only want one instance per element
// can be removed later when multiple key/instances are fine to be used
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
if (!instanceMap.has(key) && instanceMap.size !== 0) {
// eslint-disable-next-line no-console
console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
return;
}
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
instanceMap.set(key, instance);
},
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
get(element, key) {
if (elementMap.has(element)) {
return elementMap.get(element).get(key) || null;
}
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
return null;
},
2019-03-01 16:31:34 +00:00
2021-03-23 16:26:54 +00:00
remove(element, key) {
if (!elementMap.has(element)) {
return;
2019-03-01 16:31:34 +00:00
}
2021-03-23 16:26:54 +00:00
const instanceMap = elementMap.get(element);
instanceMap.delete(key); // free up element references if there are no instances left for an element
if (instanceMap.size === 0) {
elementMap.delete(element);
}
2019-03-01 16:31:34 +00:00
}
2021-03-23 16:26:54 +00:00
2019-03-01 16:31:34 +00:00
};
2021-03-23 16:26:54 +00:00
return data;
2019-03-01 16:31:34 +00:00
2021-10-05 15:50:18 +00:00
}));
2019-03-01 16:31:34 +00:00
//# sourceMappingURL=data.js.map