Skip to content

Commit

Permalink
Fixed lack of reframe issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fchasen committed Jun 21, 2015
1 parent c66f2aa commit 2a95b28
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
18 changes: 11 additions & 7 deletions dist/epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3900,7 +3900,9 @@ EPUBJS.View.prototype.create = function() {

this.iframe.style.width = "0";
this.iframe.style.height = "0";

this._width = 0;
this._height = 0;

this.element.appendChild(this.iframe);
this.added = true;

Expand Down Expand Up @@ -4010,8 +4012,9 @@ EPUBJS.View.prototype.expand = function(force) {
}
}

// Only Resize if dimensions have changed
if(width != this._width || height != this._height){
// Only Resize if dimensions have changed or
// if Frame is still hidden, so needs reframing
if(this._needsReframe || width != this._width || height != this._height){
this.resize(width, height);
}

Expand All @@ -4029,7 +4032,6 @@ EPUBJS.View.prototype.contentWidth = function(min) {
width = this.document.body.scrollWidth;
// Reset iframe size back
this.iframe.style.width = prev;

return width;
}

Expand All @@ -4053,7 +4055,6 @@ EPUBJS.View.prototype.textWidth = function() {

// get the width of the text content
width = range.getBoundingClientRect().width;

return width;

};
Expand Down Expand Up @@ -4091,8 +4092,11 @@ EPUBJS.View.prototype.resize = function(width, height) {
EPUBJS.View.prototype.reframe = function(width, height) {
//var prevBounds;

if(!this.displayed) return;

if(!this.displayed) {
this._needsReframe = true;
return;
}

if(EPUBJS.core.isNumber(width)){
this.element.style.width = width + "px";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/epub.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/spread.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
and (min-device-width : 320px)
and (max-device-width : 667px) {
#viewer {
/* height: 96.5%; */
height: 96.5%;
}
#viewer iframe {
pointer-events: none;
Expand All @@ -97,8 +97,8 @@
height: "100%"
});

var displayed = rendition.display("chapter_001.xhtml");

// var displayed = rendition.display("chapter_001.xhtml");
var displayed = rendition.display();

displayed.then(function(renderer){
// -- do stuff
Expand Down
2 changes: 1 addition & 1 deletion examples/spreads.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
height: 600
});

var displayed = rendition.display(6);
var displayed = rendition.display();


displayed.then(function(renderer){
Expand Down
18 changes: 11 additions & 7 deletions src/epubjs/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ EPUBJS.View.prototype.create = function() {

this.iframe.style.width = "0";
this.iframe.style.height = "0";

this._width = 0;
this._height = 0;

this.element.appendChild(this.iframe);
this.added = true;

Expand Down Expand Up @@ -164,8 +166,9 @@ EPUBJS.View.prototype.expand = function(force) {
}
}

// Only Resize if dimensions have changed
if(width != this._width || height != this._height){
// Only Resize if dimensions have changed or
// if Frame is still hidden, so needs reframing
if(this._needsReframe || width != this._width || height != this._height){
this.resize(width, height);
}

Expand All @@ -183,7 +186,6 @@ EPUBJS.View.prototype.contentWidth = function(min) {
width = this.document.body.scrollWidth;
// Reset iframe size back
this.iframe.style.width = prev;

return width;
}

Expand All @@ -207,7 +209,6 @@ EPUBJS.View.prototype.textWidth = function() {

// get the width of the text content
width = range.getBoundingClientRect().width;

return width;

};
Expand Down Expand Up @@ -245,8 +246,11 @@ EPUBJS.View.prototype.resize = function(width, height) {
EPUBJS.View.prototype.reframe = function(width, height) {
//var prevBounds;

if(!this.displayed) return;

if(!this.displayed) {
this._needsReframe = true;
return;
}

if(EPUBJS.core.isNumber(width)){
this.element.style.width = width + "px";
}
Expand Down

0 comments on commit 2a95b28

Please sign in to comment.