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:
parent
8884638852
commit
ed82dfe736
12 changed files with 89 additions and 43 deletions
2
books
2
books
|
@ -1 +1 @@
|
|||
Subproject commit 09bd1725f5839996e747cf83500a2526b86ae6af
|
||||
Subproject commit 950c742b3d66cc7ac53bd0663a41315f001da1c4
|
|
@ -2128,7 +2128,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
|
||||
|
||||
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
|
||||
var nextPage = true;//pager.nextPage();
|
||||
var nextPage = true;
|
||||
|
||||
// Page though the entire chapter
|
||||
while (nextPage) {
|
||||
nextPage = pager.nextPage();
|
||||
|
@ -2574,12 +2575,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
|
|||
|
||||
EPUBJS.Book.prototype.goto = function(target){
|
||||
|
||||
if(typeof target === "number"){
|
||||
return this.gotoPage(target);
|
||||
} else if(target.indexOf("epubcfi(") === 0) {
|
||||
if(target.indexOf("epubcfi(") === 0) {
|
||||
return this.gotoCfi(target);
|
||||
} 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 {
|
||||
return this.gotoHref(target);
|
||||
}
|
||||
|
@ -2675,14 +2676,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
|
|||
//-- Load new chapter if different than current
|
||||
return this.displayChapter(spinePos).then(function(){
|
||||
if(section){
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}.bind(this));
|
||||
}else{
|
||||
//-- Only goto section
|
||||
if(section) {
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}
|
||||
|
@ -2701,7 +2702,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
|
|||
|
||||
EPUBJS.Book.prototype.gotoPercentage = function(percent){
|
||||
var pg = this.pagination.pageFromPercentage(percent);
|
||||
return this.gotoCfi(pg);
|
||||
return this.gotoPage(pg);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.preloadNextChapter = function() {
|
||||
|
@ -4530,6 +4531,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
content = findAnchorOrSpan(item),
|
||||
href = content.getAttribute('href') || '',
|
||||
text = content.textContent || "",
|
||||
page = parseInt(text),
|
||||
isCfi = href.indexOf("epubcfi"),
|
||||
split,
|
||||
packageUrl,
|
||||
|
@ -4543,12 +4545,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
"cfi" : cfi,
|
||||
"href" : href,
|
||||
"packageUrl" : packageUrl,
|
||||
"page" : text
|
||||
"page" : page
|
||||
});
|
||||
} else {
|
||||
list.push({
|
||||
"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){
|
||||
if(typeof(bool) === "undefined") {
|
||||
return this.container.style.visibility;
|
||||
|
|
2
build/epub.min.js
vendored
2
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -2127,7 +2127,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
|
||||
|
||||
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
|
||||
var nextPage = true;//pager.nextPage();
|
||||
var nextPage = true;
|
||||
|
||||
// Page though the entire chapter
|
||||
while (nextPage) {
|
||||
nextPage = pager.nextPage();
|
||||
|
@ -2573,12 +2574,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
|
|||
|
||||
EPUBJS.Book.prototype.goto = function(target){
|
||||
|
||||
if(typeof target === "number"){
|
||||
return this.gotoPage(target);
|
||||
} else if(target.indexOf("epubcfi(") === 0) {
|
||||
if(target.indexOf("epubcfi(") === 0) {
|
||||
return this.gotoCfi(target);
|
||||
} 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 {
|
||||
return this.gotoHref(target);
|
||||
}
|
||||
|
@ -2674,14 +2675,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
|
|||
//-- Load new chapter if different than current
|
||||
return this.displayChapter(spinePos).then(function(){
|
||||
if(section){
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}.bind(this));
|
||||
}else{
|
||||
//-- Only goto section
|
||||
if(section) {
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}
|
||||
|
@ -2700,7 +2701,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
|
|||
|
||||
EPUBJS.Book.prototype.gotoPercentage = function(percent){
|
||||
var pg = this.pagination.pageFromPercentage(percent);
|
||||
return this.gotoCfi(pg);
|
||||
return this.gotoPage(pg);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.preloadNextChapter = function() {
|
||||
|
@ -4529,6 +4530,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
content = findAnchorOrSpan(item),
|
||||
href = content.getAttribute('href') || '',
|
||||
text = content.textContent || "",
|
||||
page = parseInt(text),
|
||||
isCfi = href.indexOf("epubcfi"),
|
||||
split,
|
||||
packageUrl,
|
||||
|
@ -4542,12 +4544,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
"cfi" : cfi,
|
||||
"href" : href,
|
||||
"packageUrl" : packageUrl,
|
||||
"page" : text
|
||||
"page" : page
|
||||
});
|
||||
} else {
|
||||
list.push({
|
||||
"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){
|
||||
if(typeof(bool) === "undefined") {
|
||||
return this.container.style.visibility;
|
||||
|
|
|
@ -30,6 +30,7 @@ EPUBJS.Reader = function(path, _options) {
|
|||
var reader = this;
|
||||
var book;
|
||||
var plugin;
|
||||
var $viewer = $("#viewer");
|
||||
|
||||
this.settings = _.defaults(_options || {}, {
|
||||
restore : true,
|
||||
|
@ -39,7 +40,8 @@ EPUBJS.Reader = function(path, _options) {
|
|||
bookKey : null,
|
||||
styles : null,
|
||||
sidebarReflow: false,
|
||||
generatePagination: false
|
||||
generatePagination: false,
|
||||
history: true
|
||||
});
|
||||
|
||||
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) {
|
||||
book.generatePagination(1076, 588);
|
||||
book.generatePagination($viewer.width(), $viewer.height());
|
||||
}
|
||||
|
||||
book.renderTo("viewer");
|
||||
|
@ -104,11 +106,15 @@ EPUBJS.Reader = function(path, _options) {
|
|||
|
||||
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||
|
||||
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
|
||||
|
||||
document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
|
||||
|
||||
book.on("renderer:keydown", this.adjustFontSize.bind(this));
|
||||
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
|
||||
|
||||
book.on("renderer:selected", this.selectedRange.bind(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
|
||||
RSVP.EventTarget.mixin(EPUBJS.Reader.prototype);
|
||||
EPUBJS.reader.BookmarksController = function() {
|
||||
|
@ -399,10 +415,14 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
.removeClass("icon-bookmark-empty");
|
||||
}
|
||||
|
||||
// Update the History Location
|
||||
if(reader.settings.history) {
|
||||
history.pushState({}, '', "#"+cfi);
|
||||
}
|
||||
});
|
||||
|
||||
book.on('book:pageChanged', function(location){
|
||||
console.log("page", location.page, location.percentage)
|
||||
// console.log("page", location.page, location.percentage)
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
2
demo/js/epub.min.js
vendored
2
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/reader.min.js
vendored
2
demo/js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -92,10 +92,14 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
.removeClass("icon-bookmark-empty");
|
||||
}
|
||||
|
||||
// Update the History Location
|
||||
if(reader.settings.history) {
|
||||
history.pushState({}, '', "#"+cfi);
|
||||
}
|
||||
});
|
||||
|
||||
book.on('book:pageChanged', function(location){
|
||||
console.log("page", location.page, location.percentage)
|
||||
// console.log("page", location.page, location.percentage)
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -30,6 +30,7 @@ EPUBJS.Reader = function(path, _options) {
|
|||
var reader = this;
|
||||
var book;
|
||||
var plugin;
|
||||
var $viewer = $("#viewer");
|
||||
|
||||
this.settings = _.defaults(_options || {}, {
|
||||
restore : true,
|
||||
|
@ -39,7 +40,8 @@ EPUBJS.Reader = function(path, _options) {
|
|||
bookKey : null,
|
||||
styles : null,
|
||||
sidebarReflow: false,
|
||||
generatePagination: false
|
||||
generatePagination: false,
|
||||
history: true
|
||||
});
|
||||
|
||||
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) {
|
||||
book.generatePagination(1076, 588);
|
||||
book.generatePagination($viewer.width(), $viewer.height());
|
||||
}
|
||||
|
||||
book.renderTo("viewer");
|
||||
|
@ -104,11 +106,15 @@ EPUBJS.Reader = function(path, _options) {
|
|||
|
||||
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||
|
||||
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
|
||||
|
||||
document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
|
||||
|
||||
book.on("renderer:keydown", this.adjustFontSize.bind(this));
|
||||
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
|
||||
|
||||
book.on("renderer:selected", this.selectedRange.bind(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
|
||||
RSVP.EventTarget.mixin(EPUBJS.Reader.prototype);
|
17
src/book.js
17
src/book.js
|
@ -352,7 +352,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){
|
|||
chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store);
|
||||
|
||||
pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){
|
||||
var nextPage = true;//pager.nextPage();
|
||||
var nextPage = true;
|
||||
|
||||
// Page though the entire chapter
|
||||
while (nextPage) {
|
||||
nextPage = pager.nextPage();
|
||||
|
@ -798,12 +799,12 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
|
|||
|
||||
EPUBJS.Book.prototype.goto = function(target){
|
||||
|
||||
if(typeof target === "number"){
|
||||
return this.gotoPage(target);
|
||||
} else if(target.indexOf("epubcfi(") === 0) {
|
||||
if(target.indexOf("epubcfi(") === 0) {
|
||||
return this.gotoCfi(target);
|
||||
} 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 {
|
||||
return this.gotoHref(target);
|
||||
}
|
||||
|
@ -899,14 +900,14 @@ EPUBJS.Book.prototype.gotoHref = function(url, defer){
|
|||
//-- Load new chapter if different than current
|
||||
return this.displayChapter(spinePos).then(function(){
|
||||
if(section){
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}.bind(this));
|
||||
}else{
|
||||
//-- Only goto section
|
||||
if(section) {
|
||||
this.render.section(section);
|
||||
this.renderer.section(section);
|
||||
}
|
||||
deferred.resolve(this.renderer.currentLocationCfi);
|
||||
}
|
||||
|
@ -925,7 +926,7 @@ EPUBJS.Book.prototype.gotoPage = function(pg){
|
|||
|
||||
EPUBJS.Book.prototype.gotoPercentage = function(percent){
|
||||
var pg = this.pagination.pageFromPercentage(percent);
|
||||
return this.gotoCfi(pg);
|
||||
return this.gotoPage(pg);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.preloadNextChapter = function() {
|
||||
|
|
|
@ -425,6 +425,7 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
content = findAnchorOrSpan(item),
|
||||
href = content.getAttribute('href') || '',
|
||||
text = content.textContent || "",
|
||||
page = parseInt(text),
|
||||
isCfi = href.indexOf("epubcfi"),
|
||||
split,
|
||||
packageUrl,
|
||||
|
@ -438,12 +439,12 @@ EPUBJS.Parser.prototype.pageList = function(navHtml, spineIndexByURL, bookSpine)
|
|||
"cfi" : cfi,
|
||||
"href" : href,
|
||||
"packageUrl" : packageUrl,
|
||||
"page" : text
|
||||
"page" : page
|
||||
});
|
||||
} else {
|
||||
list.push({
|
||||
"href" : href,
|
||||
"page" : text
|
||||
"page" : page
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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){
|
||||
if(typeof(bool) === "undefined") {
|
||||
return this.container.style.visibility;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue