X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F90-themes.js;h=5196574e3064decfb59ce85729acb174c51ff530;hb=1115b827f7dd520c9776d3e59848ddf5b475534d;hp=0b043b8e393adc21146c4a698286f441ea499f98;hpb=43a857a965517d3fcdeae0300a01c1297f9d211c;p=plack-app-gruntmaster.git
diff --git a/js/90-themes.js b/js/90-themes.js
index 0b043b8..5196574 100644
--- a/js/90-themes.js
+++ b/js/90-themes.js
@@ -1,36 +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);
}
-
- var selector;
-
- function add_themelink(theme, text) {
- var link = $('' + text + '');
- link.appendTo(selector.find('ul')).wrap('
').on('click', function () { set_style(theme) });
- }
-
- $( document ).ready(function() {
- selector = $('');
- add_themelink('cyborg', 'Black');
- add_themelink('slate', 'Grey');
- add_themelink('readable', 'White');
- $('#sidebar').prepend(selector);
+ 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);