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:
commit
0056b5f2c4
4 changed files with 26 additions and 4 deletions
|
@ -269,8 +269,12 @@ EPUBJS.Reader.prototype.applySavedSettings = function() {
|
|||
if(!localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
stored = JSON.parse(localStorage.getItem(this.settings.bookKey));
|
||||
} catch (e) { // parsing error of localStorage
|
||||
return false;
|
||||
}
|
||||
|
||||
if(stored) {
|
||||
this.settings = _.defaults(this.settings, stored);
|
||||
|
|
|
@ -40,8 +40,14 @@ EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) {
|
|||
// Start of Chapter
|
||||
return "epubcfi(" + chapter + "!/4/)";
|
||||
} 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
|
||||
return "epubcfi(" + chapter + "!" + path + "/1:0)";
|
||||
return "epubcfi(" + chapter + "!" + path + offset + ")";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -484,6 +484,15 @@ EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) {
|
|||
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
|
||||
EPUBJS.Renderer.prototype.walk = function(node, x, y) {
|
||||
var r, children, leng,
|
||||
|
@ -495,7 +504,7 @@ EPUBJS.Renderer.prototype.walk = function(node, x, y) {
|
|||
|
||||
while(!r && stack.length) {
|
||||
node = stack.shift();
|
||||
if( this.containsPoint(node, x, y) && this.firstElementisTextNode(node)) {
|
||||
if( this.containsPoint(node, x, y) && this.isGoodNode(node)) {
|
||||
r = node;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,10 @@ EPUBJS.replace.links = function(_store, full, done, link){
|
|||
}, 5); //-- Allow for css to apply before displaying chapter
|
||||
});
|
||||
}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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue