jekyll-ebook_reader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/jekyll-ebook_reader.gemspec +34 -0
- data/lib/jekyll/ebook_reader.rb +66 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/ajax-loader.gif +0 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/ebook_include_body_tag.html +42 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/ebook_include_header.html +3 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/ebookreader_iframe.css +348 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/ebookreader_main.css +369 -0
- data/lib/jekyll/ebook_reader/assets/jekyll-ebookreader-assets/reader.js +305 -0
- data/lib/jekyll/ebook_reader/version.rb +7 -0
- metadata +119 -0
@@ -0,0 +1,369 @@
|
|
1
|
+
#ebook-includes #ebook-main {
|
2
|
+
/*position: absolute;*/
|
3
|
+
top: 50px;
|
4
|
+
left: 3%;
|
5
|
+
width: calc(100% - 100px);
|
6
|
+
max-width: 3000px;
|
7
|
+
z-index: 2;
|
8
|
+
transition: left .15s cubic-bezier(.55, 0, .2, .8) .08s;
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
#ebook-includes div#bottom-nav-arrows {
|
13
|
+
|
14
|
+
}
|
15
|
+
|
16
|
+
#ebook-includes svg {
|
17
|
+
display: block;
|
18
|
+
}
|
19
|
+
|
20
|
+
#ebook-includes .close-x {
|
21
|
+
stroke: #cccddd;
|
22
|
+
fill: transparent;
|
23
|
+
stroke-linecap: round;
|
24
|
+
stroke-width: 5;
|
25
|
+
}
|
26
|
+
|
27
|
+
#ebook-includes .close-x:hover {
|
28
|
+
stroke: #fff;
|
29
|
+
}
|
30
|
+
|
31
|
+
#ebook-includes #viewer {
|
32
|
+
overflow: hidden;
|
33
|
+
width: 100%;
|
34
|
+
min-width: 500px;
|
35
|
+
max-width: 1000px;
|
36
|
+
background-color: white;
|
37
|
+
box-shadow: 0 0 4px #ccc;
|
38
|
+
margin: 20px 20px 20px 20px;
|
39
|
+
padding: 40px 40px;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
#ebook-includes #navigation {
|
44
|
+
width: 400px;
|
45
|
+
position: fixed;
|
46
|
+
overflow: auto;
|
47
|
+
top: 0;
|
48
|
+
right: 100%;
|
49
|
+
|
50
|
+
background: #ECECEC;
|
51
|
+
min-height: 100%;
|
52
|
+
height: 100%;
|
53
|
+
height: 100vh;
|
54
|
+
|
55
|
+
overflow: scroll;
|
56
|
+
-webkit-overflow-scrolling: touch;
|
57
|
+
padding: 9px;
|
58
|
+
padding-top: 10px;
|
59
|
+
|
60
|
+
transition: left .2s ease-out;
|
61
|
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
|
62
|
+
}
|
63
|
+
|
64
|
+
#ebook-includes #navigation.open {
|
65
|
+
left: calc(100% - 410px);
|
66
|
+
z-index: 4;
|
67
|
+
}
|
68
|
+
|
69
|
+
#ebook-includes #navigation.fixed {
|
70
|
+
position: fixed;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
#ebook-includes #navigation h1 {
|
75
|
+
width: 200px;
|
76
|
+
font-size: 16px;
|
77
|
+
font-weight: normal;
|
78
|
+
color: #777;
|
79
|
+
margin-bottom: 10px;
|
80
|
+
}
|
81
|
+
|
82
|
+
#ebook-includes #navigation h2 {
|
83
|
+
font-size: 14px;
|
84
|
+
font-weight: normal;
|
85
|
+
color: #B0B0B0;
|
86
|
+
margin-bottom: 20px;
|
87
|
+
}
|
88
|
+
|
89
|
+
#ebook-includes #navigation ul {
|
90
|
+
padding-left: 28px;
|
91
|
+
margin-left: 0;
|
92
|
+
}
|
93
|
+
|
94
|
+
#ebook-includes #navigation ul li {
|
95
|
+
list-style: decimal;
|
96
|
+
margin-bottom: 10px;
|
97
|
+
color: #585858;
|
98
|
+
font-size: 1em;
|
99
|
+
padding-left: 0;
|
100
|
+
margin-left: 0;
|
101
|
+
}
|
102
|
+
|
103
|
+
#ebook-includes #navigation ul li a {
|
104
|
+
color: #585858;
|
105
|
+
text-decoration: none;
|
106
|
+
}
|
107
|
+
|
108
|
+
#ebook-includes #navigation ul li a:hover {
|
109
|
+
color: #585858;
|
110
|
+
text-decoration: underline;
|
111
|
+
}
|
112
|
+
|
113
|
+
#ebook-includes #navigation ul li a.active {
|
114
|
+
color: #000;
|
115
|
+
font-weight: 400;
|
116
|
+
}
|
117
|
+
|
118
|
+
#ebook-includes #navigation #author {
|
119
|
+
text-align: center;
|
120
|
+
}
|
121
|
+
|
122
|
+
#ebook-includes #cover {
|
123
|
+
display: inline;
|
124
|
+
}
|
125
|
+
|
126
|
+
#ebook-includes #ebook-main {
|
127
|
+
margin-top: 60px;
|
128
|
+
}
|
129
|
+
|
130
|
+
#ebook-includes #pagination {
|
131
|
+
text-align: center;
|
132
|
+
margin: 20px;
|
133
|
+
/*padding: 0 50px;*/
|
134
|
+
}
|
135
|
+
|
136
|
+
#ebook-includes .arrow:hover {
|
137
|
+
color: #777;
|
138
|
+
}
|
139
|
+
|
140
|
+
#ebook-includes .arrow:active {
|
141
|
+
color: #000;
|
142
|
+
}
|
143
|
+
|
144
|
+
#ebook-includes .arrow .material-icons {
|
145
|
+
font-size: 64px;
|
146
|
+
}
|
147
|
+
|
148
|
+
#ebook-includes #prev {
|
149
|
+
/*float: left;*/
|
150
|
+
}
|
151
|
+
|
152
|
+
#ebook-includes #next {
|
153
|
+
/*float: right;*/
|
154
|
+
}
|
155
|
+
|
156
|
+
#ebook-includes #toc {
|
157
|
+
display: block;
|
158
|
+
margin: 10px auto;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
#ebook-includes #navigation #cover {
|
163
|
+
display: block;
|
164
|
+
margin: 24px auto;
|
165
|
+
}
|
166
|
+
|
167
|
+
#ebook-includes #closer {
|
168
|
+
position: absolute;
|
169
|
+
padding: 12px;
|
170
|
+
left: 0;
|
171
|
+
top: 0;
|
172
|
+
color: #333;
|
173
|
+
cursor: pointer;
|
174
|
+
}
|
175
|
+
|
176
|
+
#ebook-includes #closer .material-icons {
|
177
|
+
color: #333;
|
178
|
+
}
|
179
|
+
|
180
|
+
#ebook-includes #opener {
|
181
|
+
position: sticky;
|
182
|
+
float: right;
|
183
|
+
top: 0;
|
184
|
+
right: 20px;
|
185
|
+
padding: 10px;
|
186
|
+
stroke: #E2E2E2;
|
187
|
+
fill: #E2E2E2;
|
188
|
+
z-index: 4;
|
189
|
+
|
190
|
+
}
|
191
|
+
|
192
|
+
#ebook-includes #opener:hover {
|
193
|
+
stroke: #777;
|
194
|
+
fill: #777;
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
#ebook-includes #hiddenTitle {
|
199
|
+
display: none;
|
200
|
+
}
|
201
|
+
|
202
|
+
#ebook-includes #title {
|
203
|
+
width: 900px;
|
204
|
+
min-height: 18px;
|
205
|
+
margin: 10px auto;
|
206
|
+
text-align: center;
|
207
|
+
font-size: 16px;
|
208
|
+
color: #E2E2E2;
|
209
|
+
font-weight: 400;
|
210
|
+
}
|
211
|
+
|
212
|
+
#ebook-includes #title:hover {
|
213
|
+
color: #777;
|
214
|
+
}
|
215
|
+
|
216
|
+
#ebook-includes #prev {
|
217
|
+
left: 0;
|
218
|
+
}
|
219
|
+
|
220
|
+
#ebook-includes #next {
|
221
|
+
right: 0;
|
222
|
+
}
|
223
|
+
|
224
|
+
#ebook-includes #toc {
|
225
|
+
display: block;
|
226
|
+
margin: 10px auto;
|
227
|
+
}
|
228
|
+
|
229
|
+
#ebook-includes #viewer.spreads {
|
230
|
+
width: 84vw;
|
231
|
+
height: 80vh;
|
232
|
+
box-shadow: 0 0 4px #ccc;
|
233
|
+
border-radius: 5px;
|
234
|
+
padding: 0;
|
235
|
+
position: relative;
|
236
|
+
margin: 10vh auto;
|
237
|
+
background: white;
|
238
|
+
top: 0;
|
239
|
+
}
|
240
|
+
|
241
|
+
#ebook-includes #viewer.loading {
|
242
|
+
background: white url('ajax-loader.gif') center center no-repeat;
|
243
|
+
}
|
244
|
+
|
245
|
+
#ebook-includes div#bottom-nav-arrows {
|
246
|
+
height: 100px;
|
247
|
+
width: 100%;
|
248
|
+
}
|
249
|
+
|
250
|
+
#ebook-includes .arrow {
|
251
|
+
font-size: 1rem;
|
252
|
+
margin: 14px;
|
253
|
+
display: inline-block;
|
254
|
+
text-align: center;
|
255
|
+
text-decoration: none;
|
256
|
+
color: #ccc;
|
257
|
+
margin-bottom: 50px;
|
258
|
+
width: calc(50% - 60px);
|
259
|
+
}
|
260
|
+
|
261
|
+
#ebook-includes .navlink {
|
262
|
+
margin: 14px;
|
263
|
+
display: block;
|
264
|
+
text-align: center;
|
265
|
+
text-decoration: none;
|
266
|
+
color: #ccc;
|
267
|
+
}
|
268
|
+
|
269
|
+
#ebook-includes .arrow:hover,
|
270
|
+
#ebook-includes .navlink:hover {
|
271
|
+
color: #777;
|
272
|
+
}
|
273
|
+
|
274
|
+
#ebook-includes .arrow:active,
|
275
|
+
#ebook-includes .navlink:hover {
|
276
|
+
color: #000;
|
277
|
+
}
|
278
|
+
|
279
|
+
#ebook-includes #book-wrapper {
|
280
|
+
width: 480px;
|
281
|
+
height: 640px;
|
282
|
+
overflow: hidden;
|
283
|
+
border: 1px solid #ccc;
|
284
|
+
margin: 28px auto;
|
285
|
+
background: #fff;
|
286
|
+
border-radius: 0 5px 5px 0;
|
287
|
+
position: absolute;
|
288
|
+
}
|
289
|
+
|
290
|
+
#ebook-includes #book-viewer {
|
291
|
+
width: 480px;
|
292
|
+
height: 660px;
|
293
|
+
margin: -30px auto;
|
294
|
+
-moz-box-shadow: inset 10px 0 20px rgba(0, 0, 0, .1);
|
295
|
+
-webkit-box-shadow: inset 10px 0 20px rgba(0, 0, 0, .1);
|
296
|
+
box-shadow: inset 10px 0 20px rgba(0, 0, 0, .1);
|
297
|
+
}
|
298
|
+
|
299
|
+
#ebook-includes #book-viewer iframe {
|
300
|
+
padding: 40px 40px;
|
301
|
+
}
|
302
|
+
|
303
|
+
#ebook-includes #controls {
|
304
|
+
position: absolute;
|
305
|
+
bottom: 16px;
|
306
|
+
left: 50%;
|
307
|
+
width: 400px;
|
308
|
+
margin-left: -200px;
|
309
|
+
text-align: center;
|
310
|
+
display: none;
|
311
|
+
}
|
312
|
+
|
313
|
+
#ebook-includes>#controls>input[type=range] {
|
314
|
+
width: 400px;
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
/* Navigation */
|
319
|
+
|
320
|
+
@media screen and (max-width: 600px) {
|
321
|
+
#ebook-includes #navigation {
|
322
|
+
width: 100%;
|
323
|
+
}
|
324
|
+
|
325
|
+
#ebook-includes #navigation.open {
|
326
|
+
left: 0px;
|
327
|
+
}
|
328
|
+
|
329
|
+
#ebook-includes #ebook-main {
|
330
|
+
width: calc(100% - 32px);
|
331
|
+
position: relative;
|
332
|
+
left: 0px;
|
333
|
+
top: 42px;
|
334
|
+
margin-top: 0px;
|
335
|
+
}
|
336
|
+
|
337
|
+
#ebook-includes #viewer {
|
338
|
+
width: 92%;
|
339
|
+
min-width: 1px;
|
340
|
+
|
341
|
+
margin: 2%;
|
342
|
+
padding: 2%;
|
343
|
+
}
|
344
|
+
|
345
|
+
#ebook-includes #opener {
|
346
|
+
position: absolute;
|
347
|
+
top: 0;
|
348
|
+
right: 6%;
|
349
|
+
padding: 10px 20px;
|
350
|
+
stroke: #E2E2E2;
|
351
|
+
fill: #E2E2E2;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
/* === ALONE EDITS =========== */
|
359
|
+
|
360
|
+
|
361
|
+
#ebook-includes #ebook-main {
|
362
|
+
width: calc(100% - 200px);
|
363
|
+
}
|
364
|
+
|
365
|
+
#ebook-includes #opener {
|
366
|
+
right: 45px;
|
367
|
+
}
|
368
|
+
|
369
|
+
|
@@ -0,0 +1,305 @@
|
|
1
|
+
// window.launchEpubJS = launchEpubJS;
|
2
|
+
// window.handleHypothesisChange = handleHypothesisChange;
|
3
|
+
|
4
|
+
function launchEpubJS(bookURL, bookRenderOptions) {
|
5
|
+
console.log('launchEpubJS...', bookURL, bookRenderOptions);
|
6
|
+
let params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
|
7
|
+
let url = params && params.get("url") && decodeURIComponent(params.get("url"));
|
8
|
+
let defaultBookRenderOptions = {
|
9
|
+
flow: "scrolled-doc",
|
10
|
+
ignoreClass: "annotator-hl",
|
11
|
+
width: "100%",
|
12
|
+
height: "100%",
|
13
|
+
stylesheet: "/assets/books/graeber_debt/epub/assets/epub_iframe_stylesheet.css"
|
14
|
+
};
|
15
|
+
|
16
|
+
|
17
|
+
// Load the opf
|
18
|
+
book = ePub(bookURL || url || "https://cdn.hypothes.is/demos/epub/content/moby-dick/book.epub", {
|
19
|
+
canonical: function(path) {
|
20
|
+
return window.location.origin + window.location.pathname + "?loc=" + path;
|
21
|
+
}
|
22
|
+
});
|
23
|
+
rendition = book.renderTo("viewer", bookRenderOptions || defaultBookRenderOptions);
|
24
|
+
|
25
|
+
// var hash = window.location.hash.slice(2);
|
26
|
+
var loc = window.location.href.indexOf("?loc=");
|
27
|
+
if (loc > -1) {
|
28
|
+
var href = window.location.href.slice(loc + 5);
|
29
|
+
var hash = decodeURIComponent(href);
|
30
|
+
}
|
31
|
+
|
32
|
+
rendition.display(hash || undefined);
|
33
|
+
|
34
|
+
|
35
|
+
var next = document.getElementById("next");
|
36
|
+
next.addEventListener("click", function(e) {
|
37
|
+
rendition.next();
|
38
|
+
e.preventDefault();
|
39
|
+
}, false);
|
40
|
+
|
41
|
+
var prev = document.getElementById("prev");
|
42
|
+
prev.addEventListener("click", function(e) {
|
43
|
+
rendition.prev();
|
44
|
+
e.preventDefault();
|
45
|
+
}, false);
|
46
|
+
|
47
|
+
rendition.on("rendered", function(section) {
|
48
|
+
var nextSection = section.next();
|
49
|
+
var prevSection = section.prev();
|
50
|
+
|
51
|
+
if (nextSection) {
|
52
|
+
nextNav = book.navigation.get(nextSection.href);
|
53
|
+
|
54
|
+
if (nextNav) {
|
55
|
+
nextLabel = nextNav.label;
|
56
|
+
} else {
|
57
|
+
nextLabel = "next";
|
58
|
+
}
|
59
|
+
|
60
|
+
next.textContent = nextLabel + " »";
|
61
|
+
} else {
|
62
|
+
next.textContent = "";
|
63
|
+
}
|
64
|
+
|
65
|
+
if (prevSection) {
|
66
|
+
prevNav = book.navigation.get(prevSection.href);
|
67
|
+
|
68
|
+
if (prevNav) {
|
69
|
+
prevLabel = prevNav.label;
|
70
|
+
} else {
|
71
|
+
prevLabel = "previous";
|
72
|
+
}
|
73
|
+
|
74
|
+
prev.textContent = "« " + prevLabel;
|
75
|
+
} else {
|
76
|
+
prev.textContent = "";
|
77
|
+
}
|
78
|
+
});
|
79
|
+
|
80
|
+
var nav = document.getElementById("navigation");
|
81
|
+
var opener = document.getElementById("opener");
|
82
|
+
opener.addEventListener("click", function(e) {
|
83
|
+
if (nav.classList.contains("open")) {
|
84
|
+
nav.classList.remove("open")
|
85
|
+
} else {
|
86
|
+
nav.classList.add("open");
|
87
|
+
}
|
88
|
+
}, false);
|
89
|
+
|
90
|
+
var closer = document.getElementById("closer");
|
91
|
+
closer.addEventListener("click", function(e) {
|
92
|
+
nav.classList.remove("open");
|
93
|
+
}, false);
|
94
|
+
|
95
|
+
// Hidden
|
96
|
+
var hiddenTitle = document.getElementById("hiddenTitle");
|
97
|
+
|
98
|
+
rendition.on("rendered", function(section) {
|
99
|
+
var current = book.navigation && book.navigation.get(section.href);
|
100
|
+
|
101
|
+
if (current) {
|
102
|
+
document.title = current.label;
|
103
|
+
}
|
104
|
+
|
105
|
+
// TODO: this is needed to trigger the hypothesis client
|
106
|
+
// to inject into the iframe
|
107
|
+
requestAnimationFrame(function() {
|
108
|
+
hiddenTitle.textContent = section.href;
|
109
|
+
})
|
110
|
+
|
111
|
+
var old = document.querySelectorAll('.active');
|
112
|
+
Array.prototype.slice.call(old, 0)
|
113
|
+
.forEach(function(link) {
|
114
|
+
link.classList.remove("active");
|
115
|
+
})
|
116
|
+
|
117
|
+
var active = document.querySelector('a[href="' + section.href + '"]');
|
118
|
+
if (active) {
|
119
|
+
active.classList.add("active");
|
120
|
+
}
|
121
|
+
// Add CFI fragment to the history
|
122
|
+
history.pushState({}, '', "?loc=" + encodeURIComponent(section.href));
|
123
|
+
// window.location.hash = "#/"+section.href
|
124
|
+
});
|
125
|
+
|
126
|
+
var keyListener = function(e) {
|
127
|
+
|
128
|
+
// Left Key
|
129
|
+
if ((e.keyCode || e.which) == 37) {
|
130
|
+
rendition.prev();
|
131
|
+
}
|
132
|
+
|
133
|
+
// Right Key
|
134
|
+
if ((e.keyCode || e.which) == 39) {
|
135
|
+
rendition.next();
|
136
|
+
}
|
137
|
+
|
138
|
+
};
|
139
|
+
|
140
|
+
rendition.on("keyup", keyListener);
|
141
|
+
document.addEventListener("keyup", keyListener, false);
|
142
|
+
|
143
|
+
book.ready.then(function() {
|
144
|
+
var $viewer = document.getElementById("viewer");
|
145
|
+
$viewer.classList.remove("loading");
|
146
|
+
});
|
147
|
+
|
148
|
+
book.loaded.navigation.then(function(toc) {
|
149
|
+
var $nav = document.getElementById("toc"),
|
150
|
+
docfrag = document.createDocumentFragment();
|
151
|
+
|
152
|
+
toc.forEach(function(chapter, index) {
|
153
|
+
var item = document.createElement("li");
|
154
|
+
var link = document.createElement("a");
|
155
|
+
link.id = "chap-" + chapter.id;
|
156
|
+
link.textContent = chapter.label;
|
157
|
+
link.href = chapter.href;
|
158
|
+
item.appendChild(link);
|
159
|
+
docfrag.appendChild(item);
|
160
|
+
|
161
|
+
link.onclick = function() {
|
162
|
+
var url = link.getAttribute("href");
|
163
|
+
rendition.display(url);
|
164
|
+
return false;
|
165
|
+
};
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
$nav.appendChild(docfrag);
|
170
|
+
|
171
|
+
|
172
|
+
});
|
173
|
+
|
174
|
+
book.loaded.metadata.then(function(meta) {
|
175
|
+
var $title = document.getElementById("title");
|
176
|
+
var $author = document.getElementById("author");
|
177
|
+
var $cover = document.getElementById("cover");
|
178
|
+
var $nav = document.getElementById('navigation');
|
179
|
+
|
180
|
+
$title.textContent = meta.title;
|
181
|
+
$author.textContent = meta.creator;
|
182
|
+
if (book.archive) {
|
183
|
+
book.archive.createUrl(book.cover)
|
184
|
+
.then(function(url) {
|
185
|
+
$cover.src = url;
|
186
|
+
})
|
187
|
+
} else {
|
188
|
+
$cover.src = book.cover;
|
189
|
+
}
|
190
|
+
|
191
|
+
});
|
192
|
+
|
193
|
+
book.rendition.hooks.content.register(function(contents, view) {
|
194
|
+
|
195
|
+
contents.window.addEventListener('scrolltorange', function(e) {
|
196
|
+
var range = e.detail;
|
197
|
+
var cfi = new ePub.CFI(range, contents.cfiBase)
|
198
|
+
.toString();
|
199
|
+
if (cfi) {
|
200
|
+
book.rendition.display(cfi);
|
201
|
+
}
|
202
|
+
e.preventDefault();
|
203
|
+
});
|
204
|
+
|
205
|
+
});
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
function wait(t) {
|
211
|
+
return new Promise(function(resolve) {
|
212
|
+
window.setTimeout(resolve, t)
|
213
|
+
});
|
214
|
+
}
|
215
|
+
|
216
|
+
function handleHypothesisChange(state) {
|
217
|
+
|
218
|
+
let epubjsStyleIfHypoOpen = `body.hypothesis-highlights-always-on { padding-left: 5px !important; }`
|
219
|
+
|
220
|
+
let main = document.querySelector('#ebook-main');
|
221
|
+
let hypoWasAlreadyOpen = main.classList.contains('hypoIsOpen');
|
222
|
+
let hypoSidebarDidChange = (
|
223
|
+
(hypoWasAlreadyOpen && !state.expanded)
|
224
|
+
|| (!hypoWasAlreadyOpen && state.expanded));
|
225
|
+
if (hypoSidebarDidChange) {
|
226
|
+
// Wait until epub.js iframe is loaded
|
227
|
+
if (!document.querySelector('div.epub-view iframe')) {
|
228
|
+
wait(1500)
|
229
|
+
.then(
|
230
|
+
(a) => {
|
231
|
+
console.log('waiting...', a);
|
232
|
+
resizeReflowAndScroll();
|
233
|
+
}
|
234
|
+
);
|
235
|
+
} else {
|
236
|
+
resizeReflowAndScroll();
|
237
|
+
}
|
238
|
+
} else {
|
239
|
+
return;
|
240
|
+
}
|
241
|
+
|
242
|
+
// Reflow txt to still be visible, scroll to maintain location
|
243
|
+
function resizeReflowAndScroll() {
|
244
|
+
console.log('reflowing...')
|
245
|
+
|
246
|
+
// Main window
|
247
|
+
let currScroll = scrollY;
|
248
|
+
let viewer = document.querySelector("#viewer");
|
249
|
+
let parsedRenditionWidthPct = Number.parseInt(rendition.settings.width) / 100;
|
250
|
+
|
251
|
+
// Hypothesis
|
252
|
+
let hypoSidebar = document.querySelector("hypothesis-sidebar")
|
253
|
+
.shadowRoot.querySelector('div.annotator-frame');
|
254
|
+
|
255
|
+
// epub.js iframe
|
256
|
+
let iframeEl = document.querySelector('iframe');
|
257
|
+
let iframePaddingElement = iframeEl.contentDocument.querySelector("#iframePaddingElement");
|
258
|
+
console.log(iframeEl, iframePaddingElement);
|
259
|
+
if (!iframePaddingElement) {
|
260
|
+
iframePaddingElement = document.createElement("style");
|
261
|
+
iframePaddingElement.id = "iframePaddingElement";
|
262
|
+
iframeEl.contentDocument.head.appendChild(iframePaddingElement);
|
263
|
+
}
|
264
|
+
console.log(iframeEl, iframePaddingElement);
|
265
|
+
|
266
|
+
let bodyEl = iframeEl.contentDocument.body;
|
267
|
+
let currBodyPadding = [Number.parseInt(bodyEl.style.paddingLeft),
|
268
|
+
Number.parseInt(bodyEl.style.paddingRight)
|
269
|
+
];
|
270
|
+
|
271
|
+
// If hypothesis expanded (this fn is only called if it was a real sidebar open/close)
|
272
|
+
if (state.expanded) {
|
273
|
+
main.classList.add('hypoIsOpen');
|
274
|
+
|
275
|
+
// Inject reduced padding styling to epub iframe
|
276
|
+
iframePaddingElement.textContent = epubjsStyleIfHypoOpen;
|
277
|
+
|
278
|
+
// Calculate new size
|
279
|
+
let rectViewer = viewer.getBoundingClientRect();
|
280
|
+
let rectHypo = hypoSidebar.getBoundingClientRect();
|
281
|
+
let spaceNeeded = Number.parseFloat(rectViewer.right - (rectHypo.left - rectHypo.width));
|
282
|
+
let pct = spaceNeeded / Number.parseFloat(rectViewer.width);
|
283
|
+
pct = (1 - pct) * 100;
|
284
|
+
pct = Number.parseInt(pct).toString();
|
285
|
+
pct = pct + '%';
|
286
|
+
console.log('resizeDetails', {pct, spaceNeeded, rectHypo, rectViewer});
|
287
|
+
rendition.resize(pct);
|
288
|
+
|
289
|
+
let scrollNew = currScroll + 0.262 * currScroll;
|
290
|
+
wait(300).then(() => scrollTo({ 'top': scrollNew }));
|
291
|
+
|
292
|
+
} else if ((state.expanded === false)) {
|
293
|
+
rendition.resize("100%");
|
294
|
+
main.classList.remove("hypoIsOpen");
|
295
|
+
iframePaddingElement.textContent = "";
|
296
|
+
|
297
|
+
let scrollNew = currScroll / 1.262;
|
298
|
+
wait(300)
|
299
|
+
.then(() => scrollTo({ 'top': scrollNew }));
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
};
|
304
|
+
|
305
|
+
}
|