1 | /*!
|
---|
2 | * Bootstrap manipulator.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.Manipulator = factory());
|
---|
10 | })(this, (function () { 'use strict';
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * --------------------------------------------------------------------------
|
---|
14 | * Bootstrap (v5.1.3): dom/manipulator.js
|
---|
15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
16 | * --------------------------------------------------------------------------
|
---|
17 | */
|
---|
18 | function normalizeData(val) {
|
---|
19 | if (val === 'true') {
|
---|
20 | return true;
|
---|
21 | }
|
---|
22 |
|
---|
23 | if (val === 'false') {
|
---|
24 | return false;
|
---|
25 | }
|
---|
26 |
|
---|
27 | if (val === Number(val).toString()) {
|
---|
28 | return Number(val);
|
---|
29 | }
|
---|
30 |
|
---|
31 | if (val === '' || val === 'null') {
|
---|
32 | return null;
|
---|
33 | }
|
---|
34 |
|
---|
35 | return val;
|
---|
36 | }
|
---|
37 |
|
---|
38 | function normalizeDataKey(key) {
|
---|
39 | return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`);
|
---|
40 | }
|
---|
41 |
|
---|
42 | const Manipulator = {
|
---|
43 | setDataAttribute(element, key, value) {
|
---|
44 | element.setAttribute(`data-bs-${normalizeDataKey(key)}`, value);
|
---|
45 | },
|
---|
46 |
|
---|
47 | removeDataAttribute(element, key) {
|
---|
48 | element.removeAttribute(`data-bs-${normalizeDataKey(key)}`);
|
---|
49 | },
|
---|
50 |
|
---|
51 | getDataAttributes(element) {
|
---|
52 | if (!element) {
|
---|
53 | return {};
|
---|
54 | }
|
---|
55 |
|
---|
56 | const attributes = {};
|
---|
57 | Object.keys(element.dataset).filter(key => key.startsWith('bs')).forEach(key => {
|
---|
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 |
|
---|
65 | getDataAttribute(element, key) {
|
---|
66 | return normalizeData(element.getAttribute(`data-bs-${normalizeDataKey(key)}`));
|
---|
67 | },
|
---|
68 |
|
---|
69 | offset(element) {
|
---|
70 | const rect = element.getBoundingClientRect();
|
---|
71 | return {
|
---|
72 | top: rect.top + window.pageYOffset,
|
---|
73 | left: rect.left + window.pageXOffset
|
---|
74 | };
|
---|
75 | },
|
---|
76 |
|
---|
77 | position(element) {
|
---|
78 | return {
|
---|
79 | top: element.offsetTop,
|
---|
80 | left: element.offsetLeft
|
---|
81 | };
|
---|
82 | }
|
---|
83 |
|
---|
84 | };
|
---|
85 |
|
---|
86 | return Manipulator;
|
---|
87 |
|
---|
88 | }));
|
---|
89 | //# sourceMappingURL=manipulator.js.map
|
---|