-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookCategory.js
86 lines (68 loc) · 2.65 KB
/
BookCategory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const htmlFirst = '<div class="GridItem"><a href="'
const htmlMiddle = '"><img class="BookImage" src="'
const htmlLast = '" alt="Book Image"></a></div>'
let parms = (new URL(document.location)).searchParams
let category = parms.get("category")
var coverImageCount = 2
console.log(category)
FetchData()
async function FetchData(searchValue = " ") {
const data = await fetch("BookCategory.json")
const response = await data.json()
if (category != undefined) {
console.log("If condition", category)
document.getElementById("BooksGrid").innerHTML = ""
books = response[category]
document.getElementById("CoverText").innerHTML = category
// Change cover Image
ChangeCover()
// Update category color
ChangeCategoryColor(category)
for (let key in books) {
if (books[key][0].toLowerCase().search(searchValue) != -1 || searchValue == " ") {
document.getElementById("BooksGrid").innerHTML += htmlFirst + "BookDescription.html?bookId=" + String(key) + htmlMiddle + "Assets/" + category + "/" + books[key][0] + "/" + books[key][1] + htmlLast
}
}
}
else {
console.log("else condition", category)
document.getElementById("BooksGrid").innerHTML = ""
for (let bookCategory in response) {
books = response[bookCategory]
for (let key in books) {
if (books[key][0].toLowerCase().search(searchValue) != -1 || searchValue == " ") {
document.getElementById("BooksGrid").innerHTML += htmlFirst + "BookDescription.html?bookId=" + String(key) + htmlMiddle + "Assets/" + bookCategory + "/" + books[key][0] + "/" + books[key][1] + htmlLast
}
}
}
}
}
function Search() {
const searchValue = document.getElementById("Search").value.toLowerCase()
FetchData(searchValue)
}
function goBack() {
window.history.back();
}
function ChangeCover(){
document.getElementById("Cover").src = `images/Cover/cover${RandomRange(2,6)}.jpg`
}
function RandomRange(min,max){
// window.coverImageCount++;
// console.log((coverImageCount%(max-min)) + min,coverImageCount)
// return (coverImageCount%(max-min)) + min;
// return Math.floor(Math.random()*(max-min)) + min;
return 3;
}
function ChangeCategoryColor(category){
document.getElementById(category).style.backgroundColor = "pink"
}
function CharacterDescription(){
let char = document.getElementById("CharacterDescriptionText")
if(char.style.visibility == "hidden"){
char.style.visibility = "visible"
}
else{
char.style.visibility = "hidden"
}
}