diff --git a/todo.yaml b/spike/review/reinvent/ezmded/server/todo.yaml similarity index 95% rename from todo.yaml rename to spike/review/reinvent/ezmded/server/todo.yaml index bc26274..74579de 100644 --- a/todo.yaml +++ b/spike/review/reinvent/ezmded/server/todo.yaml @@ -1,4 +1,5 @@ todo: -- https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#change_a_query_parameter - preview default via q param - css +done: +- https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#change_a_query_parameter diff --git a/spike/review/reinvent/ezmded/ui/index.html b/spike/review/reinvent/ezmded/ui/index.html index 82ed804..b9087a4 100644 --- a/spike/review/reinvent/ezmded/ui/index.html +++ b/spike/review/reinvent/ezmded/ui/index.html @@ -42,6 +42,10 @@ function init() { drawTree() setInterval(drawTree, 100000) + navigateToQueryParams() + } + + function navigateToQueryParams() { var queryF = getParameterByName("f") var queryQ = getParameterByName("q") console.log("init query f:", queryF, "q:", queryQ) @@ -99,7 +103,7 @@ if (!results || results.length == 0) innerHTML = "no results" disableMDE() - window.location.hash = "#?q="+q + navigateToQuery("q", q) document.getElementById("searchResults").innerHTML = innerHTML }) } @@ -174,7 +178,29 @@ easyMDE.meta = { id: id, } - window.location.hash = "#?f="+id + navigateToQuery("f", id) + } + + var lastNavigateToQuery = new Date() + + function navigateToQuery(k, v) { + if (new Date() - lastNavigateToQuery < .1) + return + lastNavigateToQuery = new Date() + const url = new URL(window.location) + url.searchParams.set(k, v) + var hash = "#?" + const it = url.searchParams.entries() + let result = it.next() + while (!result.done) { + hash = hash + result.value[0] + "=" + result.value[1] + "&" + result = it.next() + } + window.location.hash = hash + } + + window.onhashchange = () => { + navigateToQueryParams() } function drawTree() { @@ -255,7 +281,9 @@