timezone handling now moved to a separate script that does not leak any symbols.

This commit is contained in:
Erik Brakkee 2024-08-13 11:33:15 +02:00
parent 00a9a91788
commit 3bbebd0dda
2 changed files with 27 additions and 27 deletions

View File

@ -25,8 +25,6 @@ templ BasePage(tab int) {
<script src="../static/js/htmx.1.9.12.js"></script> <script src="../static/js/htmx.1.9.12.js"></script>
<script src="../static/js/htmx.ws.1.9.12.js"></script> <script src="../static/js/htmx.ws.1.9.12.js"></script>
<script type="module" src="../static/js/modules.js"></script> <script type="module" src="../static/js/modules.js"></script>
<script src="../static/js/persistentforms.js"></script>
<title>Converge</title> <title>Converge</title>
</head> </head>
@ -46,32 +44,7 @@ templ BasePage(tab int) {
<!-- script> <!-- script>
htmx.logAll(); htmx.logAll();
</script --> </script -->
<script>
function getTimezone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}
if (!window.originalWebSocket) {
window.originalWebSocket = htmx.createWebSocket
htmx.createWebSocket = function(url) {
url = new URL(url, window.location.href).href
url = url.replace(/^http/, 'ws');
let modifiedUrl = url + "?timezone=" + getTimezone()
return window.originalWebSocket(modifiedUrl)
}
}
document.body.addEventListener(
"htmx:configRequest",
function(evt) {
//console.log("Adding timezone to htmx request headers and making URL absolute");
evt.detail.headers["X-Timezone"] = getTimezone();
}
);
</script>
<script src="../static/js/bootstrap.bundle.min.js"
crossorigin="anonymous"></script>
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
@ -106,6 +79,11 @@ templ BasePage(tab int) {
</div> </div>
</div> </div>
<script src="../static/js/bootstrap.bundle.min.js"></script>
<script src="../static/js/persistentforms.js"></script>
<script src="../static/js/timezonehandling.js"></script>
</body> </body>
</html> </html>
} }

View File

@ -0,0 +1,22 @@
(() => {
function getTimezone() {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}
if (!window.originalWebSocket) {
window.originalWebSocket = htmx.createWebSocket
htmx.createWebSocket = function(url) {
url = new URL(url, window.location.href).href
url = url.replace(/^http/, 'ws');
let modifiedUrl = url + "?timezone=" + getTimezone()
return window.originalWebSocket(modifiedUrl)
}
}
document.body.addEventListener(
"htmx:configRequest",
function(evt) {
//console.log("Adding timezone to htmx request headers and making URL absolute");
evt.detail.headers["X-Timezone"] = getTimezone();
}
);
})()