(function () {
var input = document.getElementById("query");
var list = document.getElementById("results");
var count = document.getElementById("count");
var most = 300;
function show(words) {
var q = words.trim().toLowerCase();
list.textContent = "";
if (!q) {
count.textContent = "";
return;
}
var found = [];
for (var i = 0; i < SEARCH.length; i++) {
var name = SEARCH[i][0].toLowerCase();
var at = name.indexOf(q);
if (at < 0) {
continue;
}
var rank = name === q ? 0 : at === 0 ? 1 : 2;
found.push([rank, name.length, SEARCH[i]]);
}
found.sort(function (a, b) {
return a[0] - b[0] || a[1] - b[1] || (a[2][0] < b[2][0] ? -1 : a[2][0] > b[2][0] ? 1 : 0);
});
count.textContent =
found.length === 0
? "Nothing matches."
: found.length > most
? found.length + " match; the first " + most + " are shown."
: found.length + (found.length === 1 ? " matches." : " match.");
for (var j = 0; j < found.length && j < most; j++) {
var entry = found[j][2];
var item = document.createElement("li");
var link = document.createElement("a");
link.href = entry[3];
link.textContent = entry[0];
var kind = document.createElement("span");
kind.className = "kind";
kind.textContent = " " + entry[1];
item.appendChild(link);
item.appendChild(kind);
if (entry[2]) {
var what = document.createElement("span");
what.className = "what";
what.textContent = " " + entry[2];
item.appendChild(what);
}
list.appendChild(item);
}
}
var asked = new URLSearchParams(window.location.search).get("q") || "";
input.value = asked;
show(asked);
input.addEventListener("input", function () {
show(input.value);
});
})();