From 3f7093882489d5cea0ae61b7e96f64aeffca4e60 Mon Sep 17 00:00:00 2001 From: radl97 <radl97@users.noreply.github.com> Date: Sat, 11 Jun 2022 16:28:50 +0200 Subject: [PATCH] Move inline script for theming to separate JS file Removed XMLHttpRequest, because it seems to serve no purpose. The first to read this notice, gets an ice cream. --- homepage/navbar.template.html | 24 +----------------------- static/js/theme.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 static/js/theme.js diff --git a/homepage/navbar.template.html b/homepage/navbar.template.html index d9d1bb1..0e436df 100644 --- a/homepage/navbar.template.html +++ b/homepage/navbar.template.html @@ -29,29 +29,7 @@ {{- end }} <li class="nav-item"> <a class="nav-link" id="theme"><img src="{{ if .Dark }}/static/images/moon.png{{ else }}/static/images/sun.png{{ end }}" class="icon_small" id="icon"></a> - <script> - let theme = document.getElementById('theme'); - let icon = document.getElementById('icon'); - let body = document.body; - theme.onclick = () => { - let url = "/theme/" - if (body.classList.contains('light')) { - body.classList.remove('light'); - body.classList.add('dark'); - url += "dark" - icon.src="/static/images/moon.png" - } else { - body.classList.remove('dark'); - body.classList.add('light'); - url += "light" - icon.src="/static/images/sun.png" - //window.alert("Nesze Robotka!") - } - const req = new XMLHttpRequest(); - req.open('GET', url); - req.send(); - } - </script> + <script src="/static/js/theme.js"></script> </li> diff --git a/static/js/theme.js b/static/js/theme.js new file mode 100644 index 0000000..f32d86b --- /dev/null +++ b/static/js/theme.js @@ -0,0 +1,18 @@ +let theme = document.getElementById('theme'); +let icon = document.getElementById('icon'); +let body = document.body; +theme.onclick = () => { + let url = "/theme/" + if (body.classList.contains('light')) { + body.classList.remove('light'); + body.classList.add('dark'); + url += "dark" + icon.src="/static/images/moon.png" + } else { + body.classList.remove('dark'); + body.classList.add('light'); + url += "light" + icon.src="/static/images/sun.png" + //window.alert("Nesze Robotka!") + } +} \ No newline at end of file -- GitLab