diff --git a/homepage/navbar.template.html b/homepage/navbar.template.html index d9d1bb1b9e37df0d5486028589677e3086e4c703..0e436dfae6f7e80f1be83b97fb14dbca728ab7e3 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 0000000000000000000000000000000000000000..f32d86b925069875b6ed21bbd5dff8949f400714 --- /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