1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

updated grunt file to compress zip in correct order

This commit is contained in:
Fred Chasen 2013-07-14 13:07:54 -07:00
parent f1eb2d8707
commit ec377d9132
22 changed files with 2347 additions and 100 deletions

View file

@ -8,23 +8,34 @@ module.exports = function(grunt) {
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
concat : {
'build/epub.js': ['<banner>', 'src/*.js'],
'build/epub.js': ['<banner>', 'libs/rsvp/rsvp.min.js', 'src/*.js'],
'build/reader.js': ['<banner>', 'reader/*.js'],
'build/hooks.js': ['<banner>', 'hooks/default/*.js'],
'demo/js/libs/fileStorage.min.js': 'libs/fileStorage/fileStorage.min.js',
'demo/js/libs/loader_filesystem.min.js': 'libs/fileStorage/workers/loader_filesystem.min.js',
'demo/js/libs/jquery-1.9.0.min.js': 'libs/jquery/jquery-1.9.0.min.js'
'demo/js/libs/jquery-1.9.0.min.js': 'libs/jquery/jquery-1.9.0.min.js',
'demo/js/libs/inflate.js': 'libs/zip/inflate.js'
},
min: {
'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'libs/rsvp/rsvp.min.js', 'build/epub.js'],
'demo/js/reader.min.js': 'build/reader.js',
'demo/js/hooks.min.js': 'build/hooks.js',
'demo/js/libs/zip.min.js': ['libs/zip/*.js'],
'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js']
uglify: {
options: {
preserveComments: 'some'
},
my_target: {
files: {
'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'],
'demo/js/reader.min.js': 'build/reader.js',
'demo/js/hooks.min.js': 'build/hooks.js',
'demo/js/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['concat', 'min']);
grunt.registerTask('default', ['concat', 'uglify']);
};

View file

@ -1,4 +1,4 @@
/*! FuturePress - v0.1.0 - 2013-07-08 */
(function(e){"use strict";function v(e,n){t.async(function(){e.trigger("promise:resolved",{detail:n}),e.isResolved=!0,e.resolvedValue=n})}function m(e,n){t.async(function(){e.trigger("promise:failed",{detail:n}),e.isRejected=!0,e.rejectedValue=n})}function g(e){var t,n=[],r=new h,i=e.length;i===0&&r.resolve([]);var s=function(e){return function(t){o(e,t)}},o=function(e,t){n[e]=t,--i===0&&r.resolve(n)},u=function(e){r.reject(e)};for(t=0;t<i;t++)e[t].then(s(t),u);return r}function y(e,n){t[e]=n}var t={},n=typeof window!="undefined"?window:{},r=n.MutationObserver||n.WebKitMutationObserver,i;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")t.async=function(e,t){process.nextTick(function(){e.call(t)})};else if(r){var s=[],o=new r(function(){var e=s.slice();s=[],e.forEach(function(e){var t=e[0],n=e[1];t.call(n)})}),u=document.createElement("div");o.observe(u,{attributes:!0}),window.addEventListener("unload",function(){o.disconnect(),o=null}),t.async=function(e,t){s.push([e,t]),u.setAttribute("drainQueue","drainQueue")}}else t.async=function(e,t){setTimeout(function(){e.call(t)},1)};var a=function(e,t){this.type=e;for(var n in t){if(!t.hasOwnProperty(n))continue;this[n]=t[n]}},f=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n][0]===t)return n;return-1},l=function(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t},c={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e},on:function(e,t,n){var r=l(this),i,s;e=e.split(/\s+/),n=n||this;while(s=e.shift())i=r[s],i||(i=r[s]=[]),f(i,t)===-1&&i.push([t,n])},off:function(e,t){var n=l(this),r,i,s;e=e.split(/\s+/);while(i=e.shift()){if(!t){n[i]=[];continue}r=n[i],s=f(r,t),s!==-1&&r.splice(s,1)}},trigger:function(e,t){var n=l(this),r,i,s,o,u;if(r=n[e])for(var f=0,c=r.length;f<c;f++)i=r[f],s=i[0],o=i[1],typeof t!="object"&&(t={detail:t}),u=new a(e,t),s.call(o,u)}},h=function(){this.on("promise:resolved",function(e){this.trigger("success",{detail:e.detail})},this),this.on("promise:failed",function(e){this.trigger("error",{detail:e.detail})},this)},p=function(){},d=function(e,t,n,r){var i=typeof n=="function",s,o,u,a;if(i)try{s=n(r.detail),u=!0}catch(f){a=!0,o=f}else s=r.detail,u=!0;s&&typeof s.then=="function"?s.then(function(e){t.resolve(e)},function(e){t.reject(e)}):i&&u?t.resolve(s):a?t.reject(o):t[e](s)};h.prototype={then:function(e,n){var r=new h;return this.isResolved&&t.async(function(){d("resolve",r,e,{detail:this.resolvedValue})},this),this.isRejected&&t.async(function(){d("reject",r,n,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(t){d("resolve",r,e,t)}),this.on("promise:failed",function(e){d("reject",r,n,e)}),r},resolve:function(e){v(this,e),this.resolve=p,this.reject=p},reject:function(e){m(this,e),this.resolve=p,this.reject=p}},c.mixin(h.prototype),e.Promise=h,e.Event=a,e.EventTarget=c,e.all=g,e.configure=y})(window.RSVP={});
var EPUBJS = EPUBJS || {};
EPUBJS.VERSION = "0.1.5";
@ -13,6 +13,7 @@ EPUBJS.Book = function(bookPath, options){
this.settings = _.defaults(options || {}, {
element : false,
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
fromStorage : false,
saved : false,
online : true,
contained : false,
@ -20,7 +21,7 @@ EPUBJS.Book = function(bookPath, options){
height: false,
spreads: true,
responsive: true,
version: 1,
version: 1.1,
restore: true
});
@ -393,9 +394,8 @@ EPUBJS.Book.prototype.restore = function(){
reject = false,
fromStore = localStorage.getItem(contentsKey);
if(fromStore != 'undefined'){
if(fromStore != 'undefined' && fromStore != 'null'){
this.contents = JSON.parse(fromStore);
fetch.forEach(function(item){
book[item] = book.contents[item];
if(!book[item]) {
@ -1176,10 +1176,11 @@ EPUBJS.EpubCFI.prototype.getElement = function(cfi, doc) {
while(sections.length > 0) {
part = sections.shift();
if(part.id){
console.log(part.id)
element = cfi.doc.querySelector("#" + part.id);
element = doc.querySelector("#" + part.id);
}else{
element = children[part.index];
@ -1440,15 +1441,28 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
}
EPUBJS.Parser.prototype.toc = function(tocXml){
var toc = [];
var navMap = tocXml.querySelector("navMap");
function getTOC(nodes, parent, list){
var list = list || [];
var navMap = tocXml.querySelector("navMap");
items = Array.prototype.slice.call(nodes);
function getTOC(parent){
var list = [],
items = [],
nodes = parent.childNodes,
nodesArray = Array.prototype.slice.call(nodes),
length = nodesArray.length,
iter = length,
node;
if(length == 0) return false;
while(iter--){
node = nodesArray[iter];
if(node.nodeName === "navPoint") {
items.push(node);
}
}
items.forEach(function(item){
var id = item.getAttribute('id'),
content = item.querySelector("content"),
@ -1456,23 +1470,21 @@ EPUBJS.Parser.prototype.toc = function(tocXml){
split = src.split("#"),
navLabel = item.querySelector("navLabel"),
text = navLabel.textContent ? navLabel.textContent : "",
subitems = item.querySelectorAll("navPoint");
list.push({
subitems = getTOC(item);
list.unshift({
"id": id,
"href": src,
"label": text,
"subitems" : subitems.length ? getTOC(item.querySelectorAll("navPoint"), item, list) : false
"subitems" : subitems
});
});
return list;
}
return getTOC(navMap.querySelectorAll("navPoint"), navMap);
return getTOC(navMap);
}
@ -1647,7 +1659,7 @@ EPUBJS.Renderer.prototype.crossBrowserColumnCss = function(){
EPUBJS.Renderer.columnAxis = EPUBJS.core.prefixed('columnAxis');
EPUBJS.Renderer.columnGap = EPUBJS.core.prefixed('columnGap');
EPUBJS.Renderer.columnWidth = EPUBJS.core.prefixed('columnWidth');
EPUBJS.Renderer.transform = EPUBJS.core.prefixed('transform');
}
@ -1665,7 +1677,7 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
renderer.doc = renderer.iframe.contentDocument;
renderer.docEl = renderer.doc.documentElement;
renderer.bodyEl = renderer.doc.body;
renderer.applyStyles();
renderer.formatSpread();
@ -1714,7 +1726,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
this.gap = this.gap || Math.ceil(this.elWidth / 8);
if(this.elWidth < cutoff || this.settings.single) {
if(this.elWidth < cutoff || !this.book.settings.spreads) {
this.spread = false; //-- Single Page
divisor = 1;
@ -1867,7 +1879,9 @@ EPUBJS.Renderer.prototype.chapterEnd = function(){
EPUBJS.Renderer.prototype.setLeft = function(leftPos){
// this.bodyEl.style.marginLeft = -leftPos + "px";
this.doc.defaultView.scrollTo(leftPos, 0)
// this.docEl.style.marginLeft = -leftPos + "px";
// this.docEl.style[EPUBJS.Renderer.transform] = 'translate('+ (-leftPos) + 'px, 0)';
this.doc.defaultView.scrollTo(leftPos, 0);
}
EPUBJS.Renderer.prototype.replace = function(query, func, callback){
@ -2056,9 +2070,14 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
links.forEach(function(link){
var path,
href = link.getAttribute("href"),
relative = href.search("://"),
fragment = href[0] == "#";
relative,
fragment;
if(!href) return;
relative = href.search("://"),
fragment = href[0] == "#";
if(relative != -1){
link.setAttribute("target", "_blank");
@ -2067,10 +2086,10 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
link.onclick = function(){
that.book.goto(href);
return false;
}
}
});
if(callback) callback();
@ -2273,7 +2292,7 @@ RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
EPUBJS.Unarchiver = function(url){
this.libPath = EPUBJS.filePath + "zip/";
this.libPath = EPUBJS.filePath;
this.zipUrl = url;
this.loadLib()
this.urlCache = {};

View file

@ -1,5 +1,3 @@
/*! FuturePress - v0.1.0 - 2013-07-08 */
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chapter){
var notes = chapter.doc.querySelectorAll('a[href]'),
@ -8,10 +6,9 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
type = "noteref",
popups = {};
EPUBJS.core.addCss("../demo/css/popup.css", false, chapter.doc.head);
// EPUBJS.core.addCss("css/popup.css", false, chapter.doc.head);
//console.log("notes", items)
items.forEach(function(item){
var epubType = item.getAttribute(attr),
href,
@ -24,7 +21,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
txt;
if(epubType != type) return;
href = item.getAttribute("href");
id = href.replace("#", '');
el = chapter.doc.getElementById(id);
@ -63,11 +60,13 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
//-- TODO: will these leak memory? - Fred
popups[id].addEventListener("mouseover", onPop, false);
popups[id].addEventListener("mouseout", offPop, false);
//-- Add hide on page change
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
chapter.book.on("book:pageChanged", hidePop, this);
chapter.book.on("book:pageChanged", offPop, this);
// chapter.book.on("book:chapterDestroy", hidePop, this);
}
pop = popups[id];
@ -77,7 +76,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
itemRect = item.getBoundingClientRect();
left = itemRect.left;
top = itemRect.top;
//-- show the popup
pop.classList.add("show");

View file

@ -1,5 +1,3 @@
/*! FuturePress - v0.1.0 - 2013-07-08 */
var EPUBJSR = EPUBJSR || {};
EPUBJSR.app = {};
@ -64,6 +62,7 @@ EPUBJSR.app.init = (function($){
controls();
});
return Book;
}

View file

@ -14,6 +14,8 @@
<script src="js/libs/jquery-1.9.0.min.js"></script>
<script src="js/libs/zip.min.js"></script>
<script>
"use strict";
@ -21,14 +23,14 @@
if (document.readyState == "complete") {
EPUBJS.VERSION = "0.1.6";
EPUBJS.filePath = "js/";
EPUBJS.filePath = "js/libs/";
fileStorage.filePath = EPUBJS.filePath + "libs/";
EPUBJSR.app.init("moby-dick/");
EPUBJSR.app.init("moby-dick.epub");
}
};
</script>
</script>
<!-- Render -->
<script src="js/epub.min.js"></script>

3
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(e,t){var n=t.doc.querySelectorAll("a[href]"),r=Array.prototype.slice.call(n),i="epub:type",s="noteref",o={};r.forEach(function(e){function d(){var n,r=t.iframe.height,i=t.iframe.width,s,f,l=225;p||(f=a.cloneNode(!0),p=f.querySelector("p")),o[u]||(o[u]=document.createElement("div"),o[u].setAttribute("class","popup"),pop_content=document.createElement("div"),o[u].appendChild(pop_content),pop_content.appendChild(p),pop_content.setAttribute("class","pop_content"),t.bodyEl.appendChild(o[u]),o[u].addEventListener("mouseover",v,!1),o[u].addEventListener("mouseout",m,!1),t.book.listenUntil("book:pageChanged","book:chapterDestroy",g),t.book.listenUntil("book:pageChanged","book:chapterDestroy",m)),f=o[u],itemRect=e.getBoundingClientRect(),c=itemRect.left,h=itemRect.top,f.classList.add("show"),popRect=f.getBoundingClientRect(),f.style.left=c-popRect.width/2+"px",f.style.top=h+"px",l>r/2.5&&(l=r/2.5,pop_content.style.maxHeight=l+"px"),popRect.height+h>=r-25?(f.style.top=h-popRect.height+"px",f.classList.add("above")):f.classList.remove("above"),c-popRect.width<=0?(f.style.left=c+"px",f.classList.add("left")):f.classList.remove("left"),c+popRect.width/2>=i?(f.style.left=c-300+"px",popRect=f.getBoundingClientRect(),f.style.left=c-popRect.width+"px",popRect.height+h>=r-25?(f.style.top=h-popRect.height+"px",f.classList.add("above")):f.classList.remove("above"),f.classList.add("right")):f.classList.remove("right")}function v(){o[u].classList.add("on")}function m(){o[u].classList.remove("on")}function g(){setTimeout(function(){o[u].classList.remove("show")},100)}var n=e.getAttribute(i),r,u,a,f,l,c,h,p;if(n!=s)return;r=e.getAttribute("href"),u=r.replace("#",""),a=t.doc.getElementById(u),e.addEventListener("mouseover",d,!1),e.addEventListener("mouseout",g,!1)}),e&&e()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(e,t){var n=t.doc.querySelectorAll("img"),r=Array.prototype.slice.call(n),i=t.height(),s;r.forEach(function(e){function n(){var n=e.getBoundingClientRect(),r=n.height,s=n.top,o=e.getAttribute("data-height"),u=o||r,a;i=t.height(),s<0&&(s=0),u+s>=i?(s<i/2?(a=i-s,e.style.maxHeight=a+"px",e.style.width="auto"):(u=u<i?u:i,e.style.maxHeight=a+"px",e.style.marginTop=i-s+"px",e.style.width="auto"),e.setAttribute("data-height",a)):(e.style.removeProperty("max-height"),e.style.removeProperty("margin-top"))}e.addEventListener("load",n,!1),t.on("book:resized",n),t.on("book:chapterDestroyed",function(){e.removeEventListener("load",n),t.off("book:resized",n)}),n()}),e&&e()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(e,t){var n=t.doc.querySelectorAll("[transclusion]"),r=Array.prototype.slice.call(n);r.forEach(function(e){function l(){u=i,a=s,u>t.colWidth&&(f=t.colWidth/u,u=t.colWidth,a*=f),r.width=u,r.height=a}var n=e.getAttribute("ref"),r=document.createElement("iframe"),i=e.getAttribute("width"),s=e.getAttribute("height"),o=e.parentNode,u=i,a=s,f;l(),t.book.listenUntil("book:resized","book:chapterDestroy",l),r.src=n,o.replaceChild(r,e)}),e&&e()};
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("book:resized",c),b.on("book:chapterDestroyed",function(){a.removeEventListener("load",c),b.off("book: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()};

2163
demo/js/libs/inflate.js Normal file

File diff suppressed because it is too large Load diff

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 +1 @@
var EPUBJSR=EPUBJSR||{};EPUBJSR.app={},EPUBJSR.app.init=function(e){"use strict";function s(n){var s=window.location.search.match(/book=(.*)/),n=n||(s?s[1]:"moby-dick");i=e(window).width(),i>550?e("#main").width(i-r):e("#main").width(i),t=new EPUBJS.Book(n),t.on("book:online",c),t.on("book:offline",h),t.getMetadata().then(o),t.getToc().then(u),t.ready.all.then(l),t.renderTo("area"),e(function(){d()})}function o(t){var n=t.bookTitle,r=t.creator,i=e("#book-title"),s=e("#chapter-title"),o=e("#title-seperator");document.title=n+" "+r,i.html(n),s.html(r),o.show()}function u(n){var r=e("#toc"),i,s;r.empty(),s=f(n,1),r.append(s),i=e(".toc_link"),i.on("click",function(n){var r=e(this),i=r.data("url");e(".openChapter").removeClass("openChapter"),r.parents("li").addClass("openChapter"),t.goto(i),n.preventDefault()})}function a(){var n="";localStorage.getItem("fontSize")?n=localStorage.getItem("fontSize"):(n="medium",localStorage.setItem("fontSize",n));var r=e("#settingsPanel");r.append("<ul></ul>");var i=e("<li><h3></h3></li>"),s=e("<input type='radio' name='fontSize' value='x-small'><span class='xsmall'>Extra Small</span><br><input type='radio' name='fontSize' value='small'><span class='small'>Small</span><br><input type='radio' name='fontSize' value='medium'><span class='medium'>Medium</span><br><input type='radio' name='fontSize' value='large'><span class='large'>Large</span><br><input type='radio' name='fontSize' value='x-large'><span class='xlarge'>Extra Large</span>");i.find("h3").text("Font Size").after(s),r.find("ul").append(i);var o=e('input[name="fontSize"]');o.each(function(){e(this).attr("value")==n&&e(this).attr("checked","checked"),e(this).on("click",function(){localStorage.setItem("fontSize",e(this).attr("value")),t.iframe.contentDocument.location.reload(!0)})})}function f(t,n){var r=e("<ul>"),i=n==1?"chapter":"section";return t.forEach(function(t){var s,o=e("<li id='toc-"+t.id+"'>"),u=e("<a class='toc_link "+i+"' href='#/"+t.href+"' data-url='"+t.href+"'>"+t.label+"</a>");o.append(u),t.subitems&&t.subitems.length&&(n++,s=f(t.subitems,n),o.append(s)),r.append(o)}),r}function l(){var n=e("#divider"),r=e("#loader");r.hide(),t.single||n.addClass("show")}function c(){var t=e("#store");n=!1,t.attr("src",t.data("save"))}function h(){var t=e("#store");n=!0,t.attr("src",t.data("saved"))}function p(t){var n=t.msg,r=e("#toc-"+n),i=e(".currentChapter");r.length&&(i.removeClass("currentChapter"),r.addClass("currentChapter"))}function d(){function y(){f.addClass("open"),u.addClass("closed"),c.attr("src",c.data("close"))}function b(){a.css("pointer-events","visible"),f.removeClass("open"),u.removeClass("closed"),c.attr("src",c.data("open"))}function w(){v.hide(),d.show()}function E(){d.hide(),v.show()}var s=e("#next"),o=e("#prev"),u=e("#main"),a=e("#area"),f=e("#sidebar"),l=e("#open"),c=l.find("img"),h=e("#network"),p=e("#setting"),d=e("#settingsPanel"),v=e("#toc"),m=e(window);m.on("resize",function(){i=e(window).width(),i>550?u.width(i-r):u.width(i)}),s.on("click",function(){t.nextPage()}),o.on("click",function(){t.prevPage()}),p.on("click",function(){d.is(":visible")?E():w()});var g=!1;e(document).keydown(function(e){if(g)return;if(e.keyCode==37)return o.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1;if(e.keyCode==39)return s.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1}),l.on("click",function(){f.hasClass("open")?b():y()}),h.on("click",function(){n=!n,t.fromStorage(n)})}var t,n=!1,r=0,i;return s}(jQuery),jQuery.fn.extend({clickOutside:function(e,t){var n=this;return jQuery(document).on("click.offer",function(r){if(t&&jQuery.inArray(r.target,t)>-1)return;if(jQuery.contains(n[0],r.target))return;jQuery(document).off("click.offer"),e(r,n)}),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(b),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

@ -24,7 +24,8 @@
fileStorage.filePath = "../libs/fileStorage/workers/";
EPUBJS.VERSION = "0.1.5";
EPUBJSR.app.init('/demo/moby-dick.epub');
// EPUBJSR.app.init('/demo/moby-dick.epub');
window.book = EPUBJSR.app.init('/demo/moby-dick/');
}
};

View file

@ -6,10 +6,9 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
type = "noteref",
popups = {};
EPUBJS.core.addCss("../demo/css/popup.css", false, chapter.doc.head);
// EPUBJS.core.addCss("css/popup.css", false, chapter.doc.head);
//console.log("notes", items)
items.forEach(function(item){
var epubType = item.getAttribute(attr),
href,
@ -22,7 +21,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
txt;
if(epubType != type) return;
href = item.getAttribute("href");
id = href.replace("#", '');
el = chapter.doc.getElementById(id);
@ -61,11 +60,13 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
//-- TODO: will these leak memory? - Fred
popups[id].addEventListener("mouseover", onPop, false);
popups[id].addEventListener("mouseout", offPop, false);
//-- Add hide on page change
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", hidePop);
// chapter.book.listenUntil("book:pageChanged", "book:chapterDestroy", offPop);
chapter.book.on("book:pageChanged", hidePop, this);
chapter.book.on("book:pageChanged", offPop, this);
// chapter.book.on("book:chapterDestroy", hidePop, this);
}
pop = popups[id];
@ -75,7 +76,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
itemRect = item.getBoundingClientRect();
left = itemRect.left;
top = itemRect.top;
//-- show the popup
pop.classList.add("show");

View file

@ -1,8 +1,9 @@
/*!
// Underscore.js 1.4.4
// http://underscorejs.org
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
*/
(function() {
// Baseline setup

View file

@ -1,4 +1,4 @@
/*
/*!
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -7,6 +7,8 @@
"connect": "~2.8.4",
"colors": "~0.6.0-1",
"optimist": "~0.6.0",
"portfinder": "~0.2.1"
"portfinder": "~0.2.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2"
}
}

View file

@ -62,6 +62,7 @@ EPUBJSR.app.init = (function($){
controls();
});
return Book;
}

View file

@ -5,6 +5,7 @@ EPUBJS.Book = function(bookPath, options){
this.settings = _.defaults(options || {}, {
element : false,
storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem'
fromStorage : false,
saved : false,
online : true,
contained : false,
@ -12,7 +13,7 @@ EPUBJS.Book = function(bookPath, options){
height: false,
spreads: true,
responsive: true,
version: 1,
version: 1.1,
restore: true
});
@ -385,9 +386,8 @@ EPUBJS.Book.prototype.restore = function(){
reject = false,
fromStore = localStorage.getItem(contentsKey);
if(fromStore != 'undefined'){
if(fromStore != 'undefined' && fromStore != 'null'){
this.contents = JSON.parse(fromStore);
fetch.forEach(function(item){
book[item] = book.contents[item];
if(!book[item]) {

View file

@ -147,10 +147,11 @@ EPUBJS.EpubCFI.prototype.getElement = function(cfi, doc) {
while(sections.length > 0) {
part = sections.shift();
if(part.id){
console.log(part.id)
element = cfi.doc.querySelector("#" + part.id);
element = doc.querySelector("#" + part.id);
}else{
element = children[part.index];

View file

@ -159,15 +159,28 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
}
EPUBJS.Parser.prototype.toc = function(tocXml){
var toc = [];
var navMap = tocXml.querySelector("navMap");
function getTOC(nodes, parent, list){
var list = list || [];
var navMap = tocXml.querySelector("navMap");
items = Array.prototype.slice.call(nodes);
function getTOC(parent){
var list = [],
items = [],
nodes = parent.childNodes,
nodesArray = Array.prototype.slice.call(nodes),
length = nodesArray.length,
iter = length,
node;
if(length == 0) return false;
while(iter--){
node = nodesArray[iter];
if(node.nodeName === "navPoint") {
items.push(node);
}
}
items.forEach(function(item){
var id = item.getAttribute('id'),
content = item.querySelector("content"),
@ -175,23 +188,21 @@ EPUBJS.Parser.prototype.toc = function(tocXml){
split = src.split("#"),
navLabel = item.querySelector("navLabel"),
text = navLabel.textContent ? navLabel.textContent : "",
subitems = item.querySelectorAll("navPoint");
list.push({
subitems = getTOC(item);
list.unshift({
"id": id,
"href": src,
"label": text,
"subitems" : subitems.length ? getTOC(item.querySelectorAll("navPoint"), item, list) : false
"subitems" : subitems
});
});
return list;
}
return getTOC(navMap.querySelectorAll("navPoint"), navMap);
return getTOC(navMap);
}

View file

@ -167,7 +167,7 @@ EPUBJS.Renderer.prototype.crossBrowserColumnCss = function(){
EPUBJS.Renderer.columnAxis = EPUBJS.core.prefixed('columnAxis');
EPUBJS.Renderer.columnGap = EPUBJS.core.prefixed('columnGap');
EPUBJS.Renderer.columnWidth = EPUBJS.core.prefixed('columnWidth');
EPUBJS.Renderer.transform = EPUBJS.core.prefixed('transform');
}
@ -185,7 +185,7 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
renderer.doc = renderer.iframe.contentDocument;
renderer.docEl = renderer.doc.documentElement;
renderer.bodyEl = renderer.doc.body;
renderer.applyStyles();
renderer.formatSpread();
@ -234,7 +234,7 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
this.gap = this.gap || Math.ceil(this.elWidth / 8);
if(this.elWidth < cutoff || this.settings.single) {
if(this.elWidth < cutoff || !this.book.settings.spreads) {
this.spread = false; //-- Single Page
divisor = 1;
@ -387,7 +387,9 @@ EPUBJS.Renderer.prototype.chapterEnd = function(){
EPUBJS.Renderer.prototype.setLeft = function(leftPos){
// this.bodyEl.style.marginLeft = -leftPos + "px";
this.doc.defaultView.scrollTo(leftPos, 0)
// this.docEl.style.marginLeft = -leftPos + "px";
// this.docEl.style[EPUBJS.Renderer.transform] = 'translate('+ (-leftPos) + 'px, 0)';
this.doc.defaultView.scrollTo(leftPos, 0);
}
EPUBJS.Renderer.prototype.replace = function(query, func, callback){
@ -576,9 +578,14 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
links.forEach(function(link){
var path,
href = link.getAttribute("href"),
relative = href.search("://"),
fragment = href[0] == "#";
relative,
fragment;
if(!href) return;
relative = href.search("://"),
fragment = href[0] == "#";
if(relative != -1){
link.setAttribute("target", "_blank");
@ -587,10 +594,10 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
link.onclick = function(){
that.book.goto(href);
return false;
}
}
});
if(callback) callback();

View file

@ -1,7 +1,7 @@
EPUBJS.Unarchiver = function(url){
this.libPath = EPUBJS.filePath + "zip/";
this.libPath = EPUBJS.filePath;
this.zipUrl = url;
this.loadLib()
this.urlCache = {};