X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F90-themes.js;h=50834da65622a6ffd71536067798d34a8ad54d95;hb=c13e110a3f07e2aef0892f64207f20dcd01ebdd6;hp=a61b4c0c0089983ff69f06341667ceb9f6d57e15;hpb=7093e9ba00cf7727a52a49d34d4df12e4f865dd4;p=plack-app-gruntmaster.git
diff --git a/js/90-themes.js b/js/90-themes.js
index a61b4c0..50834da 100644
--- a/js/90-themes.js
+++ b/js/90-themes.js
@@ -1,34 +1,28 @@
-function set_style(name){
- $('link[rel~="stylesheet"]').each(function (e){
- e.disabled = true;
- });
- $('link[title="' + name + '"]')[0].disabled = false;
+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 theme_ul;
-
-function add_themelink(theme, text) {
- theme_ul.innerHTML += '
' + text + ''
+ $(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')));
+ });
}
$(function() {
- theme_ul = document.createElement('ul');
- theme_ul.className = 'list-inline';
- theme_ul.id = 'themes';
- add_themelink('cyborg', 'Black');
- add_themelink('slate', 'Grey');
- add_themelink('readable', 'White');
- var sidebar = $('#sidebar')[0];
- sidebar.insertBefore(theme_ul, sidebar.firstChild);
- $('#themes a').on('click', function(e){
- set_style(this.dataset.theme);
- });
+ 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));
});
-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);