From 66eed9dcac37e8ae8a3906a2b0c0a3391e394043 Mon Sep 17 00:00:00 2001 From: AntonPieper Date: Sat, 24 Feb 2024 07:14:52 +0100 Subject: [PATCH] Add undo/redo --- index.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 960a2cd..aa1162c 100644 --- a/index.html +++ b/index.html @@ -89,10 +89,12 @@ const isHosted = protocol !== "file:"; let raylibJs = undefined; - function startRaylib(selectedWasm){ - var queryParams = new URLSearchParams(window.location.search); - queryParams.set("example", selectedWasm); - history.pushState(null, null, "?"+queryParams.toString()); + function startRaylib(selectedWasm, save = true) { + if (save) { + const queryParams = new URLSearchParams(window.location.search); + queryParams.set("example", selectedWasm); + history.pushState(selectedWasm, null, "?"+queryParams.toString()); + } raylibExampleSelect.value = selectedWasm; if (isHosted) { @@ -125,6 +127,9 @@ if (Object.values(wasmPaths).flat().includes(exampleParam)) startRaylib(exampleParam); else startRaylib(defaultWasm); + window.addEventListener("popstate", (ev) => { + startRaylib(ev.state, false); + })