From b6c1b3aeaca30b67f2e555f9689f7d8d69431205 Mon Sep 17 00:00:00 2001 From: bel Date: Wed, 9 Feb 2022 21:57:56 -0700 Subject: [PATCH] navigation --- spike/review/reinvent/ezmded/ui/index.html | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/spike/review/reinvent/ezmded/ui/index.html b/spike/review/reinvent/ezmded/ui/index.html index 82ed804..5c96a20 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) @@ -50,7 +54,7 @@ } else if (queryQ && queryQ.length > 0) { searchFilesFor(queryQ) } - } + } function getParameterByName(name, url = window.location.href) { name = name.replace(/[\[\]]/g, '\\$&'); @@ -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,9 +178,25 @@ 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) + window.location.hash = "#?"+k+"="+v + //window.history.pushState({}, '', url) + } + + window.onhashchange = () => { + navigateToQueryParams() + } + function drawTree() { function htmlifyBranch(id, branch) { var parent = `