mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Check if view is rendering before displaying, proper check promises
This commit is contained in:
parent
6785addc75
commit
812be32e71
8 changed files with 106 additions and 72 deletions
85
dist/epub.js
vendored
85
dist/epub.js
vendored
|
@ -2818,7 +2818,7 @@ EPUBJS.Queue.prototype.dequeue = function(){
|
||||||
inwait = this._q.shift();
|
inwait = this._q.shift();
|
||||||
task = inwait.task;
|
task = inwait.task;
|
||||||
if(task){
|
if(task){
|
||||||
|
// console.log(task)
|
||||||
|
|
||||||
result = task.apply(this.context, inwait.args);
|
result = task.apply(this.context, inwait.args);
|
||||||
|
|
||||||
|
@ -4403,8 +4403,6 @@ EPUBJS.View = function(section, options) {
|
||||||
this.settings = options || {};
|
this.settings = options || {};
|
||||||
|
|
||||||
this.id = "epubjs-view:" + EPUBJS.core.uuid();
|
this.id = "epubjs-view:" + EPUBJS.core.uuid();
|
||||||
this.displaying = new RSVP.defer();
|
|
||||||
this.displayed = this.displaying.promise;
|
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.index = section.index;
|
this.index = section.index;
|
||||||
|
|
||||||
|
@ -4501,6 +4499,14 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
this.resize(null, this.lockedHeight);
|
this.resize(null, this.lockedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(EPUBJS.core.isNumber(width) &&
|
||||||
|
EPUBJS.core.isNumber(height)){
|
||||||
|
|
||||||
|
this.lockedWidth = width - elBorders.width - iframeBorders.width;
|
||||||
|
this.lockedHeight = height - elBorders.height - iframeBorders.height;
|
||||||
|
|
||||||
|
this.resize(this.lockedWidth, this.lockedHeight);
|
||||||
|
}
|
||||||
|
|
||||||
if(this.shown && this.iframe) {
|
if(this.shown && this.iframe) {
|
||||||
|
|
||||||
|
@ -4570,6 +4576,15 @@ EPUBJS.View.prototype.resized = function(e) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.View.prototype.display = function(_request) {
|
EPUBJS.View.prototype.display = function(_request) {
|
||||||
|
|
||||||
|
if(this.rendering){
|
||||||
|
return this.displayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rendering = true;
|
||||||
|
this.displaying = new RSVP.defer();
|
||||||
|
this.displayed = this.displaying.promise;
|
||||||
|
|
||||||
return this.section.render(_request)
|
return this.section.render(_request)
|
||||||
.then(function(contents){
|
.then(function(contents){
|
||||||
return this.load(contents);
|
return this.load(contents);
|
||||||
|
@ -4592,7 +4607,7 @@ EPUBJS.View.prototype.load = function(contents) {
|
||||||
|
|
||||||
this.window = this.iframe.contentWindow;
|
this.window = this.iframe.contentWindow;
|
||||||
this.document = this.iframe.contentDocument;
|
this.document = this.iframe.contentDocument;
|
||||||
|
this.rendering = false;
|
||||||
loading.resolve(this);
|
loading.resolve(this);
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
@ -5192,7 +5207,6 @@ EPUBJS.Rendition.prototype.render = function(view) {
|
||||||
.then(function(view){
|
.then(function(view){
|
||||||
|
|
||||||
// this.map = new EPUBJS.Map(view, this.layout);
|
// this.map = new EPUBJS.Map(view, this.layout);
|
||||||
|
|
||||||
this.trigger("rendered", view.section);
|
this.trigger("rendered", view.section);
|
||||||
|
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
@ -5587,7 +5601,8 @@ EPUBJS.Continuous.prototype.append = function(view){
|
||||||
// view.on("shown", this.afterDisplayed.bind(this));
|
// view.on("shown", this.afterDisplayed.bind(this));
|
||||||
view.onShown = this.afterDisplayed.bind(this);
|
view.onShown = this.afterDisplayed.bind(this);
|
||||||
|
|
||||||
return this.check();
|
//this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.prepend = function(view){
|
EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
|
@ -5597,9 +5612,10 @@ EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
// view.on("shown", this.afterDisplayedAbove.bind(this));
|
// view.on("shown", this.afterDisplayedAbove.bind(this));
|
||||||
view.onShown = this.afterDisplayed.bind(this);
|
view.onShown = this.afterDisplayed.bind(this);
|
||||||
|
|
||||||
//might need to enqueue
|
|
||||||
view.on("resized", this.counter.bind(this));
|
view.on("resized", this.counter.bind(this));
|
||||||
return this.check();
|
|
||||||
|
// this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.counter = function(bounds){
|
EPUBJS.Continuous.prototype.counter = function(bounds){
|
||||||
|
@ -5637,7 +5653,8 @@ EPUBJS.Continuous.prototype.insert = function(view, index) {
|
||||||
this.container.appendChild(view.element);
|
this.container.appendChild(view.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.check();
|
// this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove the render element and clean up listeners
|
// Remove the render element and clean up listeners
|
||||||
|
@ -5683,6 +5700,7 @@ EPUBJS.Continuous.prototype.each = function(func) {
|
||||||
EPUBJS.Continuous.prototype.check = function(){
|
EPUBJS.Continuous.prototype.check = function(){
|
||||||
var checking = new RSVP.defer();
|
var checking = new RSVP.defer();
|
||||||
var container;//this.container.getBoundingClientRect();
|
var container;//this.container.getBoundingClientRect();
|
||||||
|
var promises = [];
|
||||||
|
|
||||||
if(!this.settings.height) {
|
if(!this.settings.height) {
|
||||||
container = EPUBJS.core.windowBounds();
|
container = EPUBJS.core.windowBounds();
|
||||||
|
@ -5695,38 +5713,39 @@ EPUBJS.Continuous.prototype.check = function(){
|
||||||
|
|
||||||
if(visible) {
|
if(visible) {
|
||||||
|
|
||||||
if(!view.shown && !this.rendering) {
|
if(!view.shown && !view.rendering) {
|
||||||
|
promises.push(this.render(view));
|
||||||
this.q.enqueue(function(){
|
|
||||||
|
|
||||||
return this.render(view)
|
|
||||||
.then(function(){
|
|
||||||
|
|
||||||
// Check to see if anything new is on screen after rendering
|
|
||||||
this.q.enqueue(this.check);
|
|
||||||
|
|
||||||
}.bind(this));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(view.shown) {
|
if(view.shown) {
|
||||||
view.destroy();
|
view.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
clearTimeout(this.trimTimeout);
|
|
||||||
this.trimTimeout = setTimeout(function(){
|
|
||||||
this.q.enqueue(this.trim);
|
|
||||||
}.bind(this), 250);
|
|
||||||
|
|
||||||
checking.resolve();
|
clearTimeout(this.trimTimeout);
|
||||||
return checking.promise;
|
this.trimTimeout = setTimeout(function(){
|
||||||
|
this.q.enqueue(this.trim);
|
||||||
|
}.bind(this), 250);
|
||||||
|
|
||||||
|
if(promises.length){
|
||||||
|
|
||||||
|
return RSVP.all(promises)
|
||||||
|
.then(function(posts) {
|
||||||
|
|
||||||
|
// Check to see if anything new is on screen after rendering
|
||||||
|
this.q.enqueue(this.check);
|
||||||
|
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
checking.resolve();
|
||||||
|
return checking.promise;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5927,7 +5946,6 @@ EPUBJS.Continuous.prototype.scrollBy = function(x, y, silent){
|
||||||
} else {
|
} else {
|
||||||
window.scrollBy(x,y);
|
window.scrollBy(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrolled = true;
|
this.scrolled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5944,7 +5962,6 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrolled = true;
|
this.scrolled = true;
|
||||||
|
|
||||||
// if(this.container.scrollLeft != x){
|
// if(this.container.scrollLeft != x){
|
||||||
// setTimeout(function() {
|
// setTimeout(function() {
|
||||||
// this.scrollTo(x, y, silent);
|
// this.scrollTo(x, y, silent);
|
||||||
|
@ -6172,7 +6189,7 @@ EPUBJS.Paginate.prototype.next = function(){
|
||||||
return this.q.enqueue(function(){
|
return this.q.enqueue(function(){
|
||||||
this.scrollBy(this.layout.delta, 0);
|
this.scrollBy(this.layout.delta, 0);
|
||||||
this.reportLocation();
|
this.reportLocation();
|
||||||
this.check();
|
return this.check();
|
||||||
});
|
});
|
||||||
|
|
||||||
// return this.page(this.currentPage + 1);
|
// return this.page(this.currentPage + 1);
|
||||||
|
@ -6183,7 +6200,7 @@ EPUBJS.Paginate.prototype.prev = function(){
|
||||||
return this.q.enqueue(function(){
|
return this.q.enqueue(function(){
|
||||||
this.scrollBy(-this.layout.delta, 0);
|
this.scrollBy(-this.layout.delta, 0);
|
||||||
this.reportLocation();
|
this.reportLocation();
|
||||||
this.check();
|
return this.check();
|
||||||
});
|
});
|
||||||
// return this.page(this.currentPage - 1);
|
// return this.page(this.currentPage - 1);
|
||||||
};
|
};
|
||||||
|
|
6
dist/epub.min.js
vendored
6
dist/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -126,7 +126,7 @@
|
||||||
height: 600
|
height: 600
|
||||||
});
|
});
|
||||||
|
|
||||||
var displayed = rendition.display();
|
var displayed = rendition.display(6);
|
||||||
|
|
||||||
|
|
||||||
displayed.then(function(renderer){
|
displayed.then(function(renderer){
|
||||||
|
|
|
@ -130,7 +130,8 @@ EPUBJS.Continuous.prototype.append = function(view){
|
||||||
// view.on("shown", this.afterDisplayed.bind(this));
|
// view.on("shown", this.afterDisplayed.bind(this));
|
||||||
view.onShown = this.afterDisplayed.bind(this);
|
view.onShown = this.afterDisplayed.bind(this);
|
||||||
|
|
||||||
return this.check();
|
//this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.prepend = function(view){
|
EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
|
@ -140,9 +141,10 @@ EPUBJS.Continuous.prototype.prepend = function(view){
|
||||||
// view.on("shown", this.afterDisplayedAbove.bind(this));
|
// view.on("shown", this.afterDisplayedAbove.bind(this));
|
||||||
view.onShown = this.afterDisplayed.bind(this);
|
view.onShown = this.afterDisplayed.bind(this);
|
||||||
|
|
||||||
//might need to enqueue
|
|
||||||
view.on("resized", this.counter.bind(this));
|
view.on("resized", this.counter.bind(this));
|
||||||
return this.check();
|
|
||||||
|
// this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.Continuous.prototype.counter = function(bounds){
|
EPUBJS.Continuous.prototype.counter = function(bounds){
|
||||||
|
@ -180,7 +182,8 @@ EPUBJS.Continuous.prototype.insert = function(view, index) {
|
||||||
this.container.appendChild(view.element);
|
this.container.appendChild(view.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.check();
|
// this.q.enqueue(this.check);
|
||||||
|
return this.check();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove the render element and clean up listeners
|
// Remove the render element and clean up listeners
|
||||||
|
@ -226,6 +229,7 @@ EPUBJS.Continuous.prototype.each = function(func) {
|
||||||
EPUBJS.Continuous.prototype.check = function(){
|
EPUBJS.Continuous.prototype.check = function(){
|
||||||
var checking = new RSVP.defer();
|
var checking = new RSVP.defer();
|
||||||
var container;//this.container.getBoundingClientRect();
|
var container;//this.container.getBoundingClientRect();
|
||||||
|
var promises = [];
|
||||||
|
|
||||||
if(!this.settings.height) {
|
if(!this.settings.height) {
|
||||||
container = EPUBJS.core.windowBounds();
|
container = EPUBJS.core.windowBounds();
|
||||||
|
@ -238,38 +242,39 @@ EPUBJS.Continuous.prototype.check = function(){
|
||||||
|
|
||||||
if(visible) {
|
if(visible) {
|
||||||
|
|
||||||
if(!view.shown && !this.rendering) {
|
if(!view.shown && !view.rendering) {
|
||||||
|
promises.push(this.render(view));
|
||||||
this.q.enqueue(function(){
|
|
||||||
|
|
||||||
return this.render(view)
|
|
||||||
.then(function(){
|
|
||||||
|
|
||||||
// Check to see if anything new is on screen after rendering
|
|
||||||
this.q.enqueue(this.check);
|
|
||||||
|
|
||||||
}.bind(this));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(view.shown) {
|
if(view.shown) {
|
||||||
view.destroy();
|
view.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
clearTimeout(this.trimTimeout);
|
|
||||||
this.trimTimeout = setTimeout(function(){
|
|
||||||
this.q.enqueue(this.trim);
|
|
||||||
}.bind(this), 250);
|
|
||||||
|
|
||||||
checking.resolve();
|
clearTimeout(this.trimTimeout);
|
||||||
return checking.promise;
|
this.trimTimeout = setTimeout(function(){
|
||||||
|
this.q.enqueue(this.trim);
|
||||||
|
}.bind(this), 250);
|
||||||
|
|
||||||
|
if(promises.length){
|
||||||
|
|
||||||
|
return RSVP.all(promises)
|
||||||
|
.then(function(posts) {
|
||||||
|
|
||||||
|
// Check to see if anything new is on screen after rendering
|
||||||
|
this.q.enqueue(this.check);
|
||||||
|
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
checking.resolve();
|
||||||
|
return checking.promise;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -470,7 +475,6 @@ EPUBJS.Continuous.prototype.scrollBy = function(x, y, silent){
|
||||||
} else {
|
} else {
|
||||||
window.scrollBy(x,y);
|
window.scrollBy(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrolled = true;
|
this.scrolled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -487,7 +491,6 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrolled = true;
|
this.scrolled = true;
|
||||||
|
|
||||||
// if(this.container.scrollLeft != x){
|
// if(this.container.scrollLeft != x){
|
||||||
// setTimeout(function() {
|
// setTimeout(function() {
|
||||||
// this.scrollTo(x, y, silent);
|
// this.scrollTo(x, y, silent);
|
||||||
|
|
|
@ -154,7 +154,7 @@ EPUBJS.Paginate.prototype.next = function(){
|
||||||
return this.q.enqueue(function(){
|
return this.q.enqueue(function(){
|
||||||
this.scrollBy(this.layout.delta, 0);
|
this.scrollBy(this.layout.delta, 0);
|
||||||
this.reportLocation();
|
this.reportLocation();
|
||||||
this.check();
|
return this.check();
|
||||||
});
|
});
|
||||||
|
|
||||||
// return this.page(this.currentPage + 1);
|
// return this.page(this.currentPage + 1);
|
||||||
|
@ -165,7 +165,7 @@ EPUBJS.Paginate.prototype.prev = function(){
|
||||||
return this.q.enqueue(function(){
|
return this.q.enqueue(function(){
|
||||||
this.scrollBy(-this.layout.delta, 0);
|
this.scrollBy(-this.layout.delta, 0);
|
||||||
this.reportLocation();
|
this.reportLocation();
|
||||||
this.check();
|
return this.check();
|
||||||
});
|
});
|
||||||
// return this.page(this.currentPage - 1);
|
// return this.page(this.currentPage - 1);
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,7 +52,7 @@ EPUBJS.Queue.prototype.dequeue = function(){
|
||||||
inwait = this._q.shift();
|
inwait = this._q.shift();
|
||||||
task = inwait.task;
|
task = inwait.task;
|
||||||
if(task){
|
if(task){
|
||||||
|
// console.log(task)
|
||||||
|
|
||||||
result = task.apply(this.context, inwait.args);
|
result = task.apply(this.context, inwait.args);
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,6 @@ EPUBJS.Rendition.prototype.render = function(view) {
|
||||||
.then(function(view){
|
.then(function(view){
|
||||||
|
|
||||||
// this.map = new EPUBJS.Map(view, this.layout);
|
// this.map = new EPUBJS.Map(view, this.layout);
|
||||||
|
|
||||||
this.trigger("rendered", view.section);
|
this.trigger("rendered", view.section);
|
||||||
|
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
|
|
@ -2,8 +2,6 @@ EPUBJS.View = function(section, options) {
|
||||||
this.settings = options || {};
|
this.settings = options || {};
|
||||||
|
|
||||||
this.id = "epubjs-view:" + EPUBJS.core.uuid();
|
this.id = "epubjs-view:" + EPUBJS.core.uuid();
|
||||||
this.displaying = new RSVP.defer();
|
|
||||||
this.displayed = this.displaying.promise;
|
|
||||||
this.section = section;
|
this.section = section;
|
||||||
this.index = section.index;
|
this.index = section.index;
|
||||||
|
|
||||||
|
@ -100,6 +98,14 @@ EPUBJS.View.prototype.lock = function(width, height) {
|
||||||
this.resize(null, this.lockedHeight);
|
this.resize(null, this.lockedHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(EPUBJS.core.isNumber(width) &&
|
||||||
|
EPUBJS.core.isNumber(height)){
|
||||||
|
|
||||||
|
this.lockedWidth = width - elBorders.width - iframeBorders.width;
|
||||||
|
this.lockedHeight = height - elBorders.height - iframeBorders.height;
|
||||||
|
|
||||||
|
this.resize(this.lockedWidth, this.lockedHeight);
|
||||||
|
}
|
||||||
|
|
||||||
if(this.shown && this.iframe) {
|
if(this.shown && this.iframe) {
|
||||||
|
|
||||||
|
@ -169,6 +175,15 @@ EPUBJS.View.prototype.resized = function(e) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.View.prototype.display = function(_request) {
|
EPUBJS.View.prototype.display = function(_request) {
|
||||||
|
|
||||||
|
if(this.rendering){
|
||||||
|
return this.displayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rendering = true;
|
||||||
|
this.displaying = new RSVP.defer();
|
||||||
|
this.displayed = this.displaying.promise;
|
||||||
|
|
||||||
return this.section.render(_request)
|
return this.section.render(_request)
|
||||||
.then(function(contents){
|
.then(function(contents){
|
||||||
return this.load(contents);
|
return this.load(contents);
|
||||||
|
@ -191,7 +206,7 @@ EPUBJS.View.prototype.load = function(contents) {
|
||||||
|
|
||||||
this.window = this.iframe.contentWindow;
|
this.window = this.iframe.contentWindow;
|
||||||
this.document = this.iframe.contentDocument;
|
this.document = this.iframe.contentDocument;
|
||||||
|
this.rendering = false;
|
||||||
loading.resolve(this);
|
loading.resolve(this);
|
||||||
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue