PEed the themer

This commit is contained in:
Heydon Pickering 2017-08-19 18:18:18 +01:00
parent 91db19dfae
commit 5c07e6d1a4
5 changed files with 33 additions and 11 deletions

View File

@ -71,6 +71,10 @@ figure p img {
div:not([tabindex]):focus { div:not([tabindex]):focus {
outline: none; outline: none;
} }
[hidden] {
display: none;
}
/* skip link */ /* skip link */
[href="#main"] { [href="#main"] {

View File

@ -128,11 +128,16 @@
/* Switch and persist theme */ /* Switch and persist theme */
(function () { (function () {
var checkbox = document.getElementById('themer'); var checkbox = document.getElementById('themer');
var invertor = document.getElementById('inverter'); var inverter = document.getElementById('inverter');
function darkTheme(media) { function darkTheme(media) {
invertor.setAttribute('media', media); if (!('filter' in document.body.style)) {
invertor.textContent = invertor.textContent.trim(); checkbox.parentNode.hidden = true;
return;
}
inverter.setAttribute('media', media);
inverter.textContent = inverter.textContent.trim();
localStorage.setItem('darkTheme', media); localStorage.setItem('darkTheme', media);
} }
@ -141,8 +146,10 @@
}); });
window.addEventListener('DOMContentLoaded', function () { window.addEventListener('DOMContentLoaded', function () {
if ('filter' in document.body.style) {
if (localStorage.getItem('darkTheme') === 'screen') { if (localStorage.getItem('darkTheme') === 'screen') {
checkbox.click(); checkbox.click();
} }
}
}); });
}()); }());

File diff suppressed because one or more lines are too long

View File

@ -71,6 +71,10 @@ figure p img {
div:not([tabindex]):focus { div:not([tabindex]):focus {
outline: none; outline: none;
} }
[hidden] {
display: none;
}
/* skip link */ /* skip link */
[href="#main"] { [href="#main"] {

View File

@ -128,11 +128,16 @@
/* Switch and persist theme */ /* Switch and persist theme */
(function () { (function () {
var checkbox = document.getElementById('themer'); var checkbox = document.getElementById('themer');
var invertor = document.getElementById('inverter'); var inverter = document.getElementById('inverter');
function darkTheme(media) { function darkTheme(media) {
invertor.setAttribute('media', media); if (!('filter' in document.body.style)) {
invertor.textContent = invertor.textContent.trim(); checkbox.parentNode.hidden = true;
return;
}
inverter.setAttribute('media', media);
inverter.textContent = inverter.textContent.trim();
localStorage.setItem('darkTheme', media); localStorage.setItem('darkTheme', media);
} }
@ -141,8 +146,10 @@
}); });
window.addEventListener('DOMContentLoaded', function () { window.addEventListener('DOMContentLoaded', function () {
if ('filter' in document.body.style) {
if (localStorage.getItem('darkTheme') === 'screen') { if (localStorage.getItem('darkTheme') === 'screen') {
checkbox.click(); checkbox.click();
} }
}
}); });
}()); }());