Use const wherever possible in js/
[plack-app-gruntmaster.git] / js / 90-themes.js
index 6afd44448943594cea0a80416b42ea0495e8d420..a9d9b5185ebf5f1bd905dffc0767b46841b7bf4e 100644 (file)
@@ -1,30 +1,23 @@
-(function(){
-       'use strict';
-       function set_style(name){
-               $('link[rel~="stylesheet"]').prop('disabled', true);
-               $('link[title="' + name + '"]').prop('disabled', false);
-               localStorage.setItem("theme", name);
+function set_style(name, trans){
+       if(trans){
+               document.body.classList.add('transition-color');
+               setTimeout(() => document.body.classList.remove('transition-color'), 1000);
        }
+       $('link[title]').each(e => e.disabled = true);
+       $('link[title="' + name + '"]')[0].disabled = false;
+       localStorage.setItem("theme", name);
+}
 
-       var selector;
+$(function() {
+       const theme_ul = '<ul class="list-inline" id="themes">' +
+               '<li><a role="button" data-theme="cyborg">Black</a>' +
+               '<li><a role="button" data-theme="slate">Grey</a>' +
+               '<li><a role="button" data-theme="readable">White</a></ul>';
+       const sidebar = $('#sidebar')[0];
+       sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
+       $('#themes a').on('click', e => set_style(e.target.dataset.theme, true));
+});
 
-       function add_themelink(theme, text) {
-               var link = $('<a role="button">' + text + '</a>');
-               link.appendTo(selector.find('ul')).wrap('<li>').on('click', function () { set_style(theme) });
-       }
-
-       $( document ).ready(function() {
-               selector = $('<div>Themes: <ul class="list-inline"></ul></div>');
-               add_themelink('cyborg', 'Black');
-               add_themelink('slate', 'Grey');
-               add_themelink('readable', 'White');
-               $('#sidebar').prepend(selector);
-       });
-
-       var theme = localStorage.getItem("theme");
-       if(theme) {
-               if(theme == "cerulean" || theme == "cosmo")
-                       theme = "readable";
-               set_style(theme);
-       }
-})();
+const theme = localStorage.getItem("theme");
+if(theme)
+       set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false);
This page took 0.010764 seconds and 4 git commands to generate.