Skip to content

Commit

Permalink
Merge pull request futurepress#883 from futurepress/overflow_scroll
Browse files Browse the repository at this point in the history
Update oveflow scroll
  • Loading branch information
fchasen authored Dec 8, 2018
2 parents f314d06 + 48b564e commit c1739e6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
18 changes: 13 additions & 5 deletions examples/continuous-scrolled.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<style type="text/css">

.epub-container {
min-width: 320px;
margin: 0 auto;
position: relative;
/* min-width: 320px; */
/* margin: 0 auto; */
/* position: relative; */
}

.epub-container .epub-view > iframe {
Expand All @@ -24,6 +24,13 @@
padding: 20px;*/
}

#viewer {
width: 600px;
height: 100vh;
/* overflow: auto; */
margin: 0 auto;
}

</style>
</head>
<body>
Expand All @@ -33,10 +40,11 @@
var currentSectionIndex = 8;
// Load the opf
var book = ePub("https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf");
var rendition = book.renderTo(document.body, {
var rendition = book.renderTo("viewer", {
manager: "continuous",
flow: "scrolled",
width: "60%"
width: "100%",
height: "100%"
});
var displayed = rendition.display("epubcfi(/6/14[xchapter_001]!4/2/24/2[c001p0011]/1:799)");

Expand Down
7 changes: 1 addition & 6 deletions examples/examples.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ body {
margin: 0 auto;
position: relative;
background: url('ajax-loader.gif') center center no-repeat;

}

#viewer.scrolled .epub-container {
background: white;
box-shadow: 0 0 4px #ccc;
margin: 10px;
padding: 20px;
background: white;
}

#viewer.scrolled .epub-view > iframe {
Expand Down
3 changes: 2 additions & 1 deletion examples/scrolled.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
// Load the opf
var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", {
flow: "scrolled-doc"
flow: "scrolled-doc",
width: "100%"
});

rendition.display("chapter_008.xhtml");
Expand Down
2 changes: 1 addition & 1 deletion src/managers/continuous/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class ContinuousViewManager extends DefaultViewManager {
this.snapper = undefined;
}

super.updateFlow(flow);
super.updateFlow(flow, "scroll");

if (this.rendered && this.isPaginated && this.settings.snap) {
this.snapper = new Snap(this, this.settings.snap && (typeof this.settings.snap === "object") && this.settings.snap);
Expand Down
4 changes: 2 additions & 2 deletions src/managers/default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ class DefaultViewManager {
}
}

updateFlow(flow){
updateFlow(flow, defaultScrolledOverflow="auto"){
let isPaginated = (flow === "paginated" || flow === "auto");

this.isPaginated = isPaginated;
Expand All @@ -911,7 +911,7 @@ class DefaultViewManager {
this.viewSettings.flow = flow;

if (!this.settings.overflow) {
this.overflow = isPaginated ? "hidden" : "auto";
this.overflow = isPaginated ? "hidden" : defaultScrolledOverflow;
} else {
this.overflow = this.settings.overflow;
}
Expand Down
36 changes: 26 additions & 10 deletions src/managers/helpers/stage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {uuid, isNumber, isElement, windowBounds} from "../../utils/core";
import {uuid, isNumber, isElement, windowBounds, extend} from "../../utils/core";
import throttle from 'lodash/throttle'

class Stage {
Expand All @@ -25,6 +25,8 @@ class Stage {
let axis = options.axis || "vertical";
let direction = options.direction;

extend(this.settings, options);

if(options.height && isNumber(options.height)) {
height = options.height + "px";
}
Expand Down Expand Up @@ -62,7 +64,15 @@ class Stage {
}

if (overflow) {
container.style.overflow = overflow;
if (overflow === "scroll" && axis === "vertical") {
container.style["overflow-y"] = overflow;
container.style["overflow-x"] = "hidden";
} else if (overflow === "scroll" && axis === "horizontal") {
container.style["overflow-y"] = "hidden";
container.style["overflow-x"] = overflow;
} else {
container.style["overflow"] = overflow;
}
}

if (direction) {
Expand Down Expand Up @@ -187,18 +197,13 @@ class Stage {
}

if(!isNumber(width)) {
bounds = this.container.getBoundingClientRect();
width = Math.floor(bounds.width);
//height = bounds.height;
width = this.container.clientWidth;
}

if(!isNumber(height)) {
bounds = bounds || this.container.getBoundingClientRect();
//width = bounds.width;
height = bounds.height;
height = this.container.clientHeight;
}


this.containerStyles = window.getComputedStyle(this.container);

this.containerPadding = {
Expand Down Expand Up @@ -293,6 +298,7 @@ class Stage {
} else {
this.container.style.display = "block";
}
this.settings.axis = axis;
}

// orientation(orientation) {
Expand All @@ -314,12 +320,22 @@ class Stage {
if (this.settings.fullsize) {
document.body.style["direction"] = dir;
}
this.settings.dir = dir;
}

overflow(overflow) {
if (this.container) {
this.container.style["overflow"] = overflow;
if (overflow === "scroll" && this.settings.axis === "vertical") {
this.container.style["overflow-y"] = overflow;
this.container.style["overflow-x"] = "hidden";
} else if (overflow === "scroll" && this.settings.axis === "horizontal") {
this.container.style["overflow-y"] = "hidden";
this.container.style["overflow-x"] = overflow;
} else {
this.container.style["overflow"] = overflow;
}
}
this.settings.overflow = overflow;
}

destroy() {
Expand Down

0 comments on commit c1739e6

Please sign in to comment.