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

added url routes

This commit is contained in:
fchasen 2014-02-18 09:47:10 -08:00
parent 8884638852
commit ed82dfe736
12 changed files with 89 additions and 43 deletions

2
books

@ -1 +1 @@
Subproject commit 09bd1725f5839996e747cf83500a2526b86ae6af Subproject commit 950c742b3d66cc7ac53bd0663a41315f001da1c4

View file

@ -2128,7 +2128,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
var nextPage = true;//pager.nextPage(); var nextPage = true;
// Page though the entire chapter // Page though the entire chapter
while (nextPage) { while (nextPage) {
nextPage = pager.nextPage(); nextPage = pager.nextPage();
@ -2574,12 +2575,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
EPUBJS.Book.prototype.goto = function(target){ EPUBJS.Book.prototype.goto = function(target){
if(typeof target === "number"){ if(target.indexOf("epubcfi(") === 0) {
return this.gotoPage(target);
} else if(target.indexOf("epubcfi(") === 0) {
return this.gotoCfi(target); return this.gotoCfi(target);
} else if(target.indexOf("%") === target.length-1) { } else if(target.indexOf("%") === target.length-1) {
return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); return this.gotoPercentage(parseInt(target.substring(0, target.length-1))/100);
} else if(typeof target === "number" || isNaN(target) === false){
return this.gotoPage(target);
} else { } else {
return this.gotoHref(target); return this.gotoHref(target);
} }
@ -2675,14 +2676,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
//-- Load new chapter if different than current //-- Load new chapter if different than current
return this.displayChapter(spinePos).then(function(){ return this.displayChapter(spinePos).then(function(){
if(section){ if(section){
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
}.bind(this)); }.bind(this));
}else{ }else{
//-- Only goto section //-- Only goto section
if(section) { if(section) {
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
} }
@ -2701,7 +2702,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
EPUBJS.Book.prototype.gotoPercentage = function(percent){ EPUBJS.Book.prototype.gotoPercentage = function(percent){
var pg = this.pagination.pageFromPercentage(percent); var pg = this.pagination.pageFromPercentage(percent);
return this.gotoCfi(pg); return this.gotoPage(pg);
}; };
EPUBJS.Book.prototype.preloadNextChapter = function() { EPUBJS.Book.prototype.preloadNextChapter = function() {
@ -4530,6 +4531,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
content = findAnchorOrSpan(item), content = findAnchorOrSpan(item),
href = content.getAttribute('href') || '', href = content.getAttribute('href') || '',
text = content.textContent || "", text = content.textContent || "",
page = parseInt(text),
isCfi = href.indexOf("epubcfi"), isCfi = href.indexOf("epubcfi"),
split, split,
packageUrl, packageUrl,
@ -4543,12 +4545,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
"cfi" : cfi, "cfi" : cfi,
"href" : href, "href" : href,
"packageUrl" : packageUrl, "packageUrl" : packageUrl,
"page" : text "page" : page
}); });
} else { } else {
list.push({ list.push({
"href" : href, "href" : href,
"page" : text "page" : page
}); });
} }
@ -5041,7 +5043,7 @@ EPUBJS.Renderer.prototype.reformat = function(){
}; };
// Hide and show the render's container element. // Hide and show the render's container .
EPUBJS.Renderer.prototype.visible = function(bool){ EPUBJS.Renderer.prototype.visible = function(bool){
if(typeof(bool) === "undefined") { if(typeof(bool) === "undefined") {
return this.container.style.visibility; return this.container.style.visibility;

2
build/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -2127,7 +2127,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
var nextPage = true;//pager.nextPage(); var nextPage = true;
// Page though the entire chapter // Page though the entire chapter
while (nextPage) { while (nextPage) {
nextPage = pager.nextPage(); nextPage = pager.nextPage();
@ -2573,12 +2574,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
EPUBJS.Book.prototype.goto = function(target){ EPUBJS.Book.prototype.goto = function(target){
if(typeof target === "number"){ if(target.indexOf("epubcfi(") === 0) {
return this.gotoPage(target);
} else if(target.indexOf("epubcfi(") === 0) {
return this.gotoCfi(target); return this.gotoCfi(target);
} else if(target.indexOf("%") === target.length-1) { } else if(target.indexOf("%") === target.length-1) {
return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); return this.gotoPercentage(parseInt(target.substring(0, target.length-1))/100);
} else if(typeof target === "number" || isNaN(target) === false){
return this.gotoPage(target);
} else { } else {
return this.gotoHref(target); return this.gotoHref(target);
} }
@ -2674,14 +2675,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
//-- Load new chapter if different than current //-- Load new chapter if different than current
return this.displayChapter(spinePos).then(function(){ return this.displayChapter(spinePos).then(function(){
if(section){ if(section){
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
}.bind(this)); }.bind(this));
}else{ }else{
//-- Only goto section //-- Only goto section
if(section) { if(section) {
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
} }
@ -2700,7 +2701,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
EPUBJS.Book.prototype.gotoPercentage = function(percent){ EPUBJS.Book.prototype.gotoPercentage = function(percent){
var pg = this.pagination.pageFromPercentage(percent); var pg = this.pagination.pageFromPercentage(percent);
return this.gotoCfi(pg); return this.gotoPage(pg);
}; };
EPUBJS.Book.prototype.preloadNextChapter = function() { EPUBJS.Book.prototype.preloadNextChapter = function() {
@ -4529,6 +4530,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
content = findAnchorOrSpan(item), content = findAnchorOrSpan(item),
href = content.getAttribute('href') || '', href = content.getAttribute('href') || '',
text = content.textContent || "", text = content.textContent || "",
page = parseInt(text),
isCfi = href.indexOf("epubcfi"), isCfi = href.indexOf("epubcfi"),
split, split,
packageUrl, packageUrl,
@ -4542,12 +4544,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
"cfi" : cfi, "cfi" : cfi,
"href" : href, "href" : href,
"packageUrl" : packageUrl, "packageUrl" : packageUrl,
"page" : text "page" : page
}); });
} else { } else {
list.push({ list.push({
"href" : href, "href" : href,
"page" : text "page" : page
}); });
} }
@ -5040,7 +5042,7 @@ EPUBJS.Renderer.prototype.reformat = function(){
}; };
// Hide and show the render's container element. // Hide and show the render's container .
EPUBJS.Renderer.prototype.visible = function(bool){ EPUBJS.Renderer.prototype.visible = function(bool){
if(typeof(bool) === "undefined") { if(typeof(bool) === "undefined") {
return this.container.style.visibility; return this.container.style.visibility;

View file

@ -30,6 +30,7 @@ EPUBJS.Reader = function(path, _options) {
var reader = this; var reader = this;
var book; var book;
var plugin; var plugin;
var $viewer = $("#viewer");
this.settings = _.defaults(_options || {}, { this.settings = _.defaults(_options || {}, {
restore : true, restore : true,
@ -39,7 +40,8 @@ EPUBJS.Reader = function(path, _options) {
bookKey : null, bookKey : null,
styles : null, styles : null,
sidebarReflow: false, sidebarReflow: false,
generatePagination: false generatePagination: false,
history: true
}); });
this.setBookKey(path); //-- This could be username + path or any unique string this.setBookKey(path); //-- This could be username + path or any unique string
@ -72,7 +74,7 @@ EPUBJS.Reader = function(path, _options) {
} }
if(this.settings.generatePagination) { if(this.settings.generatePagination) {
book.generatePagination(1076, 588); book.generatePagination($viewer.width(), $viewer.height());
} }
book.renderTo("viewer"); book.renderTo("viewer");
@ -104,11 +106,15 @@ EPUBJS.Reader = function(path, _options) {
window.addEventListener("beforeunload", this.unload.bind(this), false); window.addEventListener("beforeunload", this.unload.bind(this), false);
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
document.addEventListener('keydown', this.adjustFontSize.bind(this), false); document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
book.on("renderer:keydown", this.adjustFontSize.bind(this)); book.on("renderer:keydown", this.adjustFontSize.bind(this));
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this)); book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
book.on("renderer:selected", this.selectedRange.bind(this));
return this; return this;
}; };
@ -236,6 +242,16 @@ EPUBJS.Reader.prototype.unload = function(){
} }
}; };
EPUBJS.Reader.prototype.hashChanged = function(){
var hash = window.location.hash.slice(1);
this.book.goto(hash);
};
EPUBJS.Reader.prototype.selectedRange = function(range){
console.log("range", range)
};
//-- Enable binding events to reader //-- Enable binding events to reader
RSVP.EventTarget.mixin(EPUBJS.Reader.prototype); RSVP.EventTarget.mixin(EPUBJS.Reader.prototype);
EPUBJS.reader.BookmarksController = function() { EPUBJS.reader.BookmarksController = function() {
@ -399,10 +415,14 @@ EPUBJS.reader.ControlsController = function(book) {
.removeClass("icon-bookmark-empty"); .removeClass("icon-bookmark-empty");
} }
// Update the History Location
if(reader.settings.history) {
history.pushState({}, '', "#"+cfi);
}
}); });
book.on('book:pageChanged', function(location){ book.on('book:pageChanged', function(location){
console.log("page", location.page, location.percentage) // console.log("page", location.page, location.percentage)
}); });
return { return {

2
demo/js/epub.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -92,10 +92,14 @@ EPUBJS.reader.ControlsController = function(book) {
.removeClass("icon-bookmark-empty"); .removeClass("icon-bookmark-empty");
} }
// Update the History Location
if(reader.settings.history) {
history.pushState({}, '', "#"+cfi);
}
}); });
book.on('book:pageChanged', function(location){ book.on('book:pageChanged', function(location){
console.log("page", location.page, location.percentage) // console.log("page", location.page, location.percentage)
}); });
return { return {

View file

@ -30,6 +30,7 @@ EPUBJS.Reader = function(path, _options) {
var reader = this; var reader = this;
var book; var book;
var plugin; var plugin;
var $viewer = $("#viewer");
this.settings = _.defaults(_options || {}, { this.settings = _.defaults(_options || {}, {
restore : true, restore : true,
@ -39,7 +40,8 @@ EPUBJS.Reader = function(path, _options) {
bookKey : null, bookKey : null,
styles : null, styles : null,
sidebarReflow: false, sidebarReflow: false,
generatePagination: false generatePagination: false,
history: true
}); });
this.setBookKey(path); //-- This could be username + path or any unique string this.setBookKey(path); //-- This could be username + path or any unique string
@ -72,7 +74,7 @@ EPUBJS.Reader = function(path, _options) {
} }
if(this.settings.generatePagination) { if(this.settings.generatePagination) {
book.generatePagination(1076, 588); book.generatePagination($viewer.width(), $viewer.height());
} }
book.renderTo("viewer"); book.renderTo("viewer");
@ -104,11 +106,15 @@ EPUBJS.Reader = function(path, _options) {
window.addEventListener("beforeunload", this.unload.bind(this), false); window.addEventListener("beforeunload", this.unload.bind(this), false);
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
document.addEventListener('keydown', this.adjustFontSize.bind(this), false); document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
book.on("renderer:keydown", this.adjustFontSize.bind(this)); book.on("renderer:keydown", this.adjustFontSize.bind(this));
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this)); book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
book.on("renderer:selected", this.selectedRange.bind(this));
return this; return this;
}; };
@ -236,5 +242,15 @@ EPUBJS.Reader.prototype.unload = function(){
} }
}; };
EPUBJS.Reader.prototype.hashChanged = function(){
var hash = window.location.hash.slice(1);
this.book.goto(hash);
};
EPUBJS.Reader.prototype.selectedRange = function(range){
console.log("range", range)
};
//-- Enable binding events to reader //-- Enable binding events to reader
RSVP.EventTarget.mixin(EPUBJS.Reader.prototype); RSVP.EventTarget.mixin(EPUBJS.Reader.prototype);

