Skip to content

Commit ab59b2b

Browse files
committed
Use absolute path to tinysearch_engine
1 parent 2b69855 commit ab59b2b

File tree

2 files changed

+90
-86
lines changed

2 files changed

+90
-86
lines changed

static/search.mjs

+89-85
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,114 @@
1-
import { search, default as init } from './tinysearch_engine.js';
1+
import { search, default as init } from "/tinysearch_engine.js";
22
async function lazyLoad() {
3-
await init('/tinysearch_engine_bg.wasm');
3+
await init("/tinysearch_engine_bg.wasm");
44
}
55

66
var loaded = false;
77

88
function autocomplete(inp) {
9-
var currentFocus;
9+
var currentFocus;
1010

11-
inp.addEventListener("click", function (e) {
12-
// There's probably a better way to do lazy loading.
13-
// Then again, I'm not a JavaScript developer ¯\_(ツ)_/¯
14-
if (!loaded) {
15-
lazyLoad();
16-
loaded = true;
17-
}
18-
});
11+
inp.addEventListener("click", function (e) {
12+
// There's probably a better way to do lazy loading.
13+
// Then again, I'm not a JavaScript developer ¯\_(ツ)_/¯
14+
if (!loaded) {
15+
lazyLoad();
16+
loaded = true;
17+
}
18+
});
1919

20-
inp.addEventListener("input", function (e) {
21-
var a, b, i, val = this.value;
20+
inp.addEventListener("input", function (e) {
21+
var a,
22+
b,
23+
i,
24+
val = this.value;
2225

23-
/*close any already open lists of autocompleted values*/
24-
closeAllLists();
25-
if (!val) {
26-
return false;
27-
}
28-
currentFocus = -1;
26+
/*close any already open lists of autocompleted values*/
27+
closeAllLists();
28+
if (!val) {
29+
return false;
30+
}
31+
currentFocus = -1;
2932

30-
/* Create a DIV element that will contain the items (values):*/
31-
a = document.createElement("DIV");
32-
a.setAttribute("id", this.id + "autocomplete-list");
33-
a.setAttribute("class", "autocomplete-items");
33+
/* Create a DIV element that will contain the items (values):*/
34+
a = document.createElement("DIV");
35+
a.setAttribute("id", this.id + "autocomplete-list");
36+
a.setAttribute("class", "autocomplete-items");
3437

35-
/* Append the DIV element as a child of the autocomplete container:*/
36-
this.parentNode.appendChild(a);
38+
/* Append the DIV element as a child of the autocomplete container:*/
39+
this.parentNode.appendChild(a);
3740

38-
let arr = search(val, 3);
41+
let arr = search(val, 3);
3942

40-
for (i = 0; i < arr.length; i++) {
41-
let elem = arr[i];
43+
for (i = 0; i < arr.length; i++) {
44+
let elem = arr[i];
4245

43-
b = document.createElement("DIV");
44-
b.innerHTML = elem[0];
46+
b = document.createElement("DIV");
47+
b.innerHTML = elem[0];
4548

46-
b.addEventListener("click", function (e) {
47-
window.location.href = `${elem[1]}?q=${encodeURIComponent(val)}`;
48-
});
49-
a.appendChild(b);
50-
}
51-
});
49+
b.addEventListener("click", function (e) {
50+
window.location.href = `${elem[1]}?q=${encodeURIComponent(val)}`;
51+
});
52+
a.appendChild(b);
53+
}
54+
});
5255

53-
inp.addEventListener("keydown", function (e) {
54-
var x = document.getElementById(this.id + "autocomplete-list");
55-
if (x) x = x.getElementsByTagName("div");
56-
if (e.keyCode == 40) {
57-
/* If the arrow DOWN key is pressed,
56+
inp.addEventListener("keydown", function (e) {
57+
var x = document.getElementById(this.id + "autocomplete-list");
58+
if (x) x = x.getElementsByTagName("div");
59+
if (e.keyCode == 40) {
60+
/* If the arrow DOWN key is pressed,
5861
increase the currentFocus variable:*/
59-
currentFocus++;
60-
/* and make the current item more visible:*/
61-
addActive(x);
62-
} else if (e.keyCode == 38) { //up
63-
/* If the arrow UP key is pressed,
62+
currentFocus++;
63+
/* and make the current item more visible:*/
64+
addActive(x);
65+
} else if (e.keyCode == 38) {
66+
//up
67+
/* If the arrow UP key is pressed,
6468
decrease the currentFocus variable:*/
65-
currentFocus--;
66-
/* and and make the current item more visible:*/
67-
addActive(x);
68-
} else if (e.keyCode == 13) {
69-
/* If the ENTER key is pressed, prevent the form from being submitted,*/
70-
e.preventDefault();
71-
if (currentFocus > -1) {
72-
/* and simulate a click on the "active" item:*/
73-
if (x) x[currentFocus].click();
74-
}
75-
}
76-
});
77-
78-
function addActive(x) {
79-
/* A function to classify an item as "active":*/
80-
if (!x) return false;
81-
/* Start by removing the "active" class on all items:*/
82-
removeActive(x);
83-
if (currentFocus >= x.length) currentFocus = 0;
84-
if (currentFocus < 0) currentFocus = (x.length - 1);
85-
/* Add class "autocomplete-active":*/
86-
x[currentFocus].classList.add("autocomplete-active");
69+
currentFocus--;
70+
/* and and make the current item more visible:*/
71+
addActive(x);
72+
} else if (e.keyCode == 13) {
73+
/* If the ENTER key is pressed, prevent the form from being submitted,*/
74+
e.preventDefault();
75+
if (currentFocus > -1) {
76+
/* and simulate a click on the "active" item:*/
77+
if (x) x[currentFocus].click();
78+
}
8779
}
80+
});
81+
82+
function addActive(x) {
83+
/* A function to classify an item as "active":*/
84+
if (!x) return false;
85+
/* Start by removing the "active" class on all items:*/
86+
removeActive(x);
87+
if (currentFocus >= x.length) currentFocus = 0;
88+
if (currentFocus < 0) currentFocus = x.length - 1;
89+
/* Add class "autocomplete-active":*/
90+
x[currentFocus].classList.add("autocomplete-active");
91+
}
8892

