update epub.js
This commit is contained in:
parent
3c12da48d3
commit
c0190bd7d1
9 changed files with 118 additions and 104 deletions
122
epub.js/epub.js
122
epub.js/epub.js
|
@ -5377,20 +5377,6 @@ EPUBJS.Parser.prototype.findTocPath = function(manifestNode, spineNode){
|
||||||
return node ? node.getAttribute('href') : false;
|
return node ? node.getAttribute('href') : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-- Find Cover: <item properties="cover-image" id="ci" href="cover.svg" media-type="image/svg+xml" />
|
|
||||||
//-- Fallback for Epub 2.0
|
|
||||||
EPUBJS.Parser.prototype.findCoverPath = function(packageXml){
|
|
||||||
var epubVersion = packageXml.querySelector('package').getAttribute('version');
|
|
||||||
if (epubVersion === '2.0') {
|
|
||||||
var coverId = packageXml.querySelector('meta[name="cover"]').getAttribute('content');
|
|
||||||
return packageXml.querySelector("item[id='" + coverId + "']").getAttribute('href');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var node = packageXml.querySelector("item[properties='cover-image']");
|
|
||||||
return node ? node.getAttribute('href') : false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//-- Expanded to match Readium web components
|
//-- Expanded to match Readium web components
|
||||||
EPUBJS.Parser.prototype.metadata = function(xml){
|
EPUBJS.Parser.prototype.metadata = function(xml){
|
||||||
var metadata = {},
|
var metadata = {},
|
||||||
|
@ -5416,6 +5402,28 @@ EPUBJS.Parser.prototype.metadata = function(xml){
|
||||||
return metadata;
|
return metadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-- Find Cover: <item properties="cover-image" id="ci" href="cover.svg" media-type="image/svg+xml" />
|
||||||
|
//-- Fallback for Epub 2.0
|
||||||
|
EPUBJS.Parser.prototype.findCoverPath = function(packageXml){
|
||||||
|
|
||||||
|
var epubVersion = packageXml.querySelector('package').getAttribute('version');
|
||||||
|
if (epubVersion === '2.0') {
|
||||||
|
var metaCover = packageXml.querySelector('meta[name="cover"]');
|
||||||
|
if (metaCover) {
|
||||||
|
var coverId = metaCover.getAttribute('content');
|
||||||
|
var cover = packageXml.querySelector("item[id='" + coverId + "']");
|
||||||
|
return cover ? cover.getAttribute('href') : false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var node = packageXml.querySelector("item[properties='cover-image']");
|
||||||
|
return node ? node.getAttribute('href') : false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
EPUBJS.Parser.prototype.getElementText = function(xml, tag){
|
EPUBJS.Parser.prototype.getElementText = function(xml, tag){
|
||||||
var found = xml.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/", tag),
|
var found = xml.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/", tag),
|
||||||
el;
|
el;
|
||||||
|
@ -6296,7 +6304,6 @@ EPUBJS.Renderer.prototype.updatePages = function(layout){
|
||||||
this.displayedPages = this.pageMap.length;
|
this.displayedPages = this.pageMap.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.currentChapter.pages = layout.pageCount;
|
|
||||||
this.currentChapter.pages = this.pageMap.length;
|
this.currentChapter.pages = this.pageMap.length;
|
||||||
|
|
||||||
this._q.flush();
|
this._q.flush();
|
||||||
|
@ -6597,12 +6604,16 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
var elLimit = 0;
|
var elLimit = 0;
|
||||||
var prevRange;
|
var prevRange;
|
||||||
var cfi;
|
var cfi;
|
||||||
|
var lastChildren = null;
|
||||||
|
var prevElement;
|
||||||
|
var startRange, endRange;
|
||||||
|
var startCfi, endCfi;
|
||||||
var check = function(node) {
|
var check = function(node) {
|
||||||
var elPos;
|
var elPos;
|
||||||
var elRange;
|
var elRange;
|
||||||
var children = Array.prototype.slice.call(node.childNodes);
|
var found;
|
||||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
if (node.nodeType == Node.TEXT_NODE) {
|
||||||
// elPos = node.getBoundingClientRect();
|
|
||||||
elRange = document.createRange();
|
elRange = document.createRange();
|
||||||
elRange.selectNodeContents(node);
|
elRange.selectNodeContents(node);
|
||||||
elPos = elRange.getBoundingClientRect();
|
elPos = elRange.getBoundingClientRect();
|
||||||
|
@ -6613,28 +6624,26 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
|
|
||||||
//-- Element starts new Col
|
//-- Element starts new Col
|
||||||
if(elPos.left > elLimit) {
|
if(elPos.left > elLimit) {
|
||||||
children.forEach(function(node){
|
found = checkText(node);
|
||||||
if(node.nodeType == Node.TEXT_NODE &&
|
|
||||||
node.textContent.trim().length) {
|
|
||||||
checkText(node);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- Element Spans new Col
|
//-- Element Spans new Col
|
||||||
if(elPos.right > elLimit) {
|
if(elPos.right > elLimit) {
|
||||||
children.forEach(function(node){
|
found = checkText(node);
|
||||||
if(node.nodeType == Node.TEXT_NODE &&
|
|
||||||
node.textContent.trim().length) {
|
|
||||||
checkText(node);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
prevElement = node;
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
prevRange = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
var checkText = function(node){
|
var checkText = function(node){
|
||||||
|
var result;
|
||||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||||
|
var prevRanges;
|
||||||
ranges.forEach(function(range){
|
ranges.forEach(function(range){
|
||||||
var pos = range.getBoundingClientRect();
|
var pos = range.getBoundingClientRect();
|
||||||
|
|
||||||
|
@ -6646,18 +6655,25 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||||
// map[page-1].start = cfi;
|
// map[page-1].start = cfi;
|
||||||
map.push({ start: cfi, end: null });
|
result = map.push({ start: cfi, end: null });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Previous Range is null since we already found our last map pair
|
||||||
|
// Use that last walked textNode
|
||||||
|
if(!prevRange && prevElement) {
|
||||||
|
prevRanges = renderer.splitTextNodeIntoWordsRanges(prevElement);
|
||||||
|
prevRange = prevRanges[prevRanges.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
if(prevRange){
|
if(prevRange){
|
||||||
prevRange.collapse(true);
|
prevRange.collapse(false);
|
||||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||||
map[map.length-1].end = cfi;
|
map[map.length-1].end = cfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||||
map.push({
|
result = map.push({
|
||||||
start: cfi,
|
start: cfi,
|
||||||
end: null
|
end: null
|
||||||
});
|
});
|
||||||
|
@ -6670,7 +6686,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
prevRange = range;
|
prevRange = range;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
var docEl = this.render.getDocumentElement();
|
var docEl = this.render.getDocumentElement();
|
||||||
var dir = docEl.dir;
|
var dir = docEl.dir;
|
||||||
|
@ -6681,7 +6697,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
docEl.style.position = "static";
|
docEl.style.position = "static";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sprint(root, check);
|
this.textSprint(root, check);
|
||||||
|
|
||||||
// Reset back to previous RTL settings
|
// Reset back to previous RTL settings
|
||||||
if(dir == "rtl") {
|
if(dir == "rtl") {
|
||||||
|
@ -6690,31 +6706,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
||||||
docEl.style.right = "0";
|
docEl.style.right = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.textSprint(root, checkText);
|
// Check the remaining children that fit on this page
|
||||||
|
// to ensure the end is correctly calculated
|
||||||
|
if(!prevRange && prevElement) {
|
||||||
|
prevRanges = renderer.splitTextNodeIntoWordsRanges(prevElement);
|
||||||
|
prevRange = prevRanges[prevRanges.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
if(prevRange){
|
if(prevRange){
|
||||||
prevRange.collapse(true);
|
prevRange.collapse(false);
|
||||||
|
|
||||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||||
map[map.length-1].end = cfi;
|
map[map.length-1].end = cfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle empty map
|
// Handle empty map
|
||||||
if(!map.length) {
|
if(!map.length) {
|
||||||
range = this.doc.createRange();
|
startRange = this.doc.createRange();
|
||||||
range.selectNodeContents(root);
|
startRange.selectNodeContents(root);
|
||||||
range.collapse(true);
|
startRange.collapse(true);
|
||||||
|
startCfi = renderer.currentChapter.cfiFromRange(startRange);
|
||||||
|
|
||||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
endRange = this.doc.createRange();
|
||||||
|
endRange.selectNodeContents(root);
|
||||||
|
endRange.collapse(false);
|
||||||
|
endCfi = renderer.currentChapter.cfiFromRange(endRange);
|
||||||
|
|
||||||
map.push({ start: cfi, end: cfi });
|
|
||||||
|
map.push({ start: startCfi, end: endCfi });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
prevRange = null;
|
prevRange = null;
|
||||||
|
prevRanges = null;
|
||||||
ranges = null;
|
ranges = null;
|
||||||
range = null;
|
startRange = null;
|
||||||
|
endRange = null;
|
||||||
root = null;
|
root = null;
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
@ -6746,7 +6773,7 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||||
var range;
|
var range;
|
||||||
var rect;
|
var rect;
|
||||||
var list;
|
var list;
|
||||||
// jaroslaw.bielski@7bulls.com
|
|
||||||
// Usage of indexOf() function for space character as word delimiter
|
// Usage of indexOf() function for space character as word delimiter
|
||||||
// is not sufficient in case of other breakable characters like \r\n- etc
|
// is not sufficient in case of other breakable characters like \r\n- etc
|
||||||
pos = this.indexOfBreakableChar(text);
|
pos = this.indexOfBreakableChar(text);
|
||||||
|
@ -6762,7 +6789,6 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
||||||
range.setEnd(node, pos);
|
range.setEnd(node, pos);
|
||||||
ranges.push(range);
|
ranges.push(range);
|
||||||
|
|
||||||
// jaroslaw.bielski@7bulls.com
|
|
||||||
// there was a word miss in case of one letter words
|
// there was a word miss in case of one letter words
|
||||||
range = this.doc.createRange();
|
range = this.doc.createRange();
|
||||||
range.setStart(node, pos+1);
|
range.setStart(node, pos+1);
|
||||||
|
@ -6904,7 +6930,7 @@ EPUBJS.Renderer.prototype.currentRenderedPage = function(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.spreads && this.layout.pageCount > 1) {
|
if (this.spreads && this.pageMap.length > 1) {
|
||||||
pg = this.chapterPos*2;
|
pg = this.chapterPos*2;
|
||||||
} else {
|
} else {
|
||||||
pg = this.chapterPos;
|
pg = this.chapterPos;
|
||||||
|
@ -6950,7 +6976,7 @@ EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
||||||
startRange = this.pageMap[pg-2];
|
startRange = this.pageMap[pg-2];
|
||||||
endRange = startRange;
|
endRange = startRange;
|
||||||
|
|
||||||
if(this.layout.pageCount > 1) {
|
if(this.pageMap.length > 1) {
|
||||||
endRange = this.pageMap[pg-1];
|
endRange = this.pageMap[pg-1];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -7218,7 +7244,7 @@ EPUBJS.replace = {};
|
||||||
EPUBJS.replace.hrefs = function(callback, renderer){
|
EPUBJS.replace.hrefs = function(callback, renderer){
|
||||||
var book = this;
|
var book = this;
|
||||||
var replacments = function(link, done){
|
var replacments = function(link, done){
|
||||||
var href = link.getAttribute("href"),
|
var href = decodeURI(link.getAttribute("href")),
|
||||||
isRelative = href.search("://"),
|
isRelative = href.search("://"),
|
||||||
directory,
|
directory,
|
||||||
relative,
|
relative,
|
||||||
|
|
File diff suppressed because one or more lines are too long
6
epub.js/epub.min.js
vendored
6
epub.js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,8 +1,13 @@
|
||||||
|
// Hypothesis Customized embedding
|
||||||
|
// This hypothesis config function returns a new constructor which modifies
|
||||||
|
// annotator for a better integration. Below we create our own EpubAnnotationSidebar
|
||||||
|
// Constructor, customizing the show and hide function to take acount for the reader UI.
|
||||||
|
|
||||||
window.hypothesisConfig = function() {
|
window.hypothesisConfig = function() {
|
||||||
var Annotator = window.Annotator;
|
var Annotator = window.Annotator;
|
||||||
var $main = $("#main");
|
var $main = $("#main");
|
||||||
|
|
||||||
function MySidebar(elem, options) {
|
function EpubAnnotationSidebar(elem, options) {
|
||||||
options = {
|
options = {
|
||||||
server: true,
|
server: true,
|
||||||
origin: true,
|
origin: true,
|
||||||
|
@ -13,9 +18,9 @@ window.hypothesisConfig = function() {
|
||||||
Annotator.Host.call(this, elem, options);
|
Annotator.Host.call(this, elem, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
MySidebar.prototype = Object.create(Annotator.Host.prototype);
|
EpubAnnotationSidebar.prototype = Object.create(Annotator.Host.prototype);
|
||||||
|
|
||||||
MySidebar.prototype.show = function() {
|
EpubAnnotationSidebar.prototype.show = function() {
|
||||||
this.frame.css({
|
this.frame.css({
|
||||||
'margin-left': (-1 * this.frame.width()) + "px"
|
'margin-left': (-1 * this.frame.width()) + "px"
|
||||||
});
|
});
|
||||||
|
@ -27,7 +32,7 @@ window.hypothesisConfig = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MySidebar.prototype.hide = function() {
|
EpubAnnotationSidebar.prototype.hide = function() {
|
||||||
this.frame.css({
|
this.frame.css({
|
||||||
'margin-left': ''
|
'margin-left': ''
|
||||||
});
|
});
|
||||||
|
@ -40,11 +45,11 @@ window.hypothesisConfig = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
constructor: MySidebar,
|
constructor: EpubAnnotationSidebar,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is the Epub.js plugin. Annotations are updated on location change.
|
||||||
EPUBJS.reader.plugins.HypothesisController = function (Book) {
|
EPUBJS.reader.plugins.HypothesisController = function (Book) {
|
||||||
var reader = this;
|
var reader = this;
|
||||||
var $main = $("#main");
|
var $main = $("#main");
|
||||||
|
@ -69,25 +74,7 @@ EPUBJS.reader.plugins.HypothesisController = function (Book) {
|
||||||
}).get();
|
}).get();
|
||||||
};
|
};
|
||||||
|
|
||||||
// $("#annotations").on("click", function () {
|
|
||||||
// var annotator = Book.renderer.render.window.annotator;
|
|
||||||
// var currentPosition = Book.getCurrentLocationCfi();
|
|
||||||
|
|
||||||
// if ($main.hasClass("single")) {
|
|
||||||
// $main.removeClass("single");
|
|
||||||
// annotator.setVisibleHighlights(false);
|
|
||||||
// } else {
|
|
||||||
// $main.addClass("single");
|
|
||||||
// annotator.setVisibleHighlights(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $main.one("transitionend", function(){
|
|
||||||
// Book.gotoCfi(currentPosition);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
Book.on("renderer:locationChanged", updateAnnotations);
|
Book.on("renderer:locationChanged", updateAnnotations);
|
||||||
// Book.on("renderer:chapterDisplayed", updateAnnotations);
|
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -349,7 +349,7 @@ EPUBJS.reader.BookmarksController = function() {
|
||||||
link.classList.add('bookmark_link');
|
link.classList.add('bookmark_link');
|
||||||
|
|
||||||
link.addEventListener("click", function(event){
|
link.addEventListener("click", function(event){
|
||||||
var cfi = this.getAttribute('href');
|
var cfi = decodeURI(this.getAttribute('href'));
|
||||||
book.gotoCfi(cfi);
|
book.gotoCfi(cfi);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -383,6 +383,7 @@ EPUBJS.reader.BookmarksController = function() {
|
||||||
"hide" : hide
|
"hide" : hide
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
EPUBJS.reader.ControlsController = function(book) {
|
EPUBJS.reader.ControlsController = function(book) {
|
||||||
var reader = this;
|
var reader = this;
|
||||||
|
|
||||||
|
@ -1109,7 +1110,7 @@ EPUBJS.reader.TocController = function(toc) {
|
||||||
|
|
||||||
$list.append(docfrag);
|
$list.append(docfrag);
|
||||||
$list.find(".toc_link").on("click", function(event){
|
$list.find(".toc_link").on("click", function(event){
|
||||||
var url = this.getAttribute('href');
|
var url = decodeURI(this.getAttribute('href'));
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
2
epub.js/reader.min.js
vendored
2
epub.js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue