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

@ -7,10 +7,10 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
folder = EPUBJS.core.folder(location.pathname),
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){
var epubType = item.getAttribute(attr),
href,
@ -21,17 +21,17 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
left,
top,
txt;
if(epubType != type) return;
href = item.getAttribute("href");
id = href.replace("#", '');
el = renderer.render.document.getElementById(id);
item.addEventListener("mouseover", showPop, false);
item.addEventListener("mouseout", hidePop, false);
item.addEventListener("mouseout", hidePop, false);
function showPop(){
var poppos,
iheight = renderer.height,
@ -40,7 +40,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
pop,
maxHeight = 225,
itemRect;
if(!txt) {
pop = el.cloneNode(true);
txt = pop.querySelector("p");
@ -51,17 +51,17 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
if(!popups[id]) {
popups[id] = document.createElement("div");
popups[id].setAttribute("class", "popup");
pop_content = document.createElement("div");
pop_content = document.createElement("div");
popups[id].appendChild(pop_content);
pop_content.appendChild(txt);
pop_content.setAttribute("class", "pop_content");
renderer.render.document.body.appendChild(popups[id]);
//-- TODO: will these leak memory? - Fred
//-- TODO: will these leak memory? - Fred
popups[id].addEventListener("mouseover", onPop, false);
popups[id].addEventListener("mouseout", offPop, false);
@ -72,32 +72,32 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
renderer.on("renderer:pageChanged", offPop, this);
// chapter.book.on("renderer:chapterDestroy", hidePop, this);
}
pop = popups[id];
//-- get location of item
itemRect = item.getBoundingClientRect();
left = itemRect.left;
top = itemRect.top;
//-- show the popup
pop.classList.add("show");
//-- locations of popup
popRect = pop.getBoundingClientRect();
//-- position the popup
pop.style.left = left - popRect.width / 2 + "px";
pop.style.top = top + "px";
//-- Adjust max height
if(maxHeight > iheight / 2.5) {
maxHeight = iheight / 2.5;
pop_content.style.maxHeight = maxHeight + "px";
}
//-- switch above / below
if(popRect.height + top >= iheight - 25) {
pop.style.top = top - popRect.height + "px";
@ -105,7 +105,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
}else{
pop.classList.remove("above");
}
//-- switch left
if(left - popRect.width <= 0) {
pop.style.left = left + "px";
@ -113,42 +113,42 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, rend
}else{
pop.classList.remove("left");
}
//-- switch right
if(left + popRect.width / 2 >= iwidth) {
//-- TEMP MOVE: 300
pop.style.left = left - 300 + "px";
popRect = pop.getBoundingClientRect();
pop.style.left = left - popRect.width + "px";
//-- switch above / below again
if(popRect.height + top >= iheight - 25) {
if(popRect.height + top >= iheight - 25) {
pop.style.top = top - popRect.height + "px";
pop.classList.add("above");
}else{
pop.classList.remove("above");
}
pop.classList.add("right");
}else{
pop.classList.remove("right");
}
}
function onPop(){
popups[id].classList.add("on");
}
function offPop(){
popups[id].classList.remove("on");
}
function hidePop(){
setTimeout(function(){
popups[id].classList.remove("show");
}, 100);
}, 100);
}
});
@ -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 @@
EPUBJS.reader.plugins.HypothesisController = function(Book) {
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;
};
_$ = guestAnnotator.constructor.$;
$annotations = _$(".annotator-hl");
width = reader.book.renderer.render.iframe.clientWidth;
//-- Find visible annotations
$annotations.each(function(){
var $this = _$(this),
left = this.getBoundingClientRect().left;
if(left >= 0 && left <= width) {
annotatations.push($this.data('annotation'));
}
});
//-- Update viewer
annotator.updateViewer(annotatations);
};
var attach = function(){
annotator = window.annotator;
annotator.frame.appendTo(element);
annotator.subscribe('annotationEditorShown', function () {
showAnnotations(true);
});
annotator.subscribe('annotationViewerShown', function () {
showAnnotations(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;
// });
});
});
$(".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);
var updateAnnotations = function () {
var annotator = Book.renderer.render.window.annotator;
if (annotator && annotator.constructor.$) {
var annotations = getVisibleAnnotations(annotator.constructor.$);
annotator.showAnnotations(annotations)
}
$main.one("transitionend", function(){
book.gotoCfi(currentPosition);
});
};
book.ready.all.then(function() {
reader.HypothesisController.attach();
});
return {
'attach': attach
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();
};
};
// $("#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

@ -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)
//AMD
define(function(){ return Reader; });
else if (typeof module != "undefined" && module.exports)
//Node
module.exports = ePubReader;
if (typeof define === 'function' && define.amd) {
//AMD
define(function(){ return Reader; });
} 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,12 +49,12 @@ 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);
});
}
this.setBookKey(this.settings.bookPath); //-- This could be username + path or any unique string
if(this.settings.restore && this.isSaved()) {
this.applySavedSettings();
}
@ -68,26 +62,19 @@ EPUBJS.Reader = function(bookPath, _options) {
this.settings.styles = this.settings.styles || {
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);
}
this.offline = false;
this.sidebarOpen = false;
if(!this.settings.bookmarks) {
this.settings.bookmarks = [];
}
if(!this.settings.annotations) {
this.settings.annotations = [];
}
@ -97,21 +84,21 @@ EPUBJS.Reader = function(bookPath, _options) {
}
book.renderTo("viewer");
reader.ReaderController = EPUBJS.reader.ReaderController.call(reader, book);
reader.SettingsController = EPUBJS.reader.SettingsController.call(reader, book);
reader.ControlsController = EPUBJS.reader.ControlsController.call(reader, book);
reader.SidebarController = EPUBJS.reader.SidebarController.call(reader, book);
reader.BookmarksController = EPUBJS.reader.BookmarksController.call(reader, book);
reader.NotesController = EPUBJS.reader.NotesController.call(reader, book);
// Call Plugins
for(plugin in EPUBJS.reader.plugins) {
if(EPUBJS.reader.plugins.hasOwnProperty(plugin)) {
reader[plugin] = EPUBJS.reader.plugins[plugin].call(reader, book);
}
}
book.ready.all.then(function() {
reader.ReaderController.hideLoader();
});
@ -123,16 +110,16 @@ EPUBJS.Reader = function(bookPath, _options) {
book.getToc().then(function(toc) {
reader.TocController = EPUBJS.reader.TocController.call(reader, toc);
});
window.addEventListener("beforeunload", this.unload.bind(this), false);
window.addEventListener("hashchange", this.hashChanged.bind(this), false);
document.addEventListener('keydown', this.adjustFontSize.bind(this), false);
book.on("renderer:keydown", this.adjustFontSize.bind(this));
book.on("renderer:keydown", reader.ReaderController.arrowKeys.bind(this));
book.on("renderer:selected", this.selectedRange.bind(this));
return this;
@ -145,19 +132,19 @@ EPUBJS.Reader.prototype.adjustFontSize = function(e) {
var MINUS = 189;
var ZERO = 48;
var MOD = (e.ctrlKey || e.metaKey );
if(!this.settings.styles) return;
if(!this.settings.styles.fontSize) {
this.settings.styles.fontSize = "100%";
}
fontSize = parseInt(this.settings.styles.fontSize.slice(0, -1));
if(MOD && e.keyCode == PLUS) {
e.preventDefault();
this.book.setStyle("fontSize", (fontSize + interval) + "%");
}
if(MOD && e.keyCode == MINUS){
@ -165,7 +152,7 @@ EPUBJS.Reader.prototype.adjustFontSize = function(e) {
e.preventDefault();
this.book.setStyle("fontSize", (fontSize - interval) + "%");
}
if(MOD && e.keyCode == ZERO){
e.preventDefault();
this.book.setStyle("fontSize", "100%");
@ -177,22 +164,22 @@ EPUBJS.Reader.prototype.addBookmark = function(cfi) {
if(present > -1 ) return;
this.settings.bookmarks.push(cfi);
this.trigger("reader:bookmarked", cfi);
};
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);
};
EPUBJS.Reader.prototype.isBookmarked = function(cfi) {
var bookmarks = this.settings.bookmarks;
return bookmarks.indexOf(cfi);
};
@ -201,7 +188,7 @@ EPUBJS.Reader.prototype.searchBookmarked = function(cfi) {
var bookmarks = this.settings.bookmarks,
len = bookmarks.length,
i;
for(i = 0; i < len; i++) {
if (bookmarks[i]['cfi'] === cfi) return i;
}
@ -241,11 +228,11 @@ EPUBJS.Reader.prototype.setBookKey = function(identifier){
//-- Checks if the book setting can be retrieved from localStorage
EPUBJS.Reader.prototype.isSaved = function(bookPath) {
var storedSettings;
if(!localStorage) {
return false;
}
storedSettings = localStorage.getItem(this.settings.bookKey);
if(storedSettings === null) {
@ -259,21 +246,30 @@ EPUBJS.Reader.prototype.removeSavedSettings = function() {
if(!localStorage) {
return false;
}
localStorage.removeItem(this.settings.bookKey);
};
EPUBJS.Reader.prototype.applySavedSettings = function() {
var stored;
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);
// 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;
@ -409,7 +405,7 @@ EPUBJS.reader.ControlsController = function(book) {
reader.offline = true;
// $store.attr("src", $icon.data("saved"));
};
var fullscreen = false;
book.on("book:online", goOnline);
@ -427,25 +423,26 @@ EPUBJS.reader.ControlsController = function(book) {
}
});
$fullscreen.on("click", function() {
screenfull.toggle($('#container')[0]);
});
if(screenfull) {
document.addEventListener(screenfull.raw.fullscreenchange, function() {
fullscreen = screenfull.isFullscreen;
if(fullscreen) {
$fullscreen
.addClass("icon-resize-small")
.removeClass("icon-resize-full");
} else {
$fullscreen
.addClass("icon-resize-full")
.removeClass("icon-resize-small");
}
if(typeof screenfull !== 'undefined') {
$fullscreen.on("click", function() {
screenfull.toggle($('#container')[0]);
});
if(screenfull.raw) {
document.addEventListener(screenfull.raw.fullscreenchange, function() {
fullscreen = screenfull.isFullscreen;
if(fullscreen) {
$fullscreen
.addClass("icon-resize-small")
.removeClass("icon-resize-full");
} else {
$fullscreen
.addClass("icon-resize-full")
.removeClass("icon-resize-small");
}
});
}
}
$settings.on("click", function() {
reader.SettingsController.show();
});
@ -453,17 +450,17 @@ EPUBJS.reader.ControlsController = function(book) {
$bookmark.on("click", function() {
var cfi = reader.book.getCurrentLocationCfi();
var bookmarked = reader.isBookmarked(cfi);
if(bookmarked === -1) { //-- Add bookmark
reader.addBookmark(cfi);
$bookmark
.addClass("icon-bookmark")
.removeClass("icon-bookmark-empty");
.removeClass("icon-bookmark-empty");
} else { //-- Remove Bookmark
reader.removeBookmark(cfi);
$bookmark
.removeClass("icon-bookmark")
.addClass("icon-bookmark-empty");
.addClass("icon-bookmark-empty");
}
});
@ -475,15 +472,15 @@ EPUBJS.reader.ControlsController = function(book) {
if(bookmarked === -1) { //-- Not bookmarked
$bookmark
.removeClass("icon-bookmark")
.addClass("icon-bookmark-empty");
.addClass("icon-bookmark-empty");
} else { //-- Bookmarked
$bookmark
.addClass("icon-bookmark")
.removeClass("icon-bookmark-empty");
.removeClass("icon-bookmark-empty");
}
reader.currentLocationCfi = cfi;
// Update the History Location
if(reader.settings.history &&
window.location.hash != cfiFragment) {
@ -491,7 +488,7 @@ EPUBJS.reader.ControlsController = function(book) {
history.pushState({}, '', cfiFragment);
}
});
book.on('book:pageChanged', function(location){
// console.log("page", location.page, location.percentage)
});
@ -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) {
book.prevPage();
if(book.metadata.direction === "rtl") {
book.nextPage();
} else {
book.prevPage();
}
$prev.addClass("active");
keylock = true;
@ -870,8 +874,14 @@ EPUBJS.reader.ReaderController = function(book) {
e.preventDefault();
}
if(e.keyCode == 39) {
book.nextPage();
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){
book.nextPage();
if(book.metadata.direction === "rtl") {
book.prevPage();
} else {
book.nextPage();
}
e.preventDefault();
});
$prev.on("click", function(e){
book.prevPage();
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