mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Added ePub() function, book.destroy, moved reader dev to demo folder
This commit is contained in:
parent
53955612ca
commit
660d570c02
28 changed files with 236 additions and 90 deletions
123
build/epub.js
123
build/epub.js
|
@ -6,11 +6,69 @@ EPUBJS.VERSION = "0.1.5";
|
||||||
EPUBJS.plugins = EPUBJS.plugins || {};
|
EPUBJS.plugins = EPUBJS.plugins || {};
|
||||||
|
|
||||||
EPUBJS.filePath = EPUBJS.filePath || "/epubjs/";
|
EPUBJS.filePath = EPUBJS.filePath || "/epubjs/";
|
||||||
EPUBJS.Book = function(bookPath, options){
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var root = this;
|
||||||
|
var previousEpub = root.ePub || {};
|
||||||
|
|
||||||
|
var ePub = root.ePub = function() {
|
||||||
|
var bookPath, options;
|
||||||
|
|
||||||
|
//-- var book = ePub("path/to/book.epub", { restore: true })
|
||||||
|
if(arguments[0] &&
|
||||||
|
typeof arguments[0] === 'string') {
|
||||||
|
|
||||||
|
bookPath = arguments[0];
|
||||||
|
|
||||||
|
if( arguments[1] && typeof arguments[1] === 'object' ) {
|
||||||
|
options = arguments[1];
|
||||||
|
options.bookPath = bookPath;
|
||||||
|
} else {
|
||||||
|
options = { 'bookPath' : bookPath }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* var book = ePub({ bookPath: "path/to/book.epub", restore: true });
|
||||||
|
*
|
||||||
|
* - OR -
|
||||||
|
*
|
||||||
|
* var book = ePub({ restore: true });
|
||||||
|
* book.open("path/to/book.epub");
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( arguments[0] && typeof arguments[0] === 'object' ) {
|
||||||
|
options = arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new EPUBJS.Book(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
_.extend(ePub, {
|
||||||
|
noConflict : function() {
|
||||||
|
root.ePub = previousEpub;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//exports to multiple environments
|
||||||
|
if (typeof define === 'function' && define.amd)
|
||||||
|
//AMD
|
||||||
|
define(function(){ return ePub; });
|
||||||
|
else if (typeof module != "undefined" && module.exports)
|
||||||
|
//Node
|
||||||
|
module.exports = ePub;
|
||||||
|
|
||||||
|
})();
|
||||||
|
EPUBJS.Book = function(options){
|
||||||
|
|
||||||
var book = this;
|
var book = this;
|
||||||
|
|
||||||
this.settings = _.defaults(options || {}, {
|
this.settings = _.defaults(options || {}, {
|
||||||
|
bookPath : null,
|
||||||
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
|
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
|
||||||
fromStorage : false,
|
fromStorage : false,
|
||||||
saved : false,
|
saved : false,
|
||||||
|
@ -73,27 +131,14 @@ EPUBJS.Book = function(bookPath, options){
|
||||||
this.trigger("book:ready");
|
this.trigger("book:ready");
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this.opened = new RSVP.Promise();
|
||||||
// BookUrl is optional, but if present start loading process
|
// BookUrl is optional, but if present start loading process
|
||||||
if(bookPath) {
|
if(this.settings.bookPath) {
|
||||||
this.opened = this.open(bookPath);
|
this.open(this.settings.bookPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Likewise if an element is present start rendering process
|
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||||
// if(bookPath && this.settings.element) {
|
|
||||||
// this.opened.then(function(){
|
|
||||||
// this.rendered = this.renderTo(el);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function(e) {
|
|
||||||
|
|
||||||
if(book.settings.restore) {
|
|
||||||
book.saveSettings();
|
|
||||||
book.saveContents();
|
|
||||||
}
|
|
||||||
|
|
||||||
book.trigger("book:unload");
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
//-- Listen for these promises:
|
//-- Listen for these promises:
|
||||||
//-- book.opened.then()
|
//-- book.opened.then()
|
||||||
|
@ -101,7 +146,6 @@ EPUBJS.Book = function(bookPath, options){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-- Check bookUrl and start parsing book Assets or load them from storage
|
//-- Check bookUrl and start parsing book Assets or load them from storage
|
||||||
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
var book = this,
|
var book = this,
|
||||||
|
@ -158,6 +202,10 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
if(!this.settings.stored) opened.then(book.storeOffline());
|
if(!this.settings.stored) opened.then(book.storeOffline());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opened.then(function(){
|
||||||
|
book.opened.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
return opened;
|
return opened;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -628,6 +676,28 @@ EPUBJS.Book.prototype.removeStyle = function(style, val, prefixed) {
|
||||||
delete this.settings.styles[style];
|
delete this.settings.styles[style];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.unload = function(bookPath, forceReload){
|
||||||
|
|
||||||
|
if(this.settings.restore) {
|
||||||
|
this.saveSettings();
|
||||||
|
this.saveContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.trigger("book:unload");
|
||||||
|
}
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.destroy = function() {
|
||||||
|
|
||||||
|
window.removeEventListener("beforeunload", this.unload);
|
||||||
|
|
||||||
|
if(this.currentChapter) this.currentChapter.unload();
|
||||||
|
|
||||||
|
this.unload();
|
||||||
|
|
||||||
|
if(this.render) this.render.remove();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-- Get pre-registered hooks
|
//-- Get pre-registered hooks
|
||||||
EPUBJS.Book.prototype.getHooks = function(){
|
EPUBJS.Book.prototype.getHooks = function(){
|
||||||
|
@ -1673,12 +1743,6 @@ EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.destroy = function(){
|
|
||||||
window.removeEventListener("resize", this.resized, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){
|
EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
@ -1806,7 +1870,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
|
||||||
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
||||||
|
|
||||||
//-- Clear Margins
|
//-- Clear Margins
|
||||||
// this.bodyEl.style.margin = "0";
|
this.bodyEl.style.margin = "0";
|
||||||
|
|
||||||
this.docEl.style.overflow = "hidden";
|
this.docEl.style.overflow = "hidden";
|
||||||
|
|
||||||
|
@ -2347,7 +2411,10 @@ EPUBJS.Renderer.prototype.height = function(el){
|
||||||
return this.docEl.offsetHeight;
|
return this.docEl.offsetHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EPUBJS.Renderer.prototype.remove = function() {
|
||||||
|
window.removeEventListener("resize", this.resized);
|
||||||
|
this.el.removeChild(this.iframe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -4,9 +4,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
||||||
items = Array.prototype.slice.call(notes), //[].slice.call()
|
items = Array.prototype.slice.call(notes), //[].slice.call()
|
||||||
attr = "epub:type",
|
attr = "epub:type",
|
||||||
type = "noteref",
|
type = "noteref",
|
||||||
|
folder = EPUBJS.core.folder(location.pathname),
|
||||||
|
cssPath = folder + EPUBJS.cssPath || folder,
|
||||||
popups = {};
|
popups = {};
|
||||||
|
|
||||||
EPUBJS.core.addCss("../demo/css/popup.css", false, chapter.doc.head);
|
EPUBJS.core.addCss(cssPath + "popup.css", false, chapter.doc.head);
|
||||||
|
|
||||||
|
|
||||||
items.forEach(function(item){
|
items.forEach(function(item){
|
||||||
|
@ -157,7 +159,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
|
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
|
||||||
var images = chapter.doc.querySelectorAll('img'),
|
var images = chapter.doc.querySelectorAll('img'),
|
||||||
items = Array.prototype.slice.call(images),
|
items = Array.prototype.slice.call(images),
|
||||||
iheight = chapter.height(),//chapter.doc.body.getBoundingClientRect().height,
|
iheight = chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
||||||
oheight;
|
oheight;
|
||||||
|
|
||||||
items.forEach(function(item){
|
items.forEach(function(item){
|
||||||
|
@ -170,7 +172,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
|
||||||
height = oHeight || rectHeight,
|
height = oHeight || rectHeight,
|
||||||
newHeight;
|
newHeight;
|
||||||
|
|
||||||
iheight = chapter.height();
|
iheight = chapter.bodyEl.clientHeight;
|
||||||
if(top < 0) top = 0;
|
if(top < 0) top = 0;
|
||||||
|
|
||||||
if(height + top >= iheight) {
|
if(height + top >= iheight) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ EPUBJSR.app.init = (function($){
|
||||||
|
|
||||||
//-- Create a new book object,
|
//-- Create a new book object,
|
||||||
// this will create an iframe in the el with the ID provided
|
// this will create an iframe in the el with the ID provided
|
||||||
Book = new EPUBJS.Book(bookURL, { restore : true });
|
Book = new EPUBJS.Book({ bookPath: bookURL, restore : true });
|
||||||
|
|
||||||
|
|
||||||
//Book.single = true;
|
//Book.single = true;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
EPUBJS.filePath = "../libs/zip/";
|
EPUBJS.filePath = "../libs/zip/";
|
||||||
|
EPUBJS.cssPath = "css/";
|
||||||
fileStorage.filePath = "../libs/fileStorage/workers/";
|
fileStorage.filePath = "../libs/fileStorage/workers/";
|
||||||
|
|
||||||
EPUBJS.VERSION = "0.1.5";
|
EPUBJS.VERSION = "0.1.5";
|
|
@ -25,7 +25,8 @@
|
||||||
EPUBJS.VERSION = "0.1.6";
|
EPUBJS.VERSION = "0.1.6";
|
||||||
|
|
||||||
EPUBJS.filePath = "js/libs/";
|
EPUBJS.filePath = "js/libs/";
|
||||||
fileStorage.filePath = EPUBJS.filePath + "libs/";
|
EPUBJS.cssPath = "css/";
|
||||||
|
fileStorage.filePath = EPUBJS.filePath;
|
||||||
|
|
||||||
EPUBJSR.app.init("moby-dick/");
|
EPUBJSR.app.init("moby-dick/");
|
||||||
}
|
}
|
||||||
|
|
4
demo/js/epub.min.js
vendored
4
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/hooks.min.js
vendored
2
demo/js/hooks.min.js
vendored
|
@ -1 +1 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g={};EPUBJS.core.addCss("../demo/css/popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),g[k]||(g[k]=document.createElement("div"),g[k].setAttribute("class","popup"),pop_content=document.createElement("div"),g[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(g[k]),g[k].addEventListener("mouseover",d,!1),g[k].addEventListener("mouseout",h,!1),b.book.on("book:pageChanged",i,this),b.book.on("book:pageChanged",h,this)),c=g[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-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>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-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(){g[k].classList.add("on")}function h(){g[k].classList.remove("on")}function i(){setTimeout(function(){g[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.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",i,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.height();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;e=b.height(),0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(i=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),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()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.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.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.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.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=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.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("book:pageChanged",h,this),b.book.on("book:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-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>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-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.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;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;e=b.bodyEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(i=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto"),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()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.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.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
2
demo/js/reader.min.js
vendored
2
demo/js/reader.min.js
vendored
|
@ -1 +1 @@
|
||||||
var EPUBJSR=EPUBJSR||{};EPUBJSR.app={},EPUBJSR.app.init=function(a){"use strict";function b(b){var e=window.location.search.match(/book=(.*)/),b=b||(e?e[1]:"moby-dick");return k=a(window).width(),k>550?a("#main").width(k-m):a("#main").width(k),j=new EPUBJS.Book(b,{restore:!0}),j.on("book:online",g),j.on("book:offline",h),j.getMetadata().then(c),j.getToc().then(d),j.ready.all.then(f),j.renderTo("area"),a(function(){i()}),j}function c(b){var c=b.bookTitle,d=b.creator,e=a("#book-title"),f=a("#chapter-title"),g=a("#title-seperator");document.title=c+" – "+d,e.html(c),f.html(d),g.show()}function d(b){var c,d,f=a("#toc");f.empty(),d=e(b,1),f.append(d),c=a(".toc_link"),c.on("click",function(b){var c=a(this),d=c.data("url");a(".openChapter").removeClass("openChapter"),c.parents("li").addClass("openChapter"),j.goto(d),b.preventDefault()})}function e(b,c){var d=a("<ul>"),f=1==c?"chapter":"section";return b.forEach(function(b){var g,h=a("<li id='toc-"+b.id+"'>"),i=a("<a class='toc_link "+f+"' href='#/"+b.href+"' data-url='"+b.href+"'>"+b.label+"</a>");h.append(i),b.subitems&&b.subitems.length&&(c++,g=e(b.subitems,c),h.append(g)),d.append(h)}),d}function f(){var b=a("#divider"),c=a("#loader");c.hide(),j.single||b.addClass("show")}function g(){var b=a("#store");l=!1,b.attr("src",b.data("save"))}function h(){var b=a("#store");l=!0,b.attr("src",b.data("saved"))}function i(){function b(){n.addClass("open"),h.addClass("closed"),p.attr("src",p.data("close"))}function c(){i.css("pointer-events","visible"),n.removeClass("open"),h.removeClass("closed"),p.attr("src",p.data("open"))}function d(){t.hide(),s.show()}function e(){s.hide(),t.show()}var f=a("#next"),g=a("#prev"),h=a("#main"),i=a("#area"),n=a("#sidebar"),o=a("#open"),p=o.find("img"),q=a("#network"),r=a("#setting"),s=a("#settingsPanel"),t=a("#toc"),u=a(window);u.on("resize",function(){k=a(window).width(),k>550?h.width(k-m):h.width(k)}),f.on("click",function(){j.nextPage()}),g.on("click",function(){j.prevPage()}),r.on("click",function(){s.is(":visible")?e():d()});var v=!1;a(document).keydown(function(a){return v?void 0:37==a.keyCode?(g.trigger("click"),v=!0,setTimeout(function(){v=!1},100),!1):39==a.keyCode?(f.trigger("click"),v=!0,setTimeout(function(){v=!1},100),!1):void 0}),o.on("click",function(){n.hasClass("open")?c():b()}),q.on("click",function(){l=!l,j.fromStorage(l)})}var j,k,l=!1,m=0;return b}(jQuery),jQuery.fn.extend({clickOutside:function(a,b){var c=this;return jQuery(document).on("click.offer",function(d){b&&jQuery.inArray(d.target,b)>-1||jQuery.contains(c[0],d.target)||(jQuery(document).off("click.offer"),a(d,c))}),this}});
|
var EPUBJSR=EPUBJSR||{};EPUBJSR.app={},EPUBJSR.app.init=function(a){"use strict";function b(b){var e=window.location.search.match(/book=(.*)/),b=b||(e?e[1]:"moby-dick");return k=a(window).width(),k>550?a("#main").width(k-m):a("#main").width(k),j=new EPUBJS.Book({bookPath:b,restore:!0}),j.on("book:online",g),j.on("book:offline",h),j.getMetadata().then(c),j.getToc().then(d),j.ready.all.then(f),j.renderTo("area"),a(function(){i()}),j}function c(b){var c=b.bookTitle,d=b.creator,e=a("#book-title"),f=a("#chapter-title"),g=a("#title-seperator");document.title=c+" – "+d,e.html(c),f.html(d),g.show()}function d(b){var c,d,f=a("#toc");f.empty(),d=e(b,1),f.append(d),c=a(".toc_link"),c.on("click",function(b){var c=a(this),d=c.data("url");a(".openChapter").removeClass("openChapter"),c.parents("li").addClass("openChapter"),j.goto(d),b.preventDefault()})}function e(b,c){var d=a("<ul>"),f=1==c?"chapter":"section";return b.forEach(function(b){var g,h=a("<li id='toc-"+b.id+"'>"),i=a("<a class='toc_link "+f+"' href='#/"+b.href+"' data-url='"+b.href+"'>"+b.label+"</a>");h.append(i),b.subitems&&b.subitems.length&&(c++,g=e(b.subitems,c),h.append(g)),d.append(h)}),d}function f(){var b=a("#divider"),c=a("#loader");c.hide(),j.single||b.addClass("show")}function g(){var b=a("#store");l=!1,b.attr("src",b.data("save"))}function h(){var b=a("#store");l=!0,b.attr("src",b.data("saved"))}function i(){function b(){n.addClass("open"),h.addClass("closed"),p.attr("src",p.data("close"))}function c(){i.css("pointer-events","visible"),n.removeClass("open"),h.removeClass("closed"),p.attr("src",p.data("open"))}function d(){t.hide(),s.show()}function e(){s.hide(),t.show()}var f=a("#next"),g=a("#prev"),h=a("#main"),i=a("#area"),n=a("#sidebar"),o=a("#open"),p=o.find("img"),q=a("#network"),r=a("#setting"),s=a("#settingsPanel"),t=a("#toc"),u=a(window);u.on("resize",function(){k=a(window).width(),k>550?h.width(k-m):h.width(k)}),f.on("click",function(){j.nextPage()}),g.on("click",function(){j.prevPage()}),r.on("click",function(){s.is(":visible")?e():d()});var v=!1;a(document).keydown(function(a){return v?void 0:37==a.keyCode?(g.trigger("click"),v=!0,setTimeout(function(){v=!1},100),!1):39==a.keyCode?(f.trigger("click"),v=!0,setTimeout(function(){v=!1},100),!1):void 0}),o.on("click",function(){n.hasClass("open")?c():b()}),q.on("click",function(){l=!l,j.fromStorage(l)})}var j,k,l=!1,m=0;return b}(jQuery),jQuery.fn.extend({clickOutside:function(a,b){var c=this;return jQuery(document).on("click.offer",function(d){b&&jQuery.inArray(d.target,b)>-1||jQuery.contains(c[0],d.target)||(jQuery(document).off("click.offer"),a(d,c))}),this}});
|
|
@ -44,7 +44,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/", { restore: true });
|
var Book = ePub("../demo/moby-dick/", { restore: true });
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("/demo/moby-dick/", { restore: true });
|
var Book = ePub("/demo/moby-dick/", { restore: true });
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -33,10 +33,10 @@
|
||||||
<script src="../src/renderer.js"></script>
|
<script src="../src/renderer.js"></script>
|
||||||
<script src="../src/epubcfi.js"></script>
|
<script src="../src/epubcfi.js"></script>
|
||||||
|
|
||||||
<!-- Plugins -->
|
<!-- Hooks -->
|
||||||
<script async src="../hooks/default/transculsions.js"></script>
|
<!-- <script src="../hooks/default/transculsions.js"></script> -->
|
||||||
<script async src="../hooks/default/endnotes.js"></script>
|
<!-- <script src="../hooks/default/endnotes.js"></script> -->
|
||||||
<script async src="../hooks/default/smartimages.js"></script>
|
<!-- <script src="../hooks/default/smartimages.js"></script> -->
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/");
|
var Book = ePub("../demo/moby-dick/");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/");
|
var Book = ePub("../demo/moby-dick/");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/");
|
var Book = ePub("../demo/moby-dick/");
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -66,13 +66,15 @@
|
||||||
spreads = this.getAttribute("spreads") != null ? true : false,
|
spreads = this.getAttribute("spreads") != null ? true : false,
|
||||||
restore = this.getAttribute("restore") != null ? true : false;
|
restore = this.getAttribute("restore") != null ? true : false;
|
||||||
|
|
||||||
this.Book = new EPUBJS.Book(src, {
|
this.Book = new EPUBJS.Book({
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
spreads : spreads,
|
spreads : spreads,
|
||||||
restore : restore
|
restore : restore
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.Book.open(src);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
epubPrototype.prevPage = function() {
|
epubPrototype.prevPage = function() {
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/", {
|
var Book = ePub("../demo/moby-dick/", {
|
||||||
width: 480,
|
width: 480,
|
||||||
height: 645,
|
height: 645,
|
||||||
spreads : false,
|
spreads : false,
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/", {
|
var Book = ePub("../demo/moby-dick/", {
|
||||||
fixedLayout : true
|
fixedLayout : true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -353,13 +353,15 @@
|
||||||
|
|
||||||
if(this.Book) this.Book.destroy();
|
if(this.Book) this.Book.destroy();
|
||||||
|
|
||||||
this.Book = new EPUBJS.Book(src, {
|
this.Book = new EPUBJS.Book({
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
spreads : spreads,
|
spreads : spreads,
|
||||||
restore : restore
|
restore : restore
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.Book.open(src);
|
||||||
|
|
||||||
this.events();
|
this.events();
|
||||||
|
|
||||||
this.Book.renderTo(this.$.area);
|
this.Book.renderTo(this.$.area);
|
||||||
|
|
|
@ -48,13 +48,15 @@
|
||||||
|
|
||||||
if(this.Book) this.Book.destroy();
|
if(this.Book) this.Book.destroy();
|
||||||
|
|
||||||
this.Book = new EPUBJS.Book(src, {
|
this.Book = new EPUBJS.Book({
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
spreads : spreads,
|
spreads : spreads,
|
||||||
restore : restore
|
restore : restore
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.Book.open(src);
|
||||||
|
|
||||||
this.events();
|
this.events();
|
||||||
|
|
||||||
this.Book.renderTo(this.$.area);
|
this.Book.renderTo(this.$.area);
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
<!-- // <script src="../../build/epub.min.js"></script> -->
|
<!-- // <script src="../../build/epub.min.js"></script> -->
|
||||||
|
|
||||||
<!-- <link rel="import" href="epub-reader/epub-reader.html"> -->
|
<link rel="import" href="epub-reader/epub-reader.html">
|
||||||
<link rel="import" href="epub-reader.html">
|
<!-- <link rel="import" href="epub-reader.html"> -->
|
||||||
|
|
||||||
<link rel="stylesheet" href="../../demo/css/normalize.css">
|
<link rel="stylesheet" href="../../demo/css/normalize.css">
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/", { restore: true });
|
var Book = ePub("../demo/moby-dick/", { restore: true });
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = new EPUBJS.Book("../demo/moby-dick/", {
|
var Book = ePub("../demo/moby-dick/", {
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 600,
|
height: 600,
|
||||||
spreads : false
|
spreads : false
|
||||||
|
|
|
@ -4,9 +4,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
||||||
items = Array.prototype.slice.call(notes), //[].slice.call()
|
items = Array.prototype.slice.call(notes), //[].slice.call()
|
||||||
attr = "epub:type",
|
attr = "epub:type",
|
||||||
type = "noteref",
|
type = "noteref",
|
||||||
|
folder = EPUBJS.core.folder(location.pathname),
|
||||||
|
cssPath = folder + EPUBJS.cssPath || folder,
|
||||||
popups = {};
|
popups = {};
|
||||||
|
|
||||||
EPUBJS.core.addCss("../demo/css/popup.css", false, chapter.doc.head);
|
EPUBJS.core.addCss(cssPath + "popup.css", false, chapter.doc.head);
|
||||||
|
|
||||||
|
|
||||||
items.forEach(function(item){
|
items.forEach(function(item){
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
|
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
|
||||||
var images = chapter.doc.querySelectorAll('img'),
|
var images = chapter.doc.querySelectorAll('img'),
|
||||||
items = Array.prototype.slice.call(images),
|
items = Array.prototype.slice.call(images),
|
||||||
iheight = chapter.height(),//chapter.doc.body.getBoundingClientRect().height,
|
iheight = chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
|
||||||
oheight;
|
oheight;
|
||||||
|
|
||||||
items.forEach(function(item){
|
items.forEach(function(item){
|
||||||
|
@ -14,7 +14,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
|
||||||
height = oHeight || rectHeight,
|
height = oHeight || rectHeight,
|
||||||
newHeight;
|
newHeight;
|
||||||
|
|
||||||
iheight = chapter.height();
|
iheight = chapter.bodyEl.clientHeight;
|
||||||
if(top < 0) top = 0;
|
if(top < 0) top = 0;
|
||||||
|
|
||||||
if(height + top >= iheight) {
|
if(height + top >= iheight) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ EPUBJSR.app.init = (function($){
|
||||||
|
|
||||||
//-- Create a new book object,
|
//-- Create a new book object,
|
||||||
// this will create an iframe in the el with the ID provided
|
// this will create an iframe in the el with the ID provided
|
||||||
Book = new EPUBJS.Book(bookURL, { restore : true });
|
Book = new EPUBJS.Book({ bookPath: bookURL, restore : true });
|
||||||
|
|
||||||
|
|
||||||
//Book.single = true;
|
//Book.single = true;
|
||||||
|
|
59
src/base.js
59
src/base.js
|
@ -3,4 +3,61 @@ EPUBJS.VERSION = "0.1.5";
|
||||||
|
|
||||||
EPUBJS.plugins = EPUBJS.plugins || {};
|
EPUBJS.plugins = EPUBJS.plugins || {};
|
||||||
|
|
||||||
EPUBJS.filePath = EPUBJS.filePath || "/epubjs/";
|
EPUBJS.filePath = EPUBJS.filePath || "/epubjs/";
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var root = this;
|
||||||
|
var previousEpub = root.ePub || {};
|
||||||
|
|
||||||
|
var ePub = root.ePub = function() {
|
||||||
|
var bookPath, options;
|
||||||
|
|
||||||
|
//-- var book = ePub("path/to/book.epub", { restore: true })
|
||||||
|
if(arguments[0] &&
|
||||||
|
typeof arguments[0] === 'string') {
|
||||||
|
|
||||||
|
bookPath = arguments[0];
|
||||||
|
|
||||||
|
if( arguments[1] && typeof arguments[1] === 'object' ) {
|
||||||
|
options = arguments[1];
|
||||||
|
options.bookPath = bookPath;
|
||||||
|
} else {
|
||||||
|
options = { 'bookPath' : bookPath }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* var book = ePub({ bookPath: "path/to/book.epub", restore: true });
|
||||||
|
*
|
||||||
|
* - OR -
|
||||||
|
*
|
||||||
|
* var book = ePub({ restore: true });
|
||||||
|
* book.open("path/to/book.epub");
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( arguments[0] && typeof arguments[0] === 'object' ) {
|
||||||
|
options = arguments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new EPUBJS.Book(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
_.extend(ePub, {
|
||||||
|
noConflict : function() {
|
||||||
|
root.ePub = previousEpub;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//exports to multiple environments
|
||||||
|
if (typeof define === 'function' && define.amd)
|
||||||
|
//AMD
|
||||||
|
define(function(){ return ePub; });
|
||||||
|
else if (typeof module != "undefined" && module.exports)
|
||||||
|
//Node
|
||||||
|
module.exports = ePub;
|
||||||
|
|
||||||
|
})();
|
53
src/book.js
53
src/book.js
|
@ -1,8 +1,9 @@
|
||||||
EPUBJS.Book = function(bookPath, options){
|
EPUBJS.Book = function(options){
|
||||||
|
|
||||||
var book = this;
|
var book = this;
|
||||||
|
|
||||||
this.settings = _.defaults(options || {}, {
|
this.settings = _.defaults(options || {}, {
|
||||||
|
bookPath : null,
|
||||||
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
|
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
|
||||||
fromStorage : false,
|
fromStorage : false,
|
||||||
saved : false,
|
saved : false,
|
||||||
|
@ -65,27 +66,14 @@ EPUBJS.Book = function(bookPath, options){
|
||||||
this.trigger("book:ready");
|
this.trigger("book:ready");
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this.opened = new RSVP.Promise();
|
||||||
// BookUrl is optional, but if present start loading process
|
// BookUrl is optional, but if present start loading process
|
||||||
if(bookPath) {
|
if(this.settings.bookPath) {
|
||||||
this.opened = this.open(bookPath);
|
this.open(this.settings.bookPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Likewise if an element is present start rendering process
|
window.addEventListener("beforeunload", this.unload.bind(this), false);
|
||||||
// if(bookPath && this.settings.element) {
|
|
||||||
// this.opened.then(function(){
|
|
||||||
// this.rendered = this.renderTo(el);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function(e) {
|
|
||||||
|
|
||||||
if(book.settings.restore) {
|
|
||||||
book.saveSettings();
|
|
||||||
book.saveContents();
|
|
||||||
}
|
|
||||||
|
|
||||||
book.trigger("book:unload");
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
//-- Listen for these promises:
|
//-- Listen for these promises:
|
||||||
//-- book.opened.then()
|
//-- book.opened.then()
|
||||||
|
@ -93,7 +81,6 @@ EPUBJS.Book = function(bookPath, options){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-- Check bookUrl and start parsing book Assets or load them from storage
|
//-- Check bookUrl and start parsing book Assets or load them from storage
|
||||||
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
var book = this,
|
var book = this,
|
||||||
|
@ -150,6 +137,10 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
if(!this.settings.stored) opened.then(book.storeOffline());
|
if(!this.settings.stored) opened.then(book.storeOffline());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opened.then(function(){
|
||||||
|
book.opened.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
return opened;
|
return opened;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -620,6 +611,28 @@ EPUBJS.Book.prototype.removeStyle = function(style, val, prefixed) {
|
||||||
delete this.settings.styles[style];
|
delete this.settings.styles[style];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.unload = function(bookPath, forceReload){
|
||||||
|
|
||||||
|
if(this.settings.restore) {
|
||||||
|
this.saveSettings();
|
||||||
|
this.saveContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.trigger("book:unload");
|
||||||
|
}
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.destroy = function() {
|
||||||
|
|
||||||
|
window.removeEventListener("beforeunload", this.unload);
|
||||||
|
|
||||||
|
if(this.currentChapter) this.currentChapter.unload();
|
||||||
|
|
||||||
|
this.unload();
|
||||||
|
|
||||||
|
if(this.render) this.render.remove();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-- Get pre-registered hooks
|
//-- Get pre-registered hooks
|
||||||
EPUBJS.Book.prototype.getHooks = function(){
|
EPUBJS.Book.prototype.getHooks = function(){
|
||||||
|
|
|
@ -143,12 +143,6 @@ EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.destroy = function(){
|
|
||||||
window.removeEventListener("resize", this.resized, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){
|
EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){
|
||||||
var width, height;
|
var width, height;
|
||||||
|
|
||||||
|
@ -276,7 +270,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
|
||||||
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
||||||
|
|
||||||
//-- Clear Margins
|
//-- Clear Margins
|
||||||
// this.bodyEl.style.margin = "0";
|
this.bodyEl.style.margin = "0";
|
||||||
|
|
||||||
this.docEl.style.overflow = "hidden";
|
this.docEl.style.overflow = "hidden";
|
||||||
|
|
||||||
|
@ -817,7 +811,10 @@ EPUBJS.Renderer.prototype.height = function(el){
|
||||||
return this.docEl.offsetHeight;
|
return this.docEl.offsetHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EPUBJS.Renderer.prototype.remove = function() {
|
||||||
|
window.removeEventListener("resize", this.resized);
|
||||||
|
this.el.removeChild(this.iframe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue