1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Fixed locking to solve single page issues

This commit is contained in:
Fred Chasen 2015-06-05 15:20:45 -04:00
parent 61ebe6d16e
commit 23ca0b840d
8 changed files with 32 additions and 29 deletions

21
dist/epub.js vendored
View file

@ -4512,7 +4512,7 @@ EPUBJS.View.prototype.create = function() {
}; };
EPUBJS.View.prototype.lock = function(width, height) { EPUBJS.View.prototype.lock = function(what, width, height) {
var elBorders = EPUBJS.core.borders(this.element); var elBorders = EPUBJS.core.borders(this.element);
var iframeBorders; var iframeBorders;
@ -4523,17 +4523,18 @@ EPUBJS.View.prototype.lock = function(width, height) {
iframeBorders = {width: 0, height: 0}; iframeBorders = {width: 0, height: 0};
} }
if(EPUBJS.core.isNumber(width)){ if(what == "width" && EPUBJS.core.isNumber(width)){
this.lockedWidth = width - elBorders.width - iframeBorders.width; this.lockedWidth = width - elBorders.width - iframeBorders.width;
this.resize(this.lockedWidth, width); // width keeps ratio correct this.resize(this.lockedWidth, width); // width keeps ratio correct
} }
if(EPUBJS.core.isNumber(height)){ if(what == "height" && EPUBJS.core.isNumber(height)){
this.lockedHeight = height - elBorders.height - iframeBorders.height; this.lockedHeight = height - elBorders.height - iframeBorders.height;
this.resize(null, this.lockedHeight); this.resize(width, this.lockedHeight);
} }
if(EPUBJS.core.isNumber(width) && if(what === "both" &&
EPUBJS.core.isNumber(width) &&
EPUBJS.core.isNumber(height)){ EPUBJS.core.isNumber(height)){
this.lockedWidth = width - elBorders.width - iframeBorders.width; this.lockedWidth = width - elBorders.width - iframeBorders.width;
@ -4957,6 +4958,7 @@ EPUBJS.Layout.Reflowable.prototype.calculate = function(_width, _height, _gap, _
this.column = colWidth; this.column = colWidth;
this.gap = gap; this.gap = gap;
this.divisor = divisor; this.divisor = divisor;
}; };
EPUBJS.Layout.Reflowable.prototype.format = function(view){ EPUBJS.Layout.Reflowable.prototype.format = function(view){
@ -4980,7 +4982,6 @@ EPUBJS.Layout.Reflowable.prototype.format = function(view){
// Add extra padding for the gap between this and the next view // Add extra padding for the gap between this and the next view
view.iframe.style.marginRight = this.gap+"px"; view.iframe.style.marginRight = this.gap+"px";
}; };
EPUBJS.Layout.Reflowable.prototype.count = function(view) { EPUBJS.Layout.Reflowable.prototype.count = function(view) {
@ -5372,9 +5373,9 @@ EPUBJS.Rendition.prototype._remove = function(view) {
EPUBJS.Rendition.prototype.resizeView = function(view) { EPUBJS.Rendition.prototype.resizeView = function(view) {
if(this.globalLayoutProperties.layout === "pre-paginated") { if(this.globalLayoutProperties.layout === "pre-paginated") {
view.lock(this.stage.width, this.stage.height); view.lock("both", this.stage.width, this.stage.height);
} else { } else {
view.lock(this.stage.width, null); view.lock("width", this.stage.width, this.stage.height);
} }
}; };
@ -6207,9 +6208,9 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
EPUBJS.Continuous.prototype.resizeView = function(view) { EPUBJS.Continuous.prototype.resizeView = function(view) {
if(this.settings.axis === "horizontal") { if(this.settings.axis === "horizontal") {
view.lock(null, this.stage.height); view.lock("height", this.stage.width, this.stage.height);
} else { } else {
view.lock(this.stage.width, null); view.lock("width", this.stage.width, this.stage.height);
} }
}; };

4
dist/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -17,7 +17,7 @@
color: #333; color: #333;
position: absolute; position: absolute;
height: 96.5%; height: 100%;
width: 100%; width: 100%;
display: flex; display: flex;
-webkit-align-items: center; -webkit-align-items: center;
@ -26,7 +26,7 @@
#viewer { #viewer {
width: 290px; width: 290px;
height: 100%; height: 580px;
background: white; background: white;
box-shadow: 0 0 4px #ccc; box-shadow: 0 0 4px #ccc;
padding: 10px 10px 0px 10px; padding: 10px 10px 0px 10px;
@ -70,7 +70,10 @@
@media only screen @media only screen
and (min-device-width : 320px) and (min-device-width : 320px)
and (max-device-width : 667px) { and (max-device-width : 667px) {
#viewer {
height: 96.5%;
}
.arrow { .arrow {
position: inherit; position: inherit;
display: none; display: none;
@ -84,7 +87,6 @@
<div id="prev" class="arrow"></div> <div id="prev" class="arrow"></div>
<div id="next" class="arrow"></div> <div id="next" class="arrow"></div>
<script> <script>
var currentSectionIndex = 14;
// Load the opf // Load the opf
// var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf"); // var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
var book = ePub("../books/moby-dick/OPS/package.opf"); var book = ePub("../books/moby-dick/OPS/package.opf");
@ -93,9 +95,8 @@
width: "100%", width: "100%",
height: "100%" height: "100%"
}); });
// var pagination = rendition.paginate();
var displayed = rendition.display(currentSectionIndex); var displayed = rendition.display();
displayed.then(function(renderer){ displayed.then(function(renderer){

View file

@ -126,7 +126,7 @@
height: 600 height: 600
}); });
var displayed = rendition.display("epubcfi(/6/14[xchapter_001]!4/2/30/2[c001p0016]/1:47)"); var displayed = rendition.display(4);
displayed.then(function(renderer){ displayed.then(function(renderer){

View file

@ -541,9 +541,9 @@ EPUBJS.Continuous.prototype.scrollTo = function(x, y, silent){
EPUBJS.Continuous.prototype.resizeView = function(view) { EPUBJS.Continuous.prototype.resizeView = function(view) {
if(this.settings.axis === "horizontal") { if(this.settings.axis === "horizontal") {
view.lock(null, this.stage.height); view.lock("height", this.stage.width, this.stage.height);
} else { } else {
view.lock(this.stage.width, null); view.lock("width", this.stage.width, this.stage.height);
} }
}; };

View file

@ -45,6 +45,7 @@ EPUBJS.Layout.Reflowable.prototype.calculate = function(_width, _height, _gap, _
this.column = colWidth; this.column = colWidth;
this.gap = gap; this.gap = gap;
this.divisor = divisor; this.divisor = divisor;
}; };
EPUBJS.Layout.Reflowable.prototype.format = function(view){ EPUBJS.Layout.Reflowable.prototype.format = function(view){
@ -68,7 +69,6 @@ EPUBJS.Layout.Reflowable.prototype.format = function(view){
// Add extra padding for the gap between this and the next view // Add extra padding for the gap between this and the next view
view.iframe.style.marginRight = this.gap+"px"; view.iframe.style.marginRight = this.gap+"px";
}; };
EPUBJS.Layout.Reflowable.prototype.count = function(view) { EPUBJS.Layout.Reflowable.prototype.count = function(view) {

View file

@ -305,9 +305,9 @@ EPUBJS.Rendition.prototype._remove = function(view) {
EPUBJS.Rendition.prototype.resizeView = function(view) { EPUBJS.Rendition.prototype.resizeView = function(view) {
if(this.globalLayoutProperties.layout === "pre-paginated") { if(this.globalLayoutProperties.layout === "pre-paginated") {
view.lock(this.stage.width, this.stage.height); view.lock("both", this.stage.width, this.stage.height);
} else { } else {
view.lock(this.stage.width, null); view.lock("width", this.stage.width, this.stage.height);
} }
}; };

View file

@ -78,7 +78,7 @@ EPUBJS.View.prototype.create = function() {
}; };
EPUBJS.View.prototype.lock = function(width, height) { EPUBJS.View.prototype.lock = function(what, width, height) {
var elBorders = EPUBJS.core.borders(this.element); var elBorders = EPUBJS.core.borders(this.element);
var iframeBorders; var iframeBorders;
@ -89,17 +89,18 @@ EPUBJS.View.prototype.lock = function(width, height) {
iframeBorders = {width: 0, height: 0}; iframeBorders = {width: 0, height: 0};
} }
if(EPUBJS.core.isNumber(width)){ if(what == "width" && EPUBJS.core.isNumber(width)){
this.lockedWidth = width - elBorders.width - iframeBorders.width; this.lockedWidth = width - elBorders.width - iframeBorders.width;
this.resize(this.lockedWidth, width); // width keeps ratio correct this.resize(this.lockedWidth, width); // width keeps ratio correct
} }
if(EPUBJS.core.isNumber(height)){ if(what == "height" && EPUBJS.core.isNumber(height)){
this.lockedHeight = height - elBorders.height - iframeBorders.height; this.lockedHeight = height - elBorders.height - iframeBorders.height;
this.resize(null, this.lockedHeight); this.resize(width, this.lockedHeight);
} }
if(EPUBJS.core.isNumber(width) && if(what === "both" &&
EPUBJS.core.isNumber(width) &&
EPUBJS.core.isNumber(height)){ EPUBJS.core.isNumber(height)){
this.lockedWidth = width - elBorders.width - iframeBorders.width; this.lockedWidth = width - elBorders.width - iframeBorders.width;