aboutsummaryrefslogtreecommitdiffstats
path: root/browser/static/htmp.js
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-02-19 18:34:39 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-02-19 18:34:39 +0200
commitcdc78ce436459047b06163f98fc661df9f2026f4 (patch)
tree3bc6d63ee587c6dc19fdb5ad77173088b6b45262 /browser/static/htmp.js
parent371bbe0390113ecbf032ae9bcfc6a93470ffad67 (diff)
Work on stuff
Diffstat (limited to 'browser/static/htmp.js')
-rw-r--r--browser/static/htmp.js49
1 files changed, 23 insertions, 26 deletions
diff --git a/browser/static/htmp.js b/browser/static/htmp.js
index 62956a4..27d963b 100644
--- a/browser/static/htmp.js
+++ b/browser/static/htmp.js
@@ -1,41 +1,38 @@
const iframe = document.createElement("iframe");
iframe.name = "htmp";
iframe.hidden = true;
-document.body.appendChild(iframe);
-
-document
- .querySelector("iframe[name='htmp']")
- .addEventListener("load", function () {
- setTimeout(() => {
- const cd = this.contentDocument;
- const cw = this.contentWindow;
- // If the server responds with an entire HTML document, replace the current document with it.
- // To check whether the response is an entire page we check the presence of this very snippet.
- if (cd.querySelector("iframe[name='htmp']")) {
- document.documentElement.replaceWith(cd.documentElement);
- // If the server responds with a fragment, replace the target element with it.
- } else {
- document
- .querySelector(cw.location.hash || null)
- ?.replaceWith(...cd.body.childNodes);
- const url = new URL(cw.location.href);
- url.searchParams.delete("htmp");
- url.hash = "";
- history.replaceState({}, "", url.toString());
- }
- });
+iframe.addEventListener("load", function () {
+ setTimeout(() => {
+ const cd = this.contentDocument;
+ const cw = this.contentWindow;
+ // If the server responds with an entire HTML document, replace the current document with it.
+ // To check whether the response is an entire page we check the presence of this very snippet.
+ if (cd.querySelector("iframe[name='htmp']")) {
+ document.documentElement.replaceWith(cd.documentElement);
+ // If the server responds with a fragment, replace the target element with it.
+ } else {
+ document
+ .querySelector(cw.location.hash || null)
+ ?.replaceWith(...cd.body.childNodes);
+ const url = new URL(cw.location.href);
+ url.searchParams.delete("htmp");
+ url.hash = "";
+ history.replaceState({}, "", url.toString());
+ }
});
+});
+document.body.appendChild(iframe);
document.querySelectorAll("form[htmp]").forEach(function (el) {
- const re = el.attributes.replace.value;
+ const r = el.attributes.replace.value;
const input = document.createElement("input");
input.type = "hidden";
input.name = "htmp";
- input.value = re;
+ input.value = r;
el.appendChild(input);
const action = new URL(el.action);
- action.hash = re;
+ action.hash = r;
el.action = action.toString();
el.target = "htmp";
});