mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00

* Initial embedding support * Updates for rendering in embedded webviews * toLowerCase nodeName check
103 lines
2.3 KiB
HTML
103 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>EPUB.js Continuous Spreads Example</title>
|
||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.1/jszip.min.js"></script>
|
||
<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="spreads"></div>
|
||
<div id="prev" class="arrow">‹</div>
|
||
<div id="next" class="arrow">›</div>
|
||
<script>
|
||
// Load the opf
|
||
window.book = ePub("https://s3.amazonaws.com/moby-dick/moby-dick.epub");
|
||
var rendition = book.renderTo("viewer", {
|
||
manager: "continuous",
|
||
flow: "paginated",
|
||
width: "100%",
|
||
height: 600
|
||
});
|
||
|
||
var displayed = rendition.display();
|
||
|
||
|
||
displayed.then(function(renderer){
|
||
// -- do stuff
|
||
});
|
||
|
||
// Navigation loaded
|
||
book.loaded.navigation.then(function(toc){
|
||
// console.log(toc);
|
||
});
|
||
|
||
var next = document.getElementById("next");
|
||
next.addEventListener("click", function(){
|
||
rendition.next();
|
||
}, false);
|
||
|
||
var prev = document.getElementById("prev");
|
||
prev.addEventListener("click", function(){
|
||
rendition.prev();
|
||
}, false);
|
||
|
||
var keyListener = function(e){
|
||
|
||
// Left Key
|
||
if ((e.keyCode || e.which) == 37) {
|
||
rendition.prev();
|
||
}
|
||
|
||
// Right Key
|
||
if ((e.keyCode || e.which) == 39) {
|
||
rendition.next();
|
||
}
|
||
|
||
};
|
||
|
||
rendition.on("keyup", keyListener);
|
||
document.addEventListener("keyup", keyListener, false);
|
||
|
||
rendition.on("selected", function(range) {
|
||
console.log("selected", range);
|
||
});
|
||
|
||
rendition.on("relocated", function(location){
|
||
console.log(location);
|
||
});
|
||
|
||
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>
|