1
0
Fork 0
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:
Fred Chasen 2015-05-29 15:45:03 -04:00
parent 6785addc75
commit 812be32e71
8 changed files with 106 additions and 72 deletions

View file

@ -130,7 +130,8 @@ EPUBJS.Continuous.prototype.append = function(view){
// view.on("shown", 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){
@ -140,9 +141,10 @@ EPUBJS.Continuous.prototype.prepend = function(view){
// view.on("shown", this.afterDisplayedAbove.bind(this));
view.onShown = this.afterDisplayed.bind(this);
//might need to enqueue
view.on("resized", this.counter.bind(this));
return this.check();
// this.q.enqueue(this.check);
return this.check();
};
EPUBJS.Continuous.prototype.counter = function(bounds){
@ -180,7 +182,8 @@ EPUBJS.Continuous.prototype.insert = function(view, index) {
this.container.appendChild(view.element);
}
return this.check();
// this.q.enqueue(this.check);
return this.check();
};
// Remove the render element and clean up listeners
@ -226,6 +229,7 @@ EPUBJS.Continuous.prototype.each = function(func) {
EPUBJS.Continuous.prototype.check = function(){
var checking = new RSVP.defer();
var container;//this.container.getBoundingClientRect();
var promises = [];
if(!this.settings.height) {
container = EPUBJS.core.windowBounds();
@ -238,38 +242,39 @@ EPUBJS.Continuous.prototype.check = function(){
if(visible) {
if(!view.shown && !this.rendering) {
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));
});
if(!view.shown && !view.rendering) {
promises.push(this.render(view));
}
} else {
if(view.shown) {
view.destroy();
view.destroy();
}
}
}.bind(this));
clearTimeout(this.trimTimeout);
this.trimTimeout = setTimeout(function(){
this.q.enqueue(this.trim);
}.bind(this), 250);
checking.resolve();
return checking.promise;
clearTimeout(this.trimTimeout);
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 {
window.scrollBy(x,y);
}
this.scrolled = true;
};
@ -487,7 +491,6 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
}
this.scrolled = true;
// if(this.container.scrollLeft != x){
// setTimeout(function() {
// this.scrollTo(x, y, silent);