mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Goto will take you back to first page of chapter
This commit is contained in:
parent
d84203711a
commit
48612637d4
12 changed files with 752 additions and 722 deletions
350
build/epub.js
350
build/epub.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,7 @@
|
||||||
<title>Basic ePubJS Example</title>
|
<title>Basic ePubJS Example</title>
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||||
<!-- EPUBJS Renderer -->
|
<!-- EPUBJS Renderer -->
|
||||||
<!-- zip -->
|
<!-- zip -->
|
||||||
|
@ -15,8 +15,8 @@
|
||||||
<script src="../libs/zip/zip-ext.js"></script>
|
<script src="../libs/zip/zip-ext.js"></script>
|
||||||
<script src="../libs/zip/inflate.js"></script>
|
<script src="../libs/zip/inflate.js"></script>
|
||||||
<script src="../libs/zip/mime-types.js"></script>
|
<script src="../libs/zip/mime-types.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<!-- Render -->
|
<!-- Render -->
|
||||||
<script src="../libs/underscore/underscore.js"></script>
|
<script src="../libs/underscore/underscore.js"></script>
|
||||||
<script src="../libs/rsvp/rsvp.js"></script>
|
<script src="../libs/rsvp/rsvp.js"></script>
|
||||||
|
@ -39,9 +39,9 @@
|
||||||
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
||||||
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
||||||
<script src="../hooks/default/smartimages.js"></script>
|
<script src="../hooks/default/smartimages.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
EPUBJS.filePath = "../reader/js/libs/";
|
EPUBJS.filePath = "../reader/js/libs/";
|
||||||
EPUBJS.cssPath = "../reader/css/";
|
EPUBJS.cssPath = "../reader/css/";
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#main {
|
#main {
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
left: 40px;
|
left: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#next {
|
#next {
|
||||||
right: 40px;
|
right: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +96,11 @@
|
||||||
.arrow:hover {
|
.arrow:hover {
|
||||||
color: #777;
|
color: #777;
|
||||||
}
|
}
|
||||||
|
|
||||||
.arrow:active {
|
.arrow:active {
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#controls {
|
#controls {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 16px;
|
bottom: 16px;
|
||||||
|
@ -110,15 +110,15 @@
|
||||||
text-align: center;
|
text-align: center;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#controls > input[type=range] {
|
#controls > input[type=range] {
|
||||||
width: 400px;
|
width: 400px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var book = ePub("../reader/moby-dick/", { width: 1076, height: 588 });
|
var book = ePub("../reader/moby-dick/", { width: 1076, height: 588 });
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -133,7 +133,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var controls = document.getElementById("controls");
|
var controls = document.getElementById("controls");
|
||||||
var currentPage = document.getElementById("currentpg");
|
var currentPage = document.getElementById("currentpg");
|
||||||
var totalPages = document.getElementById("totalpg");
|
var totalPages = document.getElementById("totalpg");
|
||||||
|
@ -144,23 +144,23 @@
|
||||||
};
|
};
|
||||||
var throttledSlide = _.throttle(slide, 200);
|
var throttledSlide = _.throttle(slide, 200);
|
||||||
var mouseDown = false;
|
var mouseDown = false;
|
||||||
|
|
||||||
var rendered = book.renderTo("area");
|
var rendered = book.renderTo("area");
|
||||||
|
|
||||||
// Load in stored pageList from json or local storage
|
// Load in stored pageList from json or local storage
|
||||||
///*
|
///*
|
||||||
EPUBJS.core.request("page_list.json").then(function(storedPageList){
|
// EPUBJS.core.request("page_list.json").then(function(storedPageList){
|
||||||
pageList = storedPageList;
|
// pageList = storedPageList;
|
||||||
console.log(storedPageList)
|
// console.log(storedPageList)
|
||||||
book.loadPagination(pageList);
|
// book.loadPagination(pageList);
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// Or generate the pageList on the fly
|
||||||
|
book.ready.all.then(function(){
|
||||||
|
book.generatePagination();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 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
|
// Wait for the pageList to be ready and then show slider
|
||||||
book.pageListReady.then(function(pageList){
|
book.pageListReady.then(function(pageList){
|
||||||
controls.style.display = "block";
|
controls.style.display = "block";
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
slider.setAttribute("max", book.pagination.lastPage);
|
slider.setAttribute("max", book.pagination.lastPage);
|
||||||
slider.setAttribute("step", 1);
|
slider.setAttribute("step", 1);
|
||||||
slider.setAttribute("value", 0);
|
slider.setAttribute("value", 0);
|
||||||
|
|
||||||
slider.addEventListener("change", throttledSlide, false);
|
slider.addEventListener("change", throttledSlide, false);
|
||||||
slider.addEventListener("mousedown", function(){
|
slider.addEventListener("mousedown", function(){
|
||||||
mouseDown = true;
|
mouseDown = true;
|
||||||
|
@ -178,7 +178,7 @@
|
||||||
slider.addEventListener("mouseup", function(){
|
slider.addEventListener("mouseup", function(){
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// Wait for book to be rendered to get current page
|
// Wait for book to be rendered to get current page
|
||||||
rendered.then(function(){
|
rendered.then(function(){
|
||||||
var currentLocation = book.getCurrentLocationCfi();
|
var currentLocation = book.getCurrentLocationCfi();
|
||||||
|
@ -186,15 +186,15 @@
|
||||||
slider.value = currentPage;
|
slider.value = currentPage;
|
||||||
currentPage.value = currentPage;
|
currentPage.value = currentPage;
|
||||||
});
|
});
|
||||||
|
|
||||||
controls.appendChild(slider);
|
controls.appendChild(slider);
|
||||||
|
|
||||||
totalPages.innerText = book.pagination.totalPages;
|
totalPages.innerText = book.pagination.totalPages;
|
||||||
currentPage.addEventListener("change", function(){
|
currentPage.addEventListener("change", function(){
|
||||||
book.gotoPage(currentPage.value);
|
book.gotoPage(currentPage.value);
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
book.on('book:pageChanged', function(location){
|
book.on('book:pageChanged', function(location){
|
||||||
if(!mouseDown) {
|
if(!mouseDown) {
|
||||||
slider.value = location.anchorPage;
|
slider.value = location.anchorPage;
|
||||||
|
|
File diff suppressed because one or more lines are too long
350
reader/js/epub.min.js
vendored
350
reader/js/epub.min.js
vendored
File diff suppressed because it is too large
Load diff
155
src/book.js
155
src/book.js
|
@ -28,7 +28,7 @@ EPUBJS.Book = function(options){
|
||||||
});
|
});
|
||||||
|
|
||||||
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
this.settings.EPUBJSVERSION = EPUBJS.VERSION;
|
||||||
|
|
||||||
this.spinePos = 0;
|
this.spinePos = 0;
|
||||||
this.stored = false;
|
this.stored = false;
|
||||||
|
|
||||||
|
@ -42,25 +42,25 @@ EPUBJS.Book = function(options){
|
||||||
book:loadFailed
|
book:loadFailed
|
||||||
book:loadChapterFailed
|
book:loadChapterFailed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//-- Adds Hook methods to the Book prototype
|
//-- Adds Hook methods to the Book prototype
|
||||||
// Hooks will all return before triggering the callback.
|
// Hooks will all return before triggering the callback.
|
||||||
// EPUBJS.Hooks.mixin(this);
|
// EPUBJS.Hooks.mixin(this);
|
||||||
//-- Get pre-registered hooks for events
|
//-- Get pre-registered hooks for events
|
||||||
// this.getHooks("beforeChapterDisplay");
|
// this.getHooks("beforeChapterDisplay");
|
||||||
|
|
||||||
this.online = this.settings.online || navigator.onLine;
|
this.online = this.settings.online || navigator.onLine;
|
||||||
this.networkListeners();
|
this.networkListeners();
|
||||||
|
|
||||||
this.store = false; //-- False if not using storage;
|
this.store = false; //-- False if not using storage;
|
||||||
|
|
||||||
//-- Determine storage method
|
//-- Determine storage method
|
||||||
//-- Override options: none | ram | websqldatabase | indexeddb | filesystem
|
//-- Override options: none | ram | websqldatabase | indexeddb | filesystem
|
||||||
|
|
||||||
if(this.settings.storage !== false){
|
if(this.settings.storage !== false){
|
||||||
this.storage = new fileStorage.storage(this.settings.storage);
|
this.storage = new fileStorage.storage(this.settings.storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ready = {
|
this.ready = {
|
||||||
manifest: new RSVP.defer(),
|
manifest: new RSVP.defer(),
|
||||||
spine: new RSVP.defer(),
|
spine: new RSVP.defer(),
|
||||||
|
@ -69,7 +69,7 @@ EPUBJS.Book = function(options){
|
||||||
toc: new RSVP.defer(),
|
toc: new RSVP.defer(),
|
||||||
pageList: new RSVP.defer()
|
pageList: new RSVP.defer()
|
||||||
};
|
};
|
||||||
|
|
||||||
this.readyPromises = [
|
this.readyPromises = [
|
||||||
this.ready.manifest.promise,
|
this.ready.manifest.promise,
|
||||||
this.ready.spine.promise,
|
this.ready.spine.promise,
|
||||||
|
@ -77,15 +77,15 @@ EPUBJS.Book = function(options){
|
||||||
this.ready.cover.promise,
|
this.ready.cover.promise,
|
||||||
this.ready.toc.promise
|
this.ready.toc.promise
|
||||||
];
|
];
|
||||||
|
|
||||||
this.pageList = [];
|
this.pageList = [];
|
||||||
this.pagination = new EPUBJS.Pagination();
|
this.pagination = new EPUBJS.Pagination();
|
||||||
this.pageListReady = this.ready.pageList.promise;
|
this.pageListReady = this.ready.pageList.promise;
|
||||||
|
|
||||||
this.ready.all = RSVP.all(this.readyPromises);
|
this.ready.all = RSVP.all(this.readyPromises);
|
||||||
|
|
||||||
this.ready.all.then(this._ready.bind(this));
|
this.ready.all.then(this._ready.bind(this));
|
||||||
|
|
||||||
// Queue for methods used before rendering
|
// Queue for methods used before rendering
|
||||||
this.isRendered = false;
|
this.isRendered = false;
|
||||||
this._q = EPUBJS.core.queue(this);
|
this._q = EPUBJS.core.queue(this);
|
||||||
|
@ -97,7 +97,7 @@ EPUBJS.Book = function(options){
|
||||||
this._gotoQ = EPUBJS.core.queue(this);
|
this._gotoQ = EPUBJS.core.queue(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new renderer.
|
* Creates a new renderer.
|
||||||
* The renderer will handle displaying the content using the method provided in the settings
|
* The renderer will handle displaying the content using the method provided in the settings
|
||||||
*/
|
*/
|
||||||
this.renderer = new EPUBJS.Renderer(this.settings.render_method);
|
this.renderer = new EPUBJS.Renderer(this.settings.render_method);
|
||||||
|
@ -106,14 +106,14 @@ EPUBJS.Book = function(options){
|
||||||
this.renderer.setGap(this.settings.gap);
|
this.renderer.setGap(this.settings.gap);
|
||||||
//-- Pass through the renderer events
|
//-- Pass through the renderer events
|
||||||
this.listenToRenderer(this.renderer);
|
this.listenToRenderer(this.renderer);
|
||||||
|
|
||||||
this.defer_opened = new RSVP.defer();
|
this.defer_opened = new RSVP.defer();
|
||||||
this.opened = this.defer_opened.promise;
|
this.opened = this.defer_opened.promise;
|
||||||
// BookUrl is optional, but if present start loading process
|
// BookUrl is optional, but if present start loading process
|
||||||
if(typeof this.settings.bookPath === 'string') {
|
if(typeof this.settings.bookPath === 'string') {
|
||||||
this.open(this.settings.bookPath, this.settings.reload);
|
this.open(this.settings.bookPath, this.settings.reload);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||||
|
|
||||||
//-- Listen for these promises:
|
//-- Listen for these promises:
|
||||||
|
@ -121,7 +121,7 @@ EPUBJS.Book = function(options){
|
||||||
//-- book.rendered.then()
|
//-- book.rendered.then()
|
||||||
};
|
};
|
||||||
|
|
||||||
//-- Check bookUrl and start parsing book Assets or load them from storage
|
//-- Check bookUrl and start parsing book Assets or load them from storage
|
||||||
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
var book = this,
|
var book = this,
|
||||||
epubpackage,
|
epubpackage,
|
||||||
|
@ -159,9 +159,9 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
opened.resolve();
|
opened.resolve();
|
||||||
book.defer_opened.resolve();
|
book.defer_opened.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
//-- Get package information from epub opf
|
//-- Get package information from epub opf
|
||||||
epubpackage.then(function(packageXml) {
|
epubpackage.then(function(packageXml) {
|
||||||
book.unpack(packageXml);
|
book.unpack(packageXml);
|
||||||
|
@ -169,7 +169,7 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
book.defer_opened.resolve();
|
book.defer_opened.resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- If there is network connection, store the books contents
|
//-- If there is network connection, store the books contents
|
||||||
if(this.online && this.settings.storage && !this.settings.contained){
|
if(this.online && this.settings.storage && !this.settings.contained){
|
||||||
if(!this.settings.stored) opened.then(book.storeOffline());
|
if(!this.settings.stored) opened.then(book.storeOffline());
|
||||||
|
@ -187,7 +187,7 @@ EPUBJS.Book.prototype.loadPackage = function(_containerPath){
|
||||||
containerPath = _containerPath || "META-INF/container.xml",
|
containerPath = _containerPath || "META-INF/container.xml",
|
||||||
containerXml,
|
containerXml,
|
||||||
packageXml;
|
packageXml;
|
||||||
|
|
||||||
if(!this.settings.packageUrl) { //-- provide the packageUrl to skip this step
|
if(!this.settings.packageUrl) { //-- provide the packageUrl to skip this step
|
||||||
packageXml = book.loadXml(book.bookUrl + containerPath).
|
packageXml = book.loadXml(book.bookUrl + containerPath).
|
||||||
then(function(containerXml){
|
then(function(containerXml){
|
||||||
|
@ -197,12 +197,12 @@ EPUBJS.Book.prototype.loadPackage = function(_containerPath){
|
||||||
book.settings.contentsPath = book.bookUrl + paths.basePath;
|
book.settings.contentsPath = book.bookUrl + paths.basePath;
|
||||||
book.settings.packageUrl = book.bookUrl + paths.packagePath;
|
book.settings.packageUrl = book.bookUrl + paths.packagePath;
|
||||||
book.settings.encoding = paths.encoding;
|
book.settings.encoding = paths.encoding;
|
||||||
return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata
|
return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
packageXml = book.loadXml(book.settings.packageUrl);
|
packageXml = book.loadXml(book.settings.packageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
packageXml.catch(function(error) {
|
packageXml.catch(function(error) {
|
||||||
// handle errors in either of the two requests
|
// handle errors in either of the two requests
|
||||||
console.error("Could not load book at: "+ containerPath);
|
console.error("Could not load book at: "+ containerPath);
|
||||||
|
@ -221,7 +221,7 @@ EPUBJS.Book.prototype.packageIdentifier = function(packageXml){
|
||||||
EPUBJS.Book.prototype.unpack = function(packageXml){
|
EPUBJS.Book.prototype.unpack = function(packageXml){
|
||||||
var book = this,
|
var book = this,
|
||||||
parse = new EPUBJS.Parser();
|
parse = new EPUBJS.Parser();
|
||||||
|
|
||||||
book.contents = parse.packageContents(packageXml, book.settings.contentsPath); // Extract info from contents
|
book.contents = parse.packageContents(packageXml, book.settings.contentsPath); // Extract info from contents
|
||||||
|
|
||||||
book.manifest = book.contents.manifest;
|
book.manifest = book.contents.manifest;
|
||||||
|
@ -236,9 +236,9 @@ EPUBJS.Book.prototype.unpack = function(packageXml){
|
||||||
book.globalLayoutProperties = book.parseLayoutProperties(book.metadata);
|
book.globalLayoutProperties = book.parseLayoutProperties(book.metadata);
|
||||||
|
|
||||||
book.cover = book.contents.cover = book.settings.contentsPath + book.contents.coverPath;
|
book.cover = book.contents.cover = book.settings.contentsPath + book.contents.coverPath;
|
||||||
|
|
||||||
book.spineNodeIndex = book.contents.spineNodeIndex;
|
book.spineNodeIndex = book.contents.spineNodeIndex;
|
||||||
|
|
||||||
book.ready.manifest.resolve(book.contents.manifest);
|
book.ready.manifest.resolve(book.contents.manifest);
|
||||||
book.ready.spine.resolve(book.contents.spine);
|
book.ready.spine.resolve(book.contents.spine);
|
||||||
book.ready.metadata.resolve(book.contents.metadata);
|
book.ready.metadata.resolve(book.contents.metadata);
|
||||||
|
@ -258,7 +258,7 @@ EPUBJS.Book.prototype.unpack = function(packageXml){
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
book.ready.toc.resolve(false);
|
book.ready.toc.resolve(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load the optional pageList
|
// Load the optional pageList
|
||||||
book.loadXml(book.settings.navUrl).
|
book.loadXml(book.settings.navUrl).
|
||||||
then(function(navHtml){
|
then(function(navHtml){
|
||||||
|
@ -290,7 +290,7 @@ EPUBJS.Book.prototype.unpack = function(packageXml){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!wait) {
|
if(!wait) {
|
||||||
book.pagination.process(book.pageList);
|
book.pagination.process(book.pageList);
|
||||||
book.ready.pageList.resolve(book.pageList);
|
book.ready.pageList.resolve(book.pageList);
|
||||||
|
@ -331,7 +331,7 @@ EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) {
|
||||||
if(this.settings.forceSingle) {
|
if(this.settings.forceSingle) {
|
||||||
renderer.forceSingle(true);
|
renderer.forceSingle(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
hiddenContainer = document.createElement("div");
|
hiddenContainer = document.createElement("div");
|
||||||
hiddenContainer.style.visibility = "hidden";
|
hiddenContainer.style.visibility = "hidden";
|
||||||
hiddenContainer.style.overflow = "hidden";
|
hiddenContainer.style.overflow = "hidden";
|
||||||
|
@ -345,7 +345,7 @@ EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) {
|
||||||
hiddenEl.style.width = width + "px";//"0";
|
hiddenEl.style.width = width + "px";//"0";
|
||||||
hiddenEl.style.height = height +"px"; //"0";
|
hiddenEl.style.height = height +"px"; //"0";
|
||||||
hiddenContainer.appendChild(hiddenEl);
|
hiddenContainer.appendChild(hiddenEl);
|
||||||
|
|
||||||
renderer.initialize(hiddenEl);
|
renderer.initialize(hiddenEl);
|
||||||
return hiddenContainer;
|
return hiddenContainer;
|
||||||
};
|
};
|
||||||
|
@ -377,9 +377,9 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
||||||
"cfi" : item.start,
|
"cfi" : item.start,
|
||||||
"page" : currentPage
|
"page" : currentPage
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(pager.pageMap.length % 2 > 0 &&
|
if(pager.pageMap.length % 2 > 0 &&
|
||||||
pager.spreads) {
|
pager.spreads) {
|
||||||
currentPage += 1; // Handle Spreads
|
currentPage += 1; // Handle Spreads
|
||||||
|
@ -397,13 +397,13 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
||||||
}
|
}
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
var finished = nextChapter().then(function(){
|
var finished = nextChapter().then(function(){
|
||||||
pager.remove();
|
pager.remove();
|
||||||
this.element.removeChild(hiddenContainer);
|
this.element.removeChild(hiddenContainer);
|
||||||
deferred.resolve(pageList);
|
deferred.resolve(pageList);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ EPUBJS.Book.prototype.generatePagination = function(width, height) {
|
||||||
defered.resolve(book.pageList);
|
defered.resolve(book.pageList);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return defered.promise;
|
return defered.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ EPUBJS.Book.prototype.networkListeners = function(){
|
||||||
book.online = true;
|
book.online = true;
|
||||||
book.trigger("book:online");
|
book.trigger("book:online");
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Listen to all events the renderer triggers and pass them as book events
|
// Listen to all events the renderer triggers and pass them as book events
|
||||||
|
@ -496,12 +496,12 @@ EPUBJS.Book.prototype.listenToRenderer = function(renderer){
|
||||||
"percentage": percent,
|
"percentage": percent,
|
||||||
"pageRange" : pageRange
|
"pageRange" : pageRange
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Add event for first and last page.
|
// TODO: Add event for first and last page.
|
||||||
// (though last is going to be hard, since it could be several reflowed pages long)
|
// (though last is going to be hard, since it could be several reflowed pages long)
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
renderer.on("render:loaded", this.loadChange.bind(this));
|
renderer.on("render:loaded", this.loadChange.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -538,18 +538,18 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){
|
||||||
absolute = uri.protocol,
|
absolute = uri.protocol,
|
||||||
fromRoot = uri.path[0] == "/",
|
fromRoot = uri.path[0] == "/",
|
||||||
location = window.location,
|
location = window.location,
|
||||||
//-- Get URL orgin, try for native or combine
|
//-- Get URL orgin, try for native or combine
|
||||||
origin = location.origin || location.protocol + "//" + location.host,
|
origin = location.origin || location.protocol + "//" + location.host,
|
||||||
baseTag = document.getElementsByTagName('base'),
|
baseTag = document.getElementsByTagName('base'),
|
||||||
base;
|
base;
|
||||||
|
|
||||||
|
|
||||||
//-- Check is Base tag is set
|
//-- Check is Base tag is set
|
||||||
|
|
||||||
if(baseTag.length) {
|
if(baseTag.length) {
|
||||||
base = baseTag[0].href;
|
base = baseTag[0].href;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- 1. Check if url is absolute
|
//-- 1. Check if url is absolute
|
||||||
if(uri.protocol){
|
if(uri.protocol){
|
||||||
return uri.origin + uri.path;
|
return uri.origin + uri.path;
|
||||||
|
@ -571,13 +571,13 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){
|
||||||
EPUBJS.Book.prototype.unarchive = function(bookPath){
|
EPUBJS.Book.prototype.unarchive = function(bookPath){
|
||||||
var book = this,
|
var book = this,
|
||||||
unarchived;
|
unarchived;
|
||||||
|
|
||||||
//-- Must use storage
|
//-- Must use storage
|
||||||
// if(this.settings.storage == false ){
|
// if(this.settings.storage == false ){
|
||||||
// this.settings.storage = true;
|
// this.settings.storage = true;
|
||||||
// this.storage = new fileStorage.storage();
|
// this.storage = new fileStorage.storage();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
this.zip = new EPUBJS.Unarchiver();
|
this.zip = new EPUBJS.Unarchiver();
|
||||||
this.store = this.zip; // Use zip storaged in ram
|
this.store = this.zip; // Use zip storaged in ram
|
||||||
return this.zip.openZip(bookPath);
|
return this.zip.openZip(bookPath);
|
||||||
|
@ -637,7 +637,7 @@ EPUBJS.Book.prototype.removeSavedContents = function() {
|
||||||
EPUBJS.Book.prototype.renderTo = function(elem){
|
EPUBJS.Book.prototype.renderTo = function(elem){
|
||||||
var book = this,
|
var book = this,
|
||||||
rendered;
|
rendered;
|
||||||
|
|
||||||
if(_.isElement(elem)) {
|
if(_.isElement(elem)) {
|
||||||
this.element = elem;
|
this.element = elem;
|
||||||
} else if (typeof elem == "string") {
|
} else if (typeof elem == "string") {
|
||||||
|
@ -646,7 +646,7 @@ EPUBJS.Book.prototype.renderTo = function(elem){
|
||||||
console.error("Not an Element");
|
console.error("Not an Element");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rendered = this.opened.
|
rendered = this.opened.
|
||||||
then(function(){
|
then(function(){
|
||||||
// book.render = new EPUBJS.Renderer[this.settings.renderer](book);
|
// book.render = new EPUBJS.Renderer[this.settings.renderer](book);
|
||||||
|
@ -721,9 +721,9 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
pos,
|
pos,
|
||||||
store,
|
store,
|
||||||
defer = deferred || new RSVP.defer();
|
defer = deferred || new RSVP.defer();
|
||||||
|
|
||||||
var chapter;
|
var chapter;
|
||||||
|
|
||||||
if(!this.isRendered) {
|
if(!this.isRendered) {
|
||||||
this._q.enqueue("displayChapter", arguments);
|
this._q.enqueue("displayChapter", arguments);
|
||||||
// Reject for now. TODO: pass promise to queue
|
// Reject for now. TODO: pass promise to queue
|
||||||
|
@ -733,7 +733,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
});
|
});
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(this._rendering) {
|
if(this._rendering) {
|
||||||
// Pass along the current defer
|
// Pass along the current defer
|
||||||
|
@ -747,7 +747,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
cfi = new EPUBJS.EpubCFI(chap);
|
cfi = new EPUBJS.EpubCFI(chap);
|
||||||
pos = cfi.spinePos;
|
pos = cfi.spinePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos < 0 || pos >= this.spine.length){
|
if(pos < 0 || pos >= this.spine.length){
|
||||||
console.warn("Not A Valid Location");
|
console.warn("Not A Valid Location");
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
@ -755,11 +755,11 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
cfi = false;
|
cfi = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- Create a new chapter
|
//-- Create a new chapter
|
||||||
chapter = new EPUBJS.Chapter(this.spine[pos], this.store);
|
chapter = new EPUBJS.Chapter(this.spine[pos], this.store);
|
||||||
|
|
||||||
this._rendering = true;
|
this._rendering = true;
|
||||||
|
|
||||||
render = book.renderer.displayChapter(chapter, this.globalLayoutProperties);
|
render = book.renderer.displayChapter(chapter, this.globalLayoutProperties);
|
||||||
|
|
||||||
//-- Success, Clear render queue
|
//-- Success, Clear render queue
|
||||||
|
@ -767,7 +767,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
// var inwait;
|
// var inwait;
|
||||||
//-- Set the book's spine position
|
//-- Set the book's spine position
|
||||||
book.spinePos = pos;
|
book.spinePos = pos;
|
||||||
|
|
||||||
if(cfi) {
|
if(cfi) {
|
||||||
rendered.gotoCfi(cfi);
|
rendered.gotoCfi(cfi);
|
||||||
defer.resolve(book.renderer);
|
defer.resolve(book.renderer);
|
||||||
|
@ -777,13 +777,13 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
} else {
|
} else {
|
||||||
defer.resolve(book.renderer);
|
defer.resolve(book.renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(!book.settings.fromStorage &&
|
if(!book.settings.fromStorage &&
|
||||||
!book.settings.contained) {
|
!book.settings.contained) {
|
||||||
book.preloadNextChapter();
|
book.preloadNextChapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
book.currentChapter = chapter;
|
book.currentChapter = chapter;
|
||||||
book._rendering = false;
|
book._rendering = false;
|
||||||
book._displayQ.dequeue();
|
book._displayQ.dequeue();
|
||||||
|
@ -795,7 +795,7 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){
|
||||||
book._rendering = false;
|
book._rendering = false;
|
||||||
defer.reject(error);
|
defer.reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return defer.promise;
|
return defer.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ EPUBJS.Book.prototype.nextPage = function(){
|
||||||
var next;
|
var next;
|
||||||
|
|
||||||
if(!this.isRendered) return this._q.enqueue("nextPage", arguments);
|
if(!this.isRendered) return this._q.enqueue("nextPage", arguments);
|
||||||
|
|
||||||
next = this.renderer.nextPage();
|
next = this.renderer.nextPage();
|
||||||
|
|
||||||
if(!next){
|
if(!next){
|
||||||
|
@ -817,7 +817,7 @@ EPUBJS.Book.prototype.prevPage = function() {
|
||||||
if(!this.isRendered) return this._q.enqueue("prevPage", arguments);
|
if(!this.isRendered) return this._q.enqueue("prevPage", arguments);
|
||||||
|
|
||||||
prev = this.renderer.prevPage();
|
prev = this.renderer.prevPage();
|
||||||
|
|
||||||
if(!prev){
|
if(!prev){
|
||||||
return this.prevChapter();
|
return this.prevChapter();
|
||||||
}
|
}
|
||||||
|
@ -875,7 +875,7 @@ EPUBJS.Book.prototype.goto = function(target){
|
||||||
} else {
|
} else {
|
||||||
return this.gotoHref(target);
|
return this.gotoHref(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
||||||
|
@ -884,7 +884,7 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
||||||
spineItem,
|
spineItem,
|
||||||
rendered,
|
rendered,
|
||||||
deferred = defer || new RSVP.defer();
|
deferred = defer || new RSVP.defer();
|
||||||
|
|
||||||
if(!this.isRendered) {
|
if(!this.isRendered) {
|
||||||
this.settings.previousLocationCfi = cfiString;
|
this.settings.previousLocationCfi = cfiString;
|
||||||
return false;
|
return false;
|
||||||
|
@ -895,10 +895,10 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
||||||
this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]);
|
this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfi = new EPUBJS.EpubCFI(cfiString);
|
cfi = new EPUBJS.EpubCFI(cfiString);
|
||||||
spinePos = cfi.spinePos;
|
spinePos = cfi.spinePos;
|
||||||
|
|
||||||
if(spinePos == -1) {
|
if(spinePos == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -912,18 +912,18 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){
|
||||||
this._moving = false;
|
this._moving = false;
|
||||||
deferred.resolve(this.renderer.currentLocationCfi);
|
deferred.resolve(this.renderer.currentLocationCfi);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(!spineItem || spinePos == -1) {
|
if(!spineItem || spinePos == -1) {
|
||||||
spinePos = 0;
|
spinePos = 0;
|
||||||
spineItem = this.spine[spinePos];
|
spineItem = this.spine[spinePos];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentChapter = new EPUBJS.Chapter(spineItem, this.store);
|
this.currentChapter = new EPUBJS.Chapter(spineItem, this.store);
|
||||||
|
|
||||||
if(this.currentChapter) {
|
if(this.currentChapter) {
|
||||||
this.spinePos = spinePos;
|
this.spinePos = spinePos;
|
||||||
render = this.renderer.displayChapter(this.currentChapter, this.globalLayoutProperties);
|
render = this.renderer.displayChapter(this.currentChapter, this.globalLayoutProperties);
|
||||||
|
|
||||||
render.then(function(rendered){
|
render.then(function(rendered){
|
||||||
rendered.gotoCfi(cfi);
|
rendered.gotoCfi(cfi);
|
||||||
this._moving = false;
|
this._moving = false;
|
||||||
|
@ -967,7 +967,7 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
|
||||||
|
|
||||||
//-- Check that URL is present in the index, or stop
|
//-- Check that URL is present in the index, or stop
|
||||||
if(typeof(spinePos) != "number") return false;
|
if(typeof(spinePos) != "number") return false;
|
||||||
|
|
||||||
if(!this.currentChapter || spinePos != this.currentChapter.spinePos){
|
if(!this.currentChapter || spinePos != this.currentChapter.spinePos){
|
||||||
//-- Load new chapter if different than current
|
//-- Load new chapter if different than current
|
||||||
return this.displayChapter(spinePos).then(function(){
|
return this.displayChapter(spinePos).then(function(){
|
||||||
|
@ -977,9 +977,12 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
|
||||||
deferred.resolve(this.renderer.currentLocationCfi);
|
deferred.resolve(this.renderer.currentLocationCfi);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}else{
|
}else{
|
||||||
//-- Only goto section
|
//-- Goto section
|
||||||
if(section) {
|
if(section) {
|
||||||
this.renderer.section(section);
|
this.renderer.section(section);
|
||||||
|
} else {
|
||||||
|
// Or jump to the start
|
||||||
|
this.renderer.firstPage();
|
||||||
}
|
}
|
||||||
deferred.resolve(this.renderer.currentLocationCfi);
|
deferred.resolve(this.renderer.currentLocationCfi);
|
||||||
}
|
}
|
||||||
|
@ -1004,11 +1007,11 @@ EPUBJS.Book.prototype.gotoPercentage = function(percent){
|
||||||
EPUBJS.Book.prototype.preloadNextChapter = function() {
|
EPUBJS.Book.prototype.preloadNextChapter = function() {
|
||||||
var next;
|
var next;
|
||||||
var chap = this.spinePos + 1;
|
var chap = this.spinePos + 1;
|
||||||
|
|
||||||
if(chap >= this.spine.length){
|
if(chap >= this.spine.length){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
next = new EPUBJS.Chapter(this.spine[chap]);
|
next = new EPUBJS.Chapter(this.spine[chap]);
|
||||||
if(next) {
|
if(next) {
|
||||||
EPUBJS.core.request(next.absolute);
|
EPUBJS.core.request(next.absolute);
|
||||||
|
@ -1019,7 +1022,7 @@ EPUBJS.Book.prototype.preloadNextChapter = function() {
|
||||||
EPUBJS.Book.prototype.storeOffline = function() {
|
EPUBJS.Book.prototype.storeOffline = function() {
|
||||||
var book = this,
|
var book = this,
|
||||||
assets = _.values(this.manifest);
|
assets = _.values(this.manifest);
|
||||||
|
|
||||||
//-- Creates a queue of all items to load
|
//-- Creates a queue of all items to load
|
||||||
return EPUBJS.storage.batch(assets).
|
return EPUBJS.storage.batch(assets).
|
||||||
then(function(){
|
then(function(){
|
||||||
|
@ -1034,9 +1037,9 @@ EPUBJS.Book.prototype.availableOffline = function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
EPUBJS.Book.prototype.fromStorage = function(stored) {
|
EPUBJS.Book.prototype.fromStorage = function(stored) {
|
||||||
|
|
||||||
if(this.contained) return;
|
if(this.contained) return;
|
||||||
|
|
||||||
if(!stored){
|
if(!stored){
|
||||||
this.online = true;
|
this.online = true;
|
||||||
this.tell("book:online");
|
this.tell("book:online");
|
||||||
|
@ -1047,19 +1050,19 @@ EPUBJS.Book.prototype.fromStorage = function(stored) {
|
||||||
this.online = false;
|
this.online = false;
|
||||||
this.tell("book:offline");
|
this.tell("book:offline");
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
this.online = false;
|
this.online = false;
|
||||||
this.tell("book:offline");
|
this.tell("book:offline");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) {
|
EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) {
|
||||||
if(!this.isRendered) return this._q.enqueue("setStyle", arguments);
|
if(!this.isRendered) return this._q.enqueue("setStyle", arguments);
|
||||||
|
|
||||||
this.settings.styles[style] = val;
|
this.settings.styles[style] = val;
|
||||||
|
|
||||||
this.renderer.setStyle(style, val, prefixed);
|
this.renderer.setStyle(style, val, prefixed);
|
||||||
|
@ -1112,7 +1115,7 @@ EPUBJS.Book.prototype.setGap = function(gap) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Book.prototype.unload = function(){
|
EPUBJS.Book.prototype.unload = function(){
|
||||||
|
|
||||||
if(this.settings.restore && localStorage) {
|
if(this.settings.restore && localStorage) {
|
||||||
this.saveContents();
|
this.saveContents();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _h
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
|
|
||||||
//-- Check the width and create even width columns
|
//-- Check the width and create even width columns
|
||||||
var width = Math.floor(_width);
|
var width = Math.floor(_width);
|
||||||
// var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 0; // Not needed for single
|
// var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 0; // Not needed for single
|
||||||
|
@ -19,23 +19,23 @@ EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _h
|
||||||
this.documentElement = documentElement;
|
this.documentElement = documentElement;
|
||||||
//-- Single Page
|
//-- Single Page
|
||||||
this.spreadWidth = (width + gap);
|
this.spreadWidth = (width + gap);
|
||||||
|
|
||||||
|
|
||||||
documentElement.style.overflow = "hidden";
|
documentElement.style.overflow = "hidden";
|
||||||
|
|
||||||
// Must be set to the new calculated width or the columns will be off
|
// Must be set to the new calculated width or the columns will be off
|
||||||
documentElement.style.width = width + "px";
|
documentElement.style.width = width + "px";
|
||||||
|
|
||||||
//-- Adjust height
|
//-- Adjust height
|
||||||
documentElement.style.height = _height + "px";
|
documentElement.style.height = _height + "px";
|
||||||
|
|
||||||
//-- Add columns
|
//-- Add columns
|
||||||
documentElement.style[columnAxis] = "horizontal";
|
documentElement.style[columnAxis] = "horizontal";
|
||||||
documentElement.style[columnWidth] = width+"px";
|
documentElement.style[columnWidth] = width+"px";
|
||||||
documentElement.style[columnGap] = gap+"px";
|
documentElement.style[columnGap] = gap+"px";
|
||||||
this.colWidth = width;
|
this.colWidth = width;
|
||||||
this.gap = gap;
|
this.gap = gap;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : this.spreadWidth,
|
pageWidth : this.spreadWidth,
|
||||||
pageHeight : _height
|
pageHeight : _height
|
||||||
|
@ -63,14 +63,14 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(documentElement, _wi
|
||||||
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
var columnAxis = EPUBJS.core.prefixed('columnAxis');
|
||||||
var columnGap = EPUBJS.core.prefixed('columnGap');
|
var columnGap = EPUBJS.core.prefixed('columnGap');
|
||||||
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
var columnWidth = EPUBJS.core.prefixed('columnWidth');
|
||||||
|
|
||||||
var divisor = 2,
|
var divisor = 2,
|
||||||
cutoff = 800;
|
cutoff = 800;
|
||||||
|
|
||||||
//-- Check the width and create even width columns
|
//-- Check the width and create even width columns
|
||||||
var fullWidth = Math.floor(_width);
|
var fullWidth = Math.floor(_width);
|
||||||
var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 1;
|
var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 1;
|
||||||
|
|
||||||
var section = Math.floor(width / 8);
|
var section = Math.floor(width / 8);
|
||||||
var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
|
var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ EPUBJS.Layout.ReflowableSpreads.prototype.format = function(documentElement, _wi
|
||||||
|
|
||||||
this.documentElement = documentElement;
|
this.documentElement = documentElement;
|
||||||
this.spreadWidth = (colWidth + gap) * divisor;
|
this.spreadWidth = (colWidth + gap) * divisor;
|
||||||
|
|
||||||
|
|
||||||
documentElement.style.overflow = "hidden";
|
documentElement.style.overflow = "hidden";
|
||||||
|
|
||||||
// Must be set to the new calculated width or the columns will be off
|
// Must be set to the new calculated width or the columns will be off
|
||||||
|
@ -123,7 +123,7 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
|
||||||
var content;
|
var content;
|
||||||
var contents;
|
var contents;
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
this.documentElement = documentElement;
|
this.documentElement = documentElement;
|
||||||
/**
|
/**
|
||||||
* check for the viewport size
|
* check for the viewport size
|
||||||
|
@ -139,7 +139,7 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
|
||||||
height = contents[1].replace("height=", '');
|
height = contents[1].replace("height=", '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- Adjust width and height
|
//-- Adjust width and height
|
||||||
documentElement.style.width = width + "px" || "auto";
|
documentElement.style.width = width + "px" || "auto";
|
||||||
documentElement.style.height = height + "px" || "auto";
|
documentElement.style.height = height + "px" || "auto";
|
||||||
|
@ -152,12 +152,12 @@ EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
|
||||||
|
|
||||||
this.colWidth = width;
|
this.colWidth = width;
|
||||||
this.gap = 0;
|
this.gap = 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pageWidth : width,
|
pageWidth : width,
|
||||||
pageHeight : height
|
pageHeight : height
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
|
EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
|
||||||
|
@ -165,4 +165,4 @@ EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
|
||||||
displayedPages : 1,
|
displayedPages : 1,
|
||||||
pageCount : 1
|
pageCount : 1
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
165
src/renderer.js
165
src/renderer.js
|
@ -20,26 +20,26 @@ EPUBJS.Renderer = function(renderMethod, hidden) {
|
||||||
|
|
||||||
// Listen for load events
|
// Listen for load events
|
||||||
this.render.on("render:loaded", this.loaded.bind(this));
|
this.render.on("render:loaded", this.loaded.bind(this));
|
||||||
|
|
||||||
// Cached for replacement urls from storage
|
// Cached for replacement urls from storage
|
||||||
this.caches = {};
|
this.caches = {};
|
||||||
|
|
||||||
// Blank Cfi for Parsing
|
// Blank Cfi for Parsing
|
||||||
this.epubcfi = new EPUBJS.EpubCFI();
|
this.epubcfi = new EPUBJS.EpubCFI();
|
||||||
|
|
||||||
this.spreads = true;
|
this.spreads = true;
|
||||||
this.isForcedSingle = false;
|
this.isForcedSingle = false;
|
||||||
this.resized = _.throttle(this.onResized.bind(this), 10);
|
this.resized = _.throttle(this.onResized.bind(this), 10);
|
||||||
|
|
||||||
this.layoutSettings = {};
|
this.layoutSettings = {};
|
||||||
|
|
||||||
this.hidden = hidden || false;
|
this.hidden = hidden || false;
|
||||||
//-- Adds Hook methods to the Book prototype
|
//-- Adds Hook methods to the Book prototype
|
||||||
// Hooks will all return before triggering the callback.
|
// Hooks will all return before triggering the callback.
|
||||||
EPUBJS.Hooks.mixin(this);
|
EPUBJS.Hooks.mixin(this);
|
||||||
//-- Get pre-registered hooks for events
|
//-- Get pre-registered hooks for events
|
||||||
this.getHooks("beforeChapterDisplay");
|
this.getHooks("beforeChapterDisplay");
|
||||||
|
|
||||||
//-- Queue up page changes if page map isn't ready
|
//-- Queue up page changes if page map isn't ready
|
||||||
this._q = EPUBJS.core.queue(this);
|
this._q = EPUBJS.core.queue(this);
|
||||||
|
|
||||||
|
@ -66,15 +66,15 @@ EPUBJS.Renderer.prototype.Events = [
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an element to render to.
|
* Creates an element to render to.
|
||||||
* Resizes to passed width and height or to the elements size
|
* Resizes to passed width and height or to the elements size
|
||||||
*/
|
*/
|
||||||
EPUBJS.Renderer.prototype.initialize = function(element, width, height){
|
EPUBJS.Renderer.prototype.initialize = function(element, width, height){
|
||||||
this.container = element;
|
this.container = element;
|
||||||
this.element = this.render.create();
|
this.element = this.render.create();
|
||||||
|
|
||||||
this.initWidth = width;
|
this.initWidth = width;
|
||||||
this.initHeight = height;
|
this.initHeight = height;
|
||||||
|
|
||||||
this.width = width || this.container.clientWidth;
|
this.width = width || this.container.clientWidth;
|
||||||
this.height = height || this.container.clientHeight;
|
this.height = height || this.container.clientHeight;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
||||||
// Get the url string from the chapter (may be from storage)
|
// Get the url string from the chapter (may be from storage)
|
||||||
return chapter.url().
|
return chapter.url().
|
||||||
then(function(url) {
|
then(function(url) {
|
||||||
|
|
||||||
// Unload the previous chapter listener
|
// Unload the previous chapter listener
|
||||||
if(this.currentChapter) {
|
if(this.currentChapter) {
|
||||||
this.currentChapter.unload(); // Remove stored blobs
|
this.currentChapter.unload(); // Remove stored blobs
|
||||||
|
@ -110,15 +110,15 @@ EPUBJS.Renderer.prototype.displayChapter = function(chapter, globalLayout){
|
||||||
this.doc = null;
|
this.doc = null;
|
||||||
this.pageMap = null;
|
this.pageMap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentChapter = chapter;
|
this.currentChapter = chapter;
|
||||||
this.chapterPos = 1;
|
this.chapterPos = 1;
|
||||||
this.pageMap = null;
|
this.pageMap = null;
|
||||||
this.currentChapterCfiBase = chapter.cfiBase;
|
this.currentChapterCfiBase = chapter.cfiBase;
|
||||||
|
|
||||||
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
|
||||||
return this.load(url);
|
return this.load(url);
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -155,7 +155,7 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
this.render.window.addEventListener("resize", this.resized, false);
|
this.render.window.addEventListener("resize", this.resized, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.addEventListeners();
|
this.addEventListeners();
|
||||||
this.addSelectionListeners();
|
this.addSelectionListeners();
|
||||||
|
|
||||||
|
@ -172,12 +172,12 @@ EPUBJS.Renderer.prototype.load = function(url){
|
||||||
|
|
||||||
msg.cfi = this.currentLocationCfi;
|
msg.cfi = this.currentLocationCfi;
|
||||||
this.trigger("renderer:chapterDisplayed", msg);
|
this.trigger("renderer:chapterDisplayed", msg);
|
||||||
|
|
||||||
this.visible(true);
|
this.visible(true);
|
||||||
|
|
||||||
deferred.resolve(this); //-- why does this return the renderer?
|
deferred.resolve(this); //-- why does this return the renderer?
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
@ -210,11 +210,11 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){
|
||||||
var rendition = prop.replace("rendition:", '');
|
var rendition = prop.replace("rendition:", '');
|
||||||
var split = rendition.indexOf("-");
|
var split = rendition.indexOf("-");
|
||||||
var property, value;
|
var property, value;
|
||||||
|
|
||||||
if(split != -1){
|
if(split != -1){
|
||||||
property = rendition.slice(0, split);
|
property = rendition.slice(0, split);
|
||||||
value = rendition.slice(split+1);
|
value = rendition.slice(split+1);
|
||||||
|
|
||||||
settings[property] = value;
|
settings[property] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -232,7 +232,7 @@ EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
||||||
var spreads = this.determineSpreads(this.minSpreadWidth);
|
var spreads = this.determineSpreads(this.minSpreadWidth);
|
||||||
var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
|
var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
|
||||||
var scroll = false;
|
var scroll = false;
|
||||||
|
|
||||||
if(settings.layout === "pre-paginated") {
|
if(settings.layout === "pre-paginated") {
|
||||||
layoutMethod = "Fixed";
|
layoutMethod = "Fixed";
|
||||||
scroll = true;
|
scroll = true;
|
||||||
|
@ -244,7 +244,7 @@ EPUBJS.Renderer.prototype.determineLayout = function(settings){
|
||||||
scroll = false;
|
scroll = false;
|
||||||
spreads = false;
|
spreads = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settings.layout === "reflowable" && settings.spread === "both") {
|
if(settings.layout === "reflowable" && settings.spread === "both") {
|
||||||
layoutMethod = "ReflowableSpreads";
|
layoutMethod = "ReflowableSpreads";
|
||||||
scroll = false;
|
scroll = false;
|
||||||
|
@ -267,7 +267,7 @@ EPUBJS.Renderer.prototype.updatePages = function(layout){
|
||||||
this.pageMap = this.mapPage();
|
this.pageMap = this.mapPage();
|
||||||
this.displayedPages = layout.displayedPages;
|
this.displayedPages = layout.displayedPages;
|
||||||
this.currentChapter.pages = layout.pageCount;
|
this.currentChapter.pages = layout.pageCount;
|
||||||
|
|
||||||
this._q.flush();
|
this._q.flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -276,10 +276,10 @@ EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
var renderer = this;
|
var renderer = this;
|
||||||
var formated, pages;
|
var formated, pages;
|
||||||
if(!this.contents) return;
|
if(!this.contents) return;
|
||||||
|
|
||||||
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
|
|
||||||
this.formated = this.layout.format(this.contents, this.render.width, this.render.height, this.gap);
|
this.formated = this.layout.format(this.contents, this.render.width, this.render.height, this.gap);
|
||||||
this.render.setPageDimensions(this.formated.pageWidth, this.formated.pageHeight);
|
this.render.setPageDimensions(this.formated.pageWidth, this.formated.pageHeight);
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ EPUBJS.Renderer.prototype.remove = function() {
|
||||||
this.removeEventListeners();
|
this.removeEventListeners();
|
||||||
this.removeSelectionListeners();
|
this.removeSelectionListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.container.removeChild(this.element);
|
this.container.removeChild(this.element);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -348,8 +348,8 @@ EPUBJS.Renderer.prototype.applyHeadTags = function(headTags) {
|
||||||
|
|
||||||
//-- NAVIGATION
|
//-- NAVIGATION
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.page = function(pg){
|
EPUBJS.Renderer.prototype.page = function(pg){
|
||||||
|
|
||||||
if(!this.pageMap) {
|
if(!this.pageMap) {
|
||||||
this._q.enqueue("page", arguments);
|
this._q.enqueue("page", arguments);
|
||||||
return true;
|
return true;
|
||||||
|
@ -376,9 +376,9 @@ EPUBJS.Renderer.prototype.nextPage = function(){
|
||||||
var pg = this.chapterPos + 1;
|
var pg = this.chapterPos + 1;
|
||||||
if(pg <= this.displayedPages){
|
if(pg <= this.displayedPages){
|
||||||
this.chapterPos = pg;
|
this.chapterPos = pg;
|
||||||
|
|
||||||
this.render.page(pg);
|
this.render.page(pg);
|
||||||
|
|
||||||
this.currentLocationCfi = this.getPageCfi(this.visibileEl);
|
this.currentLocationCfi = this.getPageCfi(this.visibileEl);
|
||||||
this.trigger("renderer:locationChanged", this.currentLocationCfi);
|
this.trigger("renderer:locationChanged", this.currentLocationCfi);
|
||||||
|
|
||||||
|
@ -410,6 +410,11 @@ EPUBJS.Renderer.prototype.lastPage = function(){
|
||||||
this.page(this.displayedPages);
|
this.page(this.displayedPages);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Jump to the first page of the chapter
|
||||||
|
EPUBJS.Renderer.prototype.firstPage = function(){
|
||||||
|
this.page(1);
|
||||||
|
};
|
||||||
|
|
||||||
//-- Find a section by fragement id
|
//-- Find a section by fragement id
|
||||||
EPUBJS.Renderer.prototype.section = function(fragment){
|
EPUBJS.Renderer.prototype.section = function(fragment){
|
||||||
var el = this.doc.getElementById(fragment),
|
var el = this.doc.getElementById(fragment),
|
||||||
|
@ -424,7 +429,7 @@ EPUBJS.Renderer.prototype.section = function(fragment){
|
||||||
EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) {
|
EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) {
|
||||||
var children = node.childNodes;
|
var children = node.childNodes;
|
||||||
var leng = children.length;
|
var leng = children.length;
|
||||||
|
|
||||||
if(leng &&
|
if(leng &&
|
||||||
children[0] && // First Child
|
children[0] && // First Child
|
||||||
children[0].nodeType === 3 && // This is a textNodes
|
children[0].nodeType === 3 && // This is a textNodes
|
||||||
|
@ -540,33 +545,31 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
var children = Array.prototype.slice.call(node.childNodes);
|
var children = Array.prototype.slice.call(node.childNodes);
|
||||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||||
elPos = node.getBoundingClientRect();
|
elPos = node.getBoundingClientRect();
|
||||||
|
|
||||||
|
if(!elPos || (elPos.width === 0 && elPos.height === 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(elPos.left + elPos.width > elLimit) {
|
if(elPos.left + elPos.width > elLimit) {
|
||||||
|
|
||||||
// console.log("checking text node of: ", node);
|
|
||||||
children.forEach(function(node){
|
children.forEach(function(node){
|
||||||
if(node.nodeType == Node.TEXT_NODE &&
|
if(node.nodeType == Node.TEXT_NODE &&
|
||||||
node.textContent.trim().length) {
|
node.textContent.trim().length) {
|
||||||
checkText(node);
|
checkText(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// renderer.textSprint(node, checkText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (node.nodeType != Node.TEXT_NODE) {
|
|
||||||
// renderer.handleTextNode(node, map, prevRange, limit, cfi);
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
var checkText = function(node){
|
var checkText = function(node){
|
||||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||||
ranges.forEach(function(range){
|
ranges.forEach(function(range){
|
||||||
var pos = range.getBoundingClientRect();
|
var pos = range.getBoundingClientRect();
|
||||||
// console.log(pos.left, pos.top, node);
|
|
||||||
|
if(!pos || (pos.width === 0 && pos.height === 0)) {
|
||||||
// if(!pos || (pos.width === 0 && pos.height === 0)) {
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
if(pos.left + pos.width < limit) {
|
if(pos.left + pos.width < limit) {
|
||||||
if(!map[page-1].start){
|
if(!map[page-1].start){
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
|
@ -579,7 +582,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||||
map[page-1].end = cfi;
|
map[page-1].end = cfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||||
map.push({
|
map.push({
|
||||||
|
@ -590,23 +593,23 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
limit = (width * page) - offset;
|
limit = (width * page) - offset;
|
||||||
elLimit = limit;
|
elLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
prevRange = range;
|
prevRange = range;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sprint(root, check);
|
this.sprint(root, check);
|
||||||
// this.textSprint(root, checkText);
|
// this.textSprint(root, checkText);
|
||||||
|
|
||||||
if(prevRange){
|
if(prevRange){
|
||||||
prevRange.collapse(true);
|
prevRange.collapse(true);
|
||||||
|
|
||||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||||
map[page-1].end = cfi;
|
map[page-1].end = cfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle empty map
|
// Handle empty map
|
||||||
if(map.length === 1 && !map[0].start) {
|
if(map.length === 1 && !map[0].start) {
|
||||||
range = this.doc.createRange();
|
range = this.doc.createRange();
|
||||||
|
@ -617,7 +620,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
map[0].start = cfi;
|
map[0].start = cfi;
|
||||||
map[0].end = cfi;
|
map[0].end = cfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
prevRange = null;
|
prevRange = null;
|
||||||
ranges = null;
|
ranges = null;
|
||||||
|
@ -634,53 +637,53 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||||
var rect;
|
var rect;
|
||||||
var list;
|
var list;
|
||||||
pos = text.indexOf(" ");
|
pos = text.indexOf(" ");
|
||||||
|
|
||||||
if(pos === -1) {
|
if(pos === -1) {
|
||||||
range = this.doc.createRange();
|
range = this.doc.createRange();
|
||||||
range.selectNodeContents(node);
|
range.selectNodeContents(node);
|
||||||
return [range];
|
return [range];
|
||||||
}
|
}
|
||||||
|
|
||||||
range = this.doc.createRange();
|
range = this.doc.createRange();
|
||||||
range.setStart(node, 0);
|
range.setStart(node, 0);
|
||||||
range.setEnd(node, pos);
|
range.setEnd(node, pos);
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
range = false;
|
range = false;
|
||||||
|
|
||||||
while ( pos != -1 ) {
|
while ( pos != -1 ) {
|
||||||
|
|
||||||
pos = text.indexOf(" ", pos + 1);
|
pos = text.indexOf(" ", pos + 1);
|
||||||
if(pos > 0) {
|
if(pos > 0) {
|
||||||
|
|
||||||
if(range) {
|
if(range) {
|
||||||
range.setEnd(node, pos);
|
range.setEnd(node, pos);
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
range = this.doc.createRange();
|
range = this.doc.createRange();
|
||||||
range.setStart(node, pos+1);
|
range.setStart(node, pos+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(range) {
|
if(range) {
|
||||||
range.setEnd(node, text.length);
|
range.setEnd(node, text.length);
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ranges;
|
return ranges;
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.rangePosition = function(range){
|
EPUBJS.Renderer.prototype.rangePosition = function(range){
|
||||||
var rect;
|
var rect;
|
||||||
var list;
|
var list;
|
||||||
|
|
||||||
list = range.getClientRects();
|
list = range.getClientRects();
|
||||||
|
|
||||||
if(list.length) {
|
if(list.length) {
|
||||||
rect = list[0];
|
rect = list[0];
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -694,14 +697,14 @@ EPUBJS.Renderer.prototype.getPageCfi = function(prevEl){
|
||||||
var y = 1;//;this.formated.pageHeight/2;
|
var y = 1;//;this.formated.pageHeight/2;
|
||||||
|
|
||||||
range = this.getRange(x, y);
|
range = this.getRange(x, y);
|
||||||
|
|
||||||
// var test = this.doc.defaultView.getSelection();
|
// var test = this.doc.defaultView.getSelection();
|
||||||
// var r = this.doc.createRange();
|
// var r = this.doc.createRange();
|
||||||
// test.removeAllRanges();
|
// test.removeAllRanges();
|
||||||
// r.setStart(range.startContainer, range.startOffset);
|
// r.setStart(range.startContainer, range.startOffset);
|
||||||
// r.setEnd(range.startContainer, range.startOffset + 1);
|
// r.setEnd(range.startContainer, range.startOffset + 1);
|
||||||
// test.addRange(r);
|
// test.addRange(r);
|
||||||
|
|
||||||
return this.currentChapter.cfiFromRange(range);
|
return this.currentChapter.cfiFromRange(range);
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
@ -732,7 +735,7 @@ EPUBJS.Renderer.prototype.getRange = function(x, y, forceElement){
|
||||||
this.visibileEl = this.findElementAfter(x, y);
|
this.visibileEl = this.findElementAfter(x, y);
|
||||||
range.setStart(this.visibileEl, 1);
|
range.setStart(this.visibileEl, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// var test = this.doc.defaultView.getSelection();
|
// var test = this.doc.defaultView.getSelection();
|
||||||
// var r = this.doc.createRange();
|
// var r = this.doc.createRange();
|
||||||
// test.removeAllRanges();
|
// test.removeAllRanges();
|
||||||
|
@ -755,7 +758,7 @@ EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(prevEl){
|
||||||
if(endRange) {
|
if(endRange) {
|
||||||
endCfi = this.currentChapter.cfiFromRange(endRange);
|
endCfi = this.currentChapter.cfiFromRange(endRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: startCfi,
|
start: startCfi,
|
||||||
end: endCfi || false
|
end: endCfi || false
|
||||||
|
@ -809,9 +812,9 @@ EPUBJS.Renderer.prototype.getRenderedPagesLeft = function(){
|
||||||
console.warn("page map not loaded");
|
console.warn("page map not loaded");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPage = this.pageMap.length;
|
lastPage = this.pageMap.length;
|
||||||
|
|
||||||
if (this.spreads) {
|
if (this.spreads) {
|
||||||
pg = this.chapterPos*2;
|
pg = this.chapterPos*2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -820,7 +823,7 @@ EPUBJS.Renderer.prototype.getRenderedPagesLeft = function(){
|
||||||
|
|
||||||
pagesLeft = lastPage - pg;
|
pagesLeft = lastPage - pg;
|
||||||
return pagesLeft;
|
return pagesLeft;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
||||||
|
@ -831,12 +834,12 @@ EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
||||||
console.warn("page map not loaded");
|
console.warn("page map not loaded");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.spreads) {
|
if (this.spreads) {
|
||||||
pg = this.chapterPos*2;
|
pg = this.chapterPos*2;
|
||||||
startRange = this.pageMap[pg-2];
|
startRange = this.pageMap[pg-2];
|
||||||
endRange = startRange;
|
endRange = startRange;
|
||||||
|
|
||||||
if(this.layout.pageCount > 1) {
|
if(this.layout.pageCount > 1) {
|
||||||
endRange = this.pageMap[pg-1];
|
endRange = this.pageMap[pg-1];
|
||||||
}
|
}
|
||||||
|
@ -845,13 +848,13 @@ EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
||||||
startRange = this.pageMap[pg-1];
|
startRange = this.pageMap[pg-1];
|
||||||
endRange = startRange;
|
endRange = startRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!startRange) {
|
if(!startRange) {
|
||||||
console.warn("page range miss:", pg);
|
console.warn("page range miss:", pg);
|
||||||
startRange = this.pageMap[this.pageMap.length-1];
|
startRange = this.pageMap[this.pageMap.length-1];
|
||||||
endRange = startRange;
|
endRange = startRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: startRange.start,
|
start: startRange.start,
|
||||||
end: endRange.end
|
end: endRange.end
|
||||||
|
@ -867,7 +870,7 @@ EPUBJS.Renderer.prototype.gotoCfi = function(cfi){
|
||||||
if(_.isString(cfi)){
|
if(_.isString(cfi)){
|
||||||
cfi = this.epubcfi.parse(cfi);
|
cfi = this.epubcfi.parse(cfi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof document.evaluate === 'undefined') {
|
if(typeof document.evaluate === 'undefined') {
|
||||||
marker = this.epubcfi.addMarker(cfi, this.doc);
|
marker = this.epubcfi.addMarker(cfi, this.doc);
|
||||||
if(marker) {
|
if(marker) {
|
||||||
|
@ -880,7 +883,7 @@ EPUBJS.Renderer.prototype.gotoCfi = function(cfi){
|
||||||
range = this.epubcfi.generateRangeFromCfi(cfi, this.doc);
|
range = this.epubcfi.generateRangeFromCfi(cfi, this.doc);
|
||||||
if(range) {
|
if(range) {
|
||||||
pg = this.render.getPageNumberByRect(range.getBoundingClientRect());
|
pg = this.render.getPageNumberByRect(range.getBoundingClientRect());
|
||||||
this.page(pg);
|
this.page(pg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -930,14 +933,14 @@ EPUBJS.Renderer.prototype.hideHashChanges = function(){
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.resize = function(width, height, setSize){
|
EPUBJS.Renderer.prototype.resize = function(width, height, setSize){
|
||||||
var spreads;
|
var spreads;
|
||||||
|
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
if(setSize !== false) {
|
if(setSize !== false) {
|
||||||
this.render.resize(this.width, this.height);
|
this.render.resize(this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
spreads = this.determineSpreads(this.minSpreadWidth);
|
spreads = this.determineSpreads(this.minSpreadWidth);
|
||||||
// Only re-layout if the spreads have switched
|
// Only re-layout if the spreads have switched
|
||||||
if(spreads != this.spreads){
|
if(spreads != this.spreads){
|
||||||
|
@ -945,11 +948,11 @@ EPUBJS.Renderer.prototype.resize = function(width, height, setSize){
|
||||||
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
this.layoutMethod = this.determineLayout(this.layoutSettings);
|
||||||
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
this.layout = new EPUBJS.Layout[this.layoutMethod]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.contents){
|
if(this.contents){
|
||||||
this.reformat();
|
this.reformat();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.trigger("renderer:resized", {
|
this.trigger("renderer:resized", {
|
||||||
width: this.width,
|
width: this.width,
|
||||||
height: this.height
|
height: this.height
|
||||||
|
@ -1040,7 +1043,7 @@ EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
||||||
var items = this.contents.querySelectorAll(query),
|
var items = this.contents.querySelectorAll(query),
|
||||||
resources = Array.prototype.slice.call(items),
|
resources = Array.prototype.slice.call(items),
|
||||||
count = resources.length;
|
count = resources.length;
|
||||||
|
|
||||||
|
|
||||||
if(count === 0) {
|
if(count === 0) {
|
||||||
finished(false);
|
finished(false);
|
||||||
|
@ -1056,7 +1059,7 @@ EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
|
||||||
called = true;
|
called = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
func(item, after);
|
func(item, after);
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -1138,4 +1141,4 @@ EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callba
|
||||||
};
|
};
|
||||||
|
|
||||||
//-- Enable binding events to Renderer
|
//-- Enable binding events to Renderer
|
||||||
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
|
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue