epubjs
Version:
Render ePub documents in the browser, across many devices
186 lines (153 loc) • 5.71 kB
HTML
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Basic ePubJS Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Zip Support -->
<script src="../build/libs/zip.min.js"></script>
<!-- EPUBJS Renderer -->
<script src="../build/epub.js"></script>
<!-- Hooks -->
<!-- <script src="../hooks/default/transculsions.js"></script> -->
<!-- <script src="../hooks/default/endnotes.js"></script> -->
<script src="../hooks/default/smartimages.js"></script>
<script>
EPUBJS.filePath = "../reader/js/libs/";
EPUBJS.cssPath = "../reader/css/";
</script>
<style type="text/css">
body {
}
#main {
position: absolute;
width: 100%;
height: 100%;
/* overflow: hidden; */
}
#area {
width: 80%;
height: 80%;
margin: 5% auto;
max-width: 1250px;
}
#area iframe {
border: none;
}
#prev {
left: 40px;
}
#next {
right: 40px;
}
.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;
}
#controls {
position: absolute;
bottom: 16px;
left: 50%;
width: 400px;
margin-left: -200px;
text-align: center;
display: none;
}
#controls > input[type=range] {
width: 400px;
}
</style>
<script>;
var book = ePub("../books/georgia-cfi-20120521/", { width: 1076, height: 588 });
</script>
</head>
<body>
<div id="main">
<div id="prev" onclick="book.prevPage();" class="arrow">‹</div>
<div id="area"></div>
<div id="next" onclick="book.nextPage();" class="arrow">›</div>
<div id="controls">
<input id="currentpg" size="3" maxlength="3"/> / <span id="totalpg">0</span>
</div>
</div>
<script>
var controls = document.getElementById("controls");
var currentPage = document.getElementById("currentpg");
var totalPages = document.getElementById("totalpg");
var slider = document.createElement("input");
var pageList;
var slide = function(){
book.gotoPage(slider.value);
};
// var throttledSlide = _.throttle(slide, 200);
var mouseDown = false;
var rendered = book.renderTo("area");
// Load in stored pageList from json or local storage
///*
// EPUBJS.core.request("page_list.json").then(function(storedPageList){
// pageList = storedPageList;
// console.log(storedPageList)
// book.loadPagination(pageList);
// });
// Or generate the pageList on the fly
// book.ready.all.then(function(){
// book.generatePagination();
// });
// Wait for the pageList to be ready and then show slider
book.pageListReady.then(function(pageList){
controls.style.display = "block";
// console.log(JSON.stringify(pageList)); // Save the result
slider.setAttribute("type", "range");
slider.setAttribute("min", book.pagination.firstPage);
slider.setAttribute("max", book.pagination.lastPage);
slider.setAttribute("step", 1);
slider.setAttribute("value", 0);
slider.addEventListener("change", slide, false);
slider.addEventListener("mousedown", function(){
mouseDown = true;
}, false);
slider.addEventListener("mouseup", function(){
mouseDown = false;
}, false);
// Wait for book to be rendered to get current page
rendered.then(function(){
var currentLocation = book.getCurrentLocationCfi();
var currentPage = book.pagination.pageFromCfi(currentLocation);
slider.value = currentPage;
currentPage.value = currentPage;
});
controls.appendChild(slider);
totalPages.innerText = book.pagination.totalPages;
currentPage.addEventListener("change", function(){
book.gotoPage(currentPage.value);
}, false);
});
book.on('book:pageChanged', function(location){
if(!mouseDown) {
slider.value = location.anchorPage;
}
currentPage.value = location.anchorPage;
console.log(location.pageRange)
});
</script>
</body>
</html>