MCPcopy Create free account
hub / github.com/zhongsp/TypeScript / setSearchUrlParameters

Function setSearchUrlParameters

docs/searcher.js:422–441  ·  view source on GitHub ↗
(searchterm, action)

Source from the content-addressed store, hash-verified

420 // and replaces or pushes a new browser history item.
421 // "push_if_new_search_else_replace" pushes if there is no `?URL_SEARCH_PARAM=abc` yet.
422 function setSearchUrlParameters(searchterm, action) {
423 var url = parseURL(window.location.href);
424 var first_search = ! url.params.hasOwnProperty(URL_SEARCH_PARAM);
425 if (searchterm != "" || action == "push_if_new_search_else_replace") {
426 url.params[URL_SEARCH_PARAM] = searchterm;
427 delete url.params[URL_MARK_PARAM];
428 url.hash = "";
429 } else {
430 delete url.params[URL_MARK_PARAM];
431 delete url.params[URL_SEARCH_PARAM];
432 }
433 // A new search will also add a new history item, so the user can go back
434 // to the page prior to searching. A updated search term will only replace
435 // the url.
436 if (action == "push" || (action == "push_if_new_search_else_replace" && first_search) ) {
437 history.pushState({}, document.title, renderURL(url));
438 } else if (action == "replace" || (action == "push_if_new_search_else_replace" && !first_search) ) {
439 history.replaceState({}, document.title, renderURL(url));
440 }
441 }
442
443 function doSearch(searchterm) {
444

Callers 2

globalKeyHandlerFunction · 0.85
searchbarKeyUpHandlerFunction · 0.85

Calls 2

parseURLFunction · 0.85
renderURLFunction · 0.85

Tested by

no test coverage detected