diff --git a/fpjs/render/book.js b/fpjs/render/book.js index 05ac341..f223b9d 100644 --- a/fpjs/render/book.js +++ b/fpjs/render/book.js @@ -96,7 +96,7 @@ FP.Book.prototype.start = function(bookPath){ } } - if(!this.isSaved(true)){ + if(!this.isSaved()){ if(!this.online) { console.error("Not Online"); @@ -154,9 +154,12 @@ FP.Book.prototype.isSaved = function(force) { localStorage.setItem("fpjs-version", FP.VERSION); localStorage.setItem("bookPath", this.bookPath); - localStorage.setItem("spinePos", 0); localStorage.setItem("stored", 0); + localStorage.setItem("spinePos", 0); + localStorage.setItem("chapterPos", 0); + localStorage.setItem("displayedPages", 0); + this.spinePos = 0; this.stored = 0; @@ -177,6 +180,10 @@ FP.Book.prototype.isSaved = function(force) { this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL")); this.toc = JSON.parse(localStorage.getItem("toc")); + //-- Get previous page + this.prevChapterPos = parseInt(localStorage.getItem("chapterPos")); + this.prevDisplayedPages = parseInt(localStorage.getItem("displayedPages")); + //-- Check that retrieved object aren't null if(!this.assets || !this.spine || !this.spineIndexByURL || !this.toc){ this.stored = 0; @@ -457,6 +464,11 @@ FP.Book.prototype.startDisplay = function(){ this.tell("book:bookReady"); this.displayChapter(this.spinePos, function(chapter){ + //-- If there is a saved page, and the pages haven't changed go to it + if(this.prevChapterPos && this.prevDisplayedPages == chapter.displayedPages){ + chapter.page(this.prevChapterPos); + } + //-- If there is network connection, store the books contents if(this.online && !this.contained){ this.storeOffline(); diff --git a/fpjs/render/chapter.js b/fpjs/render/chapter.js index d4d7412..9ba462a 100644 --- a/fpjs/render/chapter.js +++ b/fpjs/render/chapter.js @@ -10,6 +10,8 @@ FP.Chapter = function(book, pos){ this.chapterPos = 1; this.leftPos = 0; + localStorage.setItem("chapterPos", this.chapterPos); + this.book.registerHook("beforeChapterDisplay", [this.replaceLinks.bind(this), this.replaceResources.bind(this)]); @@ -146,6 +148,8 @@ FP.Chapter.prototype.calcPages = function(){ this.displayedPages = Math.ceil(this.totalWidth / this.spreadWidth); + + localStorage.setItem("displayedPages", this.displayedPages); //console.log("Pages:", this.displayedPages) } @@ -158,6 +162,8 @@ FP.Chapter.prototype.nextPage = function(){ this.setLeft(this.leftPos); + localStorage.setItem("chapterPos", this.chapterPos); + return this.chapterPos; }else{ return false; @@ -172,6 +178,8 @@ FP.Chapter.prototype.prevPage = function(){ this.setLeft(this.leftPos); + localStorage.setItem("chapterPos", this.chapterPos); + return this.chapterPos; }else{ return false; @@ -247,6 +255,7 @@ FP.Chapter.prototype.page = function(pg){ this.leftPos = this.spreadWidth * (pg-1); //-- pages start at 1 this.setLeft(this.leftPos); + localStorage.setItem("chapterPos", pg); return true; } diff --git a/index.html b/index.html index 4d231be..b6b2fa8 100755 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@ "use strict"; var FP = FP || {}; - FP.VERSION = "0.1.2"; + FP.VERSION = "0.1.3"; document.onreadystatechange = function () { if (document.readyState == "complete") {