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

@ -2,8 +2,6 @@ EPUBJS.View = function(section, options) {
this.settings = options || {};
this.id = "epubjs-view:" + EPUBJS.core.uuid();
this.displaying = new RSVP.defer();
this.displayed = this.displaying.promise;
this.section = section;
this.index = section.index;
@ -100,6 +98,14 @@ EPUBJS.View.prototype.lock = function(width, height) {
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) {
@ -169,6 +175,15 @@ EPUBJS.View.prototype.resized = function(e) {
};
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)
.then(function(contents){
return this.load(contents);
@ -191,7 +206,7 @@ EPUBJS.View.prototype.load = function(contents) {
this.window = this.iframe.contentWindow;
this.document = this.iframe.contentDocument;
this.rendering = false;
loading.resolve(this);
}.bind(this));