worked on #20 and #21, also removed the all var, in exange for checking it on show:all

This commit is contained in:
Bizcochito 2022-06-11 09:14:50 +02:00
parent 4d56328ceb
commit 2e235e575f
2 changed files with 34 additions and 10 deletions

View File

@ -29,7 +29,7 @@
</button> </button>
</div> </div>
<div> <div>
<a id="showAllWords">show all words</a> <a href="#">random word</a> <a href="#">resources</a> <a id="showAllWords">show all words</a> <a id="randomWord">random word</a> <a href="#">resources</a>
</div> </div>
<noscript>turn on js doofus</noscript> <noscript>turn on js doofus</noscript>
</header> </header>

42
main.js
View File

@ -229,7 +229,7 @@ function loadDictionary() {
//add: translations, meanings //add: translations, meanings
for (let o = 0; o < values[i].length; o++) { for (let o = 0; o < values[i].length; o++) {
if (values[i][o].hasOwnProperty("translation")) searchDictionary[keys[i]].push(stripWord(values[i][o]["translation"], true)); if (values[i][o].hasOwnProperty("translation")){searchDictionary[keys[i]].push(stripWord(values[i][o]["translation"], true))};
if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"], true)); if (values[i][o].hasOwnProperty("meaning")) searchDictionary[keys[i]].push(stripWord(values[i][o]["meaning"], true));
} }
} catch (e) { } catch (e) {
@ -301,16 +301,19 @@ function clickSearch(word) {
//minds too hazy for this rn though... //minds too hazy for this rn though...
} }
function doSearch(state = true, all = false) { function doSearch(state = true) {
if (all == true) {
header.querySelector("input").value = "show:all";
}
let val = header.querySelector("input").value; let val = header.querySelector("input").value;
if (val == "") { if (val == "") {
main.innerHTML = "enter some search terms..."; main.innerHTML = "enter some search terms...";
return; return;
} }
let results = search(val == "show:all" ? "" : val);
//Manage search methods
val = (val.indexOf("show:random") !== -1) ? random.choice(list(searchDictionary.values())) : val;
val = (val.indexOf("show:all") !== -1) ? "" : val;
//Results
let results = search(val);
if (results.length == 0) { if (results.length == 0) {
main.innerHTML = "no results (todo: cool form)"; main.innerHTML = "no results (todo: cool form)";
} else { } else {
@ -428,9 +431,22 @@ function doSearch(state = true, all = false) {
types = sortObject(types); types = sortObject(types);
let header = document.createElement("div"); let header = document.createElement("div");
header.classList.add("results-header"); header.classList.add("results-header");
header.innerHTML += "<span class='heonian'>search results for: " + val + "</span><br>"; //When using search methods, accomodate search text.
switch(val) {
//show:all
case "":
val = "Showing all words";
break;
case "\"\"":
val = "Showing all words";
break;
//OMG A WORD
default:
val = "search results for: " + val;
}
header.innerHTML += "<span class='heonian'>" + val + "</span><br>";
for (let i in types) { for (let i in types) {
header.innerHTML += "<span class='results-header-count'>"+i+"s - "+types[i]+"</span>"; if(i !== ""){header.innerHTML += "<span class='results-header-count'>"+i+"s - "+types[i]+"</span>";}
} }
main.prepend(header); main.prepend(header);
} }
@ -459,7 +475,15 @@ window.onload = () => {
if (header.classList.contains("fullscreen")) { if (header.classList.contains("fullscreen")) {
animateHeader(false); animateHeader(false);
} }
doSearch(true, true); header.querySelector("input").value = "show:all";
doSearch(true);
};
header.querySelector("#randomWord").onclick = () => {
if (header.classList.contains("fullscreen")) {
animateHeader(false);
}
header.querySelector("input").value = "show:random";
doSearch(true);
}; };
loadDictionary(); loadDictionary();
window.addEventListener('popstate', (e) => { window.addEventListener('popstate', (e) => {