forked from dauwhe/acme-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
321 lines (226 loc) · 7.75 KB
/
main.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
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
<!DOCTYPE html>
<html>
<head>
<title>Book</title>
<style type="text/css">
main {
margin: 0 auto;
text-align: center;
background-color: #F8F8F8;
height: 100vh;
}
iframe {
margin: 1em auto;
border-top: .5in solid white;
border-bottom: .5in solid white;
background-color: white;
display: block;
text-align: center;
}
body {
background-color: #aaa;
}
#wrapper {
/* display: flex; */
}
/*
#wrapper {
position: relative;
opacity: 0;
top:-20px;
height: 30px;
-webkit-transition:all .5s ease-in-out;
-moz-transition:all .5s ease-in-out;
-o-transition:all .5s ease-in-out;
-ms-transition:all .5s ease-in-out;
transition:all .5s ease-in-out;
display: flex;
}
#wrapper:hover {
opacity:1;
top:0px;
-webkit-transition:all .5s ease-in-out;
-moz-transition:all .5s ease-in-out;
-o-transition:all .5s ease-in-out;
-ms-transition:all .5s ease-in-out;
transition:all .5s ease-in-out;
}*/
#page-controls {
display: inline-block;
}
.button, .status, span.download {
font: bold 11px Arial;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 2px 6px 2px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
}
#wrapper input, #wrapper span, #wrapper .page-controls {
-webkit-flex: 1;
-webkit-align-items: center;
}
#page-controls input.work-offline {display: none; }
#pub {
width: 600px;
height: 75vh;
}
form {
display: inline;
}
</style>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<!--
<script src="jquery-1.9.1.min.js"></script>
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<main>
<div id="wrapper">
<form method="get" action="index.html">
<button type="submit">Library</button>
</form>
<!-- <input type="button" value="Begin Reading" id="begin" /> -->
<div id="page-controls"></div>
<input type="button" value="TOC" id="toc" />
<input type="button" value="Night" id="night" />
<input type="button" value="+" id="bigger" />
<input type="button" value="-" id="smaller" />
<input type="button" value="Previous" id="decrement" />
<!-- <input type="button" value="EPUB Package" id="epub" /> -->
<input type="button" value="Next" id="increment" />
</div>
<div class="iframe-container">
<iframe id="pub" name="book-frame"></iframe>
</div>
</main>
<script type="text/javascript">
var manifest = getParameterByName('manifest');
var count = 0;
var NightLink = document.getElementById('night');
var iframe = document.getElementById('pub')
// the manifest knows all
var content = $.getJSON(manifest).done(
function(data){
// set title of page to book title
document.title = data.name;
// display first "spine" item in iframe by default
if (data.spine[0].type == 'image/jpeg') {
var html = '<html><body style="margin: 0 auto; text-align: center;"><img style="max-height: 100vh;" src="' + getPathByName() + '/' + data.spine[0].href + '"/></body></html>'
console.log(html);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
} else {
iframe.setAttribute('src', getPathByName() + '/' + data.spine[0].href );
}
// on clicking "next" go to next spine item
$('#increment').click(function (e) {
e.preventDefault();
count++;
// well, if we just get an image, we need to wrap it in HTML so we can style it
if (data.spine[count].type == 'image/jpeg') {
var html = '<html><body style="margin: 0 auto; text-align: center;"><img style="max-height: 100vh;" src="' + getPathByName() + '/' + data.spine[count].href + '" alt="' + data.spine[count].alt + '"/></body></html>'
console.log(html);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
} else {
iframe.setAttribute('src', getPathByName() + '/' + data.spine[count].href );
}
});
// on clicking "previous" go to previous spine item
$('#decrement').click(function (e) {
e.preventDefault();
count--;
if (data.spine[count].type == 'image/jpeg') {
var html = '<html><body style="margin: 0 auto; text-align: center;"><img style="max-height: 100vh;" src="' + getPathByName() + '/' + data.spine[count].href + '"/></body></html>'
console.log(html);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
} else {
iframe.setAttribute('src', getPathByName() + '/' + data.spine[count].href );
}
});
// link to table of contents
$('#toc').click(function (f) {
f.preventDefault();
for ( var i in data.resources ) {
if (data.resources[i].properties === "nav") {
iframe.setAttribute('src', getPathByName() + '/' + data.resources[i].href );
}}
});
// "begin reading" link goes to start_url, which may not be first spine item
// this screws up count, though.
$('#begin').click(function (g) {
g.preventDefault();
iframe.setAttribute('src', getPathByName() + '/' + data.start_url);
});
// to muck around inside the iframe, we need to wait for it to load
/*
iframe.addEventListener('unload', function(){
console.log('unload');
NightLink.removeEventListener('click', false);
});
*/
});
NightLink.addEventListener('click', function(){
var inside = iframe.contentWindow.document;
//NightLink.addEventListener('click', function() {
if (NightLink.value==="Night") {
inside.getElementsByTagName('html')[0].style.filter = 'invert(1) hue-rotate(180deg)';
// need to check for img elements before altering styles
// code TK... if there's no IMG then getElementsByTagName returns an empty array
//inside.getElementsByTagName('img').style.filter = 'invert(1) hue-rotate(180deg)';
inside.getElementsByTagName('html')[0].style.background = 'black';
document.getElementsByTagName('main')[0].style.background = 'black';
document.getElementById('pub').style.borderColor = 'black';
NightLink.value = 'Day';
} else {
NightLink.value = 'Night';
inside.getElementsByTagName('html')[0].style.background = 'white';
inside.getElementsByTagName('html')[0].style.filter = 'invert(0) hue-rotate(0deg)';
document.getElementsByTagName('main')[0].style.background = 'white';
document.getElementById('pub').style.borderColor = 'white';
}
}, false)
// want to increase/decrease font size inside iframe
fontPluslink = document.getElementById('bigger');
fontPluslink.addEventListener('click', function() {
console.log('clicked bigger');
var inside = iframe.contentWindow.document;
var cur = window.getComputedStyle(inside.getElementsByTagName('body')[0]).fontSize;
inside.getElementsByTagName('body')[0].style.fontSize = parseInt(cur) + 2 + "px"}, false)
fontMinuslink = document.getElementById('smaller');
fontMinuslink.addEventListener('click', function() {
var inside = iframe.contentWindow.document;
var cur = window.getComputedStyle(inside.getElementsByTagName('body')[0]).fontSize;
inside.getElementsByTagName('body')[0].style.fontSize = parseInt(cur) - 2 + "px"}, false)
// night mode!!!!
// what's the path to the manifest?
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(window.location.search);
return match ?
decodeURIComponent(match[1].replace(/\+/g, ' '))
: null;
}
//what folder is the manifest in
function getPathByName() {
//this is deeply flawed. fails on MobyDick/folder/manifest.json
var path = RegExp('[?]manifest=' + '([^/]*)')
.exec(window.location.search);
return path ?
decodeURIComponent(path[1].replace(/\+/g, ' '))
: null;
}
</script>
<script src="page.js"></script>
</body>
</html>