Changed static structure and wrapped searchsuggestions in function for compatibility
This commit is contained in:
3069
static/js/adminlte.js
Normal file
3069
static/js/adminlte.js
Normal file
File diff suppressed because it is too large
Load Diff
1
static/js/adminlte.js.map
Normal file
1
static/js/adminlte.js.map
Normal file
File diff suppressed because one or more lines are too long
7
static/js/adminlte.min.js
vendored
Normal file
7
static/js/adminlte.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
static/js/adminlte.min.js.map
Normal file
1
static/js/adminlte.min.js.map
Normal file
File diff suppressed because one or more lines are too long
41
static/js/searchsuggestions.js
Normal file
41
static/js/searchsuggestions.js
Normal file
@@ -0,0 +1,41 @@
|
||||
function searchsuggestions() {
|
||||
const searchinput = document.querySelector("#search");
|
||||
const searchsuggestions = document.querySelector("#searchdropdown");
|
||||
const li = (c) => document.createElement("li").appendChild(c);
|
||||
searchinput.addEventListener("input", (e) => {
|
||||
q(e.target.value).then((d) => {
|
||||
if (d.length < 1) searchsuggestions.replaceChildren(nothing());
|
||||
else searchsuggestions.replaceChildren(...suggestions(d));
|
||||
})
|
||||
});
|
||||
async function q(s) {
|
||||
if (s.length > 0) {
|
||||
try {
|
||||
const response = await fetch("/api/search/?q=" + s);
|
||||
const result = await response.json();
|
||||
return result;
|
||||
} catch(error) {
|
||||
console.log("Error: " + error);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function nothing() {
|
||||
const span = document.createElement("span");
|
||||
span.setAttribute("class", "dropdown-item-text");
|
||||
span.insertAdjacentText("afterbegin", "Nothing");
|
||||
return li(span);
|
||||
}
|
||||
function suggestions(d) {
|
||||
const items = [];
|
||||
for (const vid of d) {
|
||||
const a = document.createElement("a");
|
||||
a.setAttribute("class", "dropdown-item")
|
||||
a.setAttribute("href", "/view/" + vid.id);
|
||||
a.insertAdjacentText("afterbegin", vid.name + " " + vid.id);
|
||||
items.push(li(a));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
searchsuggestions();
|
||||
Reference in New Issue
Block a user