X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F90-themes.js;h=5196574e3064decfb59ce85729acb174c51ff530;hb=4798492f32c112adfd5588da7080bac2494e8fd9;hp=0bfa8bf839b2cb158da41c426e57fe9e00440538;hpb=838663d1450cf5606e59c30966e2e56b0f787416;p=plack-app-gruntmaster.git diff --git a/js/90-themes.js b/js/90-themes.js index 0bfa8bf..5196574 100644 --- a/js/90-themes.js +++ b/js/90-themes.js @@ -1,28 +1,30 @@ -(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'); - }); +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').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"); }); + if(q('html').className == name) + return; + q('html').className = name; + localStorage.setItem("theme", name); + $(function() { + if(name == 'slate' || name == 'cyborg') + $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/light', 'logos/dark'))); + else + $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/dark', 'logos/light'))); }); +} - var theme = localStorage.getItem("theme"); - if(theme) { - if(theme == "cerulean" || theme == "cosmo") - theme = "readable"; - set_style(theme); - } -})(); +$(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)); +}); + +const theme = localStorage.getItem("theme"); +if(theme) + set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false);