diff --git a/dist/epub.js b/dist/epub.js index 79b7a40..986ae9b 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -1897,7 +1897,14 @@ EPUBJS.core.request = function(url, type, withCredentials, headers) { var r; if(type == 'xml'){ - r = this.responseXML; + + // If this.responseXML wasn't set, try to parse using a DOMParser from text + if(!this.responseXML){ + r = new DOMParser().parseFromString(this.response, "text/xml"); + } else { + r = this.responseXML; + } + }else if(type == 'json'){ r = JSON.parse(this.response); @@ -2810,7 +2817,7 @@ EPUBJS.Infinite.prototype.check = function(){ this.tick.call(window, this.check.bind(this)); // setTimeout(this.check.bind(this), 100); -} +}; EPUBJS.Infinite.prototype.checkTop = function(){ @@ -3221,7 +3228,7 @@ EPUBJS.Navigation.prototype.loaded = function(toc) { item = toc[i]; this.tocByHref[item.href] = i; this.tocById[item.id] = i; - }; + } }; @@ -3371,7 +3378,6 @@ EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) { EPUBJS.Paginate.prototype.page = function(pg){ this.currentPage = pg; - console.log("page", this.currentPage * this.formated.pageWidth) this.renderer.infinite.scrollTo(this.currentPage * this.formated.pageWidth, 0); //-- Return false if page is greater than the total @@ -3387,7 +3393,7 @@ EPUBJS.Paginate.prototype.prev = function(){ }; EPUBJS.Paginate.prototype.display = function(what){ - return this.renderer.display(what) + return this.renderer.display(what); }; EPUBJS.Parser = function(){}; @@ -3930,9 +3936,13 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){ this.infinite.on("forwards", function(){ var next = this.last().section.index + 1; - if(!this.rendering && !this.filling && !this.displaying - && next < this.book.spine.length){ + if(!this.rendering && + !this.filling && + !this.displaying && + next < this.book.spine.length){ + this.forwards(); + } }.bind(this)); @@ -3940,9 +3950,13 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){ this.infinite.on("backwards", function(){ var prev = this.first().section.index - 1; - if(!this.rendering && !this.filling && !this.displaying - && prev > 0){ + if(!this.rendering && + !this.filling && + !this.displaying && + prev > 0){ + this.backwards(); + } }.bind(this)); @@ -4017,7 +4031,7 @@ EPUBJS.Renderer.prototype.render = function(section){ right: parseFloat(styles["padding-right"]) || 0, top: parseFloat(styles["padding-top"]) || 0, bottom: parseFloat(styles["padding-bottom"]) || 0 - }; + }; var width = bounds.width - padding.left - padding.right; var height = bounds.height - padding.top - padding.bottom; @@ -4026,7 +4040,7 @@ EPUBJS.Renderer.prototype.render = function(section){ rendered = new RSVP.defer(); rendered.reject(new Error("No Section Provided")); return rendered.promise; - }; + } view = new EPUBJS.View(section); @@ -4076,7 +4090,7 @@ EPUBJS.Renderer.prototype.forwards = function(){ rendered.reject(new Error("Reject Forwards")); return rendered.promise; } - console.log("going forwards") + // console.log("going forwards") this.rendering = true; @@ -4132,7 +4146,7 @@ EPUBJS.Renderer.prototype.backwards = function(view){ rendered.reject(new Error("Reject Backwards")); return rendered.promise; } - console.log("going backwards") + // console.log("going backwards") this.rendering = true; @@ -4314,7 +4328,7 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) { for (var i = 0; i < links.length; i++) { replaceLinks(links[i]); - }; + } task.resolve(); return task.promise; @@ -4358,10 +4372,10 @@ EPUBJS.Renderer.prototype.checkCurrent = function(position) { } this.current = view.section; - this.trigger("current", this.current) + this.trigger("current", this.current); break; } - }; + } } @@ -4440,7 +4454,7 @@ EPUBJS.Section.prototype.replacements = function(_document){ EPUBJS.Section.prototype.beforeSectionLoad = function(){ // Stub for a hook - replace me for now -} +}; EPUBJS.Section.prototype.render = function(_request){ var rendering = new RSVP.defer(); @@ -4685,7 +4699,7 @@ EPUBJS.View.prototype.display = function(contents) { displaying.resolve(this); // this.observer = this.observe(this.document.body); - return displayed + return displayed; }; diff --git a/dist/epub.min.js b/dist/epub.min.js index 8acddb5..ad5dc47 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,2 +1,2 @@ -"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(e){"use strict";var t=function(e){return new EPUBJS.Book(e)};t.Render={register:function(e,i){t.Render[e]=i}},"object"==typeof exports?(e.RSVP=require("rsvp"),module.exports=t):"function"==typeof define&&define.amd?define(t):e.ePub=t}(this),function(){"use strict";function e(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t)return i;return-1}function t(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}function i(e,t){return"onerror"===e?(Y.on("error",t),void 0):2!==arguments.length?Y[e]:(Y[e]=t,void 0)}function n(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(){}function a(){}function h(e){try{return e.then}catch(t){return ot.error=t,ot}}function c(e,t,i,n){try{e.call(t,i,n)}catch(r){return r}}function u(e,t,i){Y.async(function(e){var n=!1,r=c(i,t,function(i){n||(n=!0,t!==i?d(e,i):g(e,i))},function(t){n||(n=!0,y(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&r&&(n=!0,y(e,r))},e)}function p(e,t){t._state===nt?g(e,t._result):e._state===rt?y(e,t._result):m(t,void 0,function(i){t!==i?d(e,i):g(e,i)},function(t){y(e,t)})}function l(e,t){if(t.constructor===e.constructor)p(e,t);else{var i=h(t);i===ot?y(e,ot.error):void 0===i?g(e,t):r(i)?u(e,t,i):g(e,t)}}function d(e,t){e===t?g(e,t):n(t)?l(e,t):g(e,t)}function f(e){e._onerror&&e._onerror(e._result),v(e)}function g(e,t){e._state===it&&(e._result=t,e._state=nt,0===e._subscribers.length?Y.instrument&&tt("fulfilled",e):Y.async(v,e))}function y(e,t){e._state===it&&(e._state=rt,e._result=t,Y.async(f,e))}function m(e,t,i,n){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+nt]=i,r[o+rt]=n,0===o&&e._state&&Y.async(v,e)}function v(e){var t=e._subscribers,i=e._state;if(Y.instrument&&tt(i===nt?"fulfilled":"rejected",e),0!==t.length){for(var n,r,o=e._result,s=0;sa;a++)s[a]=e[a];for(n=0;nn;n++)i[n-1]=e[n];return i}function N(e,t){return{then:function(i,n){return e.call(t,i,n)}}}function I(e,t,i,n){var r=k(i,n,t);return r===gt&&y(e,r.value),e}function F(e,t,i,n){return ft.all(t).then(function(t){var r=k(i,n,t);return r===gt&&y(e,r.value),e})}function A(e){return e&&"object"==typeof e?e.constructor===ft?!0:_(e):!1}function O(e,t,i){this._superConstructor(e,t,!1,i)}function V(e,t,i){this._superConstructor(e,t,!0,i)}function q(e,t,i){this._superConstructor(e,t,!1,i)}function L(){return function(){process.nextTick(z)}}function j(){var e=0,t=new It(z),i=document.createTextNode("");return t.observe(i,{characterData:!0}),function(){i.data=e=++e%2}}function M(){var e=new MessageChannel;return e.port1.onmessage=z,function(){e.port2.postMessage(0)}}function H(){return function(){setTimeout(z,1)}}function z(){for(var e=0;Ct>e;e+=2){var t=At[e],i=At[e+1];t(i),At[e]=void 0,At[e+1]=void 0}Ct=0}function W(e,t){Y.async(e,t)}function D(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var K={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(i,n){var r,o=t(this);r=o[i],r||(r=o[i]=[]),-1===e(r,n)&&r.push(n)},off:function(i,n){var r,o,s=t(this);return n?(r=s[i],o=e(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(e,i){var n,r,o=t(this);if(n=o[e])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof e)throw new TypeError("Argument must be an object");return s.prototype=e,new s},et=[],tt=function(e,t,i){1===et.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:i&&t._guidKey+i._id,label:t._label,timeStamp:Z(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;tn;n++)this._eachEntry(i[n],n)},B.prototype._eachEntry=function(e,t){var i=this._instanceConstructor;o(e)?e.constructor===i&&e._state!==it?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(i.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(nt,t,e))},B.prototype._settledAt=function(e,t,i){var n=this.promise;n._state===it&&(this._remaining--,this._abortOnReject&&e===rt?y(n,i):this._result[t]=this._makeResult(e,t,i)),0===this._remaining&&g(n,this._result)},B.prototype._makeResult=function(e,t,i){return i},B.prototype._willSettleAt=function(e,t){var i=this;m(e,void 0,function(e){i._settledAt(nt,t,e)},function(e){i._settledAt(rt,t,e)})};var ht=function(e,t){return new at(this,e,!0,t).promise},ct=function(e,t){function i(e){d(o,e)}function n(e){y(o,e)}var r=this,o=new r(a,t);if(!Q(e))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=e.length,h=0;o._state===it&&s>h;h++)m(r.resolve(e[h]),void 0,i,n);return o},ut=function(e,t){var i=this;if(e&&"object"==typeof e&&e.constructor===i)return e;var n=new i(a,t);return d(n,e),n},pt=function(e,t){var i=this,n=new i(a,t);return y(n,e),n},lt="rsvp_"+Z()+"-",dt=0,ft=J;J.cast=ut,J.all=ht,J.race=ct,J.resolve=ut,J.reject=pt,J.prototype={constructor:J,_guidKey:lt,_onerror:function(e){Y.trigger("error",e)},then:function(e,t,i){var n=this,r=n._state;if(r===nt&&!e||r===rt&&!t)return Y.instrument&&tt("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&tt("chained",n,o),r){var h=arguments[r-1];Y.async(function(){P(r,o,h,s)})}else m(n,o,e,t);return o},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var i=this.constructor;return this.then(function(t){return i.resolve(e()).then(function(){return t})},function(t){return i.resolve(e()).then(function(){throw t})},t)}};var gt=new R,yt=new R,mt=function(e,t){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=A(i),s===yt){var c=new ft(a);return y(c,yt.value),c}s&&s!==!0&&(i=N(s,i))}o[h]=i}var u=new ft(a);return o[r]=function(e,i){e?y(u,e):void 0===t?d(u,i):t===!0?d(u,T(arguments)):Q(t)?d(u,C(arguments,t)):d(u,i)},s?F(u,o,e,n):I(u,o,e,n)};return i.__proto__=e,i},vt=function(e,t){return ft.all(e,t)};O.prototype=$(at.prototype),O.prototype._superConstructor=at,O.prototype._makeResult=b,O.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var Et=function(e,t){return new O(ft,e,t).promise},St=function(e,t){return ft.race(e,t)},Pt=V;V.prototype=$(at.prototype),V.prototype._superConstructor=at,V.prototype._init=function(){this._result={}},V.prototype._validateInput=function(e){return e&&"object"==typeof e},V.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},V.prototype._enumerate=function(){var e=this.promise,t=this._input,i=[];for(var n in t)e._state===it&&t.hasOwnProperty(n)&&i.push({position:n,entry:t[n]});var r=i.length;this._remaining=r;for(var o,s=0;e._state===it&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var wt=function(e,t){return new Pt(ft,e,t).promise};q.prototype=$(Pt.prototype),q.prototype._superConstructor=at,q.prototype._makeResult=b,q.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var bt,Bt=function(e,t){return new q(ft,e,t).promise},Ut=function(e){throw setTimeout(function(){throw e}),e},xt=function(e){var t={};return t.promise=new ft(function(e,i){t.resolve=e,t.reject=i},e),t},Jt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as map's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i)})},Rt=function(e,t){return ft.resolve(e,t)},_t=function(e,t){return ft.reject(e,t)},kt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as filter's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i).then(function(t){for(var i=new Array(n),r=0,o=0;n>o;o++)t[o]&&(i[r]=e[o],r++);return i.length=r,i})})},Ct=0,Tt=function(e,t){At[Ct]=e,At[Ct+1]=t,Ct+=2,2===Ct&&bt()},Nt="undefined"!=typeof window?window:{},It=Nt.MutationObserver||Nt.WebKitMutationObserver,Ft="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,At=new Array(1e3);bt="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?L():It?j():Ft?M():H(),Y.async=Tt;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Ot=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Vt in Ot)Ot.hasOwnProperty(Vt)&&D(Vt,Ot[Vt])}var qt={race:St,Promise:ft,allSettled:Et,hash:wt,hashSettled:Bt,denodeify:mt,on:D,off:X,map:Jt,filter:kt,resolve:Rt,reject:_t,all:vt,rethrow:Ut,defer:xt,EventTarget:K,configure:i,async:W};"function"==typeof define&&define.amd?define(function(){return qt}):"undefined"!=typeof module&&module.exports?module.exports=qt:"undefined"!=typeof this&&(this.RSVP=qt)}.call(this),EPUBJS.Book=function(e){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),e&&this.open(e)},EPUBJS.Book.prototype.open=function(e){var t,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return e?(t="object"==typeof e?e:EPUBJS.core.uri(e),"opf"===t.extension?(this.packageUrl=t.href,this.containerUrl="",t.origin?this.url=t.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,t.directory)):this.url=t.directory,i=this.request(this.packageUrl)):"epub"===t.extension||"zip"===t.extension?(this.archived=!0,this.url=""):t.extension||(this.containerUrl=e+s,i=this.request(this.containerUrl).then(function(e){return r.container(e)}).then(function(t){var i=EPUBJS.core.uri(t.packagePath);return o.packageUrl=e+t.packagePath,o.url=e+i.directory,o.encoding=t.encoding,o.request(o.packageUrl)}).catch(function(e){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(e)})),i.then(function(e){o.unpack(e),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(e){console.error(e.message,e.stack),o.opening.reject(e)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(e){var t=this,i=new EPUBJS.Parser;t.package=i.packageContents(e),t.package.baseUrl=t.url,this.spine.load(t.package),t.navigation=new EPUBJS.Navigation(t.package,this.request),t.navigation.load().then(function(e){t.toc=e,t.loading.navigation.resolve(t.toc)}),t.cover=t.url+t.package.coverPath},EPUBJS.Book.prototype.section=function(e){return this.spine.get(e)},EPUBJS.Book.prototype.renderTo=function(e,t){return this.rendition=new EPUBJS.Renderer(this,t),this.rendition.attachTo(e),this.rendition},EPUBJS.Book.prototype.requestMethod=function(e){return this.archived?void 0:EPUBJS.core.request(e,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(e){this.requestCredentials=e},EPUBJS.Book.prototype.setRequestHeaders=function(e){this.requestHeaders=e},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(e){console.error(e.detail.message,e.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(e,t,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var e;e="xml"==t?this.responseXML:"json"==t?JSON.parse(this.response):"blob"==t?s?this.response:new Blob([this.response]):this.response,h.resolve(e)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",h=new RSVP.defer,c=new XMLHttpRequest,u=XMLHttpRequest.prototype;"overrideMimeType"in u||Object.defineProperty(u,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",e,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==t&&(c.responseType=a),"json"==t&&c.setRequestHeader("Accept","application/json"),"xml"==t&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(e){var t,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:e},o=e.indexOf("://"),s=e.indexOf("?"),a=e.indexOf("#");return-1!=a&&(r.fragment=e.slice(a+1),e=e.slice(0,a)),-1!=s&&(r.search=e.slice(s+1),e=e.slice(0,s),href=e),-1!=o?(r.protocol=e.slice(0,o),t=e.slice(o+3),n=t.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=t.slice(0,n),r.path=t.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=e,r.directory=EPUBJS.core.folder(e),r.base=r.directory),r.filename=e.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/");if(-1==t)var i="";return i=e.slice(0,t+1)},EPUBJS.core.queue=function(e){var t=[],i=e,n=function(e,i,n){return t.push({funcName:e,args:i,context:n}),t},r=function(){var e;t.length&&(e=t.shift(),i[e.funcName].apply(e.context||i,e.args))},o=function(){for(;t.length;)r()},s=function(){t=[]},a=function(){return t.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(e){return!(!e||1!=e.nodeType)},EPUBJS.core.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:7&i|8).toString(16)});return t},EPUBJS.core.values=function(e){for(var t=-1,i=Object.keys(e),n=i.length,r=Array(n);++tr;r++)if("undefined"!=typeof document.body.style[t[r]+i])return t[r]+i;return e},EPUBJS.core.defaults=function(e){for(var t=1,i=arguments.length;i>t;t++){var n=arguments[t];for(var r in n)void 0===e[r]&&(e[r]=n[r])}return e},EPUBJS.EpubCFI=function(e){return e?this.parse(e):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(e,t,i){var n=parseInt(t),r=e+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(e){var t=[];return e.forEach(function(e){var i="";i+=2*(e.index+1),e.id&&(i+="["+e.id+"]"),t.push(i)}),t.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(e,t){var i=this.pathTo(e),n=this.generatePathComponent(i);return n.length?"epubcfi("+t+"!"+n+"/1:0)":"epubcfi("+t+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(e){for(var t,i=[];e&&null!==e.parentNode&&9!=e.parentNode.nodeType;)t=e.parentNode.children,i.unshift({id:e.id,tagName:e.tagName,index:t?Array.prototype.indexOf.call(t,e):0}),e=e.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(e){var t=e.split("!");return t[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(e){var t=e.split("!"),i=t[1]?t[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(e){var t=e.split(":");return t[1]||""},EPUBJS.EpubCFI.prototype.parse=function(e){var t,i,n,r,o,s,a,h,c,u={},p=function(e){var t,i,n,r;return t="element",i=parseInt(e)/2-1,n=e.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:t,index:i,id:r||!1}};return"string"!=typeof e?{spinePos:-1}:(u.str=e,0===e.indexOf("epubcfi(")&&")"===e[e.length-1]&&(e=e.slice(8,e.length-1)),i=this.getChapterComponent(e),n=this.getPathComponent(e)||"",r=this.getCharecterOffsetComponent(e),i?(t=i.split("/")[2]||"")?(u.spinePos=parseInt(t)/2-1||0,s=t.match(/\[(.*)\]/),u.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),u.steps=[],a.forEach(function(e){var t;e&&(t=p(e),u.steps.push(t))}),c=parseInt(h),isNaN(c)||(c%2===0?u.steps.push(p(h)):u.steps.push({type:"text",index:(c-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(u.characterOffset=parseInt(r.split("[")[0]),u.textLocationAssertion=o[1]):u.characterOffset=parseInt(r),u):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(e,t,i){var n,r,o,s,a=t||document,h=i||this.createMarker(a);return"string"==typeof e&&(e=this.parse(e)),r=e.steps[e.steps.length-1],-1===e.spinePos?!1:(n=this.findParent(e,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],e.characterOffset?(s=o.splitText(e.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(e){var t=e||document,i=t.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(e,t){e.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=e.nextSibling,prevSib=e.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,e.parentNode.removeChild(nextSib)),e.parentNode.removeChild(e)):e.classList.contains("EPUBJS-CFI-MARKER")&&e.parentNode.removeChild(e)},EPUBJS.EpubCFI.prototype.findParent=function(e,t){var i,n,r,o=t||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof e&&(e=this.parse(e)),n=e.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,e.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(e,t){if("string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),"string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),e.spinePos>t.spinePos)return 1;if(e.spinePost.steps[i].index)return 1;if(e.steps[i].indext.characterOffset?1:e.characterOffset=0?(o=r.length,e.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(e=n.promise,n.resolve()),e},EPUBJS.Infinite=function(e,t){this.container=e,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=500,this.views=[],this.axis=t,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.displaying?("vertical"===this.axis?this.checkTop():this.checkLeft(),this.trigger("scroll",{top:this.container.scrollTop,left:this.container.scrollLeft}),this.scrolled=!1):(this.displaying=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.checkTop=function(){var e=this.container.scrollTop,t=this.container.scrollHeight,i=e-this.prevScrollTop,n=this.container.getBoundingClientRect().height,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevScrollTop=e,e},EPUBJS.Infinite.prototype.checkLeft=function(){var e=this.container.scrollLeft,t=this.container.scrollWidth,i=e-this.prevscrollLeft,n=this.container.getBoundingClientRect().width,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevscrollLeft=e,e},EPUBJS.Infinite.prototype.scrollBy=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft+=e,this.container.scrollTop+=t,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft=e,this.container.scrollTop=t,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(t),c=Math.floor(h/8),u=n>=0?n:c%2===0?c:c-1;return this.documentElement=e,this.spreadWidth=h+u,e.style.overflow="hidden",e.style.width=h+"px",e.style.height=i+"px",e.style[r]="horizontal",e.style[a]="auto",e.style[s]=h+"px",e.style[o]=u+"px",this.colWidth=h,this.gap=u,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var e,t;return this.documentElement.style.width="auto",e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth),{displayedPages:t,pageCount:t}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=2,c=Math.floor(t),u=c%2===0?c:c-1,p=Math.floor(u/8),l=n>=0?n:p%2===0?p:p-1,d=Math.floor((u-l)/h);return this.spreadWidth=(d+l)*h,e.document.documentElement.style.overflow="hidden",e.document.body.style.width=u+"px",e.document.body.style.height=i+"px",e.document.body.style[r]="horizontal",e.document.body.style[a]="auto",e.document.body.style[o]=l+"px",e.document.body.style[s]=d+"px",this.colWidth=d,this.gap=l,e.iframe.style.width=d+"px",e.iframe.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth);return this.documentElement.style.width=e+this.spreadWidth+"px",{displayedPages:t,pageCount:2*t}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(e){var t,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=e.querySelector("[name=viewport");return this.documentElement=e,s&&s.hasAttribute("content")&&(t=s.getAttribute("content"),i=t.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),e.style.width=n+"px"||"auto",e.style.height=r+"px"||"auto",e.style[o]="auto",e.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(e,t){var i=this,n=new EPUBJS.Parser,r=t||EPUBJS.core.request;this.package=e,this.toc=[],this.tocByHref={},this.tocById={},e.navPath&&(this.navUrl=e.baseUrl+e.navPath,this.nav={},this.nav.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.navUrl,"xml").then(function(t){i.toc=n.nav(t),i.loaded(i.toc),e.resolve(i.toc)}),t}),e.ncxPath&&(this.ncxUrl=e.baseUrl+e.ncxPath,this.ncx={},this.ncx.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.ncxUrl,"xml").then(function(t){i.toc=n.ncx(t),i.loaded(i.toc),e.resolve(i.toc)}),t})},EPUBJS.Navigation.prototype.load=function(e){{var t,i;e||EPUBJS.core.request}return this.nav?t=this.nav.load():this.ncx?t=this.ncx.load():(i=new RSVP.defer,i.resolve([]),t=i.promise),t},EPUBJS.Navigation.prototype.loaded=function(e){for(var t,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),u=c.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=u.split("#"),f=(d[0],t(a));n.unshift({id:h,href:u,label:l,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=e.querySelector("navMap");return i?t(i):[]},EPUBJS.Renderer=function(e,t){var i=t||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||""},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},i=t.height!==!1?t.height:"100%",n=t.width!==!1?t.width:"100%";t.hidden||!1}return t.height&&EPUBJS.core.isNumber(t.height)&&(i=t.height+"px"),t.width&&EPUBJS.core.isNumber(t.width)&&(n=t.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var i=e,n=t,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,a=n-o.top-o.bottom;e||(i=window.innerWidth),t||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(e){"vertical"===this.settings.axis?e.resize(s,0):e.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var e=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&e0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),this.hooks.display.register(this.afterDisplay.bind(this)),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,i=t.promise;return"string"==typeof e&&(e=e.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(e);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,t.resolve(this)}.bind(this))):t.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(e){var t,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,a=n.height-o.top-o.bottom;return e?(i=new EPUBJS.View(e),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,e.index),t=i.render(this.book.request),t.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(e){this.trigger("loaderror",e)}.bind(this))):(t=new RSVP.defer,t.reject(new Error("No Section Provided")),t.promise)},EPUBJS.Renderer.prototype.forwards=function(){var e,t,i;return e=this.last().section.index+1,this.rendering||e===this.book.spine.length?(t=new RSVP.defer,t.reject(new Error("Reject Forwards")),t.promise):(console.log("going forwards"),this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e=this.first(),t=e.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-t.height>100&&(this.remove(e),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-t.height,!0):this.infinite.scrollTo(n-t.width,!0))),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,i;return e=this.first().section.index-1,this.rendering||0>e?(t=new RSVP.defer,t.reject(new Error("Reject Backwards")),t.promise):(console.log("going backwards"),this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(e=this.last(),this.remove(e),this.container.scrollTop-this.first().bounds().height>100&&this.remove(e)),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.first().section.index-1,t=this.forwards();return this.filling=!0,"vertical"===this.settings.axis?t.then(this.fillVertical.bind(this)):t.then(this.fillHorizontal.bind(this)),e>0&&t.then(this.backwards.bind(this)),t.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var e=this.container.getBoundingClientRect().height,t=this.last().bounds().bottom,i=new RSVP.defer;return e&&t&&e>t?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var e=this.container.getBoundingClientRect().width,t=this.last().bounds().right,i=new RSVP.defer;return e&&t&&e>=t?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().section.index>=0?this.append(e):t-this.last().section.index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.remove=function(e){var t=this.views.indexOf(e);e.destroy(),t>-1&&this.views.splice(t,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(e,t){for(var i=new RSVP.defer,n=e.document.querySelectorAll("a[href]"),r=function(e){var i=e.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?e.setAttribute("target","_blank"):0===i.indexOf("#")||(e.onclick=function(){return t.display(i),!1})},o=0;o=0;r--)if(e=this.views[r],t=e.bounds().top,t-1?(delete this.spineByHref[e.href],delete this.spineById[e.idref],this.spineItems.splice(t,1)):void 0},EPUBJS.View=function(e){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.rendering=new RSVP.defer,this.rendered=this.rendering.promise,this.section=e},EPUBJS.View.prototype.create=function(e,t){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resize=function(e,t){e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.resizing||(this.resizing=!0,this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:(console.log("resize"),this.expand())},EPUBJS.View.prototype.render=function(e){return this.section.render(e).then(function(e){return this.load(e)}.bind(this)).then(this.display.bind(this)).then(function(){this.rendering.resolve(this)}.bind(this))},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,i=t.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,t.resolve(this)}.bind(this)),this.document.open(),this.document.write(e),this.document.close(),i):(t.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.display=function(){var e=new RSVP.defer,t=e.promise;return this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),e.resolve(this),t},EPUBJS.View.prototype.expand=function(e,t){var i,n,r,o=e||new RSVP.defer,s=o.promise,a=t||0;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),(!i||0===i.height&&0===i.width)&&console.error("View not shown"),r=i.height,n=this.document.documentElement.scrollWidth,this.width!=n||this.height!=r?setTimeout(function(){this.expand(o,a)}.bind(this),10):o.resolve(),this.width=n,this.height=r,this.iframe.style.height=r+"px",this.iframe.style.width=n+"px",s},EPUBJS.View.prototype.observe=function(e){var t=this,i=new MutationObserver(function(){t.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(e,n),i},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.show=function(){this.iframe.style.display="inline-block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)}; \ No newline at end of file +"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(e){"use strict";var t=function(e){return new EPUBJS.Book(e)};t.Render={register:function(e,i){t.Render[e]=i}},"object"==typeof exports?(e.RSVP=require("rsvp"),module.exports=t):"function"==typeof define&&define.amd?define(t):e.ePub=t}(this),function(){"use strict";function e(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t)return i;return-1}function t(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}function i(e,t){return"onerror"===e?(Y.on("error",t),void 0):2!==arguments.length?Y[e]:(Y[e]=t,void 0)}function n(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(){}function a(){}function h(e){try{return e.then}catch(t){return ot.error=t,ot}}function c(e,t,i,n){try{e.call(t,i,n)}catch(r){return r}}function u(e,t,i){Y.async(function(e){var n=!1,r=c(i,t,function(i){n||(n=!0,t!==i?d(e,i):g(e,i))},function(t){n||(n=!0,y(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&r&&(n=!0,y(e,r))},e)}function p(e,t){t._state===nt?g(e,t._result):e._state===rt?y(e,t._result):m(t,void 0,function(i){t!==i?d(e,i):g(e,i)},function(t){y(e,t)})}function l(e,t){if(t.constructor===e.constructor)p(e,t);else{var i=h(t);i===ot?y(e,ot.error):void 0===i?g(e,t):r(i)?u(e,t,i):g(e,t)}}function d(e,t){e===t?g(e,t):n(t)?l(e,t):g(e,t)}function f(e){e._onerror&&e._onerror(e._result),v(e)}function g(e,t){e._state===it&&(e._result=t,e._state=nt,0===e._subscribers.length?Y.instrument&&tt("fulfilled",e):Y.async(v,e))}function y(e,t){e._state===it&&(e._state=rt,e._result=t,Y.async(f,e))}function m(e,t,i,n){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+nt]=i,r[o+rt]=n,0===o&&e._state&&Y.async(v,e)}function v(e){var t=e._subscribers,i=e._state;if(Y.instrument&&tt(i===nt?"fulfilled":"rejected",e),0!==t.length){for(var n,r,o=e._result,s=0;sa;a++)s[a]=e[a];for(n=0;nn;n++)i[n-1]=e[n];return i}function N(e,t){return{then:function(i,n){return e.call(t,i,n)}}}function I(e,t,i,n){var r=k(i,n,t);return r===gt&&y(e,r.value),e}function F(e,t,i,n){return ft.all(t).then(function(t){var r=k(i,n,t);return r===gt&&y(e,r.value),e})}function A(e){return e&&"object"==typeof e?e.constructor===ft?!0:_(e):!1}function O(e,t,i){this._superConstructor(e,t,!1,i)}function V(e,t,i){this._superConstructor(e,t,!0,i)}function q(e,t,i){this._superConstructor(e,t,!1,i)}function L(){return function(){process.nextTick(z)}}function M(){var e=0,t=new It(z),i=document.createTextNode("");return t.observe(i,{characterData:!0}),function(){i.data=e=++e%2}}function j(){var e=new MessageChannel;return e.port1.onmessage=z,function(){e.port2.postMessage(0)}}function H(){return function(){setTimeout(z,1)}}function z(){for(var e=0;Ct>e;e+=2){var t=At[e],i=At[e+1];t(i),At[e]=void 0,At[e+1]=void 0}Ct=0}function W(e,t){Y.async(e,t)}function D(){Y.on.apply(Y,arguments)}function X(){Y.off.apply(Y,arguments)}var K={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(i,n){var r,o=t(this);r=o[i],r||(r=o[i]=[]),-1===e(r,n)&&r.push(n)},off:function(i,n){var r,o,s=t(this);return n?(r=s[i],o=e(r,n),-1!==o&&r.splice(o,1),void 0):(s[i]=[],void 0)},trigger:function(e,i){var n,r,o=t(this);if(n=o[e])for(var s=0;s1)throw new Error("Second argument not supported");if("object"!=typeof e)throw new TypeError("Argument must be an object");return s.prototype=e,new s},et=[],tt=function(e,t,i){1===et.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:i&&t._guidKey+i._id,label:t._label,timeStamp:Z(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;tn;n++)this._eachEntry(i[n],n)},B.prototype._eachEntry=function(e,t){var i=this._instanceConstructor;o(e)?e.constructor===i&&e._state!==it?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(i.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(nt,t,e))},B.prototype._settledAt=function(e,t,i){var n=this.promise;n._state===it&&(this._remaining--,this._abortOnReject&&e===rt?y(n,i):this._result[t]=this._makeResult(e,t,i)),0===this._remaining&&g(n,this._result)},B.prototype._makeResult=function(e,t,i){return i},B.prototype._willSettleAt=function(e,t){var i=this;m(e,void 0,function(e){i._settledAt(nt,t,e)},function(e){i._settledAt(rt,t,e)})};var ht=function(e,t){return new at(this,e,!0,t).promise},ct=function(e,t){function i(e){d(o,e)}function n(e){y(o,e)}var r=this,o=new r(a,t);if(!Q(e))return y(o,new TypeError("You must pass an array to race.")),o;for(var s=e.length,h=0;o._state===it&&s>h;h++)m(r.resolve(e[h]),void 0,i,n);return o},ut=function(e,t){var i=this;if(e&&"object"==typeof e&&e.constructor===i)return e;var n=new i(a,t);return d(n,e),n},pt=function(e,t){var i=this,n=new i(a,t);return y(n,e),n},lt="rsvp_"+Z()+"-",dt=0,ft=J;J.cast=ut,J.all=ht,J.race=ct,J.resolve=ut,J.reject=pt,J.prototype={constructor:J,_guidKey:lt,_onerror:function(e){Y.trigger("error",e)},then:function(e,t,i){var n=this,r=n._state;if(r===nt&&!e||r===rt&&!t)return Y.instrument&&tt("chained",this,this),this;n._onerror=null;var o=new this.constructor(a,i),s=n._result;if(Y.instrument&&tt("chained",n,o),r){var h=arguments[r-1];Y.async(function(){P(r,o,h,s)})}else m(n,o,e,t);return o},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var i=this.constructor;return this.then(function(t){return i.resolve(e()).then(function(){return t})},function(t){return i.resolve(e()).then(function(){throw t})},t)}};var gt=new R,yt=new R,mt=function(e,t){var i=function(){for(var i,n=this,r=arguments.length,o=new Array(r+1),s=!1,h=0;r>h;++h){if(i=arguments[h],!s){if(s=A(i),s===yt){var c=new ft(a);return y(c,yt.value),c}s&&s!==!0&&(i=N(s,i))}o[h]=i}var u=new ft(a);return o[r]=function(e,i){e?y(u,e):void 0===t?d(u,i):t===!0?d(u,T(arguments)):Q(t)?d(u,C(arguments,t)):d(u,i)},s?F(u,o,e,n):I(u,o,e,n)};return i.__proto__=e,i},vt=function(e,t){return ft.all(e,t)};O.prototype=$(at.prototype),O.prototype._superConstructor=at,O.prototype._makeResult=b,O.prototype._validationError=function(){return new Error("allSettled must be called with an array")};var St=function(e,t){return new O(ft,e,t).promise},Et=function(e,t){return ft.race(e,t)},Pt=V;V.prototype=$(at.prototype),V.prototype._superConstructor=at,V.prototype._init=function(){this._result={}},V.prototype._validateInput=function(e){return e&&"object"==typeof e},V.prototype._validationError=function(){return new Error("Promise.hash must be called with an object")},V.prototype._enumerate=function(){var e=this.promise,t=this._input,i=[];for(var n in t)e._state===it&&t.hasOwnProperty(n)&&i.push({position:n,entry:t[n]});var r=i.length;this._remaining=r;for(var o,s=0;e._state===it&&r>s;s++)o=i[s],this._eachEntry(o.entry,o.position)};var wt=function(e,t){return new Pt(ft,e,t).promise};q.prototype=$(Pt.prototype),q.prototype._superConstructor=at,q.prototype._makeResult=b,q.prototype._validationError=function(){return new Error("hashSettled must be called with an object")};var bt,Bt=function(e,t){return new q(ft,e,t).promise},Ut=function(e){throw setTimeout(function(){throw e}),e},xt=function(e){var t={};return t.promise=new ft(function(e,i){t.resolve=e,t.reject=i},e),t},Jt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as map's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i)})},Rt=function(e,t){return ft.resolve(e,t)},_t=function(e,t){return ft.reject(e,t)},kt=function(e,t,i){return ft.all(e,i).then(function(e){if(!r(t))throw new TypeError("You must pass a function as filter's second argument.");for(var n=e.length,o=new Array(n),s=0;n>s;s++)o[s]=t(e[s]);return ft.all(o,i).then(function(t){for(var i=new Array(n),r=0,o=0;n>o;o++)t[o]&&(i[r]=e[o],r++);return i.length=r,i})})},Ct=0,Tt=function(e,t){At[Ct]=e,At[Ct+1]=t,Ct+=2,2===Ct&&bt()},Nt="undefined"!=typeof window?window:{},It=Nt.MutationObserver||Nt.WebKitMutationObserver,Ft="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,At=new Array(1e3);bt="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?L():It?M():Ft?j():H(),Y.async=Tt;if("undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var Ot=window.__PROMISE_INSTRUMENTATION__;i("instrument",!0);for(var Vt in Ot)Ot.hasOwnProperty(Vt)&&D(Vt,Ot[Vt])}var qt={race:Et,Promise:ft,allSettled:St,hash:wt,hashSettled:Bt,denodeify:mt,on:D,off:X,map:Jt,filter:kt,resolve:Rt,reject:_t,all:vt,rethrow:Ut,defer:xt,EventTarget:K,configure:i,async:W};"function"==typeof define&&define.amd?define(function(){return qt}):"undefined"!=typeof module&&module.exports?module.exports=qt:"undefined"!=typeof this&&(this.RSVP=qt)}.call(this),EPUBJS.Book=function(e){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),e&&this.open(e)},EPUBJS.Book.prototype.open=function(e){var t,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return e?(t="object"==typeof e?e:EPUBJS.core.uri(e),"opf"===t.extension?(this.packageUrl=t.href,this.containerUrl="",t.origin?this.url=t.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,t.directory)):this.url=t.directory,i=this.request(this.packageUrl)):"epub"===t.extension||"zip"===t.extension?(this.archived=!0,this.url=""):t.extension||(this.containerUrl=e+s,i=this.request(this.containerUrl).then(function(e){return r.container(e)}).then(function(t){var i=EPUBJS.core.uri(t.packagePath);return o.packageUrl=e+t.packagePath,o.url=e+i.directory,o.encoding=t.encoding,o.request(o.packageUrl)}).catch(function(e){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(e)})),i.then(function(e){o.unpack(e),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(e){console.error(e.message,e.stack),o.opening.reject(e)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(e){var t=this,i=new EPUBJS.Parser;t.package=i.packageContents(e),t.package.baseUrl=t.url,this.spine.load(t.package),t.navigation=new EPUBJS.Navigation(t.package,this.request),t.navigation.load().then(function(e){t.toc=e,t.loading.navigation.resolve(t.toc)}),t.cover=t.url+t.package.coverPath},EPUBJS.Book.prototype.section=function(e){return this.spine.get(e)},EPUBJS.Book.prototype.renderTo=function(e,t){return this.rendition=new EPUBJS.Renderer(this,t),this.rendition.attachTo(e),this.rendition},EPUBJS.Book.prototype.requestMethod=function(e){return this.archived?void 0:EPUBJS.core.request(e,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(e){this.requestCredentials=e},EPUBJS.Book.prototype.setRequestHeaders=function(e){this.requestHeaders=e},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(e){console.error(e.detail.message,e.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(e,t,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var e;e="xml"==t?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==t?JSON.parse(this.response):"blob"==t?s?this.response:new Blob([this.response]):this.response,h.resolve(e)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",h=new RSVP.defer,c=new XMLHttpRequest,u=XMLHttpRequest.prototype;"overrideMimeType"in u||Object.defineProperty(u,"overrideMimeType",{value:function(){}}),i&&(c.withCredentials=!0),c.open("GET",e,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==t&&(c.responseType=a),"json"==t&&c.setRequestHeader("Accept","application/json"),"xml"==t&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(e){var t,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:e},o=e.indexOf("://"),s=e.indexOf("?"),a=e.indexOf("#");return-1!=a&&(r.fragment=e.slice(a+1),e=e.slice(0,a)),-1!=s&&(r.search=e.slice(s+1),e=e.slice(0,s),href=e),-1!=o?(r.protocol=e.slice(0,o),t=e.slice(o+3),n=t.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=t.slice(0,n),r.path=t.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=e,r.directory=EPUBJS.core.folder(e),r.base=r.directory),r.filename=e.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/");if(-1==t)var i="";return i=e.slice(0,t+1)},EPUBJS.core.queue=function(e){var t=[],i=e,n=function(e,i,n){return t.push({funcName:e,args:i,context:n}),t},r=function(){var e;t.length&&(e=t.shift(),i[e.funcName].apply(e.context||i,e.args))},o=function(){for(;t.length;)r()},s=function(){t=[]},a=function(){return t.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(e){return!(!e||1!=e.nodeType)},EPUBJS.core.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?i:7&i|8).toString(16)});return t},EPUBJS.core.values=function(e){for(var t=-1,i=Object.keys(e),n=i.length,r=Array(n);++tr;r++)if("undefined"!=typeof document.body.style[t[r]+i])return t[r]+i;return e},EPUBJS.core.defaults=function(e){for(var t=1,i=arguments.length;i>t;t++){var n=arguments[t];for(var r in n)void 0===e[r]&&(e[r]=n[r])}return e},EPUBJS.EpubCFI=function(e){return e?this.parse(e):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(e,t,i){var n=parseInt(t),r=e+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(e){var t=[];return e.forEach(function(e){var i="";i+=2*(e.index+1),e.id&&(i+="["+e.id+"]"),t.push(i)}),t.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(e,t){var i=this.pathTo(e),n=this.generatePathComponent(i);return n.length?"epubcfi("+t+"!"+n+"/1:0)":"epubcfi("+t+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(e){for(var t,i=[];e&&null!==e.parentNode&&9!=e.parentNode.nodeType;)t=e.parentNode.children,i.unshift({id:e.id,tagName:e.tagName,index:t?Array.prototype.indexOf.call(t,e):0}),e=e.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(e){var t=e.split("!");return t[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(e){var t=e.split("!"),i=t[1]?t[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(e){var t=e.split(":");return t[1]||""},EPUBJS.EpubCFI.prototype.parse=function(e){var t,i,n,r,o,s,a,h,c,u={},p=function(e){var t,i,n,r;return t="element",i=parseInt(e)/2-1,n=e.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:t,index:i,id:r||!1}};return"string"!=typeof e?{spinePos:-1}:(u.str=e,0===e.indexOf("epubcfi(")&&")"===e[e.length-1]&&(e=e.slice(8,e.length-1)),i=this.getChapterComponent(e),n=this.getPathComponent(e)||"",r=this.getCharecterOffsetComponent(e),i?(t=i.split("/")[2]||"")?(u.spinePos=parseInt(t)/2-1||0,s=t.match(/\[(.*)\]/),u.spineId=s?s[1]:!1,-1!=n.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=n.split("/"),h=a.pop(),u.steps=[],a.forEach(function(e){var t;e&&(t=p(e),u.steps.push(t))}),c=parseInt(h),isNaN(c)||(c%2===0?u.steps.push(p(h)):u.steps.push({type:"text",index:(c-1)/2})),o=r.match(/\[(.*)\]/),o&&o[1]?(u.characterOffset=parseInt(r.split("[")[0]),u.textLocationAssertion=o[1]):u.characterOffset=parseInt(r),u):{spinePos:-1}:{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(e,t,i){var n,r,o,s,a=t||document,h=i||this.createMarker(a);return"string"==typeof e&&(e=this.parse(e)),r=e.steps[e.steps.length-1],-1===e.spinePos?!1:(n=this.findParent(e,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],e.characterOffset?(s=o.splitText(e.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(h,s)):n.insertBefore(h,o)):n.insertBefore(h,n.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(e){var t=e||document,i=t.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(e,t){e.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=e.nextSibling,prevSib=e.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,e.parentNode.removeChild(nextSib)),e.parentNode.removeChild(e)):e.classList.contains("EPUBJS-CFI-MARKER")&&e.parentNode.removeChild(e)},EPUBJS.EpubCFI.prototype.findParent=function(e,t){var i,n,r,o=t||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof e&&(e=this.parse(e)),n=e.steps.slice(0),!n.length)return o.getElementsByTagName("body")[0];for(;n&&n.length>0;){if(i=n.shift(),"text"===i.type?(r=s.childNodes[i.index],s=r.parentNode||s):s=i.id?o.getElementById(i.id):a[i.index],"undefined"==typeof s)return console.error("No Element For",i,e.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(e,t){if("string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),"string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),e.spinePos>t.spinePos)return 1;if(e.spinePost.steps[i].index)return 1;if(e.steps[i].indext.characterOffset?1:e.characterOffset=0?(o=r.length,e.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(e=n.promise,n.resolve()),e},EPUBJS.Infinite=function(e,t){this.container=e,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=500,this.views=[],this.axis=t,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.displaying?("vertical"===this.axis?this.checkTop():this.checkLeft(),this.trigger("scroll",{top:this.container.scrollTop,left:this.container.scrollLeft}),this.scrolled=!1):(this.displaying=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.checkTop=function(){var e=this.container.scrollTop,t=this.container.scrollHeight,i=e-this.prevScrollTop,n=this.container.getBoundingClientRect().height,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevScrollTop=e,e},EPUBJS.Infinite.prototype.checkLeft=function(){var e=this.container.scrollLeft,t=this.container.scrollWidth,i=e-this.prevscrollLeft,n=this.container.getBoundingClientRect().width,r=e+this.offset>t-n,o=e0?this.forwards():o&&0>i&&this.backwards(),this.prevscrollLeft=e,e},EPUBJS.Infinite.prototype.scrollBy=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft+=e,this.container.scrollTop+=t,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(e,t,i){i&&(this.displaying=!0),this.container.scrollLeft=e,this.container.scrollTop=t,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(t),c=Math.floor(h/8),u=n>=0?n:c%2===0?c:c-1;return this.documentElement=e,this.spreadWidth=h+u,e.style.overflow="hidden",e.style.width=h+"px",e.style.height=i+"px",e.style[r]="horizontal",e.style[a]="auto",e.style[s]=h+"px",e.style[o]=u+"px",this.colWidth=h,this.gap=u,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var e,t;return this.documentElement.style.width="auto",e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth),{displayedPages:t,pageCount:t}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(e,t,i,n){var r=EPUBJS.core.prefixed("columnAxis"),o=EPUBJS.core.prefixed("columnGap"),s=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=2,c=Math.floor(t),u=c%2===0?c:c-1,p=Math.floor(u/8),l=n>=0?n:p%2===0?p:p-1,d=Math.floor((u-l)/h);return this.spreadWidth=(d+l)*h,e.document.documentElement.style.overflow="hidden",e.document.body.style.width=u+"px",e.document.body.style.height=i+"px",e.document.body.style[r]="horizontal",e.document.body.style[a]="auto",e.document.body.style[o]=l+"px",e.document.body.style[s]=d+"px",this.colWidth=d,this.gap=l,e.iframe.style.width=d+"px",e.iframe.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var e=this.documentElement.scrollWidth,t=Math.ceil(e/this.spreadWidth);return this.documentElement.style.width=e+this.spreadWidth+"px",{displayedPages:t,pageCount:2*t}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(e){var t,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=e.querySelector("[name=viewport");return this.documentElement=e,s&&s.hasAttribute("content")&&(t=s.getAttribute("content"),i=t.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),e.style.width=n+"px"||"auto",e.style.height=r+"px"||"auto",e.style[o]="auto",e.style.overflow="auto",this.colWidth=n,this.gap=0,{pageWidth:n,pageHeight:r}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(e,t){var i=this,n=new EPUBJS.Parser,r=t||EPUBJS.core.request;this.package=e,this.toc=[],this.tocByHref={},this.tocById={},e.navPath&&(this.navUrl=e.baseUrl+e.navPath,this.nav={},this.nav.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.navUrl,"xml").then(function(t){i.toc=n.nav(t),i.loaded(i.toc),e.resolve(i.toc)}),t}),e.ncxPath&&(this.ncxUrl=e.baseUrl+e.ncxPath,this.ncx={},this.ncx.load=function(){var e=new RSVP.defer,t=e.promise;return r(i.ncxUrl,"xml").then(function(t){i.toc=n.ncx(t),i.loaded(i.toc),e.resolve(i.toc)}),t})},EPUBJS.Navigation.prototype.load=function(e){{var t,i;e||EPUBJS.core.request}return this.nav?t=this.nav.load():this.ncx?t=this.ncx.load():(i=new RSVP.defer,i.resolve([]),t=i.promise),t},EPUBJS.Navigation.prototype.loaded=function(e){for(var t,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),u=c.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=u.split("#"),f=(d[0],t(a));n.unshift({id:h,href:u,label:l,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=e.querySelector("navMap");return i?t(i):[]},EPUBJS.Renderer=function(e,t){var i=t||{};this.settings={infinite:"undefined"==typeof i.infinite?!0:i.infinite,hidden:"undefined"==typeof i.hidden?!1:i.hidden,axis:i.axis||"vertical",viewsLimit:i.viewsLimit||5,width:"undefined"==typeof i.width?!1:i.width,height:"undefined"==typeof i.height?!1:i.height,overflow:"undefined"==typeof i.overflow?"auto":i.overflow,padding:i.padding||""},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.filling=!1,this.displaying=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},i=t.height!==!1?t.height:"100%",n=t.width!==!1?t.width:"100%";t.hidden||!1}return t.height&&EPUBJS.core.isNumber(t.height)&&(i=t.height+"px"),t.width&&EPUBJS.core.isNumber(t.width)&&(n=t.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis),this.infinite.on("scroll",this.checkCurrent.bind(this))),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=n,this.container.style.height=i,this.container.style.overflow=this.settings.overflow,t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var i=e,n=t,r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=i-o.left-o.right,a=n-o.top-o.bottom;e||(i=window.innerWidth),t||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(e){"vertical"===this.settings.axis?e.resize(s,0):e.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var e=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&e0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),this.hooks.replacements.register(this.replacements.bind(this)),this.hooks.display.register(this.afterDisplay.bind(this)),void 0):(console.error("Not an Element"),void 0)},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,i=t.promise;return"string"==typeof e&&(e=e.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(e);this.displaying=!0,n?(this.clear(),i=this.render(n),this.settings.infinite&&i.then(function(){return this.fill.call(this)}.bind(this)),i.then(function(){this.trigger("displayed",n),this.displaying=!1,t.resolve(this)}.bind(this))):t.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(e){var t,i,n=this.container.getBoundingClientRect(),r=window.getComputedStyle(this.container),o={left:parseFloat(r["padding-left"])||0,right:parseFloat(r["padding-right"])||0,top:parseFloat(r["padding-top"])||0,bottom:parseFloat(r["padding-bottom"])||0},s=n.width-o.left-o.right,a=n.height-o.top-o.bottom;return e?(i=new EPUBJS.View(e),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,e.index),t=i.render(this.book.request),t.then(function(){return this.hooks.display.trigger(i)}.bind(this)).then(function(){return this.hooks.replacements.trigger(i,this)}.bind(this)).then(function(){return i.expand()}.bind(this)).then(function(){return this.rendering=!1,i.show(),this.trigger("rendered",i.section),i}.bind(this)).catch(function(e){this.trigger("loaderror",e)}.bind(this))):(t=new RSVP.defer,t.reject(new Error("No Section Provided")),t.promise)},EPUBJS.Renderer.prototype.forwards=function(){var e,t,i;return e=this.last().section.index+1,this.rendering||e===this.book.spine.length?(t=new RSVP.defer,t.reject(new Error("Reject Forwards")),t.promise):(this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e=this.first(),t=e.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-t.height>100&&(this.remove(e),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-t.height,!0):this.infinite.scrollTo(n-t.width,!0))),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,i;return e=this.first().section.index-1,this.rendering||0>e?(t=new RSVP.defer,t.reject(new Error("Reject Backwards")),t.promise):(this.rendering=!0,i=this.book.spine.get(e),t=this.render(i),t.then(function(){var e;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(e=this.last(),this.remove(e),this.container.scrollTop-this.first().bounds().height>100&&this.remove(e)),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.first().section.index-1,t=this.forwards();return this.filling=!0,"vertical"===this.settings.axis?t.then(this.fillVertical.bind(this)):t.then(this.fillHorizontal.bind(this)),e>0&&t.then(this.backwards.bind(this)),t.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var e=this.container.getBoundingClientRect().height,t=this.last().bounds().bottom,i=new RSVP.defer;return e&&t&&e>t?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var e=this.container.getBoundingClientRect().width,t=this.last().bounds().right,i=new RSVP.defer;return e&&t&&e>=t?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().section.index>=0?this.append(e):t-this.last().section.index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.remove=function(e){var t=this.views.indexOf(e);e.destroy(),t>-1&&this.views.splice(t,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(e,t){for(var i=new RSVP.defer,n=e.document.querySelectorAll("a[href]"),r=function(e){var i=e.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?e.setAttribute("target","_blank"):0===i.indexOf("#")||(e.onclick=function(){return t.display(i),!1})},o=0;o=0;r--)if(e=this.views[r],t=e.bounds().top,t-1?(delete this.spineByHref[e.href],delete this.spineById[e.idref],this.spineItems.splice(t,1)):void 0},EPUBJS.View=function(e){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.rendering=new RSVP.defer,this.rendered=this.rendering.promise,this.section=e},EPUBJS.View.prototype.create=function(e,t){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resize=function(e,t){e&&(this.iframe.style.width=e+"px"),t&&(this.iframe.style.height=t+"px"),this.resizing||(this.resizing=!0,this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:(console.log("resize"),this.expand())},EPUBJS.View.prototype.render=function(e){return this.section.render(e).then(function(e){return this.load(e)}.bind(this)).then(this.display.bind(this)).then(function(){this.rendering.resolve(this)}.bind(this))},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,i=t.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,t.resolve(this)}.bind(this)),this.document.open(),this.document.write(e),this.document.close(),i):(t.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.display=function(){var e=new RSVP.defer,t=e.promise;return this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),e.resolve(this),t},EPUBJS.View.prototype.expand=function(e,t){var i,n,r,o=e||new RSVP.defer,s=o.promise,a=t||0;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),(!i||0===i.height&&0===i.width)&&console.error("View not shown"),r=i.height,n=this.document.documentElement.scrollWidth,this.width!=n||this.height!=r?setTimeout(function(){this.expand(o,a)}.bind(this),10):o.resolve(),this.width=n,this.height=r,this.iframe.style.height=r+"px",this.iframe.style.width=n+"px",s},EPUBJS.View.prototype.observe=function(e){var t=this,i=new MutationObserver(function(){t.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(e,n),i},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.show=function(){this.iframe.style.display="inline-block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)}; \ No newline at end of file diff --git a/lib/epubjs/core.js b/lib/epubjs/core.js index 6233634..3f36893 100644 --- a/lib/epubjs/core.js +++ b/lib/epubjs/core.js @@ -52,7 +52,14 @@ EPUBJS.core.request = function(url, type, withCredentials, headers) { var r; if(type == 'xml'){ - r = this.responseXML; + + // If this.responseXML wasn't set, try to parse using a DOMParser from text + if(!this.responseXML){ + r = new DOMParser().parseFromString(this.response, "text/xml"); + } else { + r = this.responseXML; + } + }else if(type == 'json'){ r = JSON.parse(this.response); diff --git a/lib/epubjs/infinite.js b/lib/epubjs/infinite.js index a95d336..0dedbf9 100644 --- a/lib/epubjs/infinite.js +++ b/lib/epubjs/infinite.js @@ -70,7 +70,7 @@ EPUBJS.Infinite.prototype.check = function(){ this.tick.call(window, this.check.bind(this)); // setTimeout(this.check.bind(this), 100); -} +}; EPUBJS.Infinite.prototype.checkTop = function(){ diff --git a/lib/epubjs/navigation.js b/lib/epubjs/navigation.js index 52019e0..f8006cb 100644 --- a/lib/epubjs/navigation.js +++ b/lib/epubjs/navigation.js @@ -73,7 +73,7 @@ EPUBJS.Navigation.prototype.loaded = function(toc) { item = toc[i]; this.tocByHref[item.href] = i; this.tocById[item.id] = i; - }; + } }; diff --git a/lib/epubjs/pagination.js b/lib/epubjs/pagination.js index 6a8c41e..312c9f7 100644 --- a/lib/epubjs/pagination.js +++ b/lib/epubjs/pagination.js @@ -128,7 +128,6 @@ EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) { EPUBJS.Paginate.prototype.page = function(pg){ this.currentPage = pg; - console.log("page", this.currentPage * this.formated.pageWidth) this.renderer.infinite.scrollTo(this.currentPage * this.formated.pageWidth, 0); //-- Return false if page is greater than the total @@ -144,5 +143,5 @@ EPUBJS.Paginate.prototype.prev = function(){ }; EPUBJS.Paginate.prototype.display = function(what){ - return this.renderer.display(what) + return this.renderer.display(what); }; \ No newline at end of file diff --git a/lib/epubjs/renderer.js b/lib/epubjs/renderer.js index ded96da..8e269ea 100644 --- a/lib/epubjs/renderer.js +++ b/lib/epubjs/renderer.js @@ -173,9 +173,13 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){ this.infinite.on("forwards", function(){ var next = this.last().section.index + 1; - if(!this.rendering && !this.filling && !this.displaying - && next < this.book.spine.length){ + if(!this.rendering && + !this.filling && + !this.displaying && + next < this.book.spine.length){ + this.forwards(); + } }.bind(this)); @@ -183,9 +187,13 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){ this.infinite.on("backwards", function(){ var prev = this.first().section.index - 1; - if(!this.rendering && !this.filling && !this.displaying - && prev > 0){ + if(!this.rendering && + !this.filling && + !this.displaying && + prev > 0){ + this.backwards(); + } }.bind(this)); @@ -260,7 +268,7 @@ EPUBJS.Renderer.prototype.render = function(section){ right: parseFloat(styles["padding-right"]) || 0, top: parseFloat(styles["padding-top"]) || 0, bottom: parseFloat(styles["padding-bottom"]) || 0 - }; + }; var width = bounds.width - padding.left - padding.right; var height = bounds.height - padding.top - padding.bottom; @@ -269,7 +277,7 @@ EPUBJS.Renderer.prototype.render = function(section){ rendered = new RSVP.defer(); rendered.reject(new Error("No Section Provided")); return rendered.promise; - }; + } view = new EPUBJS.View(section); @@ -319,7 +327,7 @@ EPUBJS.Renderer.prototype.forwards = function(){ rendered.reject(new Error("Reject Forwards")); return rendered.promise; } - console.log("going forwards") + // console.log("going forwards") this.rendering = true; @@ -375,7 +383,7 @@ EPUBJS.Renderer.prototype.backwards = function(view){ rendered.reject(new Error("Reject Backwards")); return rendered.promise; } - console.log("going backwards") + // console.log("going backwards") this.rendering = true; @@ -557,7 +565,7 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) { for (var i = 0; i < links.length; i++) { replaceLinks(links[i]); - }; + } task.resolve(); return task.promise; @@ -601,10 +609,10 @@ EPUBJS.Renderer.prototype.checkCurrent = function(position) { } this.current = view.section; - this.trigger("current", this.current) + this.trigger("current", this.current); break; } - }; + } } diff --git a/lib/epubjs/section.js b/lib/epubjs/section.js index e83b2f6..62c21e8 100644 --- a/lib/epubjs/section.js +++ b/lib/epubjs/section.js @@ -66,7 +66,7 @@ EPUBJS.Section.prototype.replacements = function(_document){ EPUBJS.Section.prototype.beforeSectionLoad = function(){ // Stub for a hook - replace me for now -} +}; EPUBJS.Section.prototype.render = function(_request){ var rendering = new RSVP.defer(); diff --git a/lib/epubjs/view.js b/lib/epubjs/view.js index d035aa4..cd1ac24 100644 --- a/lib/epubjs/view.js +++ b/lib/epubjs/view.js @@ -129,7 +129,7 @@ EPUBJS.View.prototype.display = function(contents) { displaying.resolve(this); // this.observer = this.observe(this.document.body); - return displayed + return displayed; }; diff --git a/test/tests/epub.js b/test/tests/epub.js index c23cbb4..2455b46 100644 --- a/test/tests/epub.js +++ b/test/tests/epub.js @@ -286,7 +286,7 @@ asyncTest("Get all TOC", 1, function() { }); -asyncTest("Get TOC time by href", 1, function() { +asyncTest("Get TOC item by href", 1, function() { var book = ePub("../books/moby-dick/OPS/package.opf"); book.loaded.navigation.then(function(){ @@ -297,7 +297,7 @@ asyncTest("Get TOC time by href", 1, function() { }); -asyncTest("Get TOC time by ID", 1, function() { +asyncTest("Get TOC item by ID", 1, function() { var book = ePub("../books/moby-dick/OPS/package.opf"); book.loaded.navigation.then(function(){