50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
$(document).ready(() => {
|
|
});
|
|
|
|
/*
|
|
const searchinput = document.querySelector("#searchinput");
|
|
const searchsuggestions = document.querySelector("#searchsuggestions");
|
|
searchinput.addEventListener("input", (e) => {
|
|
q(e.target.value);
|
|
});
|
|
async function q(s) {
|
|
try {
|
|
const response = await fetch("/api/?q=" + s);
|
|
const result = await response.json();
|
|
console.log("Success: " + JSON.stringify(result));
|
|
setSuggestions(searchsuggestions, result);
|
|
} catch(error) {
|
|
console.log("Error: " + error);
|
|
}
|
|
}
|
|
function setSuggestions(o, s) {
|
|
const newSuggestions = [];
|
|
for (const vid of s) {
|
|
const newSugg = document.createElement("a");
|
|
newSugg.setAttribute("href", "/view/" + vid.id);
|
|
newSugg.insertAdjacentText("afterbegin", vid.name + " " + vid.id);
|
|
newSuggestions.push(newSugg);
|
|
}
|
|
o.replaceChildren(...newSuggestions);
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
$('.select2').select2({
|
|
placeholder: 'Search for videos',
|
|
ajax: {
|
|
url: '/api/search/',
|
|
data: (params) => { return { q: params.term } },
|
|
dataType: 'json',
|
|
processResults: function(data) {
|
|
for(const vid of data) {
|
|
vid.text = vid.name + " " + vid.id;
|
|
delete vid['name'];
|
|
}
|
|
return {
|
|
results: data
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
*/ |