X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F90-themes.js;h=a94d1300d9434140fc60004ea80eff1a09fb30fe;hb=db73dc0cea19c7992776392125cd49e28014ea81;hp=6afd44448943594cea0a80416b42ea0495e8d420;hpb=bdaa8919598cbbd8753fd6795b34b594b1b30805;p=plack-app-gruntmaster.git diff --git a/js/90-themes.js b/js/90-themes.js index 6afd444..a94d130 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -1,30 +1,22 @@ -(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); } + q('html').className = name; + localStorage.setItem("theme", name); +} - var selector; +$(function() { + const theme_ul = ''; + const sidebar = q('#sidebar'); + 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 = $('' + text + ''); - link.appendTo(selector.find('ul')).wrap('
  • ').on('click', function () { set_style(theme) }); - } - - $( document ).ready(function() { - selector = $('
    Themes:
    '); - 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);