forked from futurepress/epub.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoc.html
52 lines (40 loc) · 1.26 KB
/
toc.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>EPUB.js Basic Example</title>
<script src="../dist/epub.js"></script>
<link rel="stylesheet" type="text/css" href="examples.css">
</head>
<body>
<select id="toc"></select>
<div id="viewer" class="scrolled"></div>
<script>
var $viewer = document.getElementById("viewer");
var $next = document.getElementById("next");
var $prev = document.getElementById("prev");
var currentSectionIndex = 9;
// Load the opf
var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
var rendition = book.renderTo("viewer", { flow: "scrolled-doc", width: 600, height: 400});
var displayed = rendition.display(currentSectionIndex);
book.loaded.navigation.then(function(toc){
var $select = document.getElementById("toc"),
docfrag = document.createDocumentFragment();
toc.forEach(function(chapter) {
var option = document.createElement("option");
option.textContent = chapter.label;
option.ref = chapter.href;
docfrag.appendChild(option);
});
$select.appendChild(docfrag);
$select.onchange = function(){
var index = $select.selectedIndex,
url = $select.options[index].ref;
rendition.display(url);
return false;
};
});
</script>
</body>
</html>