-(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 = $('<a role="button">' + text + '</a>');
- link.appendTo(selector.find('ul')).wrap('<li>').on('click', function () { set_style(theme) });
- }
-
- $( document ).ready(function() {
- selector = $('<div>Themes: <ul class="list-inline"></ul></div>');
- 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 = '<ul class="list-inline" id="themes">' +
+ '<li><a role="button" data-theme="cyborg">Black</a>' +
+ '<li><a role="button" data-theme="slate">Grey</a>' +
+ '<li><a role="button" data-theme="readable">White</a></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);