You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

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