-(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_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"); });
+ 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) {
- 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);