0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-12 00:08:59 +01:00
Bootstrap/js/dist/dom/data.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-03-01 17:31:34 +01:00
/*!
* Bootstrap data.js v5.3.0-alpha1 (https://getbootstrap.com/)
2022-05-13 08:07:23 +02:00
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
2020-09-14 17:12:06 +02:00
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Data = factory());
2021-10-05 17:50:18 +02:00
})(this, (function () { 'use strict';
2019-03-01 17:31:34 +01:00
/**
* --------------------------------------------------------------------------
* Bootstrap (v5.3.0-alpha1): dom/data.js
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
* --------------------------------------------------------------------------
*/
/**
* Constants
*/
2021-03-23 17:26:54 +01:00
const elementMap = new Map();
2021-10-05 17:50:18 +02:00
const data = {
2021-03-23 17:26:54 +01:00
set(element, key, instance) {
if (!elementMap.has(element)) {
elementMap.set(element, new Map());
}
const instanceMap = elementMap.get(element);
2019-03-01 17:31:34 +01:00
// make it clear we only want one instance per element
2021-03-23 17:26:54 +01:00
// can be removed later when multiple key/instances are fine to be used
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;
}
instanceMap.set(key, instance);
},
get(element, key) {
if (elementMap.has(element)) {
return elementMap.get(element).get(key) || null;
}
return null;
},
remove(element, key) {
if (!elementMap.has(element)) {
return;
2019-03-01 17:31:34 +01:00
}
2021-03-23 17:26:54 +01:00
const instanceMap = elementMap.get(element);
instanceMap.delete(key);
2021-03-23 17:26:54 +01:00
// free up element references if there are no instances left for an element
2021-03-23 17:26:54 +01:00
if (instanceMap.size === 0) {
elementMap.delete(element);
}
2019-03-01 17:31:34 +01:00
}
};
2021-03-23 17:26:54 +01:00
return data;
2019-03-01 17:31:34 +01:00
2021-10-05 17:50:18 +02:00
}));
2019-03-01 17:31:34 +01:00
//# sourceMappingURL=data.js.map