add 'childrens' as a field on books
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -10,9 +10,17 @@ function init() {
|
||||
// prepare response
|
||||
books.forEach(apiResponseParsing);
|
||||
document.getElementById("search").addEventListener("input", (e) => {
|
||||
renderTable(search(books, e.target.value));
|
||||
renderTable(
|
||||
search(
|
||||
books,
|
||||
e.target.value,
|
||||
document.getElementById("childrens").checked
|
||||
)
|
||||
);
|
||||
});
|
||||
renderTable(books);
|
||||
renderTable(
|
||||
search(books, "", document.getElementById("childrens").checked)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,12 +89,12 @@ function apiResponseParsing(book) {
|
||||
return book;
|
||||
}
|
||||
|
||||
function search(books, searchBy) {
|
||||
function search(books, searchBy, includeChildrensBooks) {
|
||||
searchBy = searchCleaner(searchBy);
|
||||
if (searchBy !== "") {
|
||||
books = books.filter(
|
||||
({ title, authors, genre, publisher, series, year }) => {
|
||||
return Object.values({
|
||||
({ title, authors, genre, publisher, series, year, childrens }) => {
|
||||
var inSearch = Object.values({
|
||||
title,
|
||||
authors: authors.join(" "),
|
||||
genre,
|
||||
@@ -94,6 +102,10 @@ function search(books, searchBy) {
|
||||
series,
|
||||
year,
|
||||
}).find((field) => searchCleaner(field).indexOf(searchBy) !== -1);
|
||||
if (!includeChildrensBooks) {
|
||||
return inSearch && !childrens;
|
||||
}
|
||||
return inSearch;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -13,7 +13,11 @@
|
||||
<script type="text/javascript">
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
</script>
|
||||
<script defer data-domain="library.yetaga.in" src="https://stats.yetaga.in/js/script.js"></script>
|
||||
<script
|
||||
defer
|
||||
data-domain="library.yetaga.in"
|
||||
src="https://stats.yetaga.in/js/script.js"
|
||||
></script>
|
||||
<meta name="description" content="A personal library record." />
|
||||
</head>
|
||||
<body>
|
||||
@@ -28,6 +32,8 @@
|
||||
>git</a
|
||||
>
|
||||
<div id="searchBox">
|
||||
<span id="bookCount" class="bookCount">Include Childrens Books?</span>
|
||||
<input id="childrens" type="checkbox" name="childrens" />
|
||||
<span id="bookCount" class="bookCount">_ books</span>
|
||||
<input
|
||||
id="search"
|
||||
|
@@ -157,10 +157,10 @@ body {
|
||||
right: 10px;
|
||||
top: 7px;
|
||||
text-align: right;
|
||||
width: 400px;
|
||||
width: 800px;
|
||||
}
|
||||
|
||||
#searchBox input {
|
||||
#searchBox input#search {
|
||||
width: 300px;
|
||||
font-size: 16px;
|
||||
background: #f9f8ed;
|
||||
|
Reference in New Issue
Block a user