demo.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*!
  2. * Tabler v1.0.0-beta17 (https://tabler.io)
  3. * @version 1.0.0-beta17
  4. * @link https://tabler.io
  5. * Copyright 2018-2023 The Tabler Authors
  6. * Copyright 2018-2023 codecalm.net Paweł Kuna
  7. * Licensed under MIT (https://github.com/tabler/tabler/blob/master/LICENSE)
  8. */
  9. (function (factory) {
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. factory();
  12. })((function () { 'use strict';
  13. function _iterableToArrayLimit(arr, i) {
  14. var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
  15. if (null != _i) {
  16. var _s,
  17. _e,
  18. _x,
  19. _r,
  20. _arr = [],
  21. _n = !0,
  22. _d = !1;
  23. try {
  24. if (_x = (_i = _i.call(arr)).next, 0 === i) {
  25. if (Object(_i) !== _i) return;
  26. _n = !1;
  27. } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
  28. } catch (err) {
  29. _d = !0, _e = err;
  30. } finally {
  31. try {
  32. if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
  33. } finally {
  34. if (_d) throw _e;
  35. }
  36. }
  37. return _arr;
  38. }
  39. }
  40. function _slicedToArray(arr, i) {
  41. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  42. }
  43. function _arrayWithHoles(arr) {
  44. if (Array.isArray(arr)) return arr;
  45. }
  46. function _unsupportedIterableToArray(o, minLen) {
  47. if (!o) return;
  48. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  49. var n = Object.prototype.toString.call(o).slice(8, -1);
  50. if (n === "Object" && o.constructor) n = o.constructor.name;
  51. if (n === "Map" || n === "Set") return Array.from(o);
  52. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  53. }
  54. function _arrayLikeToArray(arr, len) {
  55. if (len == null || len > arr.length) len = arr.length;
  56. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  57. return arr2;
  58. }
  59. function _nonIterableRest() {
  60. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  61. }
  62. var items = {
  63. 'menu-position': {
  64. localStorage: 'tablerMenuPosition',
  65. default: 'top'
  66. },
  67. 'menu-behavior': {
  68. localStorage: 'tablerMenuBehavior',
  69. default: 'sticky'
  70. },
  71. 'container-layout': {
  72. localStorage: 'tablerContainerLayout',
  73. default: 'boxed'
  74. }
  75. };
  76. var config = {};
  77. for (var _i = 0, _Object$entries = Object.entries(items); _i < _Object$entries.length; _i++) {
  78. var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
  79. key = _Object$entries$_i[0],
  80. params = _Object$entries$_i[1];
  81. var lsParams = localStorage.getItem(params.localStorage);
  82. config[key] = lsParams ? lsParams : params.default;
  83. }
  84. var parseUrl = function parseUrl() {
  85. var search = window.location.search.substring(1);
  86. var params = search.split('&');
  87. for (var i = 0; i < params.length; i++) {
  88. var arr = params[i].split('=');
  89. var _key = arr[0];
  90. var value = arr[1];
  91. if (!!items[_key]) {
  92. localStorage.setItem(items[_key].localStorage, value);
  93. config[_key] = value;
  94. }
  95. }
  96. };
  97. var toggleFormControls = function toggleFormControls(form) {
  98. for (var _i2 = 0, _Object$entries2 = Object.entries(items); _i2 < _Object$entries2.length; _i2++) {
  99. var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
  100. _key2 = _Object$entries2$_i[0];
  101. _Object$entries2$_i[1];
  102. var elem = form.querySelector("[name=\"settings-".concat(_key2, "\"][value=\"").concat(config[_key2], "\"]"));
  103. if (elem) {
  104. elem.checked = true;
  105. }
  106. }
  107. };
  108. var submitForm = function submitForm(form) {
  109. for (var _i3 = 0, _Object$entries3 = Object.entries(items); _i3 < _Object$entries3.length; _i3++) {
  110. var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
  111. _key3 = _Object$entries3$_i[0],
  112. _params2 = _Object$entries3$_i[1];
  113. var value = form.querySelector("[name=\"settings-".concat(_key3, "\"]:checked")).value;
  114. localStorage.setItem(_params2.localStorage, value);
  115. config[_key3] = value;
  116. }
  117. window.dispatchEvent(new Event('resize'));
  118. new bootstrap.Offcanvas(form).hide();
  119. };
  120. parseUrl();
  121. var form = document.querySelector('#offcanvasSettings');
  122. if (form) {
  123. form.addEventListener('submit', function (e) {
  124. e.preventDefault();
  125. submitForm(form);
  126. });
  127. toggleFormControls(form);
  128. }
  129. }));