all repos — nasg @ f9f540d0341d422d1a0119bda1256148240d4d50

themeswitcher actually seems to be working + styling cleanup for themeswitcher
Peter Molnar hello@petermolnar.eu
Fri, 16 Nov 2018 22:39:12 +0000
commit

f9f540d0341d422d1a0119bda1256148240d4d50

parent

534daff81a4f420fca0efb1bd72269c4bb79e4b9

3 files changed, 71 insertions(+), 88 deletions(-)

jump to
M templates/base.j2.htmltemplates/base.j2.html

@@ -58,6 +58,12 @@ <svg width="16" height="16"><use xlink:href="#icon-note" /></svg>

notes </a> </li> + <li> + <a title="follow petermolnar.net" href="{{ site.url }}/follow/"> + <svg width="16" height="16"><use xlink:href="#icon-feed" /></svg> + follow + </a> + </li> </ul> </nav>

@@ -84,15 +90,6 @@ <form role="search" method="get" action="{{ site.url }}/search.php">

<input type="search" placeholder="search..." value="" name="q" id="q" title="Search for:" /> <input type="submit" value="➡" /> </form> - - <p class="follow"> - <a title="follow petermolnar.net" href="{{ site.url }}/follow/"> - <svg width="16" height="16"> - <use xlink:href="#icon-feed" /> - </svg> - follow - </a> - </p> </div> </header>
M templates/style.csstemplates/style.css

@@ -15,15 +15,11 @@ padding: 0;

font-family: sans-serif; color: #ccc; background-color: #222; - font-size: 100%; line-height: 1.3em; - transition: all 0.2s; } svg { transform: rotate(0deg); - width: 16px; - height: 16px; fill: currentColor; vertical-align: middle; }

@@ -92,6 +88,7 @@ padding: 0.3em 0;

text-align: center; } +video, figure img { display: block; max-height: 98vh;

@@ -102,16 +99,16 @@ margin: 0 auto;

border: 1px solid #000; } -figcaption dt { - display: none; -} - -figcaption dd { +figcaption dd, label { font-size: 0.8em; display: inline-block; margin:0.3em 0.3em; } +label { + cursor: pointer; +} + ul { padding-left: 1.3em; }

@@ -131,33 +128,6 @@ background-color: transparent;

vertical-align: middle; } -label { - font-weight: bold; - font-size: 0.8em; - cursor: pointer; - margin: 0 0.3em; -} - -.theme { - margin: 0 0.3em; - display: none; - color: #ccc; -} - -.theme input { - display: none; -} - -.theme input + label::before { - content: '\2718'; - display: inline-block; - padding: 0 0.1em; -} - -.theme input:checked + label::before { - content: '\2714'; -} - input { border-bottom: 3px solid #ccc; }

@@ -175,7 +145,7 @@ }

code, pre, q, figcaption { font-family: monospace; - font-size: 0.94em; + font-size: 1em; } code, pre {

@@ -238,18 +208,8 @@ padding: 0.6em 0.6em;

background-color: #111; } -body > header form { - padding: 0.2em 0 0 0; - display: inline-block; -} - body > header p { font-size: 0.8em; -} - -body > svg, -body > script { - display: none; } body > header {

@@ -260,12 +220,19 @@ body > header nav {

margin: 0.3em 0; } +body > header form { + padding: 0.6em; + color: #ccc; + display: inline-block; +} + body > header a { font-weight: bold; color: #ccc; border-bottom: 3px solid transparent; text-decoration: none; padding-bottom: 0.3em; + font-size: 0.9em; } body > header a:hover,

@@ -279,6 +246,14 @@

body > header a svg { display: block; margin: 0.1em auto; +} + +.theme input + label { + border-bottom: 3px solid transparent; +} + +.theme input:checked + label { + border-bottom: 3px solid #ccc; } body > main,

@@ -315,10 +290,6 @@ body > footer img {

width: 1em; } -body > footer h2 { - display: none; -} - body > footer > ul >li > a > span { display: block; font-size: 0.8em;

@@ -337,11 +308,17 @@ .footnote-back {

margin: 0 0 0 0.1em; } -.h-feed h1 { +figcaption dt, +body > svg, +body > script, +body > footer h2, +.h-feed h1, +.theme, +.theme input { display: none; } -@media all and (min-width: 56em) { +@media all and (min-width: 58em) { body > header { text-align: unset; display: flex;

@@ -356,4 +333,10 @@

body > header a svg { display: inline-block; } -} + + + body > header form { + padding: 0.3em; + } + +}
M templates/themeswitcher.jstemplates/themeswitcher.js

@@ -3,15 +3,12 @@ var ALT_THEME = 'light';

var STORAGE_KEY = 'theme'; var colorscheme = document.getElementsByName('colorscheme'); -function setTheme(e) { - var mode = e.target.value; - if (mode == 'auto') { - localStorage.removeItem(STORAGE_KEY); +function indicateTheme(mode) { + for(var i = colorscheme.length; i--; ) { + if(colorscheme[i].value == mode) { + colorscheme[i].checked = true; + } } - else { - localStorage.setItem(STORAGE_KEY, mode); - } - applyTheme(mode); } function applyTheme(mode) {

@@ -22,32 +19,38 @@ }

else { st.setAttribute('media', 'speech'); } +} - for(var i = colorscheme.length; i--; ) { - if(colorscheme[i].value == mode) { - colorscheme[i].checked = true; - } +function setTheme(e) { + var mode = e.target.value; + if (mode == 'auto') { + localStorage.removeItem(STORAGE_KEY); + } + else { + localStorage.setItem(STORAGE_KEY, mode); } + var e = window.matchMedia('(prefers-color-scheme: ' + ALT_THEME + ')'); + autoTheme(e); } -function mqlTheme(e) { - if (localStorage.getItem(STORAGE_KEY) != null) { - return false; +function autoTheme(e) { + var current = localStorage.getItem(STORAGE_KEY); + var mode = 'auto'; + var indicate = 'auto'; + if ( current != null) { + indicate = mode = current; } - if (e.matches) { - applyTheme(ALT_THEME); - } - else { - applyTheme(DEFAULT_THEME); + else if (e.matches) { + mode = ALT_THEME; } + applyTheme(mode); + indicateTheme(indicate); } -var current = localStorage.getItem(STORAGE_KEY); -if (current == null) { current = 'auto'; } -applyTheme(current); +var mql = window.matchMedia('(prefers-color-scheme: ' + ALT_THEME + ')'); +autoTheme(mql); +mql.addListener(autoTheme); -var mql = window.matchMedia('(prefers-color-scheme: ' + ALT_THEME + ')'); -mql.addListener(mqlTheme); for(var i = colorscheme.length; i--; ) { colorscheme[i].onclick = setTheme; }