1
0
Fork 0
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:
Fred Chasen 2013-07-20 12:49:44 -07:00
parent 53955612ca
commit 660d570c02
28 changed files with 236 additions and 90 deletions

View file

@ -6,11 +6,69 @@ EPUBJS.VERSION = "0.1.5";
EPUBJS.plugins = EPUBJS.plugins || {};
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;
this.settings = _.defaults(options || {}, {
bookPath : null,
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
fromStorage : false,
saved : false,
@ -73,27 +131,14 @@ EPUBJS.Book = function(bookPath, options){
this.trigger("book:ready");
}.bind(this));
this.opened = new RSVP.Promise();
// BookUrl is optional, but if present start loading process
if(bookPath) {
this.opened = this.open(bookPath);
if(this.settings.bookPath) {
this.open(this.settings.bookPath);
}
// Likewise if an element is present start rendering process
// 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);
window.addEventListener("beforeunload", this.unload.bind(this), false);
//-- Listen for these promises:
//-- book.opened.then()
@ -101,7 +146,6 @@ EPUBJS.Book = function(bookPath, options){
}
//-- Check bookUrl and start parsing book Assets or load them from storage
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
var book = this,
@ -158,6 +202,10 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
if(!this.settings.stored) opened.then(book.storeOffline());
}
opened.then(function(){
book.opened.resolve();
});
return opened;
}
@ -628,6 +676,28 @@ EPUBJS.Book.prototype.removeStyle = function(style, val, prefixed) {
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
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){
var width, height;
@ -1806,7 +1870,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
//-- Clear Margins
// this.bodyEl.style.margin = "0";
this.bodyEl.style.margin = "0";
this.docEl.style.overflow = "hidden";
@ -2347,7 +2411,10 @@ EPUBJS.Renderer.prototype.height = function(el){
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

File diff suppressed because one or more lines are too long

View file

@ -4,9 +4,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
items = Array.prototype.slice.call(notes), //[].slice.call()
attr = "epub:type",
type = "noteref",
folder = EPUBJS.core.folder(location.pathname),
cssPath = folder + EPUBJS.cssPath || folder,
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){
@ -157,7 +159,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
var images = chapter.doc.querySelectorAll('img'),
items = Array.prototype.slice.call(images),
iheight = chapter.height(),//chapter.doc.body.getBoundingClientRect().height,
iheight = chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
oheight;
items.forEach(function(item){
@ -170,7 +172,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
height = oHeight || rectHeight,
newHeight;
iheight = chapter.height();
iheight = chapter.bodyEl.clientHeight;
if(top < 0) top = 0;
if(height + top >= iheight) {

View file

@ -26,7 +26,7 @@ EPUBJSR.app.init = (function($){
//-- Create a new book object,
// 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;

View file

@ -21,6 +21,7 @@
document.onreadystatechange = function () {
if (document.readyState == "complete") {
EPUBJS.filePath = "../libs/zip/";
EPUBJS.cssPath = "css/";
fileStorage.filePath = "../libs/fileStorage/workers/";
EPUBJS.VERSION = "0.1.5";

View file

@ -25,7 +25,8 @@
EPUBJS.VERSION = "0.1.6";
EPUBJS.filePath = "js/libs/";
fileStorage.filePath = EPUBJS.filePath + "libs/";
EPUBJS.cssPath = "css/";
fileStorage.filePath = EPUBJS.filePath;
EPUBJSR.app.init("moby-dick/");
}

4
demo/js/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -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()};

View file

@ -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}});

View file

@ -44,7 +44,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/", { restore: true });
var Book = ePub("../demo/moby-dick/", { restore: true });
</script>

View file

@ -19,7 +19,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("/demo/moby-dick/", { restore: true });
var Book = ePub("/demo/moby-dick/", { restore: true });
</script>

View file

@ -33,10 +33,10 @@
<script src="../src/renderer.js"></script>
<script src="../src/epubcfi.js"></script>
<!-- Plugins -->
<script async src="../hooks/default/transculsions.js"></script>
<script async src="../hooks/default/endnotes.js"></script>
<script async src="../hooks/default/smartimages.js"></script>
<!-- Hooks -->
<!-- <script src="../hooks/default/transculsions.js"></script> -->
<!-- <script src="../hooks/default/endnotes.js"></script> -->
<!-- <script src="../hooks/default/smartimages.js"></script> -->
<style type="text/css">
@ -95,7 +95,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/");
var Book = ePub("../demo/moby-dick/");
</script>
</head>

View file

@ -69,7 +69,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/");
var Book = ePub("../demo/moby-dick/");
</script>
</head>

View file

@ -18,7 +18,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/");
var Book = ePub("../demo/moby-dick/");
</script>
</head>

View file

@ -66,13 +66,15 @@
spreads = this.getAttribute("spreads") != null ? true : false,
restore = this.getAttribute("restore") != null ? true : false;
this.Book = new EPUBJS.Book(src, {
this.Book = new EPUBJS.Book({
width: width,
height: height,
spreads : spreads,
restore : restore
});
this.Book.open(src);
};
epubPrototype.prevPage = function() {

View file

@ -46,7 +46,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/", {
var Book = ePub("../demo/moby-dick/", {
width: 480,
height: 645,
spreads : false,

View file

@ -33,7 +33,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/", {
var Book = ePub("../demo/moby-dick/", {
fixedLayout : true
});

View file

@ -353,13 +353,15 @@
if(this.Book) this.Book.destroy();
this.Book = new EPUBJS.Book(src, {
this.Book = new EPUBJS.Book({
width: width,
height: height,
spreads : spreads,
restore : restore
});
this.Book.open(src);
this.events();
this.Book.renderTo(this.$.area);

View file

@ -48,13 +48,15 @@
if(this.Book) this.Book.destroy();
this.Book = new EPUBJS.Book(src, {
this.Book = new EPUBJS.Book({
width: width,
height: height,
spreads : spreads,
restore : restore
});
this.Book.open(src);
this.events();
this.Book.renderTo(this.$.area);

View file

@ -8,8 +8,8 @@
<!-- // <script src="../../build/epub.min.js"></script> -->
<!-- <link rel="import" href="epub-reader/epub-reader.html"> -->
<link rel="import" href="epub-reader.html">
<link rel="import" href="epub-reader/epub-reader.html">
<!-- <link rel="import" href="epub-reader.html"> -->
<link rel="stylesheet" href="../../demo/css/normalize.css">
<style>

View file

@ -16,7 +16,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/", { restore: true });
var Book = ePub("../demo/moby-dick/", { restore: true });
</script>

View file

@ -50,7 +50,7 @@
<script>
"use strict";
var Book = new EPUBJS.Book("../demo/moby-dick/", {
var Book = ePub("../demo/moby-dick/", {
width: 400,
height: 600,
spreads : false

View file

@ -4,9 +4,11 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
items = Array.prototype.slice.call(notes), //[].slice.call()
attr = "epub:type",
type = "noteref",
folder = EPUBJS.core.folder(location.pathname),
cssPath = folder + EPUBJS.cssPath || folder,
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){

View file

@ -1,7 +1,7 @@
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
var images = chapter.doc.querySelectorAll('img'),
items = Array.prototype.slice.call(images),
iheight = chapter.height(),//chapter.doc.body.getBoundingClientRect().height,
iheight = chapter.bodyEl.clientHeight,//chapter.doc.body.getBoundingClientRect().height,
oheight;
items.forEach(function(item){
@ -14,7 +14,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, c
height = oHeight || rectHeight,
newHeight;
iheight = chapter.height();
iheight = chapter.bodyEl.clientHeight;
if(top < 0) top = 0;
if(height + top >= iheight) {

View file

@ -26,7 +26,7 @@ EPUBJSR.app.init = (function($){
//-- Create a new book object,
// 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;

View file

@ -4,3 +4,60 @@ EPUBJS.VERSION = "0.1.5";
EPUBJS.plugins = EPUBJS.plugins || {};
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;
})();

View file

@ -1,8 +1,9 @@
EPUBJS.Book = function(bookPath, options){
EPUBJS.Book = function(options){
var book = this;
this.settings = _.defaults(options || {}, {
bookPath : null,
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
fromStorage : false,
saved : false,
@ -65,27 +66,14 @@ EPUBJS.Book = function(bookPath, options){
this.trigger("book:ready");
}.bind(this));
this.opened = new RSVP.Promise();
// BookUrl is optional, but if present start loading process
if(bookPath) {
this.opened = this.open(bookPath);
if(this.settings.bookPath) {
this.open(this.settings.bookPath);
}
// Likewise if an element is present start rendering process
// 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);
window.addEventListener("beforeunload", this.unload.bind(this), false);
//-- Listen for these promises:
//-- book.opened.then()
@ -93,7 +81,6 @@ EPUBJS.Book = function(bookPath, options){
}
//-- Check bookUrl and start parsing book Assets or load them from storage
EPUBJS.Book.prototype.open = function(bookPath, forceReload){
var book = this,
@ -150,6 +137,10 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
if(!this.settings.stored) opened.then(book.storeOffline());
}
opened.then(function(){
book.opened.resolve();
});
return opened;
}
@ -620,6 +611,28 @@ EPUBJS.Book.prototype.removeStyle = function(style, val, prefixed) {
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
EPUBJS.Book.prototype.getHooks = function(){

View file

@ -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){
var width, height;
@ -276,7 +270,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
//-- Clear Margins
// this.bodyEl.style.margin = "0";
this.bodyEl.style.margin = "0";
this.docEl.style.overflow = "hidden";
@ -817,7 +811,10 @@ EPUBJS.Renderer.prototype.height = function(el){
return this.docEl.offsetHeight;
}
EPUBJS.Renderer.prototype.remove = function() {
window.removeEventListener("resize", this.resized);
this.el.removeChild(this.iframe);
}