1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Merge pull request #1 from futurepress/master

Update to current epub js
This commit is contained in:
dsk7 2015-01-10 16:02:21 +01:00
commit 0056b5f2c4
4 changed files with 26 additions and 4 deletions

View file

@ -269,8 +269,12 @@ EPUBJS.Reader.prototype.applySavedSettings = function() {
if(!localStorage) { if(!localStorage) {
return false; return false;
} }
try {
stored = JSON.parse(localStorage.getItem(this.settings.bookKey)); stored = JSON.parse(localStorage.getItem(this.settings.bookKey));
} catch (e) { // parsing error of localStorage
return false;
}
if(stored) { if(stored) {
this.settings = _.defaults(this.settings, stored); this.settings = _.defaults(this.settings, stored);

View file

@ -40,8 +40,14 @@ EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) {
// Start of Chapter // Start of Chapter
return "epubcfi(" + chapter + "!/4/)"; return "epubcfi(" + chapter + "!/4/)";
} else { } else {
var offset = "";
var embeddedElements = ["audio", "canvas", "embed", "iframe", "img", "math", "object", "svg", "video"];
if (embeddedElements.indexOf(element.tagName.toLowerCase()) === -1) {
// if the element could contain text, set the character offset;
offset += "/1:0";
}
// First Text Node // First Text Node
return "epubcfi(" + chapter + "!" + path + "/1:0)"; return "epubcfi(" + chapter + "!" + path + offset + ")";
} }
}; };

View file

@ -484,6 +484,15 @@ EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) {
return false; return false;
}; };
EPUBJS.Renderer.prototype.isGoodNode = function(node) {
var embeddedElements = ["audio", "canvas", "embed", "iframe", "img", "math", "object", "svg", "video"];
if (embeddedElements.indexOf(node.tagName.toLowerCase()) !== -1) {
// Embedded elements usually do not have a text node as first element, but are also good nodes
return true;
}
return this.firstElementisTextNode(node);
};
// Walk the node tree from a start element to next visible element // Walk the node tree from a start element to next visible element
EPUBJS.Renderer.prototype.walk = function(node, x, y) { EPUBJS.Renderer.prototype.walk = function(node, x, y) {
var r, children, leng, var r, children, leng,
@ -495,7 +504,7 @@ EPUBJS.Renderer.prototype.walk = function(node, x, y) {
while(!r && stack.length) { while(!r && stack.length) {
node = stack.shift(); node = stack.shift();
if( this.containsPoint(node, x, y) && this.firstElementisTextNode(node)) { if( this.containsPoint(node, x, y) && this.isGoodNode(node)) {
r = node; r = node;
} }

View file

@ -77,7 +77,10 @@ EPUBJS.replace.links = function(_store, full, done, link){
}, 5); //-- Allow for css to apply before displaying chapter }, 5); //-- Allow for css to apply before displaying chapter
}); });
}else{ }else{
_store.getUrl(full).then(done); _store.getUrl(full).then(done, function(reason) {
// we were unable to get the url, signal to upper layer
done(null);
});
} }
}; };