View file

@ -352,7 +352,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
var nextPage = true;//pager.nextPage(); var nextPage = true;
// Page though the entire chapter // Page though the entire chapter
while (nextPage) { while (nextPage) {
nextPage = pager.nextPage(); nextPage = pager.nextPage();
@ -798,12 +799,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
EPUBJS.Book.prototype.goto = function(target){ EPUBJS.Book.prototype.goto = function(target){
if(typeof target === "number"){ if(target.indexOf("epubcfi(") === 0) {
return this.gotoPage(target);
} else if(target.indexOf("epubcfi(") === 0) {
return this.gotoCfi(target); return this.gotoCfi(target);
} else if(target.indexOf("%") === target.length-1) { } else if(target.indexOf("%") === target.length-1) {
return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); return this.gotoPercentage(parseInt(target.substring(0, target.length-1))/100);
} else if(typeof target === "number" || isNaN(target) === false){
return this.gotoPage(target);
} else { } else {
return this.gotoHref(target); return this.gotoHref(target);
} }
@ -899,14 +900,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
//-- Load new chapter if different than current //-- Load new chapter if different than current
return this.displayChapter(spinePos).then(function(){ return this.displayChapter(spinePos).then(function(){
if(section){ if(section){
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
}.bind(this)); }.bind(this));
}else{ }else{
//-- Only goto section //-- Only goto section
if(section) { if(section) {
this.render.section(section); this.renderer.section(section);
} }
deferred.resolve(this.renderer.currentLocationCfi); deferred.resolve(this.renderer.currentLocationCfi);
} }
@ -925,7 +926,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
EPUBJS.Book.prototype.gotoPercentage = function(percent){ EPUBJS.Book.prototype.gotoPercentage = function(percent){
var pg = this.pagination.pageFromPercentage(percent); var pg = this.pagination.pageFromPercentage(percent);
return this.gotoCfi(pg); return this.gotoPage(pg);
}; };
EPUBJS.Book.prototype.preloadNextChapter = function() { EPUBJS.Book.prototype.preloadNextChapter = function() {

View file

@ -425,6 +425,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
content = findAnchorOrSpan(item), content = findAnchorOrSpan(item),
href = content.getAttribute('href') || '', href = content.getAttribute('href') || '',
text = content.textContent || "", text = content.textContent || "",
page = parseInt(text),
isCfi = href.indexOf("epubcfi"), isCfi = href.indexOf("epubcfi"),
split, split,
packageUrl, packageUrl,
@ -438,12 +439,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
"cfi" : cfi, "cfi" : cfi,
"href" : href, "href" : href,
"packageUrl" : packageUrl, "packageUrl" : packageUrl,
"page" : text "page" : page
}); });
} else { } else {
list.push({ list.push({
"href" : href, "href" : href,
"page" : text "page" : page
}); });
} }

View file

@ -274,7 +274,7 @@ EPUBJS.Renderer.prototype.reformat = function(){
}; };
// Hide and show the render's container element. // Hide and show the render's container .
EPUBJS.Renderer.prototype.visible = function(bool){ EPUBJS.Renderer.prototype.visible = function(bool){
if(typeof(bool) === "undefined") { if(typeof(bool) === "undefined") {
return this.container.style.visibility; return this.container.style.visibility;