default theme option and slight improvement to head template

merge-requests/208/head
fatchan 5 years ago
parent 47280caced
commit b85afbb0db
  1. 15
      gulp/res/js/theme.js
  2. 4
      views/includes/footer.pug
  3. 6
      views/includes/head.pug
  4. 4
      views/includes/themeswitcher.pug

@ -1,11 +1,20 @@
function changeTheme(e) { function changeTheme(e) {
var theme = e ? this.value : localStorage.getItem('theme'); var theme = e ? this.value : localStorage.getItem('theme');
if (!theme) { if (!theme) {
return; theme = 'default';
} }
localStorage.setItem('theme', theme) localStorage.setItem('theme', theme);
var themeLink = document.getElementById('theme'); var themeLink = document.getElementById('theme');
themeLink.href = '/css/themes/'+theme+'.css'; //if somebody makes a theme file named "default", it wont work. so just dont.
if (theme === 'default') {
var defaultTheme = themeLink.dataset.theme;
var defaultHref = '/css/themes/'+defaultTheme+'.css';
if (themeLink.href !== defaultHref) {
themeLink.href = '/css/themes/'+defaultTheme+'.css';
}
} else {
themeLink.href = '/css/themes/'+theme+'.css';
}
} }
changeTheme(); changeTheme();

@ -6,6 +6,4 @@ small.footer#bottom
| - | -
a(href='https://github.com/fatchan/jschan/') source code a(href='https://github.com/fatchan/jschan/') source code
| - | -
select.jsonly#theme-changer(name='theme') include ./themeswitcher.pug
each theme in themes
option(value=theme) #{theme}

@ -1,10 +1,8 @@
meta(charset='utf-8') meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1') meta(name='viewport', content='width=device-width, initial-scale=1')
link(rel='stylesheet' href='/css/style.css') link(rel='stylesheet' href='/css/style.css')
if board && board.settings.theme - const theme = board ? board.settings.theme : defaultTheme;
link#theme(rel='stylesheet' href=`/css/themes/${board.settings.theme}.css`) link#theme(rel='stylesheet' data-theme=theme href=`/css/themes/${theme}.css`)
else
link#theme(rel='stylesheet' href=`/css/themes/${defaultTheme}.css`)
noscript noscript
style style
| .jsonly { display: none } | .jsonly { display: none }

@ -0,0 +1,4 @@
select.jsonly#theme-changer(name='theme')
option(value='default') default
each theme in themes
option(value=theme) #{theme}
Loading…
Cancel
Save