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

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-03-01 17:31:34 +01:00
/*!
2021-03-23 17:26:54 +01:00
* Bootstrap data.js v5.0.0-beta3 (https://getbootstrap.com/)
* Copyright 2011-2021 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());
2019-11-08 09:11:23 +01:00
}(this, (function () { 'use strict';
2019-03-01 17:31:34 +01:00
/**
* --------------------------------------------------------------------------
2021-03-23 17:26:54 +01:00
* Bootstrap (v5.0.0-beta3): 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();
var data = {
set(element, key, instance) {
if (!elementMap.has(element)) {
elementMap.set(element, new Map());
}
2019-03-01 17:31:34 +01:00
2021-03-23 17:26:54 +01: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 17:31:34 +01:00
2021-03-23 17:26:54 +01: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 17:31:34 +01:00
2021-03-23 17:26:54 +01:00
instanceMap.set(key, instance);
},
2019-03-01 17:31:34 +01:00
2021-03-23 17:26:54 +01:00
get(element, key) {
if (elementMap.has(element)) {
return elementMap.get(element).get(key) || null;
}
2019-03-01 17:31:34 +01:00
2021-03-23 17:26:54 +01:00
return null;
},
2019-03-01 17:31:34 +01:00
2021-03-23 17:26:54 +01:00
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); // free up element references if there are no instances left for an element
if (instanceMap.size === 0) {
elementMap.delete(element);
}
2019-03-01 17:31:34 +01:00
}
2021-03-23 17:26:54 +01:00
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
2019-11-08 09:11:23 +01:00
})));
2019-03-01 17:31:34 +01:00
//# sourceMappingURL=data.js.map