diff --git a/src/contents.js b/src/contents.js index 72ff369..aca6f88 100644 --- a/src/contents.js +++ b/src/contents.js @@ -293,6 +293,8 @@ class Contents { this.removeEventListeners(); this.removeSelectionListeners(); + + clearTimeout(this.expanding); } resizeListeners() { diff --git a/src/managers/views/iframe.js b/src/managers/views/iframe.js index 0dfeaf2..4ca3a9b 100644 --- a/src/managers/views/iframe.js +++ b/src/managers/views/iframe.js @@ -146,22 +146,22 @@ class IframeView { // apply the layout function to the contents this.settings.layout.format(this.contents); - // Expand the iframe to the full size of the content - this.expand(); - // Listen for events that require an expansion of the iframe this.addListeners(); - if(show !== false) { - //this.q.enqueue(function(view){ - // this.show(); - //}, view); - } - // this.map = new Map(view, this.layout); - //this.hooks.show.trigger(view, this); - this.emit("rendered", this.section); + // Wait for formating to apply + return new Promise((resolve, reject) => { + setTimeout(() => { + // Expand the iframe to the full size of the content + this.expand(); + resolve(); + }, 1); + }); }.bind(this)) + .then(function() { + this.emit("rendered", this.section); + }.bind(this)) .catch(function(e){ this.emit("loaderror", e); }.bind(this)); @@ -432,7 +432,13 @@ class IframeView { this.document.querySelector("head").appendChild(link); } - this.contents.on("expand", function () { + this.contents.on("expand", () => { + if(this.displayed && this.iframe) { + this.expand(); + } + }); + + this.contents.on("resize", (e) => { if(this.displayed && this.iframe) { this.expand(); } diff --git a/src/rendition.js b/src/rendition.js index a3c97a0..b5c9853 100644 --- a/src/rendition.js +++ b/src/rendition.js @@ -613,6 +613,7 @@ class Rendition { "page-break-inside": "avoid" } }); + return new Promise(function(resolve, reject){ // Wait to apply setTimeout(function() {