89-
function removeActive(x) {
90-
/* A function to remove the "active" class from all autocomplete items:*/
91-
for (var i = 0; i < x.length; i++) {
92-
x[i].classList.remove("autocomplete-active");
93-
}
93+
function removeActive(x) {
94+
/* A function to remove the "active" class from all autocomplete items:*/
95+
for (var i = 0; i < x.length; i++) {
96+
x[i].classList.remove("autocomplete-active");
9497
}
98+
}
9599

96-
function closeAllLists(elmnt) {
97-
/* Close all autocomplete lists in the document,
100+
function closeAllLists(elmnt) {
101+
/* Close all autocomplete lists in the document,
98102
except the one passed as an argument:*/
99-
var x = document.getElementsByClassName("autocomplete-items");
100-
for (var i = 0; i < x.length; i++) {
101-
if (elmnt != x[i] && elmnt != inp) {
102-
x[i].parentNode.removeChild(x[i]);
103-
}
104-
}
103+
var x = document.getElementsByClassName("autocomplete-items");
104+
for (var i = 0; i < x.length; i++) {
105+
if (elmnt != x[i] && elmnt != inp) {
106+
x[i].parentNode.removeChild(x[i]);
107+
}
105108
}
106-
document.addEventListener("click", function (e) {
107-
closeAllLists(e.target);
108-
});
109+
}
110+
document.addEventListener("click", function (e) {
111+
closeAllLists(e.target);
112+
});
109113
}
110-
autocomplete(document.getElementById("tinysearch"));
114+
autocomplete(document.getElementById("tinysearch"));

static/search_min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)