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.

89 lines
2.5 KiB

  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. * Bootstrap (v5.1.3): dom/manipulator.js
  14. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  15. * --------------------------------------------------------------------------
  16. */
  17. function normalizeData(val) {
  18. if (val === 'true') {
  19. return true;
  20. }
  21. if (val === 'false') {
  22. return false;
  23. }
  24. if (val === Number(val).toString()) {
  25. return Number(val);
  26. }
  27. if (val === '' || val === 'null') {
  28. return null;
  29. }
  30. return val;
  31. }
  32. function normalizeDataKey(key) {
  33. return key.replace(/[A-Z]/g, chr => `-${chr.toLowerCase()}`);
  34. }
  35. const Manipulator = {
  36. setDataAttribute(element, key, value) {
  37. element.setAttribute(`data-bs-${normalizeDataKey(key)}`, value);
  38. },
  39. removeDataAttribute(element, key) {
  40. element.removeAttribute(`data-bs-${normalizeDataKey(key)}`);
  41. },
  42. getDataAttributes(element) {
  43. if (!element) {
  44. return {};
  45. }
  46. const attributes = {};
  47. Object.keys(element.dataset).filter(key => key.startsWith('bs')).forEach(key => {
  48. let pureKey = key.replace(/^bs/, '');
  49. pureKey = pureKey.charAt(0).toLowerCase() + pureKey.slice(1, pureKey.length);
  50. attributes[pureKey] = normalizeData(element.dataset[key]);
  51. });
  52. return attributes;
  53. },
  54. getDataAttribute(element, key) {
  55. return normalizeData(element.getAttribute(`data-bs-${normalizeDataKey(key)}`));
  56. },
  57. offset(element) {
  58. const rect = element.getBoundingClientRect();
  59. return {
  60. top: rect.top + window.pageYOffset,
  61. left: rect.left + window.pageXOffset
  62. };
  63. },
  64. position(element) {
  65. return {
  66. top: element.offsetTop,
  67. left: element.offsetLeft
  68. };
  69. }
  70. };
  71. return Manipulator;
  72. }));
  73. //# sourceMappingURL=manipulator.js.map