mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Add resources.substitute back, fix toc promise
This commit is contained in:
parent
8edc82244c
commit
662a3e1079
7 changed files with 43 additions and 8 deletions
|
@ -31,7 +31,7 @@
|
||||||
var mouseDown = false;
|
var mouseDown = false;
|
||||||
|
|
||||||
// Load the opf
|
// Load the opf
|
||||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
var book = ePub("../test/fixtures/alice/OPS/package.opf");
|
||||||
var rendition = book.renderTo("viewer", {
|
var rendition = book.renderTo("viewer", {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: 500
|
height: 500
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
book.ready.then(function(){
|
book.ready.then(function(){
|
||||||
// Load in stored locations from json or local storage
|
// Load in stored locations from json or local storage
|
||||||
var key = book.key()+'-locations';
|
var key = book.key()+'-locations';
|
||||||
var stored = localStorage.getItem(key);
|
var stored = false;//localStorage.getItem(key);
|
||||||
if (stored) {
|
if (stored) {
|
||||||
return book.locations.load(stored);
|
return book.locations.load(stored);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -321,9 +321,9 @@ Book.prototype.unpack = function(opf){
|
||||||
replacements: this.settings.replacements
|
replacements: this.settings.replacements
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loadNavigation(this.package).then(function(toc){
|
this.loadNavigation(this.package).then(function(){
|
||||||
this.toc = toc;
|
this.toc = this.navigation.toc;
|
||||||
this.loading.navigation.resolve(this.toc);
|
this.loading.navigation.resolve(this.navigation);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.cover = this.resolve(this.package.coverPath);
|
this.cover = this.resolve(this.package.coverPath);
|
||||||
|
@ -366,6 +366,7 @@ Book.prototype.loadNavigation = function(opf){
|
||||||
.then(function(xml) {
|
.then(function(xml) {
|
||||||
this.navigation = new Navigation(xml);
|
this.navigation = new Navigation(xml);
|
||||||
this.pageList = new PageList(xml);
|
this.pageList = new PageList(xml);
|
||||||
|
return this.navigation;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -480,7 +481,7 @@ Book.prototype.range = function(cfiRange) {
|
||||||
*/
|
*/
|
||||||
Book.prototype.key = function(identifier){
|
Book.prototype.key = function(identifier){
|
||||||
var ident = identifier || this.package.metadata.identifier || this.url.filename;
|
var ident = identifier || this.package.metadata.identifier || this.url.filename;
|
||||||
return "epubjs:" + ePub.VERSION + ":" + ident;
|
return "epubjs:" + (EPUBJS_VERSION || ePub.VERSION) + ":" + ident;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-- Enable binding events to book
|
//-- Enable binding events to book
|
||||||
|
|
|
@ -16,6 +16,10 @@ function ePub(url, options) {
|
||||||
|
|
||||||
ePub.VERSION = "0.3.0";
|
ePub.VERSION = "0.3.0";
|
||||||
|
|
||||||
|
if (typeof(global) !== "undefined") {
|
||||||
|
global.EPUBJS_VERSION = ePub.VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
ePub.CFI = EpubCFI;
|
ePub.CFI = EpubCFI;
|
||||||
ePub.Rendition = Rendition;
|
ePub.Rendition = Rendition;
|
||||||
ePub.Contents = Contents;
|
ePub.Contents = Contents;
|
||||||
|
|
|
@ -70,7 +70,7 @@ Locations.prototype.process = function(section) {
|
||||||
var len = node.length;
|
var len = node.length;
|
||||||
var dist;
|
var dist;
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
|
console.log(counter);
|
||||||
// Start range
|
// Start range
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
range = doc.createRange();
|
range = doc.createRange();
|
||||||
|
@ -84,6 +84,7 @@ Locations.prototype.process = function(section) {
|
||||||
counter += len;
|
counter += len;
|
||||||
pos = len;
|
pos = len;
|
||||||
}
|
}
|
||||||
|
console.log(counter);
|
||||||
|
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
counter = this.break;
|
counter = this.break;
|
||||||
|
@ -101,12 +102,14 @@ Locations.prototype.process = function(section) {
|
||||||
cfi = section.cfiFromRange(range);
|
cfi = section.cfiFromRange(range);
|
||||||
this._locations.push(cfi);
|
this._locations.push(cfi);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
console.log(cfi);
|
||||||
|
|
||||||
// Start new range
|
// Start new range
|
||||||
pos += 1;
|
pos += 1;
|
||||||
range = doc.createRange();
|
range = doc.createRange();
|
||||||
range.setStart(node, pos);
|
range.setStart(node, pos);
|
||||||
}
|
}
|
||||||
|
console.log(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -188,4 +188,13 @@ Navigation.prototype.ncxItem = function(item){
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* forEach pass through
|
||||||
|
* @param {Function} fn function to run on each item
|
||||||
|
* @return {method} forEach loop
|
||||||
|
*/
|
||||||
|
Navigation.prototype.forEach = function(fn) {
|
||||||
|
return this.toc.forEach(fn);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = Navigation;
|
module.exports = Navigation;
|
||||||
|
|
|
@ -250,7 +250,7 @@ Rendition.prototype._display = function(target){
|
||||||
|
|
||||||
return this.manager.display(section, moveTo)
|
return this.manager.display(section, moveTo)
|
||||||
.then(function(){
|
.then(function(){
|
||||||
this.emit("displayed", section);
|
// this.emit("displayed", section);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -224,4 +224,22 @@ Resources.prototype.get = function(path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Substitute urls in content, with replacements,
|
||||||
|
* relative to a url if provided
|
||||||
|
* @param {string} content
|
||||||
|
* @param {[string]} url url to resolve to
|
||||||
|
* @return {string} content with urls substituted
|
||||||
|
*/
|
||||||
|
Resources.prototype.substitute = function(content, url) {
|
||||||
|
var relUrls;
|
||||||
|
if (url) {
|
||||||
|
relUrls = this.relativeTo(url);
|
||||||
|
} else {
|
||||||
|
relUrls = this.urls;
|
||||||
|
}
|
||||||
|
return replace.substitute(content, relUrls, this.replacementUrls);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = Resources;
|
module.exports = Resources;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue