mirror of
https://github.com/mipmip/home-manager-option-search.git
synced 2024-09-11 15:16:31 +03:00
search query url param
On search it reads the search input value, sets the param, and searches. On doc load it reads the param, sets the search input value, and searches. Removed searchEnter, as I didn't find any usage of it.
This commit is contained in:
parent
aac39bc1c1
commit
f0625106ba
44
js/script.js
44
js/script.js
@ -12,30 +12,11 @@ var rebuildAndRerunSearch = function() {
|
||||
searchOptions();
|
||||
};
|
||||
|
||||
var searchEnter = function() {
|
||||
event.preventDefault();
|
||||
|
||||
console.log(window.location.href);
|
||||
if(searchInput.value !== ""){
|
||||
|
||||
newurl = window.location.href.split('?')[0]+"?"+searchInput.value.trim();
|
||||
console.log(newurl);
|
||||
|
||||
window.location.href = encodeURI(newurl);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var docOnload = function(){
|
||||
var queryString = "";
|
||||
if(window.location.href.includes("?")){
|
||||
queryString = decodeURI(window.location.href.split('?')[1]);
|
||||
searchInput.value = queryString;
|
||||
}
|
||||
|
||||
if(queryString !== ""){
|
||||
searchOptions();
|
||||
}
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const query = urlParams.get('query');
|
||||
searchInput.value = query;
|
||||
searchOptions(query);
|
||||
|
||||
$("#advcheck").prop("checked", false);
|
||||
// $("#advcheck").removeAttr("checked");
|
||||
@ -145,12 +126,23 @@ var updateOptionCountAndTable = function() {
|
||||
}
|
||||
};
|
||||
|
||||
var searchOptions = function() {
|
||||
results = search.search(searchInput.value);
|
||||
var setSearchQueryToUrlParam = function(query) {
|
||||
const urlParams = new URLSearchParams();
|
||||
urlParams.set('query', query);
|
||||
const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
|
||||
window.history.replaceState({}, '', newUrl);
|
||||
};
|
||||
|
||||
var searchOptions = function(query) {
|
||||
results = search.search(query);
|
||||
updateOptionCountAndTable();
|
||||
};
|
||||
|
||||
searchInput.oninput = searchOptions;
|
||||
searchInput.oninput = function () {
|
||||
const query = searchInput.value;
|
||||
setSearchQueryToUrlParam(query);
|
||||
searchOptions(query);
|
||||
}
|
||||
|
||||
var updateOptionCount = function(numOptions) {
|
||||
optionCountBadge.innerText = numOptions + ' options';
|
||||
|
Loading…
Reference in New Issue
Block a user