-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
178 lines (150 loc) · 4.18 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="UTF-8" />
<style type="text/css">
body {
overflow: hidden;
margin: 0;
}
#prev {
left: 40px;
}
#next {
right: 40px;
}
.fullpage {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.arrow {
position: absolute;
top: 50%;
margin-top: -32px;
font-size: 64px;
color: #E2E2E2;
font-family: arial, sans-serif;
font-weight: bold;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.arrow:hover {
color: #777;
}
.arrow:active {
color: #000;
}
#overlay {
background-color: rgba(80, 137, 255, 0);
}
#overlay.over {
background-color: rgba(80, 137, 255, 0.2);
}
#hint {
font-family: 'Indie Flower', cursive;
font-size: 1.8em;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
#pageim {
height: 100%;
display: block;
margin: auto;
border: 1px solid #DDD;
}
#pageim.hidden, #epubarea.hidden {
display: none;
}
#epubarea {
width: 80%;
height: 80%;
margin: 5% auto;
max-width: 1250px;
}
#epubarea iframe {
border: none;
}
</style>
<link href='https://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'>
<!-- PDFJS Library -->
<script src="js/pdf.js"></script>
<!-- ZIP Library -->
<script src="js/zip.min.js"></script>
<!-- EPUBJS Renderer -->
<script src="js/epub.js"></script>
</head>
<body onkeydown="keyEvent(event)">
<div class="fullpage">
<img src="" alt="" id="pageim" />
<div id="epubarea"></div>
</div>
<div id="hint" class="fullpage">Drop an ebook here...</div>
<div id="overlay" class="fullpage"></div>
<div id="prev" onclick="loadPrevPage();" class="arrow">‹</div>
<div id="next" onclick="loadNextPage();"class="arrow">›</div>
<script>
'use strict'
let PDFRenderer = require('./pdf-renderer')
let EPUBRenderer = require('./epub-renderer')
let overlayElmt = document.getElementById('overlay')
let hintElmt = document.getElementById('hint')
// Viewport related
let pageim = document.getElementById('pageim')
let epubarea = document.getElementById('epubarea')
function handleDragOver (e) {
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
overlayElmt.classList.add('over')
}
function handleDragLeave (e) {
overlayElmt.classList.remove('over')
}
let renderer = null
function keyEvent (event) {
var key = event.keyCode
if (key == 37) { // Left
renderer.prevPage()
} else if (key == 39) { // Right
renderer.nextPage()
}
}
function loadBook (path) {
if (hintElmt) {
hintElmt.parentNode.removeChild(hintElmt)
hintElmt = null
}
pageim.classList.add('hidden')
epubarea.classList.add('hidden')
if (renderer) renderer.destroy()
if (path.endsWith('.epub')) {
epubarea.classList.remove('hidden')
renderer = new EPUBRenderer(path, 'epubarea')
} else if (path.endsWith('.pdf')) {
renderer = new PDFRenderer(path)
renderer.on('data', function (data) {
pageim.classList.remove('hidden')
pageim.src = data
})
}
}
function handleDrop (e) {
e.stopPropagation()
e.preventDefault()
overlayElmt.classList.remove('over')
loadBook(e.dataTransfer.files[0].path)
}
overlayElmt.addEventListener('dragover', handleDragOver, false)
overlayElmt.addEventListener('dragleave', handleDragLeave, false)
overlayElmt.addEventListener('drop', handleDrop, false)
</script>
</body>
</html>