]> iEval git - gruntmaster-page.git/blobdiff - js/90-themes.js
Merge branch 'master' into newmc
[gruntmaster-page.git] / js / 90-themes.js
index 0bfa8bf839b2cb158da41c426e57fe9e00440538..5196574e3064decfb59ce85729acb174c51ff530 100644 (file)
@@ -1,28 +1,30 @@
-(function(){
-       'use strict';
-       function set_style(name){
-               $('link[rel~="stylesheet"]').prop('disabled', true);
-               $('link[title="' + name + '"]').prop('disabled', false);
-               localStorage.setItem("theme", name);
-               $(document).ready(function() {
-                       if(name == 'slate' || name == 'cyborg')
-                               $('.logo').removeClass('logo-light');
-                       else
-                               $('.logo').addClass('logo-light');
-               });
+function set_style(name, trans){
+       if(trans){
+               document.body.classList.add('transition-color');
+               setTimeout(() => document.body.classList.remove('transition-color'), 1000);
        }
-
-       $( document ).ready(function() {
-               $('#theme-selector').detach().prependTo($('#sidebar'));
-               $('#theme_slate'   ).on('click', function () { set_style("slate"); });
-               $('#theme_cyborg'  ).on('click', function () { set_style("cyborg"); });
-               $('#theme_readable').on('click', function () { set_style("readable"); });
+       if(q('html').className == name)
+               return;
+       q('html').className = name;
+       localStorage.setItem("theme", name);
+       $(function() {
+               if(name == 'slate' || name == 'cyborg')
+                       $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/light', 'logos/dark')));
+               else
+                       $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/dark', 'logos/light')));
        });
+}
 
-       var theme = localStorage.getItem("theme");
-       if(theme) {
-               if(theme == "cerulean" || theme == "cosmo")
-                       theme = "readable";
-               set_style(theme);
-       }
-})();
+$(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 = q('#sidebar');
+       sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
+       $('#themes a').on('click', e => set_style(e.target.dataset.theme, true));
+});
+
+const theme = localStorage.getItem("theme");
+if(theme)
+       set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false);
This page took 0.023611 seconds and 4 git commands to generate.