-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_html.py
1419 lines (1211 loc) · 61.7 KB
/
generate_html.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import json
def generate_html_from_json(json_file, output_html):
with open(json_file, 'r', encoding='utf-8') as f:
books = json.load(f)
books_json = json.dumps(books, ensure_ascii=False, indent=4)
html_content = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SERVANTS OF KNOWLEDGE</title>
<link rel="icon" href="public/servantsofknowledge-favicon.png" sizes="32x32" type="image/png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
html, body {{
height: 100%;
margin: 0;
display: flex;
flex-direction: column;
}}
body {{
font-family: Arial, sans-serif;
font-size: 16px;
}}
.head{{
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 40px;
background-color: #070202e3;
color:#aaa;
border-bottom: 2px solid #ddd;
}}
.head :hover {{
color: #fff;
}}
.logo{{
display: flex;
align-items: center;
margin-right: 20px;
color: #fff;
}}
.logo img{{
width: 30px;
height: 30px;
margin-right: 10px;
}}
.image-text {{
display: flex;
align-items: center;
margin-right: 20px;
gap:5px;
}}
.nav-links {{
display: flex;
align-items: center;
margin-left: auto;
}}
.nav-links a {{
margin-left: 20px;
text-decoration: none;
color: #aaa;
}}
.nav-links a:hover {{
color: #fff;
}}
.image-text svg {{
vertical-align: middle;
}}
.header {{
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 80px;
text-align: left;
}}
.header img {{
max-height: 100px;
margin-right: 20px;
}}
.header-content {{
flex-grow: 1;
}}
.header-content p {{
margin: 0;
font-size: 16px;
line-height: 1.5;
}}
.container {{
display: grid;
grid-template-columns: 20% 80%;
grid-template-rows: 40px;
gap: 10px;
padding: 10px 80px;
flex: 1;
}}
.filters {{
overflow-y: auto;
overflow: scroll;
grid-column: 1 / 2;
padding: 5px;
border-radius: 20px;
font-size: 16px;
margin-bottom: 20px;
height: calc(100vh - 300px);
}}
.filters fieldset {{
margin-bottom: 10px;
}}
.filters fieldset div {{
display: inline-block;
margin-right: 10px;
}}
.filters label {{
display: block;
margin-bottom: 5px;
margin-top: 10px;
}}
.filters input, .filters select {{
width: 90%;
margin-bottom: 10px;
}}
.filter-section {{
margin-bottom: 20px;
margin-top: 10px;
}}
.filter-section div {{
display: flex;
align-items: center;
margin-bottom: 5px;
}}
.filter-section input[type="checkbox"] {{
margin-right: 10px;
width:15px;
}}
.search-bar {{
grid-column: 2 / -1;
border-radius: 20px;
text-align: center;
position: relative;
}}
.search-bar input[type="text"] {{
width: 50%;
padding: 8px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 20px; /* Match the parent's border-radius */
}}
.search-bar input[type="text"]:focus {{
outline: none;
border-color: #aaa;
}}
.books-container {{
grid-column: 2 / -1;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 10px;
margin-bottom:20px;
overflow-y: auto;
padding: 80px;
margin-top: 20px;
height: calc(100vh - 400px);
}}
.view-options {{
position: absolute;
right: 200px;
top: 30px;
}}
.view-options i {{
margin-left: 10px;
cursor: pointer;
font-size: 20px;
}}
.book {{
position: relative;
overflow: visible;
margin-bottom: 10px;
padding: 0;
cursor: pointer;
}}
.book:hover .details-tooltip {{
display: flex;
}}
.thumbnail {{
position: relative;
overflow: hidden;
}}
.thumbnail img {{
max-width: 100%;
display: block;
height: auto;
width: 120px;
height: 180px;
transition: transform 0.2s;
}}
.book-title {{
text-align: left;
padding: 10px;
font-size: 16px;
}}
.details-tooltip {{
position: absolute;
top: -90px;
left: calc(-20% - 10px);
transform: translateX(0%);
width: 300px;
background-color: rgba(255, 255, 255, 0.95);
color: black;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
opacity: 1;
padding: 20px;
box-sizing: border-box;
z-index: 9999;
border: 1px solid #090909;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}}
.details {{
text-align: left;
}}
.details h3 {{
margin: 0;
}}
.details p {{
margin: 5px 0;
}}
.details-tooltip .read-icon {{
position: absolute;
right: 0;
bottom: 0;
}}
.list-view .books-container {{
display: block;
padding: 0;
height: auto;
width: 100%;
overflow: visible;
}}
.list-view .book {{
display: flex;
align-items: flex-start;
border: 1px solid #ddd;
border-radius: 10px;
background-color: #fff;
margin-bottom: 20px;
padding: 10px;
width: 100%;
}}
.list-view .thumbnail {{
width: 120px;
height: auto;
margin-right: 20px;
flex-shrink: 0;
}}
.list-view .thumbnail img {{
width: 100%;
height: auto;
margin-right: 20px;
}}
.list-view .book-title {{
font-size: 18px;
font-weight: bold;
margin-bottom: 5px;
}}
.list-view .details {{
flex-grow: 1;
font-size: 16px;
text-align: left;
}}
.list-view .details-tooltip {{
display: none;
}}
.clear {{
clear: both;
}}
#search-books{{
margin-top: 20px;
}}
.footer {{
grid-column: 1 / -1;
background-color: #070202e3;
text-align: center;
padding: 10px 5px;
border-radius: 5px;
color: #fff;
margin-top: 20px;
position: fixed;
bottom: 0;
width: 100%;
}}
.show-more {{
cursor: pointer;
color: black;
}}
#clear-filters-button {{
margin-bottom: 50px;
}}
#iframeContainer {{
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
justify-content: center;
align-items: center;
overflow: hidden;
z-index: 1000;
}}
#iframe {{
width: 80%;
height: 80%;
border: none;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}}
#closeBtn {{
position: absolute;
top: 10px;
right: 20px;
font-size: 24px;
color: white;
cursor: pointer;
z-index: 1001;
}}
.fullscreen-modal {{
display: none;
position: fixed;
z-index: 2; /* Sit on top */
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 30%;
height: 30%;
background-color: rgba(0, 0, 0, 0.8);
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}}
.fullscreen-image {{
height: 100%;
width: auto;
flex: 1;
object-fit: cover;
}}
.modal {{
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.5);
padding-top: 15px;
}}
/* Modal content box */
.modal-content {{
background-color: white;
margin: 5% auto;
padding: 20px;
border: 1px solid #888;
width: 60%;
max-width: 600px;
box-shadow: 0px 4px 8px rgba(0,0,0,0.2);
text-align: center;
}}
.justified-content {{
text-align: justify;
line-height: 1.5;
white-space: pre-wrap;
padding: 0 20px;
}}
.image-container {{
text-align: center;
margin-bottom: 20px;
}}
.gandhi-image {{
max-width: 100%;
height: auto;
display: inline-block;
}}
/* Close button */
.close {{
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}}
.close:hover,
.close:focus {{
color: black;
text-decoration: none;
cursor: pointer;
}}
@media (max-width: 600px) {{
#iframe {{
width: 85%;
height: 85%;
}}
}}
</style>
</head>
<body>
<div id="gandhiImageModal" class="fullscreen-modal">
<img src="public/gandhi.jpeg" alt="Gandhi" class="fullscreen-image">
<img src="public/gandhiknowledgetrust.jpeg" alt="Gandhi Knowledge Trust" class="fullscreen-image">
</div>
<div class="head">
<div class="logo">
<img src="public/servants of knowledge.png" alt="servantsofknowledge">
<span>#SERVANTSOFKNOWLEDGE</span>
</div>
<div class="image-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-book" viewBox="0 0 16 16">
<path d="M1 2.828c.885-.37 2.154-.769 3.388-.893 1.33-.134 2.458.063 3.112.752v9.746c-.935-.53-2.12-.603-3.213-.493-1.18.12-2.37.461-3.287.811zm7.5-.141c.654-.689 1.782-.886 3.112-.752 1.234.124 2.503.523 3.388.893v9.923c-.918-.35-2.107-.692-3.287-.81-1.094-.111-2.278-.039-3.213.492zM8 1.783C7.015.936 5.587.81 4.287.94c-1.514.153-3.042.672-3.994 1.105A.5.5 0 0 0 0 2.5v11a.5.5 0 0 0 .707.455c.882-.4 2.303-.881 3.68-1.02 1.409-.142 2.59.087 3.223.877a.5.5 0 0 0 .78 0c.633-.79 1.814-1.019 3.222-.877 1.378.139 2.8.62 3.681 1.02A.5.5 0 0 0 16 13.5v-11a.5.5 0 0 0-.293-.455c-.952-.433-2.48-.952-3.994-1.105C10.413.809 8.985.936 8 1.783"/>
</svg>
<span>BOOKS</span>
</div>
<div class="image-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-camera-video" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M0 5a2 2 0 0 1 2-2h7.5a2 2 0 0 1 1.983 1.738l3.11-1.382A1 1 0 0 1 16 4.269v7.462a1 1 0 0 1-1.406.913l-3.111-1.382A2 2 0 0 1 9.5 13H2a2 2 0 0 1-2-2zm11.5 5.175 3.5 1.556V4.269l-3.5 1.556zM2 4a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h7.5a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1z"/>
</svg>
<span>VIDEO</span>
</div>
<div class="image-text">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-file-earmark-music" viewBox="0 0 16 16">
<path d="M11 6.64a1 1 0 0 0-1.243-.97l-1 .25A1 1 0 0 0 8 6.89v4.306A2.6 2.6 0 0 0 7 11c-.5 0-.974.134-1.338.377-.36.24-.662.628-.662 1.123s.301.883.662 1.123c.364.243.839.377 1.338.377s.974-.134 1.338-.377c.36-.24.662-.628.662-1.123V8.89l2-.5z"/>
<path d="M14 14V4.5L9.5 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2M9.5 3A1.5 1.5 0 0 0 11 4.5h2V14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h5.5z"/>
</svg>
<span>AUDIO</span>
</div>
<div class="nav-links">
<a href="#aboutus" id="openAboutUs">About Us</a>
<a href="#contactus" id="openGandhiTrust">Gandhi Library Knowledge Trust</a>
</div>
</div>
<!-- About Us Modal -->
<div id="aboutUsModal" class="modal">
<div class="modal-content">
<span class="close" id="closeAboutUs">×</span>
<h2>About Us</h2>
<div class="justified-content">
“All India Gandhi Library to advance access to knowledge and spread the Mahatma’s message”
This digital repository is the result of a collaboration between Karnataka Gandhi Smaraka Nidhi and the Servants of Knowledge, a non-profit Section 8 association dedicated to advancing access to knowledge. The entire library was digitised in only 3 months and additional contributions were made by the Telangana Gandhi Smaraka Nidhi and the Andrapradesh Gandhi Smaraka Nidhi.
The library includes the volumes of Collected Works of Mahatma Gandhi as well as hundreds of other Gandhi resources including Harijan, Young India, Indian Opinion, many Navijavan Trust pamphlets, the Pyarlel biographies, the Desai diaries and much more. In addition, the repository includes extensive collections of the works of Nehru and Ambedkar, the Sardar Patel correspondence, and works by numerous others such as Netaji Subhas Chandra Bose and Sarvepalli Radhakrishnan. The multimedia collection also includes 129 audio files of Mahatma Gandhi speaking on All India Radio. The collection includes works in 12 languages.
Gandhi Bhavan already makes 1,272 public domain works available to the general public at <a href="https://archive.org/details/GandhiBhavan" target="_blank">https://archive.org/details/GandhiBhavan</a>. The presentation of the digital library to Gandhi organisations across the country allows those groups to access a much wider collection of works for noncommercial uses allowed by the Copyright Act of India, including access by the blind, research use, and uses in the course of instruction. In addition to the digital collection, the organisations are being furnished with an extensive treatise on the permitted uses of materials by public libraries.
</div>
</div>
</div>
<!-- Gandhi Trust Modal -->
<div id="gandhiTrustModal" class="modal">
<div class="modal-content">
<span class="close" id="closeGandhiTrust">×</span>
<h2>GANDHI LIBRARY KNOWLEDGE TRUST</h2>
<p> (VERSION 1.1)</p>
<div class="image-container">
<img src="public/gandhi.jpeg" alt="Gandhi" class="gandhi-image">
</div>
<div>
<p>NOTICE AND ACKNOWLEDGEMENT</p>
<p>OF TRUSTEESHIP</p>
</div>
<div class="justified-content">
By access and using the enclosed library of knowledge containing the full digitisation of the library of Gandhi Bhavan (Bengaluru), you do hereby agree and affirm that these materials shall ONLY be used for the noncommercial purposes of research, in the course of instruction, accessibility by the visually impaired and other uses AS PERMITTED UNDER THE LAWS OF INDIA. You must inform any other users of these materials of these conditions.
</div>
<div>
<p><b>“SCANNING IS THE NEW SPINNING”</b></p><p><b>JAI GYAN</b></p>
</div>
</div>
</div>
<div class="header">
<img src="public/gandhi.jpeg" alt="Gandhi">
<div class="header-content">
<p><strong>#SERVANTSOFKNOWLEDGE Scanning Is The New Spinning</strong></p>
<br>
<p>All India Gandhi Library v1.0
<br>
The library includes the volumes of Collected Works of Mahatma Gandhi as well as hundreds of other Gandhi resources including Harijan, Young India, Indian Opinion,
many Nava jeevan Trust pamphlets, the Pyarelal biographies, the Desai diaries and much more.
In addition, the repository includes extensive collections of the works of Nehru and Ambedkar, the Sardar Patel correspondence, and works by numerous others
such as Netaji Subhas Chandra Bose and Sarvepalli Radhakrishnan. The multimedia collection also includes 129 audio files of Mahatma Gandhi speaking on All India Radio.
The collection includes works in 12 languages.</p>
</div>
</div>
<div class="container">
<div class="filters">
<h3>Filters</h3>
<div class="filter-section" id="filter-section-year">
<h3>Year</h3>
<button class="show-more" onclick="toggleYearFilters()">Show more</button>
</div>
<div class="filter-section" id="filter-section-author">
<h3>Author</h3>
<button class="show-more" onclick="toggleAuthorFilters()">Show more</button>
</div>
<div class="filter-section" id="filter-section-lang">
<h3>Language</h3>
<button class="show-more" onclick="toggleLanguageFilters()">Show more</button>
</div>
<div class="filter-section" id="filter-section-sub">
<h3>Subject</h3>
<button class="show-more" onclick="toggleSubjectFilters()">Show more</button>
</div>
<div class="filter-section" id="filter-section-publisher">
<h3>Publisher</h3>
<button class="show-more" onclick="togglePublisherFilters()">Show more</button>
</div>
<button id="clear-filters-button" onclick="clearFilters()">Clear Filters</button>
</div>
<div class="search-bar">
<input type="text" id="search-books" placeholder="Search..." >
<div class="view-options">
<i class="fas fa-th-large" id="grid-view-icon" onclick="setGridView()"></i>
<i class="fas fa-list" id="list-view-icon" onclick="setListView()"></i>
</div>
</div>
<div class="books-container" id="books"></div>
<div id="iframeContainer">
<iframe id="iframe" src="" frameborder="0"></iframe>
<span id="closeBtn">×</span>
</div>
</div>
<div class="footer">
#ServantsOfKnowledge - Scanning Is The New Spinning
</div>
<script>
function setGridView() {{
console.log('setgrid');
document.querySelector('.books-container').classList.remove('list-view');
document.querySelector('.books-container').style.display = 'grid';
booksLoaded=0;
loadBooksInView('grid');
console.log("Switched to grid view");
}}
function setListView() {{
console.log('setlist');
document.querySelector('.books-container').classList.add('list-view');
document.querySelector('.books-container').style.display = 'block';
booksLoaded=0;
loadBooksInView('list');
console.log("Switched to list view");
}}
const booksData = {books_json};
let booksLoaded = 0;
const booksPerBatch = 25; // Number of books to load per batch
const totalBooks = booksData.length;
let count=0;
function loadMoreBooks(view) {{
console.log('loadmore');
const booksContainer = document.getElementById('books');
const iframeContainer = document.getElementById('iframeContainer');
const iframe = document.getElementById('iframe');
const closeBtn = document.getElementById('closeBtn');
let start = booksLoaded;
let end = Math.min(booksLoaded + booksPerBatch, totalBooks);
for (let i = start; i < end ; i++) {{
const book = booksData[i];
const bookDiv = document.createElement('div');
count++;
if (view === 'grid') {{
bookDiv.className = 'book grid-view-item'; // Class for grid view
// Create thumbnail for grid view
const thumbnail = document.createElement('div');
thumbnail.className = 'thumbnail';
const img = document.createElement('img');
if (book.thumbnail_url!=null) {{
img.src = book.thumbnail_url;
thumbnail.appendChild(img);
}}
const title = document.createElement('div');
title.className = 'book-title';
title.textContent = book.title;
// Add tooltip for grid view
const detailsTooltip = document.createElement('div');
detailsTooltip.className = 'details-tooltip';
const details = document.createElement('div');
details.className = 'details';
details.innerHTML = `
<h3>${{book.title}}</h3>
<p><strong>Author:</strong> ${{book.creators.join(', ')}}</p>
<p><strong>Publisher:</strong> ${{book.publisher}}</p>
<p><strong>Language:</strong> ${{book.language}}</p>
<p><strong>Year:</strong> ${{book.year}}</p>
<p><strong>Subject:</strong> ${{book.subject}}</p>
<img src="public/book.jpg" alt="Read Book" height="50" width="50" class="read-icon">
`;
detailsTooltip.appendChild(details);
bookDiv.appendChild(thumbnail);
bookDiv.appendChild(title);
bookDiv.appendChild(detailsTooltip);
detailsTooltip.addEventListener('click', () => {{
iframe.src = book.pdf_url;
iframeContainer.style.display = 'flex';
document.body.style.overflow = 'hidden'; // Disable scrolling
}});
}}
else if (view === 'list') {{
bookDiv.className = 'book list-view-item'; // Class for list view
// Create clickable thumbnail
const thumbnail = document.createElement('div');
thumbnail.className = 'thumbnail';
const img = document.createElement('img');
if (book.thumbnail_url!=null) {{
img.src = book.thumbnail_url;
thumbnail.appendChild(img);
}}
else{{
const title = document.createElement('div');
title.className = 'book-title';
title.textContent = book.title;
thumbnail.appendChild(title);
}}
// Add event listener to open PDF in iframe on click
thumbnail.addEventListener('click', () => {{
iframe.src = book.pdf_url;
iframeContainer.style.display = 'flex';
document.body.style.overflow = 'hidden';
}});
bookDiv.appendChild(thumbnail);
// Create book details for list view
const details = document.createElement('div');
details.className = 'details';
details.innerHTML = `
<h3>${{book.title}}</h3>
<p><strong>Author:</strong> ${{book.creators.join(', ')}}</p>
<p><strong>Publisher:</strong> ${{book.publisher}}</p>
<p><strong>Year:</strong> ${{book.year}}</p>
<p><strong>Language:</strong> ${{book.language}}</p>
<p><strong>Subject:</strong> ${{book.subject}}</p>
`;
bookDiv.appendChild(details);
}}
booksContainer.appendChild(bookDiv);
}}
closeBtn.addEventListener('click', () => {{
iframe.src = ''; // Clear the iframe source
iframeContainer.style.display = 'none';
document.body.style.overflow = 'auto'; // Enable scrolling
}});
booksLoaded += (end - start); // Increment booksLoaded by the number of books loaded
// If there are more books to load, create observer for the last book
if (booksLoaded < totalBooks) {{
createObserver(view);
}}
}}
function createObserver(view) {{
console.log('obs');
const options = {{
root: document.getElementById('books-container'), // Use books container for scroll
rootMargin: '0px',
threshold: 1.0
}};
const observer = new IntersectionObserver((entries, observer) => {{
console.log('intersect');
console.log(count);
entries.forEach(entry => {{
if (entry.isIntersecting) {{
observer.unobserve(entry.target); // Stop observing the last book
loadMoreBooks(view); // Load more books based on the view
}}
}});
}}, options);
const lastBook = document.querySelector('.book:last-child');
if (lastBook) {{
observer.observe(lastBook); // Observe the last book in the container
}}
}}
function observeLastBook() {{
console.log('obslast');
if (observer) {{
console.log('obsif');
const lastBook = document.querySelector('.book:last-child');
if (lastBook) {{
console.log('last');
observer.observe(lastBook);
}}
}}
}}
function loadBooksInView(view) {{
console.log('main');
const booksContainer = document.getElementById('books');
booksContainer.innerHTML = '';
booksLoaded = 0; // Reset loaded books count
loadMoreBooks(view); // Start loading books based on the view
console.log(count);
}}
function clearFilters() {{
console.log('clear');
document.getElementById('search-books').value = '';
// Clear other filter inputs here
document.querySelectorAll('.filters input[type="checkbox"]').forEach(checkbox => {{
checkbox.checked = false;
}});
const isListView = document.querySelector('.books-container').classList.contains('list-view');
if (isListView) {{
booksLoaded=0;
loadBooksInView('list');
}} else {{
booksLoaded=0;
loadBooksInView('grid');
}}
}}
// Initialize filter checkboxes
function initializeFilters() {{
const filterSectionYear = document.getElementById('filter-section-year');
const uniqueYears = [...new Set(booksData.map(book => book.year).filter(year => year !=="N/A" ))];
uniqueYears.sort((a,b) => b - a);
uniqueYears.slice(0, Math.min(5, uniqueYears.length)).forEach(year => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = year;
input.className = 'filter-checkbox';
input.id = `filter-year-${{year}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-year-${{year}}`;
label.textContent = year;
div.appendChild(input);
div.appendChild(label);
filterSectionYear.insertBefore(div, filterSectionYear.querySelector('.show-more'));
}});
const filterSectionAuthor = document.getElementById('filter-section-author');
const uniqueAuthors = [...new Set(booksData.flatMap(book => {{
if (Array.isArray(book.creators)) {{
return book.creators.map(author => author.trim());
}} else {{
return [];
}}
}}))];
uniqueAuthors.slice(0, Math.min(5,uniqueAuthors.length)).forEach(author => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = author;
input.className = 'filter-checkbox';
input.id = `filter-author-${{author}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-author-${{author}}`;
label.textContent = author;
div.appendChild(input);
div.appendChild(label);
filterSectionAuthor.insertBefore(div, filterSectionAuthor.querySelector('.show-more'));
}});
const filterSectionLanguage = document.getElementById('filter-section-lang');
const uniqueLanguages = [...new Set(booksData.map(book => book.language).filter(language => language !=="N/A"))];
uniqueLanguages.slice(0, Math.min(5,uniqueLanguages.length)).forEach(language => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = language;
input.className = 'filter-checkbox';
input.id = `filter-language-${{language}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-language-${{language}}`;
label.textContent = language;
div.appendChild(input);
div.appendChild(label);
filterSectionLanguage.insertBefore(div, filterSectionLanguage.querySelector('.show-more'));
}});
const filterSectionPublisher = document.getElementById('filter-section-publisher');
const uniquePublishers = [...new Set(booksData.map(book => book.publisher).filter(publisher => publisher !== "N/A"))];
uniquePublishers.slice(0, Math.min(5, uniquePublishers.length)).forEach(publisher => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = publisher;
input.className = 'filter-checkbox';
input.id = `filter-publisher-${{publisher}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-publisher-${{publisher}}`;
label.textContent = publisher;
div.appendChild(input);
div.appendChild(label);
filterSectionPublisher.insertBefore(div, filterSectionPublisher.querySelector('.show-more'));
}});
const filterSectionSubject = document.getElementById('filter-section-sub');
const uniqueSubjects = [...new Set(booksData.flatMap(book => {{
return book.subject.split(';').map(subject => subject.trim()).filter(subject => subject !== "N/A");
}}))];
// Generate checkboxes for unique subjects, show all if less than 5
uniqueSubjects.slice(0, Math.min(5, uniqueSubjects.length)).forEach(subject => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = subject;
input.className = 'filter-checkbox';
input.id = `filter-subject-${{subject}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-subject-${{subject}}`;
label.textContent = subject;
div.appendChild(input);
div.appendChild(label);
filterSectionSubject.insertBefore(div, filterSectionSubject.querySelector('.show-more'));
}});
}}
let showAllYears = false;
function toggleYearFilters() {{
const filterSectionYear = document.getElementById('filter-section-year');
filterSectionYear.innerHTML = '<h3>Year</h3>';
const uniqueYears = [...new Set(booksData.map(book => book.year).filter(year => year!=="N/A"))];
uniqueYears.sort((a,b) => b - a);
if (showAllYears) {{
uniqueYears.slice(0, Math.min(5,uniqueYears.length)).forEach(year => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = year;
input.className = 'filter-checkbox';
input.id = `filter-year-${{year}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-year-${{year}}`;
label.textContent = year;
div.appendChild(input);
div.appendChild(label);
filterSectionYear.insertBefore(div, filterSectionYear.querySelector('.show-more'));
}});
filterSectionYear.appendChild(createToggleButton('Show More', toggleYearFilters));
}} else {{
uniqueYears.forEach(year => {{
const div = document.createElement('div');
const input = document.createElement('input');
input.type = 'checkbox';
input.value = year;
input.className = 'filter-checkbox';
input.id = `filter-year-${{year}}`;
input.addEventListener('change', applyFilters);
const label = document.createElement('label');
label.htmlFor = `filter-year-${{year}}`;
label.textContent = year;
div.appendChild(input);
div.appendChild(label);
filterSectionYear.insertBefore(div, filterSectionYear.querySelector('.show-more'));
}});
filterSectionYear.appendChild(createToggleButton('Hide', toggleYearFilters));
}}
showAllYears = !showAllYears;
}}
let showAllAuthors = false;
function toggleAuthorFilters() {{
const filterSectionAuthor = document.getElementById('filter-section-author');
filterSectionAuthor.innerHTML = '<h3>Author</h3>';
const uniqueAuthors = [...new Set(booksData.flatMap(book => {{
if (Array.isArray(book.creators)) {{
return book.creators.map(author => author.trim());
}} else {{
return [];
}}
}}))];