mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
save page position
This commit is contained in:
parent
7c15cec459
commit
954aba9627
3 changed files with 24 additions and 3 deletions
|
@ -96,7 +96,7 @@ FP.Book.prototype.start = function(bookPath){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.isSaved(true)){
|
if(!this.isSaved()){
|
||||||
|
|
||||||
if(!this.online) {
|
if(!this.online) {
|
||||||
console.error("Not Online");
|
console.error("Not Online");
|
||||||
|
@ -154,9 +154,12 @@ FP.Book.prototype.isSaved = function(force) {
|
||||||
localStorage.setItem("fpjs-version", FP.VERSION);
|
localStorage.setItem("fpjs-version", FP.VERSION);
|
||||||
|
|
||||||
localStorage.setItem("bookPath", this.bookPath);
|
localStorage.setItem("bookPath", this.bookPath);
|
||||||
localStorage.setItem("spinePos", 0);
|
|
||||||
localStorage.setItem("stored", 0);
|
localStorage.setItem("stored", 0);
|
||||||
|
|
||||||
|
localStorage.setItem("spinePos", 0);
|
||||||
|
localStorage.setItem("chapterPos", 0);
|
||||||
|
localStorage.setItem("displayedPages", 0);
|
||||||
|
|
||||||
this.spinePos = 0;
|
this.spinePos = 0;
|
||||||
this.stored = 0;
|
this.stored = 0;
|
||||||
|
|
||||||
|
@ -177,6 +180,10 @@ FP.Book.prototype.isSaved = function(force) {
|
||||||
this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL"));
|
this.spineIndexByURL = JSON.parse(localStorage.getItem("spineIndexByURL"));
|
||||||
this.toc = JSON.parse(localStorage.getItem("toc"));
|
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
|
//-- Check that retrieved object aren't null
|
||||||
if(!this.assets || !this.spine || !this.spineIndexByURL || !this.toc){
|
if(!this.assets || !this.spine || !this.spineIndexByURL || !this.toc){
|
||||||
this.stored = 0;
|
this.stored = 0;
|
||||||
|
@ -457,6 +464,11 @@ FP.Book.prototype.startDisplay = function(){
|
||||||
this.tell("book:bookReady");
|
this.tell("book:bookReady");
|
||||||
this.displayChapter(this.spinePos, function(chapter){
|
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 there is network connection, store the books contents
|
||||||
if(this.online && !this.contained){
|
if(this.online && !this.contained){
|
||||||
this.storeOffline();
|
this.storeOffline();
|
||||||
|
|
|
@ -10,6 +10,8 @@ FP.Chapter = function(book, pos){
|
||||||
|
|
||||||
this.chapterPos = 1;
|
this.chapterPos = 1;
|
||||||
this.leftPos = 0;
|
this.leftPos = 0;
|
||||||
|
localStorage.setItem("chapterPos", this.chapterPos);
|
||||||
|
|
||||||
|
|
||||||
this.book.registerHook("beforeChapterDisplay",
|
this.book.registerHook("beforeChapterDisplay",
|
||||||
[this.replaceLinks.bind(this), this.replaceResources.bind(this)]);
|
[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);
|
this.displayedPages = Math.ceil(this.totalWidth / this.spreadWidth);
|
||||||
|
|
||||||
|
|
||||||
|
localStorage.setItem("displayedPages", this.displayedPages);
|
||||||
//console.log("Pages:", this.displayedPages)
|
//console.log("Pages:", this.displayedPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +162,8 @@ FP.Chapter.prototype.nextPage = function(){
|
||||||
|
|
||||||
this.setLeft(this.leftPos);
|
this.setLeft(this.leftPos);
|
||||||
|
|
||||||
|
localStorage.setItem("chapterPos", this.chapterPos);
|
||||||
|
|
||||||
return this.chapterPos;
|
return this.chapterPos;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
@ -172,6 +178,8 @@ FP.Chapter.prototype.prevPage = function(){
|
||||||
|
|
||||||
this.setLeft(this.leftPos);
|
this.setLeft(this.leftPos);
|
||||||
|
|
||||||
|
localStorage.setItem("chapterPos", this.chapterPos);
|
||||||
|
|
||||||
return this.chapterPos;
|
return this.chapterPos;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
@ -247,6 +255,7 @@ FP.Chapter.prototype.page = function(pg){
|
||||||
this.leftPos = this.spreadWidth * (pg-1); //-- pages start at 1
|
this.leftPos = this.spreadWidth * (pg-1); //-- pages start at 1
|
||||||
this.setLeft(this.leftPos);
|
this.setLeft(this.leftPos);
|
||||||
|
|
||||||
|
localStorage.setItem("chapterPos", pg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var FP = FP || {};
|
var FP = FP || {};
|
||||||
FP.VERSION = "0.1.2";
|
FP.VERSION = "0.1.3";
|
||||||
|
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue