update epub.js

This commit is contained in:
j 2015-11-19 18:33:10 +01:00
parent 2b1dc4f24e
commit 34c08333bc
20 changed files with 5593 additions and 11449 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7472
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

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -8,7 +8,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
cssPath = (folder + EPUBJS.cssPath) || folder,
popups = {};
EPUBJS.core.addCss(cssPath + "popup.css", false, renderer.render.document.head);
EPUBJS.core.addCss(EPUBJS.cssPath + "popup.css", false, renderer.render.document.head);
items.forEach(function(item){
@ -164,7 +164,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").mathml = function(callback, render
if(renderer.currentChapter.manifestProperties.indexOf("mathml") !== -1 ){
// Assign callback to be inside iframe window
renderer.iframe.contentWindow.mathmlCallback = callback;
renderer.render.iframe.contentWindow.mathmlCallback = callback;
// add MathJax config script tag to the renderer body
var s = document.createElement("script");

File diff suppressed because one or more lines are too long

View file

@ -1,2 +1,2 @@
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e,f=b.height,j=b.width,p=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.render.document.body.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",h,this),b.on("renderer:pageChanged",g,this)),c=i[k],e=a.getBoundingClientRect(),m=e.left,n=e.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",p>f/2.5&&(p=f/2.5,pop_content.style.maxHeight=p+"px"),popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=j?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.layoutSettings.layout?void a():(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(i>e&&(a.style.maxHeight=e+"px",a.style.width="auto",d=a.getBoundingClientRect(),i=d.height),a.style.display="block",a.style.WebkitColumnBreakBefore="always",a.style.breakBefore="column"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),void(a&&a()))},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.contents.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=(g+EPUBJS.cssPath||g,{});EPUBJS.core.addCss(EPUBJS.cssPath+"popup.css",!1,b.render.document.head),d.forEach(function(a){function c(){var c,e,f=b.height,j=b.width,p=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),h[k]||(h[k]=document.createElement("div"),h[k].setAttribute("class","popup"),pop_content=document.createElement("div"),h[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.render.document.body.appendChild(h[k]),h[k].addEventListener("mouseover",d,!1),h[k].addEventListener("mouseout",g,!1),b.on("renderer:pageChanged",i,this),b.on("renderer:pageChanged",g,this)),c=h[k],e=a.getBoundingClientRect(),m=e.left,n=e.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",p>f/2.5&&(p=f/2.5,pop_content.style.maxHeight=p+"px"),popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=j?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=f-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){h[k].classList.add("on")}function g(){h[k].classList.remove("on")}function i(){setTimeout(function(){h[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.render.document.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",i,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").mathml=function(a,b){if(-1!==b.currentChapter.manifestProperties.indexOf("mathml")){b.render.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { window.mathmlCallback(); }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.contents.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height;return"reflowable"!=b.layoutSettings.layout?void a():(d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f,j=Number(getComputedStyle(a,"").fontSize.match(/(\d*(\.\d*)?)px/)[1]),k=j?j/2:0;e=b.contents.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g-k,a.style.maxHeight=c+"px",a.style.width="auto"):(i>e&&(a.style.maxHeight=e+"px",a.style.width="auto",d=a.getBoundingClientRect(),i=d.height),a.style.display="block",a.style.WebkitColumnBreakBefore="always",a.style.breakBefore="column"),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),void(a&&a()))},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.contents.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>chapter.colWidth&&(d=chapter.colWidth/j,j=chapter.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.listenUntil("renderer:resized","renderer:chapterUnloaded",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
//# sourceMappingURL=hooks.min.map

File diff suppressed because one or more lines are too long

BIN
epub.js/img/loader.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

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

View file

@ -1,109 +1,93 @@
window.hypothesisConfig = function() {
var Annotator = window.Annotator;
var $main = $("#main");
function MySidebar(elem, options) {
options = {
server: true,
origin: true,
showHighlights: true,
Toolbar: {container: '#annotation-controls'}
}
Annotator.Host.call(this, elem, options);
}
MySidebar.prototype = Object.create(Annotator.Host.prototype);
MySidebar.prototype.show = function() {
this.frame.css({
'margin-left': (-1 * this.frame.width()) + "px"
});
this.frame.removeClass('annotator-collapsed');
if (!$main.hasClass('single')) {
$main.addClass("single");
this.toolbar.find('[name=sidebar-toggle]').removeClass('h-icon-chevron-left').addClass('h-icon-chevron-right');
this.setVisibleHighlights(true);
}
};
MySidebar.prototype.hide = function() {
this.frame.css({
'margin-left': ''
});
this.frame.addClass('annotator-collapsed');
if ($main.hasClass('single')) {
$main.removeClass("single");
this.toolbar.find('[name=sidebar-toggle]').removeClass('h-icon-chevron-right').addClass('h-icon-chevron-left');
this.setVisibleHighlights(false);
}
};
return {
constructor: MySidebar,
}
};
EPUBJS.reader.plugins.HypothesisController = function (Book) {
var reader = this;
var book = reader.book;
var element = document.getElementById("hypothesis");
var body = window.document.body;
var annotator;
var $main = $("#main");
var updateAnnotations = function () {
var annotatations = [],
guestAnnotator = reader.book.renderer.render.window.annotator,
_$,
$annotations, width;
if(!guestAnnotator) {
if(annotator) annotator.updateViewer([]);
return;
var annotator = Book.renderer.render.window.annotator;
if (annotator && annotator.constructor.$) {
var annotations = getVisibleAnnotations(annotator.constructor.$);
annotator.showAnnotations(annotations)
}
};
_$ = guestAnnotator.constructor.$;
$annotations = _$(".annotator-hl");
width = reader.book.renderer.render.iframe.clientWidth;
//-- Find visible annotations
$annotations.each(function(){
var $this = _$(this),
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) {
annotatations.push($this.data('annotation'));
return $this.data('annotation');
}
});
//-- Update viewer
annotator.updateViewer(annotatations);
}).get();
};
var attach = function(){
annotator = window.annotator;
annotator.frame.appendTo(element);
// $("#annotations").on("click", function () {
// var annotator = Book.renderer.render.window.annotator;
// var currentPosition = Book.getCurrentLocationCfi();
annotator.subscribe('annotationEditorShown', function () {
showAnnotations(true);
});
annotator.subscribe('annotationViewerShown', function () {
showAnnotations(true);
});
// if ($main.hasClass("single")) {
// $main.removeClass("single");
// annotator.setVisibleHighlights(false);
// } else {
// $main.addClass("single");
// annotator.setVisibleHighlights(true);
// }
annotator.subscribe("annotationsLoaded", function(e){
var _$ = reader.book.renderer.render.window.annotator.constructor.$;
reader.annotator = annotator;
updateAnnotations();
_$(reader.book.renderer.contents).on("click", ".annotator-hl", function(event){
var $this = _$(this);
reader.annotator.updateViewer([$this.data('annotation')]);
// $scope.$apply(function(){
// $scope.single = true;
// $scope.noUpdate = true;
// $main.one("transitionend", function(){
// Book.gotoCfi(currentPosition);
// });
// });
});
});
$(".h-icon-comment").on("click", function () {
if ($main.hasClass("single")) {
showAnnotations(false);
} else {
showAnnotations(true);
}
});
reader.book.on("renderer:locationChanged", function(){
updateAnnotations();
});
}
var showAnnotations = function(single) {
var currentPosition = reader.currentLocationCfi;
reader.settings.sidebarReflow = false;
if(single) {
$main.addClass("single");
window.annotator.setVisibleHighlights(true);
} else {
$main.removeClass("single");
window.annotator.setVisibleHighlights(false);
}
$main.one("transitionend", function(){
book.gotoCfi(currentPosition);
});
Book.on("renderer:locationChanged", updateAnnotations);
// Book.on("renderer:chapterDisplayed", updateAnnotations);
};
book.ready.all.then(function() {
reader.HypothesisController.attach();
});
return {
'attach': attach
};
return {}
};

View file

@ -9,20 +9,14 @@ EPUBJS.reader.plugins = {}; //-- Attach extra Controllers as plugins (like searc
return new EPUBJS.Reader(path, options);
};
_.extend(ePubReader, {
noConflict : function() {
root.ePubReader = previousReader;
return this;
}
});
//exports to multiple environments
if (typeof define === 'function' && define.amd)
if (typeof define === 'function' && define.amd) {
//AMD
define(function(){ return Reader; });
else if (typeof module != "undefined" && module.exports)
} else if (typeof module != "undefined" && module.exports) {
//Node
module.exports = ePubReader;
}
})(window, jQuery);
@ -34,15 +28,15 @@ EPUBJS.Reader = function(bookPath, _options) {
var search = window.location.search;
var parameters;
this.settings = _.defaults(_options || {}, {
this.settings = EPUBJS.core.defaults(_options || {}, {
bookPath : bookPath,
restore : true,
reload : false,
bookmarks : null,
annotations : null,
contained : null,
bookKey : null,
styles : null,
bookmarks : undefined,
annotations : undefined,
contained : undefined,
bookKey : undefined,
styles : undefined,
sidebarReflow: false,
generatePagination: false,
history: true
@ -55,7 +49,7 @@ EPUBJS.Reader = function(bookPath, _options) {
var split = p.split("=");
var name = split[0];
var value = split[1] || '';
reader.settings[name] = value;
reader.settings[name] = decodeURIComponent(value);
});
}
@ -69,14 +63,7 @@ EPUBJS.Reader = function(bookPath, _options) {
fontSize : "100%"
};
this.book = book = new EPUBJS.Book({
bookPath: this.settings.bookPath,
restore: this.settings.restore,
reload: this.settings.reload,
contained: this.settings.contained,
bookKey: this.settings.bookKey,
styles: this.settings.styles
});
this.book = book = new EPUBJS.Book(this.settings);
if(this.settings.previousLocationCfi) {
book.gotoCfi(this.settings.previousLocationCfi);
@ -185,7 +172,7 @@ EPUBJS.Reader.prototype.removeBookmark = function(cfi) {
var bookmark = this.isBookmarked(cfi);
if( bookmark === -1 ) return;
delete this.settings.bookmarks[bookmark];
this.settings.bookmarks.splice(bookmark, 1);
this.trigger("reader:unbookmarked", bookmark);
};
@ -270,10 +257,19 @@ EPUBJS.Reader.prototype.applySavedSettings = function() {
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);
// Merge styles
if(stored.styles) {
this.settings.styles = EPUBJS.core.defaults(this.settings.styles || {}, stored.styles);
}
// Merge the rest
this.settings = EPUBJS.core.defaults(this.settings, stored);
return true;
} else {
return false;
@ -427,11 +423,11 @@ EPUBJS.reader.ControlsController = function(book) {
}
});
if(typeof screenfull !== 'undefined') {
$fullscreen.on("click", function() {
screenfull.toggle($('#container')[0]);
});
if(screenfull) {
if(screenfull.raw) {
document.addEventListener(screenfull.raw.fullscreenchange, function() {
fullscreen = screenfull.isFullscreen;
if(fullscreen) {
@ -445,6 +441,7 @@ EPUBJS.reader.ControlsController = function(book) {
}
});
}
}
$settings.on("click", function() {
reader.SettingsController.show();
@ -500,6 +497,7 @@ EPUBJS.reader.ControlsController = function(book) {
};
};
EPUBJS.reader.MetaController = function(meta) {
var title = meta.bookTitle,
author = meta.creator;
@ -859,7 +857,13 @@ EPUBJS.reader.ReaderController = function(book) {
var arrowKeys = function(e) {
if(e.keyCode == 37) {
if(book.metadata.direction === "rtl") {
book.nextPage();
} else {
book.prevPage();
}
$prev.addClass("active");
keylock = true;
@ -871,7 +875,13 @@ EPUBJS.reader.ReaderController = function(book) {
e.preventDefault();
}
if(e.keyCode == 39) {
if(book.metadata.direction === "rtl") {
book.prevPage();
} else {
book.nextPage();
}
$next.addClass("active");
keylock = true;
@ -887,12 +897,24 @@ EPUBJS.reader.ReaderController = function(book) {
document.addEventListener('keydown', arrowKeys, false);
$next.on("click", function(e){
if(book.metadata.direction === "rtl") {
book.prevPage();
} else {
book.nextPage();
}
e.preventDefault();
});
$prev.on("click", function(e){
if(book.metadata.direction === "rtl") {
book.nextPage();
} else {
book.prevPage();
}
e.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

6
epub.js/update.sh Executable file
View file

@ -0,0 +1,6 @@
base=/src/epub.js
cp $base/build/* .
cp $base/build/libs/* ./libs/
cp $base/reader/js/hooks/extensions/*.js ./hooks/extensions/
cp $base/reader/js/plugins/*.js ./plugins/
cp $base/reader/img/loader.gif img/loader.gif