Add a function for making a DOM element from HTML
[plack-app-gruntmaster.git] / js / 90-themes.js
index caefa395a0bc7ce4edf0e05e49361494ba8ee103..c280266f466e6ac7506ce355df3d4c8767bcdceb 100644 (file)
@@ -1,21 +1,26 @@
-(function(){
-       'use strict';
-       function set_style(name){
-               $('#stylesheet').attr("href", "/css/" + name + ".css");
-               localStorage.setItem("theme", name);
-       }
+function set_style(name){
+       $('link[rel~="stylesheet"]').each(function (e){
+               e.disabled = true;
+       });
+       $('link[title="' + name + '"]')[0].disabled = false;
+       localStorage.setItem("theme", name);
+}
 
-       $( 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"); });
+$(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', function(e){
+               set_style(this.dataset.theme);
        });
+});
 
-       var theme = localStorage.getItem("theme");
-       if(theme) {
-               if(theme == "cerulean" || theme == "cosmo")
-                       theme = "readable";
-               set_style(theme);
-       }
-})();
+var theme = localStorage.getItem("theme");
+if(theme) {
+       if(theme == "cerulean" || theme == "cosmo")
+               theme = "readable";
+       set_style(theme);
+}
This page took 0.012536 seconds and 4 git commands to generate.