Merge branch 'master' into newmc
[gruntmaster-page.git] / js / 90-themes.js
index 0b043b8e393adc21146c4a698286f441ea499f98..9de6b1b87b510dd0e85a63d38d5e9f38bbdfe9dc 100644 (file)
@@ -1,36 +1,28 @@
-(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');
-               });
-       }
-
-       var selector;
-
-       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);
+function set_style(name){
+       $('link[rel~="stylesheet"]').each(e => e.disabled = true);
+       $('link[title="' + name + '"]')[0].disabled = false;
+       localStorage.setItem("theme", name);
+       $(function() {
+               if(name == 'slate' || name == 'cyborg')
+                       $('.logo').each(e => e.classList.remove('logo-light'));
+               else
+                       $('.logo').each(e => e.classList.add('logo-light'));
        });
+}
+
+$(function() {
+       var 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>';
+       var sidebar = $('#sidebar')[0];
+       sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
+       $('#themes a').on('click', e => set_style(e.target.dataset.theme));
+});
 
-       var theme = localStorage.getItem("theme");
-       if(theme) {
-               if(theme == "cerulean" || theme == "cosmo")
-                       theme = "readable";
-               set_style(theme);
-       }
-})();
+let theme = localStorage.getItem("theme");
+if(theme) {
+       if(theme == "cerulean" || theme == "cosmo")
+               theme = "readable";
+       set_style(theme);
+}
This page took 0.010224 seconds and 4 git commands to generate.