1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

expand views multiple times, infinite offset set to pageWidth

This commit is contained in:
fchasen 2014-10-30 09:45:51 -04:00
parent 105a3a36d6
commit d986157860
11 changed files with 1557 additions and 2095 deletions

2
books

@ -1 +1 @@
Subproject commit ab9755a74714b647290c861f666515de220935d8
Subproject commit 950c742b3d66cc7ac53bd0663a41315f001da1c4

View file

@ -25,22 +25,7 @@
"books",
"examples"
],
"devDependencies": {
"colors": "^0.6.2",
"connect": "^3.0.1",
"express": "^4.5.1",
"gulp": "^3.8.7",
"gulp-concat": "^2.3.4",
"gulp-connect": "~2.0.6",
"gulp-jshint": "^1.8.4",
"gulp-plumber": "^0.6.4",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^0.3.1",
"gulp-util": "^3.0.0",
"morgan": "^1.1.1",
"optimist": "^0.6.1",
"portfinder": "^0.2.1",
"qunitjs": "^1.14.0",
"serve-static": "^1.3.1"
"dependencies": {
"rsvp": "~3.0.13"
}
}

3530
dist/epub.js vendored

File diff suppressed because it is too large Load diff

4
dist/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -13,16 +13,18 @@
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #333;
height: 100%;
position: absolute;
height: 100%;
/* position: absolute; */
}
#viewer {
display: block;
margin: 0;
width: 100%;
height: 100%;
margin: 0 auto;
text-align: center;
position: absolute;
top: 0;
left: 0;
}
#viewer iframe {

View file

@ -111,7 +111,7 @@
<div id="prev" class="arrow"></div>
<div id="next" class="arrow"></div>
<script>
var currentSectionIndex = 10;
var currentSectionIndex = 14;
// Load the opf
var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
var rendition = book.renderTo("viewer", {axis: "horizontal", width: 900, height: 600});

View file

@ -131,20 +131,29 @@ EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
}
this.container.scrollLeft += x;
this.container.scrollTop += y;
this.scrolled = true;
this.check();
};
EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
EPUBJS.Infinite.prototype.scrollTo = function(x, y, silent){
if(silent) {
this.displaying = true;
}
this.container.scrollLeft = x;
this.container.scrollTop = y;
this.scrolled = true;
// if(this.container.scrollLeft != x){
// setTimeout(function() {
// this.scrollTo(x, y, silent);
// }.bind(this), 10);
// return;
// };
this.check();
};
RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype);

View file

@ -13,7 +13,7 @@ EPUBJS.Paginate = function(renderer, _options) {
this.renderer = renderer;
this.isForcedSingle = false;
this.initialize();
};
@ -108,6 +108,8 @@ EPUBJS.Paginate.prototype.initialize = function(){
// this.layoutMethod = this.determineLayout(this.layoutSettings);
// this.layout = new EPUBJS.Layout[this.layoutMethod]();
this.renderer.hooks.display.register(this.registerLayoutMethod.bind(this));
this.currentPage = 0;
};
EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) {
@ -116,27 +118,29 @@ EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) {
this.layoutMethod = this.determineLayout({});
this.layout = new EPUBJS.Layout[this.layoutMethod]();
this.formated = this.layout.format(view, this.settings.width, this.settings.height, this.settings.gap);
this.renderer.infinite.offset = this.formated.pageWidth;
task.resolve();
return task.promise;
};
EPUBJS.Paginate.prototype.page = function(pg){
this.currentPage = pg;
console.log("page", this.currentPage * this.formated.pageWidth)
this.renderer.infinite.scrollTo(this.currentPage * this.formated.pageWidth, 0);
//-- Return false if page is greater than the total
return false;
// return false;
};
EPUBJS.Paginate.prototype.next = function(){
// return this.page(this.chapterPos + 1);
console.log("next", this.formated.pageWidth)
this.renderer.infinite.scrollBy(this.formated.pageWidth, 0);
return this.page(this.currentPage + 1);
};
EPUBJS.Paginate.prototype.prev = function(){
console.log("prev", this.formated.pageWidth)
this.renderer.infinite.scrollBy(-this.formated.pageWidth, 0);
return this.page(this.currentPage - 1);
};
EPUBJS.Paginate.prototype.display = function(what){

View file

@ -343,9 +343,9 @@ EPUBJS.Renderer.prototype.forwards = function(){
if(this.settings.infinite) {
// Reset Position
if(this.settings.axis === "vertical") {
this.infinite.scroll(0, prevTop - firstBounds.height, true);
this.infinite.scrollTo(0, prevTop - firstBounds.height, true);
} else {
this.infinite.scroll(prevLeft - firstBounds.width, true);
this.infinite.scrollTo(prevLeft - firstBounds.width, true);
}
}
}

View file

@ -107,7 +107,7 @@ EPUBJS.View.prototype.display = function(contents) {
// Reset Body Styles
this.document.body.style.margin = "0";
this.document.body.style.display = "inline-block";
this.document.body.style.display = "inline-block";
this.document.documentElement.style.width = "auto";
setTimeout(function(){
@ -125,18 +125,26 @@ EPUBJS.View.prototype.display = function(contents) {
// displaying.resolve(this);
// }.bind(this);
// }
this.expand();
displaying.resolve(this);
displaying.resolve(this);
// this.observer = this.observe(this.document.body);
return displayed
};
EPUBJS.View.prototype.expand = function() {
EPUBJS.View.prototype.expand = function(_defer, _count) {
var bounds;
var width, height;
var expanding = _defer || new RSVP.defer();
var expanded = expanding.promise;
// Stop checking for equal height after 10 tries
var MAX = 10;
var count = _count || 0;
// Flag Changes
this.resizing = true;
// Check bounds
bounds = this.document.body.getBoundingClientRect();
@ -144,18 +152,27 @@ EPUBJS.View.prototype.expand = function() {
console.error("View not shown");
}
// Apply Changes
this.resizing = true;
height = bounds.height; //this.document.documentElement.scrollHeight;
this.iframe.style.height = height + "px";
height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle?
width = this.document.documentElement.scrollWidth;
this.iframe.style.width = width + "px";
// this.width = width;
// this.height = height;
if(this.width != width || this.height != height) {
return bounds;
setTimeout(function(){
this.expand(expanding, count);
}.bind(this), 10);
} else {
expanding.resolve();
}
this.width = width;
this.height = height;
this.iframe.style.height = height + "px";
this.iframe.style.width = width + "px";
return expanded;
};
EPUBJS.View.prototype.observe = function(target) {

View file

@ -28,5 +28,8 @@
"portfinder": "^0.2.1",
"qunitjs": "^1.14.0",
"serve-static": "^1.3.1"
},
"dependencies": {
"rsvp": "^3.0.14"
}
}