diff options
| author | Ole Mussmann <gitlab+account@ole.mn> | 2025-02-20 20:59:17 +0100 | 
|---|---|---|
| committer | Ole Mussmann <gitlab+account@ole.mn> | 2025-02-20 20:59:17 +0100 | 
| commit | a05a5b2704eec66e84c4fc3045127e354cf38e1a (patch) | |
| tree | b4b0981b35911d7ec54f790c3e933f9a99a6250a | |
| parent | 27d124b7f403030ebf996954bf271a06286508e3 (diff) | |
move inline JS to its own file
| -rw-r--r-- | layouts/_default/baseof.html | 36 | ||||
| -rw-r--r-- | static/js/theme-switch.js | 28 | 
2 files changed, 30 insertions, 34 deletions
| diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 52a6767..7a5579d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -34,38 +34,6 @@  </body> -<script> - -  function isAuto() { -    return document.body.classList.contains("auto"); -  } - -  function setTheme() { -    if (!isAuto()) { -      return -    } - -    document.body.classList.remove("auto"); -    let cls = "light"; -    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { -      cls = "dark"; -    } - -    document.body.classList.add(cls); -  } - -  function invertBody() { -    document.body.classList.toggle("dark"); -    document.body.classList.toggle("light"); -  } - -  if (isAuto()) { -    window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody); -  } - -  setTheme(); - -</script> - +<script src="{{ "js/theme-switch.js" | relURL }}"></script>  <script defer src="{{ "js/copy-code.js" | relURL }}"></script> -</html>
\ No newline at end of file +</html> diff --git a/static/js/theme-switch.js b/static/js/theme-switch.js new file mode 100644 index 0000000..a617fda --- /dev/null +++ b/static/js/theme-switch.js @@ -0,0 +1,28 @@ +function isAuto() { +  return document.body.classList.contains("auto"); +} + +function setTheme() { +  if (!isAuto()) { +    return +  } + +  document.body.classList.remove("auto"); +  let cls = "light"; +  if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { +    cls = "dark"; +  } + +  document.body.classList.add(cls); +} + +function invertBody() { +  document.body.classList.toggle("dark"); +  document.body.classList.toggle("light"); +} + +if (isAuto()) { +  window.matchMedia('(prefers-color-scheme: dark)').addListener(invertBody); +} + +setTheme(); | 
