Skip to content

Commit

Permalink
Update URL query param upon completed searches
Browse files Browse the repository at this point in the history
Load URL params lazily.

page_query_string -> GetPageQueryString()
page_args -> GetPageArgs()
  • Loading branch information
yikerman authored Oct 30, 2024
1 parent cbf7780 commit c02b8f8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scribble-lib/scribble/scribble-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@

// Page Parameters ------------------------------------------------------------

var page_query_string = location.search.substring(1);
const page_args = new URLSearchParams(location.search);
function GetURL() {
return new URL(location);
}

function GetPageArgs() {
return GetURL().searchParams;
}

function GetPageQueryString() {
return GetPageArgs().toString();
}

function GetPageArg(key, def) {
return page_args.get(key) || def;
return GetPageArgs().get(key) || def;
}

function MergePageArgsIntoLink(a) {
if (page_args.size === 0 || !a.dataset.pltdoc) return;
if (GetPageArgs().size === 0 || !a.dataset.pltdoc) return;
a.href = MergePageArgsIntoUrl(a.href);
}

function MergePageArgsIntoUrl(href) {
const url = new URL(href, window.location.href);
for (const [key, val] of page_args) {
for (const [key, val] of GetPageArgs()) {
if (url.searchParams.has(key)) continue;
url.searchParams.append(key, val)
}
Expand Down

0 comments on commit c02b8f8

Please sign in to comment.