mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Merge pull request #356 from SteveKChiu/cancel-pagination
Cancel pagination early
This commit is contained in:
commit
f512efca52
2 changed files with 17 additions and 6 deletions
21
src/book.js
21
src/book.js
|
@ -347,12 +347,12 @@ EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) {
|
|||
hiddenEl.style.height = height +"px"; //"0";
|
||||
hiddenContainer.appendChild(hiddenEl);
|
||||
|
||||
renderer.initialize(hiddenEl);
|
||||
renderer.initialize(hiddenEl, this.settings.width, this.settings.height);
|
||||
return hiddenContainer;
|
||||
};
|
||||
|
||||
// Generates the pageList array by loading every chapter and paging through them
|
||||
EPUBJS.Book.prototype.generatePageList = function(width, height){
|
||||
EPUBJS.Book.prototype.generatePageList = function(width, height, flag){
|
||||
var pageList = [];
|
||||
var pager = new EPUBJS.Renderer(this.settings.render_method, false); //hidden
|
||||
var hiddenContainer = this.createHiddenRender(pager, width, height);
|
||||
|
@ -369,6 +369,13 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
if(next >= spineLength) {
|
||||
done.resolve();
|
||||
} else {
|
||||
if (flag && flag.cancelled) {
|
||||
pager.remove();
|
||||
this.element.removeChild(hiddenContainer);
|
||||
done.reject(new Error("User cancelled"));
|
||||
return;
|
||||
}
|
||||
|
||||
spinePos = next;
|
||||
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
|
||||
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
|
||||
|
@ -403,23 +410,27 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
pager.remove();
|
||||
this.element.removeChild(hiddenContainer);
|
||||
deferred.resolve(pageList);
|
||||
}.bind(this));
|
||||
}.bind(this), function(reason) {
|
||||
deferred.reject(reason);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
// Render out entire book and generate the pagination
|
||||
// Width and Height are optional and will default to the current dimensions
|
||||
EPUBJS.Book.prototype.generatePagination = function(width, height) {
|
||||
EPUBJS.Book.prototype.generatePagination = function(width, height, flag) {
|
||||
var book = this;
|
||||
var defered = new RSVP.defer();
|
||||
|
||||
this.ready.spine.promise.then(function(){
|
||||
book.generatePageList(width, height).then(function(pageList){
|
||||
book.generatePageList(width, height, flag).then(function(pageList){
|
||||
book.pageList = book.contents.pageList = pageList;
|
||||
book.pagination.process(pageList);
|
||||
book.ready.pageList.resolve(book.pageList);
|
||||
defered.resolve(book.pageList);
|
||||
}, function(reason) {
|
||||
defered.reject(reason);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){
|
|||
// check if the cfi is in the location list
|
||||
// var index = this.locations.indexOf(cfi);
|
||||
var index = EPUBJS.core.indexOfSorted(cfi, this.locations, this.epubcfi.compare);
|
||||
if(index != -1 && index < (this.pages.length-1) ) {
|
||||
if(index != -1) {
|
||||
pg = this.pages[index];
|
||||
} else {
|
||||
// Otherwise add it to the list of locations
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue