X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=inline;f=js%2F90-themes.js;h=347cad2db80ffa61f88583759136cf7c4de28851;hb=a9159cae5cd97f3f2d52de2b7c64decd44534f77;hp=56138d36f94d7000c8cba5e6599d6e1f8c7e80d1;hpb=02a539e5023724166530a97c64b7eb8bea6ace16;p=plack-app-gruntmaster.git diff --git a/js/90-themes.js b/js/90-themes.js index 56138d3..347cad2 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -1,26 +1,32 @@ -(function(){ - 'use strict'; - function set_style(name){ - $('#stylesheet').attr("href", "/css/" + name + ".css"); - 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').removeClass('hidden'); - $('#theme_slate' ).on('click', function () { set_style("slate"); }); - $('#theme_cerulean').on('click', function () { set_style("cerulean"); }); - $('#theme_cyborg' ).on('click', function () { set_style("cyborg"); }); - $('#theme_cosmo' ).on('click', function () { set_style("cosmo"); }); + $('link[title]').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')); }); +} - var theme = localStorage.getItem("theme"); - if(theme) { - set_style(theme); - } -})(); +$(function() { + var theme_ul = '
'; + var sidebar = $('#sidebar')[0]; + sidebar.insertBefore(m(theme_ul), sidebar.firstChild); + $('#themes a').on('click', e => set_style(e.target.dataset.theme, true)); +}); + +let theme = localStorage.getItem("theme"); +if(theme) { + if(theme == "cerulean" || theme == "cosmo") + theme = "readable"; + set_style(theme, false); +}