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

offline storage

This commit is contained in:
Fred Chasen 2013-01-22 22:20:39 -08:00
parent 8e6f8289ca
commit 0690ad97d0
11 changed files with 926 additions and 342 deletions

View file

@ -106,9 +106,18 @@ FP.Chapter.prototype.formatSpread = function(){
this.bodyEl.style[FP.core.columnAxis] = "horizontal";
this.bodyEl.style[FP.core.columnGap] = this.gap+"px";
this.bodyEl.style[FP.core.columnWidth] = this.colWidth+"px";
this.calcPages();
if(!this.book.online){
//-- Temp place to parse Links
this.replaceLinks(function(){
this.visible(true);
}.bind(this));
}else{
this.visible(true);
}
//-- Go to current page after resize
if(this.OldcolWidth){
this.leftPos = (this.chapterPos - 1 ) * this.spreadWidth;
@ -120,11 +129,21 @@ FP.Chapter.prototype.goToChapterEnd = function(){
this.chapterEnd();
}
FP.Chapter.prototype.visible = function(bool){
if(bool){
this.bodyEl.style.visibility = "visible";
}else{
this.bodyEl.style.visibility = "hidden";
}
}
FP.Chapter.prototype.calcPages = function(){
this.totalWidth = this.iframe.contentDocument.documentElement.scrollWidth; //this.bodyEl.scrollWidth;
this.displayedPages = Math.ceil(this.totalWidth / this.spreadWidth);
this.bodyEl.style.visibility = "visible";
//-- I work for Chrome
//this.iframe.contentDocument.body.scrollLeft = 200;
@ -178,4 +197,28 @@ FP.Chapter.prototype.setLeft = function(leftPos){
this.bodyEl.style.marginLeft = -leftPos + "px";
}
FP.Chapter.prototype.replaceLinks = function(callback){
var doc = this.iframe.contentDocument,
links = doc.querySelectorAll('[href], [src]'),
items = Array.prototype.slice.call(links),
count = items.length;
items.forEach(function(link){
var path,
href = link.getAttribute("href"),
src = link.getAttribute("src"),
full = href ? this.book.basePath + href : this.book.basePath + src;
FP.storage.get(full, function(url){
if(href) link.setAttribute("href", url);
if(src) link.setAttribute("src", url);
count--;
if(count <= 0 && callback) callback();
});
}.bind(this));
}