update epub.js

This commit is contained in:
j 2015-12-01 16:40:31 +01:00
parent 3c12da48d3
commit c0190bd7d1
9 changed files with 118 additions and 104 deletions

View file

@ -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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -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,11 +45,11 @@ 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");
@ -69,25 +74,7 @@ EPUBJS.reader.plugins.HypothesisController = function (Book) {
}).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:chapterDisplayed", updateAnnotations);
return {}
};

View file

@ -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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long