labs.templatescript.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <script>
  2. 'use strict';
  3. var classHolder = document.getElementsByTagName("BODY")[0],
  4. /**
  5. * Load from localstorage
  6. **/
  7. themeSettings = (localStorage.getItem('themeSettings')) ? JSON.parse(localStorage.getItem('themeSettings')) :
  8. {},
  9. themeURL = themeSettings.themeURL || '',
  10. themeOptions = themeSettings.themeOptions || '';
  11. /**
  12. * Load theme options
  13. **/
  14. if (themeSettings.themeOptions)
  15. {
  16. classHolder.className = themeSettings.themeOptions;
  17. console.log("%c✔ Theme settings loaded", "color: #148f32");
  18. }
  19. else
  20. {
  21. console.log("Heads up! Theme settings is empty or does not exist, loading default settings...");
  22. }
  23. if (themeSettings.themeURL && !document.getElementById('mytheme'))
  24. {
  25. var cssfile = document.createElement('link');
  26. cssfile.id = 'mytheme';
  27. cssfile.rel = 'stylesheet';
  28. cssfile.href = themeURL;
  29. document.getElementsByTagName('head')[0].appendChild(cssfile);
  30. }
  31. /**
  32. * Save to localstorage
  33. **/
  34. var saveSettings = function()
  35. {
  36. themeSettings.themeOptions = String(classHolder.className).split(/[^\w-]+/).filter(function(item)
  37. {
  38. return /^(nav|header|mod|display)-/i.test(item);
  39. }).join(' ');
  40. if (document.getElementById('mytheme'))
  41. {
  42. themeSettings.themeURL = document.getElementById('mytheme').getAttribute("href");
  43. };
  44. localStorage.setItem('themeSettings', JSON.stringify(themeSettings));
  45. }
  46. /**
  47. * Reset settings
  48. **/
  49. var resetSettings = function()
  50. {
  51. localStorage.setItem("themeSettings", "");
  52. }
  53. </script>