diff --git a/examples/locations.html b/examples/locations.html index 788c8f2..ab0c148 100644 --- a/examples/locations.html +++ b/examples/locations.html @@ -31,7 +31,7 @@ var mouseDown = false; // 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", { width: "100%", height: 500 @@ -77,7 +77,7 @@ book.ready.then(function(){ // Load in stored locations from json or local storage var key = book.key()+'-locations'; - var stored = localStorage.getItem(key); + var stored = false;//localStorage.getItem(key); if (stored) { return book.locations.load(stored); } else { diff --git a/src/book.js b/src/book.js index 76d5b72..856d5fb 100644 --- a/src/book.js +++ b/src/book.js @@ -321,9 +321,9 @@ Book.prototype.unpack = function(opf){ replacements: this.settings.replacements }); - this.loadNavigation(this.package).then(function(toc){ - this.toc = toc; - this.loading.navigation.resolve(this.toc); + this.loadNavigation(this.package).then(function(){ + this.toc = this.navigation.toc; + this.loading.navigation.resolve(this.navigation); }.bind(this)); this.cover = this.resolve(this.package.coverPath); @@ -366,6 +366,7 @@ Book.prototype.loadNavigation = function(opf){ .then(function(xml) { this.navigation = new Navigation(xml); this.pageList = new PageList(xml); + return this.navigation; }.bind(this)); }; @@ -480,7 +481,7 @@ Book.prototype.range = function(cfiRange) { */ Book.prototype.key = function(identifier){ 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 diff --git a/src/epub.js b/src/epub.js index c249a90..4426b6e 100644 --- a/src/epub.js +++ b/src/epub.js @@ -16,6 +16,10 @@ function ePub(url, options) { ePub.VERSION = "0.3.0"; +if (typeof(global) !== "undefined") { + global.EPUBJS_VERSION = ePub.VERSION; +} + ePub.CFI = EpubCFI; ePub.Rendition = Rendition; ePub.Contents = Contents; diff --git a/src/locations.js b/src/locations.js index a276eb1..8c5eb5f 100644 --- a/src/locations.js +++ b/src/locations.js @@ -70,7 +70,7 @@ Locations.prototype.process = function(section) { var len = node.length; var dist; var pos = 0; - + console.log(counter); // Start range if (counter == 0) { range = doc.createRange(); @@ -84,6 +84,7 @@ Locations.prototype.process = function(section) { counter += len; pos = len; } + console.log(counter); while (pos < len) { counter = this.break; @@ -101,12 +102,14 @@ Locations.prototype.process = function(section) { cfi = section.cfiFromRange(range); this._locations.push(cfi); counter = 0; + console.log(cfi); // Start new range pos += 1; range = doc.createRange(); range.setStart(node, pos); } + console.log(counter); } diff --git a/src/navigation.js b/src/navigation.js index 0c21486..776ff20 100644 --- a/src/navigation.js +++ b/src/navigation.js @@ -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; diff --git a/src/rendition.js b/src/rendition.js index 4d79f8e..6b4d09a 100644 --- a/src/rendition.js +++ b/src/rendition.js @@ -250,7 +250,7 @@ Rendition.prototype._display = function(target){ return this.manager.display(section, moveTo) .then(function(){ - this.emit("displayed", section); + // this.emit("displayed", section); }.bind(this)); }; diff --git a/src/resources.js b/src/resources.js index 7572daf..0d72acb 100644 --- a/src/resources.js +++ b/src/resources.js @@ -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;