[d565449] | 1 | /*!
|
---|
| 2 | * Bootstrap manipulator.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.Manipulator = factory());
|
---|
| 10 | })(this, (function () { 'use strict';
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * --------------------------------------------------------------------------
|
---|
| 14 | * Bootstrap dom/manipulator.js
|
---|
| 15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
| 16 | * --------------------------------------------------------------------------
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | function normalizeData(value) {
|
---|
| 20 | if (value === 'true') {
|
---|
| 21 | return true;
|
---|
| 22 | }
|
---|
| 23 | if (value === 'false') {
|
---|
| 24 | return false;
|
---|
| 25 | }
|
---|
| 26 | if (value === Number(value).toString()) {
|
---|
| 27 | return Number(value);
|
---|
| 28 | }
|
---|
| 29 | if (value === '' || value === 'null') {
|
---|
| 30 | return null;
|
---|
| 31 | }
|
---|
| 32 | if (typeof value !== 'string') {
|
---|
| 33 | return value;
|
---|
| 34 | }
|
---|
| 35 | try {
|
---|
| 36 | return JSON.parse(decodeURIComponent(value));
|
---|
| 37 | } catch (_unused) {
|
---|
| 38 | return value;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | function normalizeDataKey(key) {
|
---|
| 42 | return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`);
|
---|
| 43 | }
|
---|
| 44 | const Manipulator = {
|
---|
| 45 | setDataAttribute(element, key, value) {
|
---|
| 46 | element.setAttribute(`data-bs-${normalizeDataKey(key)}`, value);
|
---|
| 47 | },
|
---|
| 48 | removeDataAttribute(element, key) {
|
---|
| 49 | element.removeAttribute(`data-bs-${normalizeDataKey(key)}`);
|
---|
| 50 | },
|
---|
| 51 | getDataAttributes(element) {
|
---|
| 52 | if (!element) {
|
---|
| 53 | return {};
|
---|
| 54 | }
|
---|
| 55 | const attributes = {};
|
---|
| 56 | const bsKeys = Object.keys(element.dataset).filter(key => key.startsWith('bs') && !key.startsWith('bsConfig'));
|
---|
| 57 | for (const key of bsKeys) {
|
---|
| 58 | let pureKey = key.replace(/^bs/, '');
|
---|
| 59 | pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length);
|
---|
| 60 | attributes[pureKey] = normalizeData(element.dataset[key]);
|
---|
| 61 | }
|
---|
| 62 | return attributes;
|
---|
| 63 | },
|
---|
| 64 | getDataAttribute(element, key) {
|
---|
| 65 | return normalizeData(element.getAttribute(`data-bs-${normalizeDataKey(key)}`));
|
---|
| 66 | }
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 | return Manipulator;
|
---|
| 70 |
|
---|
| 71 | }));
|
---|
| 72 | //# sourceMappingURL=manipulator.js.map
|
---|