X-Git-Url: http://git.ieval.ro/?p=plack-app-gruntmaster.git;a=blobdiff_plain;f=js%2F90-themes.js;h=a9d9b5185ebf5f1bd905dffc0767b46841b7bf4e;hp=6afd44448943594cea0a80416b42ea0495e8d420;hb=65d5cb3b6007fa0bc758722983b3f0afefc02f2e;hpb=bdaa8919598cbbd8753fd6795b34b594b1b30805 diff --git a/js/90-themes.js b/js/90-themes.js index 6afd444..a9d9b51 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -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 = ''; + 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 = $('' + 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);