demo-theme.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. * Tabler v1.0.0-beta19 (https://tabler.io)
  3. * @version 1.0.0-beta19
  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. var themeStorageKey = "tablerTheme";
  14. var defaultTheme = "light";
  15. var selectedTheme;
  16. var params = new Proxy(new URLSearchParams(window.location.search), {
  17. get: function get(searchParams, prop) {
  18. return searchParams.get(prop);
  19. }
  20. });
  21. if (!!params.theme) {
  22. localStorage.setItem(themeStorageKey, params.theme);
  23. selectedTheme = params.theme;
  24. } else {
  25. var storedTheme = localStorage.getItem(themeStorageKey);
  26. selectedTheme = storedTheme ? storedTheme : defaultTheme;
  27. }
  28. if (selectedTheme === 'dark') {
  29. document.body.setAttribute("data-bs-theme", selectedTheme);
  30. } else {
  31. document.body.removeAttribute("data-bs-theme");
  32. }
  33. }));