-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
159 lines (133 loc) · 6.19 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="#" type="image/x-icon">
<link rel="stylesheet" href="./water.css">
<link rel="stylesheet" href="./custom.css">
<!-- <script src="./jszip.min.js"></script>
<script src="./epub.js"></script> -->
<title>Nalanda</title>
</head>
<body>
<div class="hero">
<h1 class="heading" style="margin-bottom: 50px; margin-top: 50px;">Nalanda</h1>
<div class="summary" style="margin-bottom: 100px; font-family: Helvetica Neue; font-size: larger;">Read ebooks provided by Standard Ebooks online.</div>
</div>
<div style="display: flex; justify-content:space-between">
<div class="filter">
<label for="genres" style="float: left; margin-right: 10px;">Choose genres: </label>
<select name="genres" id="genres">
</select>
</div>
<!-- <div class="local" style="display:flex; justify-content:end">
<input type="file" name="localepub" id="localepub" accept=".epub">
<button onclick="showLocalEpub()">Go</button>
Inline function SO10607847
<button onclick="(function(){document.getElementById('localepub').value = '';})()">Reset</button>
</div> -->
</div>
<div class="grid" id="bookgrid" style="margin-top: 20px;"></div>
<script src="./book-data.js"></script>
<script>
// console.log(data);
// SO54706080
function addCards() {
const container = document.getElementById('bookgrid');
const filter = document.getElementById('genres');
const filterCriteria = filter.value;
// console.log(filterCriteria)
let allCards = "";
data.books.forEach((result, idx) => {
let bookTags = new Set(result.tags);
if (filterCriteria != "all" && bookTags.has(filterCriteria) == false) {
// SO8333403
return
}
// Create card element
const card = document.createElement('div');
card.classList = 'card-body';
// Construct card content
const newCardContent = `
<div class="card">
<div class="card-contents">
<a href="/epub.html?name=${result.epub}" target="_blank"><div class="img-wrapper">
<img src="./book-covers/${result.cover}" alt="${result.name}">
</div></a>
<div class="know-more">
<button type="button" class="dialog-trigger"> Know More </button>
<dialog class="dialog">
<header>${result.name}</header>
<span>Book Name : ${result.name}</span> <a href="${result.bookWikiLink}" target="_blank"><img style="height: 20px;" src="./img/wiki.png" /></a> <br>
<span>Author : ${result.author}</span> <a href="${result.authorWikiLink}" target="_blank"><img style="height: 20px;" src="./img/wiki.png" /></a> <br>
<span>Tags : ${result.tags.join(", ")}</span> <br>
<button class="close-dialog" type="reset">Cancel</button>
</dialog>
</div>
</div>
</div>
`;
// Append newyly created card element to the container
allCards += newCardContent;
})
container.innerHTML = allCards;
addModalWorking();
}
function addFilterOptions() {
const filter = document.getElementById('genres');
let allTags = ""
tags.forEach((result, idx) => {
let tag = result[0].toUpperCase() + result.substr(1);;
let optionContent = `
<option value="${result}">${tag}</option>
`;
allTags += optionContent;
})
filter.innerHTML = allTags;
}
function addModalWorking() {
// SO51573435
[...document.querySelectorAll('.dialog-trigger')].forEach(function (item) {
item.addEventListener('click', function () {
// console.log(this.nextElementSibling);
// console.log(document.getElementById('dialog'))
this.nextElementSibling.showModal();
});
});
// const closeDialog = document.querySelectorAll('.know-more');
// console.log(closeDialog);
[...document.querySelectorAll('.close-dialog')].forEach(function (item) {
item.addEventListener('click', function () {
// console.log(this)
this.parentElement.close()
});
});
}
function runOnLoad() {
addFilterOptions();
addCards();
// addModalWorking();
document.querySelector('#genres').addEventListener("change", addCards);
}
window.onload = runOnLoad;
// https://stackoverflow.com/questions/47058077/how-can-i-add-an-event-listener-to-a-select-element
// document.getElementById('dialog').addEventListener('close', (function (e) {
// document.getElementById('dialog-result').innerText = 'Your answer: '.concat(e.target.returnValue)
// }));
// function showLocalEpub() {
// var fileInput = document.getElementById("localepub");
// if (fileInput && fileInput.value) {
// const filename = fileInput.files[0].name;
// console.log(fileInput.files[0].name)
// // const ePubLink = URL.createObjectURL(fileInput.files[0])
// console.log(filename);
// location.href = "/localepub.html?name=" + filename;
// } else {
// alert("Enter local epub file !");
// }
// }
</script>
</body>
</html>