update epub.js
This commit is contained in:
parent
3c12da48d3
commit
c0190bd7d1
9 changed files with 118 additions and 104 deletions
124
epub.js/epub.js
124
epub.js/epub.js
|
@ -5377,20 +5377,6 @@ EPUBJS.Parser.prototype.findTocPath = function(manifestNode, spineNode){
|
|||
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
|
||||
EPUBJS.Parser.prototype.metadata = function(xml){
|
||||
var metadata = {},
|
||||
|
@ -5416,6 +5402,28 @@ EPUBJS.Parser.prototype.metadata = function(xml){
|
|||
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){
|
||||
var found = xml.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/", tag),
|
||||
el;
|
||||
|
@ -6296,7 +6304,6 @@ EPUBJS.Renderer.prototype.updatePages = function(layout){
|
|||
this.displayedPages = this.pageMap.length;
|
||||
}
|
||||
|
||||
// this.currentChapter.pages = layout.pageCount;
|
||||
this.currentChapter.pages = this.pageMap.length;
|
||||
|
||||
this._q.flush();
|
||||
|
@ -6597,12 +6604,16 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
var elLimit = 0;
|
||||
var prevRange;
|
||||
var cfi;
|
||||
var lastChildren = null;
|
||||
var prevElement;
|
||||
var startRange, endRange;
|
||||
var startCfi, endCfi;
|
||||
var check = function(node) {
|
||||
var elPos;
|
||||
var elRange;
|
||||
var children = Array.prototype.slice.call(node.childNodes);
|
||||
if (node.nodeType == Node.ELEMENT_NODE) {
|
||||
// elPos = node.getBoundingClientRect();
|
||||
var found;
|
||||
if (node.nodeType == Node.TEXT_NODE) {
|
||||
|
||||
elRange = document.createRange();
|
||||
elRange.selectNodeContents(node);
|
||||
elPos = elRange.getBoundingClientRect();
|
||||
|
@ -6613,28 +6624,26 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
|
||||
//-- Element starts new Col
|
||||
if(elPos.left > elLimit) {
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
found = checkText(node);
|
||||
}
|
||||
|
||||
//-- Element Spans new Col
|
||||
if(elPos.right > elLimit) {
|
||||
children.forEach(function(node){
|
||||
if(node.nodeType == Node.TEXT_NODE &&
|
||||
node.textContent.trim().length) {
|
||||
checkText(node);
|
||||
}
|
||||
});
|
||||
found = checkText(node);
|
||||
}
|
||||
|
||||
prevElement = node;
|
||||
|
||||
if (found) {
|
||||
prevRange = null;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
var checkText = function(node){
|
||||
var result;
|
||||
var ranges = renderer.splitTextNodeIntoWordsRanges(node);
|
||||
var prevRanges;
|
||||
ranges.forEach(function(range){
|
||||
var pos = range.getBoundingClientRect();
|
||||
|
||||
|
@ -6646,18 +6655,25 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
range.collapse(true);
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
// map[page-1].start = cfi;
|
||||
map.push({ start: cfi, end: null });
|
||||
result = map.push({ start: cfi, end: null });
|
||||
}
|
||||
} 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){
|
||||
prevRange.collapse(true);
|
||||
prevRange.collapse(false);
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[map.length-1].end = cfi;
|
||||
}
|
||||
|
||||
range.collapse(true);
|
||||
cfi = renderer.currentChapter.cfiFromRange(range);
|
||||
map.push({
|
||||
result = map.push({
|
||||
start: cfi,
|
||||
end: null
|
||||
});
|
||||
|
@ -6670,7 +6686,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
prevRange = range;
|
||||
});
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
var docEl = this.render.getDocumentElement();
|
||||
var dir = docEl.dir;
|
||||
|
@ -6681,7 +6697,7 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
docEl.style.position = "static";
|
||||
}
|
||||
|
||||
this.sprint(root, check);
|
||||
this.textSprint(root, check);
|
||||
|
||||
// Reset back to previous RTL settings
|
||||
if(dir == "rtl") {
|
||||
|
@ -6690,31 +6706,42 @@ EPUBJS.Renderer.prototype.mapPage = function(){
|
|||
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){
|
||||
prevRange.collapse(true);
|
||||
|
||||
prevRange.collapse(false);
|
||||
cfi = renderer.currentChapter.cfiFromRange(prevRange);
|
||||
map[map.length-1].end = cfi;
|
||||
}
|
||||
|
||||
// Handle empty map
|
||||
if(!map.length) {
|
||||
range = this.doc.createRange();
|
||||
range.selectNodeContents(root);
|
||||
range.collapse(true);
|
||||
startRange = this.doc.createRange();
|
||||
startRange.selectNodeContents(root);
|
||||
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
|
||||
prevRange = null;
|
||||
prevRanges = null;
|
||||
ranges = null;
|
||||
range = null;
|
||||
startRange = null;
|
||||
endRange = null;
|
||||
root = null;
|
||||
|
||||
return map;
|
||||
|
@ -6746,7 +6773,7 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
var range;
|
||||
var rect;
|
||||
var list;
|
||||
// jaroslaw.bielski@7bulls.com
|
||||
|
||||
// Usage of indexOf() function for space character as word delimiter
|
||||
// is not sufficient in case of other breakable characters like \r\n- etc
|
||||
pos = this.indexOfBreakableChar(text);
|
||||
|
@ -6762,7 +6789,6 @@ EPUBJS.Renderer.prototype.splitTextNodeIntoWordsRanges = function(node){
|
|||
range.setEnd(node, pos);
|
||||
ranges.push(range);
|
||||
|
||||
// jaroslaw.bielski@7bulls.com
|
||||
// there was a word miss in case of one letter words
|
||||
range = this.doc.createRange();
|
||||
range.setStart(node, pos+1);
|
||||
|
@ -6904,7 +6930,7 @@ EPUBJS.Renderer.prototype.currentRenderedPage = function(){
|
|||
return false;
|
||||
}
|
||||
|
||||
if (this.spreads && this.layout.pageCount > 1) {
|
||||
if (this.spreads && this.pageMap.length > 1) {
|
||||
pg = this.chapterPos*2;
|
||||
} else {
|
||||
pg = this.chapterPos;
|
||||
|
@ -6950,7 +6976,7 @@ EPUBJS.Renderer.prototype.getVisibleRangeCfi = function(){
|
|||
startRange = this.pageMap[pg-2];
|
||||
endRange = startRange;
|
||||
|
||||
if(this.layout.pageCount > 1) {
|
||||
if(this.pageMap.length > 1) {
|
||||
endRange = this.pageMap[pg-1];
|
||||
}
|
||||
} else {
|
||||
|
@ -7218,7 +7244,7 @@ EPUBJS.replace = {};
|
|||
EPUBJS.replace.hrefs = function(callback, renderer){
|
||||
var book = this;
|
||||
var replacments = function(link, done){
|
||||
var href = link.getAttribute("href"),
|
||||
var href = decodeURI(link.getAttribute("href")),
|
||||
isRelative = href.search("://"),
|
||||
directory,
|
||||
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() {
|
||||
var Annotator = window.Annotator;
|
||||
var $main = $("#main");
|
||||
|
||||
function MySidebar(elem, options) {
|
||||
function EpubAnnotationSidebar(elem, options) {
|
||||
options = {
|
||||
server: true,
|
||||
origin: true,
|
||||
|
@ -13,9 +18,9 @@ window.hypothesisConfig = function() {
|
|||
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({
|
||||
'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({
|
||||
'margin-left': ''
|
||||
});
|
||||
|
@ -40,54 +45,36 @@ window.hypothesisConfig = function() {
|
|||
};
|
||||
|
||||
return {
|
||||
constructor: MySidebar,
|
||||
constructor: EpubAnnotationSidebar,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// This is the Epub.js plugin. Annotations are updated on location change.
|
||||
EPUBJS.reader.plugins.HypothesisController = function (Book) {
|
||||
var reader = this;
|
||||
var $main = $("#main");
|
||||
var reader = this;
|
||||
var $main = $("#main");
|
||||
|
||||
var updateAnnotations = function () {
|
||||
var annotator = Book.renderer.render.window.annotator;
|
||||
if (annotator && annotator.constructor.$) {
|
||||
var annotations = getVisibleAnnotations(annotator.constructor.$);
|
||||
annotator.showAnnotations(annotations)
|
||||
}
|
||||
};
|
||||
var updateAnnotations = function () {
|
||||
var annotator = Book.renderer.render.window.annotator;
|
||||
if (annotator && annotator.constructor.$) {
|
||||
var annotations = getVisibleAnnotations(annotator.constructor.$);
|
||||
annotator.showAnnotations(annotations)
|
||||
}
|
||||
};
|
||||
|
||||
var getVisibleAnnotations = function ($) {
|
||||
var width = Book.renderer.render.iframe.clientWidth;
|
||||
return $('.annotator-hl').map(function() {
|
||||
var $this = $(this),
|
||||
left = this.getBoundingClientRect().left;
|
||||
var getVisibleAnnotations = function ($) {
|
||||
var width = Book.renderer.render.iframe.clientWidth;
|
||||
return $('.annotator-hl').map(function() {
|
||||
var $this = $(this),
|
||||
left = this.getBoundingClientRect().left;
|
||||
|
||||
if (left >= 0 && left <= width) {
|
||||
return $this.data('annotation');
|
||||
}
|
||||
}).get();
|
||||
};
|
||||
if (left >= 0 && left <= width) {
|
||||
return $this.data('annotation');
|
||||
}
|
||||
}).get();
|
||||
};
|
||||
|
||||
// $("#annotations").on("click", function () {
|
||||
// var annotator = Book.renderer.render.window.annotator;
|
||||
// var currentPosition = Book.getCurrentLocationCfi();
|
||||
Book.on("renderer:locationChanged", updateAnnotations);
|
||||
|
||||
// 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:chapterDisplayed", updateAnnotations);
|
||||
|
||||
return {}
|
||||
return {}
|
||||
};
|
||||
|
|
|
@ -349,7 +349,7 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
link.classList.add('bookmark_link');
|
||||
|
||||
link.addEventListener("click", function(event){
|
||||
var cfi = this.getAttribute('href');
|
||||
var cfi = decodeURI(this.getAttribute('href'));
|
||||
book.gotoCfi(cfi);
|
||||
event.preventDefault();
|
||||
}, false);
|
||||
|
@ -383,6 +383,7 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
"hide" : hide
|
||||
};
|
||||
};
|
||||
|
||||
EPUBJS.reader.ControlsController = function(book) {
|
||||
var reader = this;
|
||||
|
||||
|
@ -1109,7 +1110,7 @@ EPUBJS.reader.TocController = function(toc) {
|
|||
|
||||
$list.append(docfrag);
|
||||
$list.find(".toc_link").on("click", function(event){
|
||||
var url = this.getAttribute('href');
|
||||
var url = decodeURI(this.getAttribute('href'));
|
||||
|
||||
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