This is a reusable plain version the varia library website. You can host your own website of books using just a simple csv file
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.1 KiB

let searchInput = document.getElementById('booksearch');
var allpublications = document.getElementsByClassName("filter");
const ENTER_KEY_CODE = 13;
searchInput.addEventListener('keyup', function(e) {
if (e.keyCode === ENTER_KEY_CODE) {
if (searchInput.value.length > 2) {
searchBooks(searchInput.value);
} else {
clearSearchBooks();
}
}
})
function searchBooks(searchQuery) {
let searchUrl = `search/${searchQuery}`
fetch(searchUrl)
.then(response => response.json())
.then(searchdata => {
console.log(`book ids: ${searchdata} found for ${searchQuery}`);
if (searchdata === undefined || searchdata.length == 0) return;
for (i = 0; i < allpublications.length; i++) {
removeClass(allpublications[i], "show");
}
searchdata.forEach(bookid => {
showBookId(bookid)
});
})
}
function showBookId(bookid) {
let book = document.getElementById(bookid)
addClass(book, "show");
}
function clearSearchBooks() {
for (i = 0; i < allpublications.length; i++) {
addClass(allpublications[i], "show");
}
}