Merge branch 'master' into newmc
[gruntmaster-page.git] / js / 90-themes.js
1 function set_style(name, trans){
2 if(trans){
3 document.body.classList.add('transition-color');
4 setTimeout(() => document.body.classList.remove('transition-color'), 1000);
5 }
6 q('html').className = name;
7 localStorage.setItem("theme", name);
8 $(function() {
9 if(name == 'slate' || name == 'cyborg')
10 $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/light', 'logos/dark')));
11 else
12 $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/dark', 'logos/light')));
13 });
14 }
15
16 $(function() {
17 const theme_ul = '<ul class="list-inline" id="themes">' +
18 '<li><a role="button" data-theme="cyborg">Black</a>' +
19 '<li><a role="button" data-theme="slate">Grey</a>' +
20 '<li><a role="button" data-theme="readable">White</a></ul>';
21 const sidebar = q('#sidebar');
22 sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
23 $('#themes a').on('click', e => set_style(e.target.dataset.theme, true));
24 });
25
26 const theme = localStorage.getItem("theme");
27 if(theme)
28 set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false);
This page took 0.02122 seconds and 4 git commands to generate.