diff --git a/dist/epub.js b/dist/epub.js index b3fcb15..158cceb 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -4419,6 +4419,17 @@ EPUBJS.Renderer.prototype.resize = function(_width, _height){ var width = _width; var height = _height; + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + right: parseFloat(styles["padding-right"]) || 0, + top: parseFloat(styles["padding-top"]) || 0, + bottom: parseFloat(styles["padding-bottom"]) || 0 + }; + + var stagewidth = width - padding.left - padding.right; + var stageheight = height - padding.top - padding.bottom; + if(!_width) { width = window.innerWidth; } @@ -4426,14 +4437,23 @@ EPUBJS.Renderer.prototype.resize = function(_width, _height){ height = window.innerHeight; } - this.container.style.width = width + "px"; - this.container.style.height = height + "px"; + // this.container.style.width = width + "px"; + // this.container.style.height = height + "px"; this.trigger("resized", { width: this.width, height: this.height }); + + this.views.forEach(function(view){ + if(this.settings.axis === "vertical") { + view.resize(stagewidth, 0); + } else { + view.resize(0, stageheight); + } + }.bind(this)); + }; EPUBJS.Renderer.prototype.onResized = function(e) { @@ -4511,9 +4531,11 @@ EPUBJS.Renderer.prototype.display = function(what){ // TODO: check for fragments - + var split = what.split("#"); + var href = split[0]; + this.book.opened.then(function(){ - var section = this.book.spine.get(what); + var section = this.book.spine.get(href); var rendered; this.displaying = true; @@ -4550,6 +4572,16 @@ EPUBJS.Renderer.prototype.render = function(section){ var rendered; var view; var bounds = this.container.getBoundingClientRect(); + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + 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; + if(!section) { rendered = new RSVP.defer(); @@ -4560,9 +4592,9 @@ EPUBJS.Renderer.prototype.render = function(section){ view = new EPUBJS.View(section); if(this.settings.axis === "vertical") { - view.create(bounds.width, 0); + view.create(width, 0); } else { - view.create(0, bounds.height); + view.create(0, height); } @@ -4582,7 +4614,7 @@ EPUBJS.Renderer.prototype.render = function(section){ return view.expand(); }.bind(this)) .then(function(){ - // this.rendering = false; + this.rendering = false; view.show(); this.trigger("rendered", view.section); return view; @@ -4653,7 +4685,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; @@ -4727,7 +4759,7 @@ EPUBJS.Renderer.prototype.fillVertical = function() { if (height && bottom && (bottom < height)) { //&& (this.last().section.index + 1 < this.book.spine.length)) { return this.forwards().then(this.fillVertical.bind(this)); } else { - // this.rendering = false; + this.rendering = false; defer.resolve(); return defer.promise; } @@ -4741,7 +4773,7 @@ EPUBJS.Renderer.prototype.fillHorizontal = function() { if (width && right && (right <= width)) { //&& (this.last().section.index + 1 < this.book.spine.length)) { return this.forwards().then(this.fillHorizontal.bind(this)); } else { - // this.rendering = false; + this.rendering = false; defer.resolve(); return defer.promise; } @@ -4833,7 +4865,7 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) { EPUBJS.Renderer.prototype.afterDisplay = function(view, renderer) { var task = new RSVP.defer(); - view.document.documentElement.style.padding = this.settings.padding; + // view.document.documentElement.style.padding = this.settings.padding; task.resolve(); return task.promise; }; @@ -5085,9 +5117,27 @@ EPUBJS.View.prototype.create = function(width, height) { return this.iframe; }; +EPUBJS.View.prototype.resize = function(width, height) { + + if(width){ + this.iframe.style.width = width + "px"; + } + + if(height){ + this.iframe.style.height = height + "px"; + } + + if (!this.resizing) { + this.resizing = true; + this.expand(); + } + +}; + EPUBJS.View.prototype.resized = function(e) { if (!this.resizing) { + console.log("resize"); this.expand(); } else { this.resizing = false; @@ -5096,14 +5146,14 @@ EPUBJS.View.prototype.resized = function(e) { }; EPUBJS.View.prototype.render = function(_request) { - return this.section.render(_request) - .then(function(contents){ - return this.load(contents); - }.bind(this)) - .then(this.display.bind(this)) - .then(function(){ - this.rendering.resolve(this); - }.bind(this)); + return this.section.render(_request) + .then(function(contents){ + return this.load(contents); + }.bind(this)) + .then(this.display.bind(this)) + .then(function(){ + this.rendering.resolve(this); + }.bind(this)); }; EPUBJS.View.prototype.load = function(contents) { @@ -5154,15 +5204,17 @@ EPUBJS.View.prototype.display = function(contents) { - if(!this.document.fonts || this.document.fonts.status !== "loading") { - this.expand(); - displaying.resolve(this); - } else { - this.document.fonts.onloading = function(){ - this.expand(); - displaying.resolve(this); - }.bind(this); - } + // if(!this.document.fonts || this.document.fonts.status !== "loading") { + // this.expand(); + // displaying.resolve(this); + // } else { + // this.document.fonts.onloading = function(){ + // this.expand(); + // displaying.resolve(this); + // }.bind(this); + // } + this.expand(); + displaying.resolve(this); // this.observer = this.observe(this.document.body); diff --git a/dist/epub.min.js b/dist/epub.min.js index c604105..eb602fe 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(e){var t,i;!function(){var e={},n={};t=function(t,i,n){e[t]={deps:i,callback:n}},i=function(t){function r(e){if("."!==e.charAt(0))return e;for(var i=e.split("/"),n=t.split("/").slice(0,-1),r=0,o=i.length;o>r;r++){var s=i[r];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[t])return n[t];if(n[t]={},!e[t])throw new Error("Could not find module "+t);for(var o,s=e[t],a=s.deps,c=s.callback,h=[],u=0,l=a.length;l>u;u++)h.push("exports"===a[u]?o={}:i(r(a[u])));var p=c.apply(this,h);return n[t]=o||p},i.entries=e}(),t("rsvp/-internal",["./utils","./instrument","./config","exports"],function(e,t,i,n){"use strict";function r(){}function o(e){try{return e.then}catch(t){return J.error=t,J}}function s(e,t,i,n){try{e.call(t,i,n)}catch(r){return r}}function a(e,t,i){b.async(function(e){var n=!1,r=s(i,t,function(i){n||(n=!0,t!==i?u(e,i):p(e,i))},function(t){n||(n=!0,d(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&r&&(n=!0,d(e,r))},e)}function c(e,t){e._onerror=null,t._state===x?p(e,t._result):e._state===U?d(e,t._result):f(t,void 0,function(i){t!==i?u(e,i):p(e,i)},function(t){d(e,t)})}function h(e,t){if(t instanceof e.constructor)c(e,t);else{var i=o(t);i===J?d(e,J.error):void 0===i?p(e,t):P(i)?a(e,t,i):p(e,t)}}function u(e,t){e===t?p(e,t):S(t)?h(e,t):p(e,t)}function l(e){e._onerror&&e._onerror(e._result),g(e)}function p(e,t){e._state===B&&(e._result=t,e._state=x,0===e._subscribers.length?b.instrument&&w("fulfilled",e):b.async(g,e))}function d(e,t){e._state===B&&(e._state=U,e._result=t,b.async(l,e))}function f(e,t,i,n){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+x]=i,r[o+U]=n,0===o&&e._state&&b.async(g,e)}function g(e){var t=e._subscribers,i=e._state;if(b.instrument&&w(i===x?"fulfilled":"rejected",e),0!==t.length){for(var n,r,o=e._result,s=0;se;e+=2){var t=l[e],i=l[e+1];t(i),l[e]=void 0,l[e+1]=void 0}s=0}var s=0;e["default"]=function(e,t){l[s]=e,l[s+1]=t,s+=2,2===s&&a()};var a,c="undefined"!=typeof window?window:{},h=c.MutationObserver||c.WebKitMutationObserver,u="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,l=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?t():h?i():u?n():r()}),t("rsvp/config",["./events","exports"],function(e,t){"use strict";function i(e,t){return"onerror"===e?void r.on("error",t):2!==arguments.length?r[e]:void(r[e]=t)}var n=e["default"],r={instrument:!1};n.mixin(r),t.config=r,t.configure=i}),t("rsvp/defer",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e){var t={};return t.promise=new i(function(e,i){t.resolve=e,t.reject=i},e),t}}),t("rsvp/enumerator",["./utils","./-internal","exports"],function(e,t,i){"use strict";function n(e,t,i){return e===l?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(e,t,i,n){this._instanceConstructor=e,this.promise=new e(a,n),this._abortOnReject=i,this._validateInput(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._init(),0===this.length?h(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&h(this.promise,this._result))):c(this.promise,this._validationError())}var o=e.isArray,s=e.isMaybeThenable,a=t.noop,c=t.reject,h=t.fulfill,u=t.subscribe,l=t.FULFILLED,p=t.REJECTED,d=t.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(e){return o(e)},r.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},r.prototype._init=function(){this._result=new Array(this.length)},i["default"]=r,r.prototype._enumerate=function(){for(var e=this.length,t=this.promise,i=this._input,n=0;t._state===d&&e>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(e,t){var i=this._instanceConstructor;s(e)?e.constructor===i&&e._state!==d?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(i.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(l,t,e))},r.prototype._settledAt=function(e,t,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&e===p?c(n,i):this._result[t]=this._makeResult(e,t,i)),0===this._remaining&&h(n,this._result)},r.prototype._makeResult=function(e,t,i){return i},r.prototype._willSettleAt=function(e,t){var i=this;u(e,void 0,function(e){i._settledAt(l,t,e)},function(e){i._settledAt(p,t,e)})}}),t("rsvp/events",["exports"],function(e){"use strict";function t(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t)return i;return-1}function i(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}e["default"]={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,n){var r,o=i(this);r=o[e],r||(r=o[e]=[]),-1===t(r,n)&&r.push(n)},off:function(e,n){var r,o,s=i(this);return n?(r=s[e],o=t(r,n),void(-1!==o&&r.splice(o,1))):void(s[e]=[])},trigger:function(e,t){var n,r,o=i(this);if(n=o[e])for(var s=0;sa;a++)s[a]=t(e[a]);return n.all(s,i).then(function(t){for(var i=new Array(o),n=0,r=0;o>r;r++)t[r]&&(i[n]=e[r],n++);return i.length=n,i})})}}),t("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(e,t,i,n,r){"use strict";function o(e,t,i){this._superConstructor(e,t,!1,i)}var s=e["default"],a=t.makeSettledResult,c=i["default"],h=t["default"],u=n.o_create;o.prototype=u(c.prototype),o.prototype._superConstructor=h,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},r["default"]=function(e,t){return new o(s,e,t).promise}}),t("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(e,t,i,n){"use strict";{var r=e["default"],o=t["default"];i.ABORT_ON_REJECTION}n["default"]=function(e,t){return new o(r,e,t).promise}}),t("rsvp/instrument",["./config","./utils","exports"],function(e,t,i){"use strict";var n=e.config,r=t.now,o=[];i["default"]=function(e,t,i){1===o.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:i&&t._guidKey+i._id,label:t._label,timeStamp:r(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;ta;a++)s[a]=t(e[a]);return n.all(s,i)})}}),t("rsvp/node",["./promise","./utils","exports"],function(e,t,i){"use strict";var n=e["default"],r=t.isArray;i["default"]=function(e,t){function i(){for(var i=arguments.length,r=new Array(i),a=0;i>a;a++)r[a]=arguments[a];var c;return o||s||!t?c=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),c=t),n.all(r).then(function(i){function r(n,r){function a(){for(var e=arguments.length,i=new Array(e),a=0;e>a;a++)i[a]=arguments[a];var c=i[0],h=i[1];if(c)r(c);else if(o)n(i.slice(1));else if(s){var u,l,p={},d=i.slice(1);for(l=0;la;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),t("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(e,t,i,n,r,o,s,a,c,h,u){"use strict";function l(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function p(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(e,t){this._id=_++,this._label=t,this._subscribers=[],f.instrument&&g("created",this),v!==e&&(y(e)||l(),this instanceof d||p(),S(this,e))}var f=e.config,g=(t["default"],i["default"]),y=(n.objectOrFunction,n.isFunction),m=n.now,v=r.noop,E=(r.resolve,r.reject,r.fulfill,r.subscribe),S=r.initializePromise,P=r.invokeCallback,w=r.FULFILLED,b=o["default"],B=s["default"],x=a["default"],U=c["default"],J=h["default"],R="rsvp_"+m()+"-",_=0;u["default"]=d,d.cast=b,d.all=B,d.race=x,d.resolve=U,d.reject=J,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(e){f.trigger("error",e)},then:function(e,t,i){var n=this;n._onerror=null;var r=new this.constructor(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===w&&e?f.async(function(){P(o,r,e,s)}):E(n,r,e,t),r},"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)}}}),t("rsvp/promise/all",["../enumerator","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return new i(this,e,!0,t).promise}}),t("rsvp/promise/cast",["./resolve","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=i}),t("rsvp/promise/race",["../utils","../-internal","exports"],function(e,t,i){"use strict";var n=e.isArray,r=(e.isFunction,e.isMaybeThenable,t.noop),o=t.resolve,s=t.reject,a=t.subscribe,c=t.PENDING;i["default"]=function(e,t){function i(e){o(l,e)}function h(e){s(l,e)}var u=this,l=new u(r,t);if(!n(e))return s(l,new TypeError("You must pass an array to race.")),l;for(var p=e.length,d=0;l._state===c&&p>d;d++)a(u.resolve(e[d]),void 0,i,h);return l}}),t("rsvp/promise/reject",["../-internal","exports"],function(e,t){"use strict";var i=e.noop,n=e.reject;t["default"]=function(e,t){var r=this,o=new r(i,t);return n(o,e),o}}),t("rsvp/promise/resolve",["../-internal","exports"],function(e,t){"use strict";var i=e.noop,n=e.resolve;t["default"]=function(e,t){var r=this;if(e&&"object"==typeof e&&e.constructor===r)return e;var o=new r(i,t);return n(o,e),o}}),t("rsvp/race",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.race(e,t)}}),t("rsvp/reject",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.reject(e,t)}}),t("rsvp/resolve",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.resolve(e,t)}}),t("rsvp/rethrow",["exports"],function(e){"use strict";e["default"]=function(e){throw setTimeout(function(){throw e}),e}}),t("rsvp/utils",["exports"],function(e){"use strict";function t(e){return"function"==typeof e||"object"==typeof e&&null!==e}function i(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}e.objectOrFunction=t,e.isFunction=i,e.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var o=r;e.isArray=o;var s=Date.now||function(){return(new Date).getTime()};e.now=s;var a=Object.create||function(e){var t=function(){};return t.prototype=e,t};e.o_create=a}),t("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(e,t,i,n,r,o,s,a,c,h,u,l,p,d,f,g,y){"use strict";function m(e,t){k.async(e,t)}function v(){k.on.apply(k,arguments)}function E(){k.off.apply(k,arguments)}var S=e["default"],P=t["default"],w=i["default"],b=n["default"],B=r["default"],x=o["default"],U=s["default"],J=a["default"],R=c["default"],_=h["default"],k=u.config,C=u.configure,N=l["default"],T=p["default"],I=d["default"],F=f["default"],A=g["default"];if(k.async=A,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var O=window.__PROMISE_INSTRUMENTATION__;C("instrument",!0);for(var L in O)O.hasOwnProperty(L)&&v(L,O[L])}y.Promise=S,y.EventTarget=P,y.all=b,y.allSettled=B,y.race=x,y.hash=U,y.hashSettled=J,y.rethrow=R,y.defer=_,y.denodeify=w,y.configure=C,y.on=v,y.off=E,y.resolve=T,y.reject=I,y.async=m,y.map=N,y.filter=F}),e.RSVP=i("rsvp")}(self),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.origin+"/"+t.directory: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,c.resolve(e)}else c.reject({status:this.status,message:this.response,stack:(new Error).stack})}var o,s=window.URL,a=s?"blob":"arraybuffer",c=new RSVP.defer,h=new XMLHttpRequest,u=XMLHttpRequest.prototype;"overrideMimeType"in u||Object.defineProperty(u,"overrideMimeType",{value:function(){}}),i&&(h.withCredentials=!0),h.open("GET",e,!0);for(o in n)h.setRequestHeader(o,n[o]);return h.onreadystatechange=r,"blob"==t&&(h.responseType=a),"json"==t&&h.setRequestHeader("Accept","application/json"),"xml"==t&&h.overrideMimeType("text/xml"),h.send(),c.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,c,h,u={},l=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("/"),c=a.pop(),u.steps=[],a.forEach(function(e){var t;e&&(t=l(e),u.steps.push(t))}),h=parseInt(c),isNaN(h)||u.steps.push(h%2===0?l(c):{type:"text",index:(h-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})},EPUBJS.EpubCFI.prototype.addMarker=function(e,t,i){var n,r,o,s,a=t||document,c=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),c.classList.add("EPUBJS-CFI-SPLIT"),n.insertBefore(c,s)):n.insertBefore(c,o)):n.insertBefore(c,n.firstChild),c):!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=900,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.scroll=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"),c=Math.floor(t),h=Math.floor(c/8),u=n>=0?n:h%2===0?h:h-1;return this.documentElement=e,this.spreadWidth=c+u,e.style.overflow="hidden",e.style.width=c+"px",e.style.height=i+"px",e.style[r]="horizontal",e.style[a]="auto",e.style[s]=c+"px",e.style[o]=u+"px",this.colWidth=c,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"),c=2,h=Math.floor(t),u=h%2===0?h:h-1,l=Math.floor(u/8),p=n>=0?n:l%2===0?l:l-1,d=Math.floor((u-p)/c); -return this.spreadWidth=(d+p)*c,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]=p+"px",e.document.body.style[s]=d+"px",this.colWidth=d,this.gap=p,e.iframe.style.width=d+"px",e.iframe.style.paddingRight=p+"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),c=a.getAttribute("id")||!1,h=a.querySelector("content"),u=h.getAttribute("src"),l=a.querySelector("navLabel"),p=l.textContent?l.textContent:"",d=u.split("#"),f=(d[0],t(a));n.unshift({id:c,href:u,label:p,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;e||(i=window.innerWidth),t||(n=window.innerHeight),this.container.style.width=i+"px",this.container.style.height=n+"px",this.trigger("resized",{width:this.width,height:this.height})},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)),void this.hooks.display.register(this.afterDisplay.bind(this))):void console.error("Not an Element")},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 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();return e?(i=new EPUBJS.View(e),"vertical"===this.settings.axis?i.create(n.width,0):i.create(0,n.height),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 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.container.scrollTop,n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&(this.remove(e),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scroll(0,i-t.height,!0):this.infinite.scroll(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.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.first().section.index-1,t=this.forwards();return this.filling=!0,t.then("vertical"===this.settings.axis?this.fillVertical.bind(this):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)):(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)):(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"):e.onclick=function(){return t.display(i),!1}},o=0;o=0;n--)if(e=this.views[n],t=e.bounds().top,t0){if(this.current==e.section)break;this.current=e.section,this.trigger("current",this.current);break}},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Section=function(e){this.idref=e.idref,this.linear=e.linear,this.properties=e.properties,this.index=e.index,this.href=e.href,this.url=e.url,this.cfiBase=e.cfiBase,this.hooks={},this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(this.replacements)},EPUBJS.Section.prototype.load=function(e){var t=e||this.request||EPUBJS.core.request,i=new RSVP.defer,n=i.promise;return this.contents?i.resolve(this.contents):t(this.url,"xml").then(function(e){EPUBJS.core.folder(this.url);return this.document=e,this.contents=e.documentElement,this.hooks.replacements.trigger(this.document)}.bind(this)).then(function(){i.resolve(this.contents)}.bind(this)).catch(function(e){i.reject(e)}),n},EPUBJS.Section.prototype.replacements=function(e){var t,i=new RSVP.defer,n=e.createElement("base");return n.setAttribute("href",this.url),e&&(t=e.querySelector("head")),t?(t.insertBefore(n,t.firstChild),i.resolve()):i.reject(new Error("No head to insert into")),i.promise},EPUBJS.Section.prototype.beforeSectionLoad=function(){},EPUBJS.Section.prototype.render=function(e){var t=new RSVP.defer,i=t.promise;return this.load(e).then(function(e){var i=new XMLSerializer,n=i.serializeToString(e);t.resolve(n)}).catch(function(e){t.reject(e)}),i},EPUBJS.Section.prototype.find=function(){},EPUBJS.Spine=function(e){this.request=e,this.spineItems=[],this.spineByHref={},this.spineById={}},EPUBJS.Spine.prototype.load=function(e){this.items=e.spine,this.manifest=e.manifest,this.spineNodeIndex=e.spineNodeIndex,this.baseUrl=e.baseUrl||"",this.length=this.items.length,this.epubcfi=new EPUBJS.EpubCFI,this.items.forEach(function(e){var t,i=this.manifest[e.idref];e.cfiBase=this.epubcfi.generateChapterComponent(this.spineNodeIndex,e.index,e.idref),i&&(e.href=i.href,e.url=this.baseUrl+e.href),t=new EPUBJS.Section(e),this.append(t)}.bind(this))},EPUBJS.Spine.prototype.get=function(e){var t=0;return!e||"number"!=typeof e&&isNaN(e)!==!1?e&&0===e.indexOf("#")?t=this.spineById[e.substring(1)]:e&&(t=this.spineByHref[e]):t=e,this.spineItems[t]},EPUBJS.Spine.prototype.append=function(e){var t=this.spineItems.length;return e.index=t,this.spineItems.push(e),this.spineByHref[e.href]=t,this.spineById[e.idref]=t,t},EPUBJS.Spine.prototype.prepend=function(e){this.spineItems.unshift(e);return this.spineByHref[e.href]=0,this.spineById[e.idref]=0,this.spineItems.forEach(function(e,t){e.index=t}),0},EPUBJS.Spine.prototype.insert=function(){},EPUBJS.Spine.prototype.remove=function(e){var t=this.spineItems.indexOf(e);return 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.resized=function(){this.resizing?this.resizing=!1: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),this.document.fonts&&"loading"===this.document.fonts.status?this.document.fonts.onloading=function(){this.expand(),e.resolve(this)}.bind(this):(this.expand(),e.resolve(this)),t},EPUBJS.View.prototype.expand=function(){var e,t,i;return e=this.document.body.getBoundingClientRect(),(!e||0===e.height&&0===e.width)&&console.error("View not shown"),this.resizing=!0,i=e.height,this.iframe.style.height=i+"px",t=this.document.documentElement.scrollWidth,this.iframe.style.width=t+"px",e},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(e){var t,i;!function(){var e={},n={};t=function(t,i,n){e[t]={deps:i,callback:n}},i=function(t){function r(e){if("."!==e.charAt(0))return e;for(var i=e.split("/"),n=t.split("/").slice(0,-1),r=0,o=i.length;o>r;r++){var s=i[r];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[t])return n[t];if(n[t]={},!e[t])throw new Error("Could not find module "+t);for(var o,s=e[t],a=s.deps,h=s.callback,c=[],u=0,l=a.length;l>u;u++)c.push("exports"===a[u]?o={}:i(r(a[u])));var p=h.apply(this,c);return n[t]=o||p},i.entries=e}(),t("rsvp/-internal",["./utils","./instrument","./config","exports"],function(e,t,i,n){"use strict";function r(){}function o(e){try{return e.then}catch(t){return J.error=t,J}}function s(e,t,i,n){try{e.call(t,i,n)}catch(r){return r}}function a(e,t,i){b.async(function(e){var n=!1,r=s(i,t,function(i){n||(n=!0,t!==i?u(e,i):p(e,i))},function(t){n||(n=!0,d(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&r&&(n=!0,d(e,r))},e)}function h(e,t){e._onerror=null,t._state===x?p(e,t._result):e._state===U?d(e,t._result):f(t,void 0,function(i){t!==i?u(e,i):p(e,i)},function(t){d(e,t)})}function c(e,t){if(t instanceof e.constructor)h(e,t);else{var i=o(t);i===J?d(e,J.error):void 0===i?p(e,t):P(i)?a(e,t,i):p(e,t)}}function u(e,t){e===t?p(e,t):S(t)?c(e,t):p(e,t)}function l(e){e._onerror&&e._onerror(e._result),g(e)}function p(e,t){e._state===B&&(e._result=t,e._state=x,0===e._subscribers.length?b.instrument&&w("fulfilled",e):b.async(g,e))}function d(e,t){e._state===B&&(e._state=U,e._result=t,b.async(l,e))}function f(e,t,i,n){var r=e._subscribers,o=r.length;e._onerror=null,r[o]=t,r[o+x]=i,r[o+U]=n,0===o&&e._state&&b.async(g,e)}function g(e){var t=e._subscribers,i=e._state;if(b.instrument&&w(i===x?"fulfilled":"rejected",e),0!==t.length){for(var n,r,o=e._result,s=0;se;e+=2){var t=l[e],i=l[e+1];t(i),l[e]=void 0,l[e+1]=void 0}s=0}var s=0;e["default"]=function(e,t){l[s]=e,l[s+1]=t,s+=2,2===s&&a()};var a,h="undefined"!=typeof window?window:{},c=h.MutationObserver||h.WebKitMutationObserver,u="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,l=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?t():c?i():u?n():r()}),t("rsvp/config",["./events","exports"],function(e,t){"use strict";function i(e,t){return"onerror"===e?void r.on("error",t):2!==arguments.length?r[e]:void(r[e]=t)}var n=e["default"],r={instrument:!1};n.mixin(r),t.config=r,t.configure=i}),t("rsvp/defer",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e){var t={};return t.promise=new i(function(e,i){t.resolve=e,t.reject=i},e),t}}),t("rsvp/enumerator",["./utils","./-internal","exports"],function(e,t,i){"use strict";function n(e,t,i){return e===l?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(e,t,i,n){this._instanceConstructor=e,this.promise=new e(a,n),this._abortOnReject=i,this._validateInput(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._init(),0===this.length?c(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&c(this.promise,this._result))):h(this.promise,this._validationError())}var o=e.isArray,s=e.isMaybeThenable,a=t.noop,h=t.reject,c=t.fulfill,u=t.subscribe,l=t.FULFILLED,p=t.REJECTED,d=t.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(e){return o(e)},r.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},r.prototype._init=function(){this._result=new Array(this.length)},i["default"]=r,r.prototype._enumerate=function(){for(var e=this.length,t=this.promise,i=this._input,n=0;t._state===d&&e>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(e,t){var i=this._instanceConstructor;s(e)?e.constructor===i&&e._state!==d?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(i.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(l,t,e))},r.prototype._settledAt=function(e,t,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&e===p?h(n,i):this._result[t]=this._makeResult(e,t,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(e,t,i){return i},r.prototype._willSettleAt=function(e,t){var i=this;u(e,void 0,function(e){i._settledAt(l,t,e)},function(e){i._settledAt(p,t,e)})}}),t("rsvp/events",["exports"],function(e){"use strict";function t(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t)return i;return-1}function i(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}e["default"]={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,n){var r,o=i(this);r=o[e],r||(r=o[e]=[]),-1===t(r,n)&&r.push(n)},off:function(e,n){var r,o,s=i(this);return n?(r=s[e],o=t(r,n),void(-1!==o&&r.splice(o,1))):void(s[e]=[])},trigger:function(e,t){var n,r,o=i(this);if(n=o[e])for(var s=0;sa;a++)s[a]=t(e[a]);return n.all(s,i).then(function(t){for(var i=new Array(o),n=0,r=0;o>r;r++)t[r]&&(i[n]=e[r],n++);return i.length=n,i})})}}),t("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(e,t,i,n,r){"use strict";function o(e,t,i){this._superConstructor(e,t,!1,i)}var s=e["default"],a=t.makeSettledResult,h=i["default"],c=t["default"],u=n.o_create;o.prototype=u(h.prototype),o.prototype._superConstructor=c,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},r["default"]=function(e,t){return new o(s,e,t).promise}}),t("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(e,t,i,n){"use strict";{var r=e["default"],o=t["default"];i.ABORT_ON_REJECTION}n["default"]=function(e,t){return new o(r,e,t).promise}}),t("rsvp/instrument",["./config","./utils","exports"],function(e,t,i){"use strict";var n=e.config,r=t.now,o=[];i["default"]=function(e,t,i){1===o.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:i&&t._guidKey+i._id,label:t._label,timeStamp:r(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;ta;a++)s[a]=t(e[a]);return n.all(s,i)})}}),t("rsvp/node",["./promise","./utils","exports"],function(e,t,i){"use strict";var n=e["default"],r=t.isArray;i["default"]=function(e,t){function i(){for(var i=arguments.length,r=new Array(i),a=0;i>a;a++)r[a]=arguments[a];var h;return o||s||!t?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=t),n.all(r).then(function(i){function r(n,r){function a(){for(var e=arguments.length,i=new Array(e),a=0;e>a;a++)i[a]=arguments[a];var h=i[0],c=i[1];if(h)r(h);else if(o)n(i.slice(1));else if(s){var u,l,p={},d=i.slice(1);for(l=0;la;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),t("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(e,t,i,n,r,o,s,a,h,c,u){"use strict";function l(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function p(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(e,t){this._id=_++,this._label=t,this._subscribers=[],f.instrument&&g("created",this),v!==e&&(y(e)||l(),this instanceof d||p(),S(this,e))}var f=e.config,g=(t["default"],i["default"]),y=(n.objectOrFunction,n.isFunction),m=n.now,v=r.noop,E=(r.resolve,r.reject,r.fulfill,r.subscribe),S=r.initializePromise,P=r.invokeCallback,w=r.FULFILLED,b=o["default"],B=s["default"],x=a["default"],U=h["default"],J=c["default"],R="rsvp_"+m()+"-",_=0;u["default"]=d,d.cast=b,d.all=B,d.race=x,d.resolve=U,d.reject=J,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(e){f.trigger("error",e)},then:function(e,t,i){var n=this;n._onerror=null;var r=new this.constructor(v,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===w&&e?f.async(function(){P(o,r,e,s)}):E(n,r,e,t),r},"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)}}}),t("rsvp/promise/all",["../enumerator","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return new i(this,e,!0,t).promise}}),t("rsvp/promise/cast",["./resolve","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=i}),t("rsvp/promise/race",["../utils","../-internal","exports"],function(e,t,i){"use strict";var n=e.isArray,r=(e.isFunction,e.isMaybeThenable,t.noop),o=t.resolve,s=t.reject,a=t.subscribe,h=t.PENDING;i["default"]=function(e,t){function i(e){o(l,e)}function c(e){s(l,e)}var u=this,l=new u(r,t);if(!n(e))return s(l,new TypeError("You must pass an array to race.")),l;for(var p=e.length,d=0;l._state===h&&p>d;d++)a(u.resolve(e[d]),void 0,i,c);return l}}),t("rsvp/promise/reject",["../-internal","exports"],function(e,t){"use strict";var i=e.noop,n=e.reject;t["default"]=function(e,t){var r=this,o=new r(i,t);return n(o,e),o}}),t("rsvp/promise/resolve",["../-internal","exports"],function(e,t){"use strict";var i=e.noop,n=e.resolve;t["default"]=function(e,t){var r=this;if(e&&"object"==typeof e&&e.constructor===r)return e;var o=new r(i,t);return n(o,e),o}}),t("rsvp/race",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.race(e,t)}}),t("rsvp/reject",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.reject(e,t)}}),t("rsvp/resolve",["./promise","exports"],function(e,t){"use strict";var i=e["default"];t["default"]=function(e,t){return i.resolve(e,t)}}),t("rsvp/rethrow",["exports"],function(e){"use strict";e["default"]=function(e){throw setTimeout(function(){throw e}),e}}),t("rsvp/utils",["exports"],function(e){"use strict";function t(e){return"function"==typeof e||"object"==typeof e&&null!==e}function i(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}e.objectOrFunction=t,e.isFunction=i,e.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var o=r;e.isArray=o;var s=Date.now||function(){return(new Date).getTime()};e.now=s;var a=Object.create||function(e){var t=function(){};return t.prototype=e,t};e.o_create=a}),t("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(e,t,i,n,r,o,s,a,h,c,u,l,p,d,f,g,y){"use strict";function m(e,t){k.async(e,t)}function v(){k.on.apply(k,arguments)}function E(){k.off.apply(k,arguments)}var S=e["default"],P=t["default"],w=i["default"],b=n["default"],B=r["default"],x=o["default"],U=s["default"],J=a["default"],R=h["default"],_=c["default"],k=u.config,C=u.configure,N=l["default"],F=p["default"],T=d["default"],I=f["default"],A=g["default"];if(k.async=A,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var O=window.__PROMISE_INSTRUMENTATION__;C("instrument",!0);for(var L in O)O.hasOwnProperty(L)&&v(L,O[L])}y.Promise=S,y.EventTarget=P,y.all=b,y.allSettled=B,y.race=x,y.hash=U,y.hashSettled=J,y.rethrow=R,y.defer=_,y.denodeify=w,y.configure=C,y.on=v,y.off=E,y.resolve=F,y.reject=T,y.async=m,y.map=N,y.filter=I}),e.RSVP=i("rsvp")}(self),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.origin+"/"+t.directory: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={},l=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=l(e),u.steps.push(t))}),c=parseInt(h),isNaN(c)||u.steps.push(c%2===0?l(h):{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})},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=900,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.scroll=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,l=Math.floor(u/8),p=n>=0?n:l%2===0?l:l-1,d=Math.floor((u-p)/h); +return this.spreadWidth=(d+p)*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]=p+"px",e.document.body.style[s]=d+"px",this.colWidth=d,this.gap=p,e.iframe.style.width=d+"px",e.iframe.style.paddingRight=p+"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"),l=a.querySelector("navLabel"),p=l.textContent?l.textContent:"",d=u.split("#"),f=(d[0],t(a));n.unshift({id:h,href:u,label:p,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)),void this.hooks.display.register(this.afterDisplay.bind(this))):void console.error("Not an Element")},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,n=e.split("#"),r=n[0];return this.book.opened.then(function(){var e,i=this.book.spine.get(r);this.displaying=!0,i?(this.clear(),e=this.render(i),this.settings.infinite&&e.then(function(){return this.fill.call(this)}.bind(this)),e.then(function(){this.trigger("displayed",i),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.container.scrollTop,n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&(this.remove(e),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scroll(0,i-t.height,!0):this.infinite.scroll(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.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.first().section.index-1,t=this.forwards();return this.filling=!0,t.then("vertical"===this.settings.axis?this.fillVertical.bind(this):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"):e.onclick=function(){return t.display(i),!1}},o=0;o=0;n--)if(e=this.views[n],t=e.bounds().top,t0){if(this.current==e.section)break;this.current=e.section,this.trigger("current",this.current);break}},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Section=function(e){this.idref=e.idref,this.linear=e.linear,this.properties=e.properties,this.index=e.index,this.href=e.href,this.url=e.url,this.cfiBase=e.cfiBase,this.hooks={},this.hooks.replacements=new EPUBJS.Hook(this),this.hooks.replacements.register(this.replacements)},EPUBJS.Section.prototype.load=function(e){var t=e||this.request||EPUBJS.core.request,i=new RSVP.defer,n=i.promise;return this.contents?i.resolve(this.contents):t(this.url,"xml").then(function(e){EPUBJS.core.folder(this.url);return this.document=e,this.contents=e.documentElement,this.hooks.replacements.trigger(this.document)}.bind(this)).then(function(){i.resolve(this.contents)}.bind(this)).catch(function(e){i.reject(e)}),n},EPUBJS.Section.prototype.replacements=function(e){var t,i=new RSVP.defer,n=e.createElement("base");return n.setAttribute("href",this.url),e&&(t=e.querySelector("head")),t?(t.insertBefore(n,t.firstChild),i.resolve()):i.reject(new Error("No head to insert into")),i.promise},EPUBJS.Section.prototype.beforeSectionLoad=function(){},EPUBJS.Section.prototype.render=function(e){var t=new RSVP.defer,i=t.promise;return this.load(e).then(function(e){var i=new XMLSerializer,n=i.serializeToString(e);t.resolve(n)}).catch(function(e){t.reject(e)}),i},EPUBJS.Section.prototype.find=function(){},EPUBJS.Spine=function(e){this.request=e,this.spineItems=[],this.spineByHref={},this.spineById={}},EPUBJS.Spine.prototype.load=function(e){this.items=e.spine,this.manifest=e.manifest,this.spineNodeIndex=e.spineNodeIndex,this.baseUrl=e.baseUrl||"",this.length=this.items.length,this.epubcfi=new EPUBJS.EpubCFI,this.items.forEach(function(e){var t,i=this.manifest[e.idref];e.cfiBase=this.epubcfi.generateChapterComponent(this.spineNodeIndex,e.index,e.idref),i&&(e.href=i.href,e.url=this.baseUrl+e.href),t=new EPUBJS.Section(e),this.append(t)}.bind(this))},EPUBJS.Spine.prototype.get=function(e){var t=0;return!e||"number"!=typeof e&&isNaN(e)!==!1?e&&0===e.indexOf("#")?t=this.spineById[e.substring(1)]:e&&(t=this.spineByHref[e]):t=e,this.spineItems[t]},EPUBJS.Spine.prototype.append=function(e){var t=this.spineItems.length;return e.index=t,this.spineItems.push(e),this.spineByHref[e.href]=t,this.spineById[e.idref]=t,t},EPUBJS.Spine.prototype.prepend=function(e){this.spineItems.unshift(e);return this.spineByHref[e.href]=0,this.spineById[e.idref]=0,this.spineItems.forEach(function(e,t){e.index=t}),0},EPUBJS.Spine.prototype.insert=function(){},EPUBJS.Spine.prototype.remove=function(e){var t=this.spineItems.indexOf(e);return 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),this.expand(),e.resolve(this),t},EPUBJS.View.prototype.expand=function(){var e,t,i;return e=this.document.body.getBoundingClientRect(),(!e||0===e.height&&0===e.width)&&console.error("View not shown"),this.resizing=!0,i=e.height,this.iframe.style.height=i+"px",t=this.document.documentElement.scrollWidth,this.iframe.style.width=t+"px",e},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/renderer.js b/lib/epubjs/renderer.js index 5011291..c0911d2 100644 --- a/lib/epubjs/renderer.js +++ b/lib/epubjs/renderer.js @@ -100,6 +100,17 @@ EPUBJS.Renderer.prototype.resize = function(_width, _height){ var width = _width; var height = _height; + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + right: parseFloat(styles["padding-right"]) || 0, + top: parseFloat(styles["padding-top"]) || 0, + bottom: parseFloat(styles["padding-bottom"]) || 0 + }; + + var stagewidth = width - padding.left - padding.right; + var stageheight = height - padding.top - padding.bottom; + if(!_width) { width = window.innerWidth; } @@ -107,14 +118,23 @@ EPUBJS.Renderer.prototype.resize = function(_width, _height){ height = window.innerHeight; } - this.container.style.width = width + "px"; - this.container.style.height = height + "px"; + // this.container.style.width = width + "px"; + // this.container.style.height = height + "px"; this.trigger("resized", { width: this.width, height: this.height }); + + this.views.forEach(function(view){ + if(this.settings.axis === "vertical") { + view.resize(stagewidth, 0); + } else { + view.resize(0, stageheight); + } + }.bind(this)); + }; EPUBJS.Renderer.prototype.onResized = function(e) { @@ -192,9 +212,11 @@ EPUBJS.Renderer.prototype.display = function(what){ // TODO: check for fragments - + var split = what.split("#"); + var href = split[0]; + this.book.opened.then(function(){ - var section = this.book.spine.get(what); + var section = this.book.spine.get(href); var rendered; this.displaying = true; @@ -231,6 +253,16 @@ EPUBJS.Renderer.prototype.render = function(section){ var rendered; var view; var bounds = this.container.getBoundingClientRect(); + var styles = window.getComputedStyle(this.container); + var padding = { + left: parseFloat(styles["padding-left"]) || 0, + 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; + if(!section) { rendered = new RSVP.defer(); @@ -241,9 +273,9 @@ EPUBJS.Renderer.prototype.render = function(section){ view = new EPUBJS.View(section); if(this.settings.axis === "vertical") { - view.create(bounds.width, 0); + view.create(width, 0); } else { - view.create(0, bounds.height); + view.create(0, height); } @@ -263,7 +295,7 @@ EPUBJS.Renderer.prototype.render = function(section){ return view.expand(); }.bind(this)) .then(function(){ - // this.rendering = false; + this.rendering = false; view.show(); this.trigger("rendered", view.section); return view; @@ -334,7 +366,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; @@ -408,7 +440,7 @@ EPUBJS.Renderer.prototype.fillVertical = function() { if (height && bottom && (bottom < height)) { //&& (this.last().section.index + 1 < this.book.spine.length)) { return this.forwards().then(this.fillVertical.bind(this)); } else { - // this.rendering = false; + this.rendering = false; defer.resolve(); return defer.promise; } @@ -422,7 +454,7 @@ EPUBJS.Renderer.prototype.fillHorizontal = function() { if (width && right && (right <= width)) { //&& (this.last().section.index + 1 < this.book.spine.length)) { return this.forwards().then(this.fillHorizontal.bind(this)); } else { - // this.rendering = false; + this.rendering = false; defer.resolve(); return defer.promise; } @@ -514,7 +546,7 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) { EPUBJS.Renderer.prototype.afterDisplay = function(view, renderer) { var task = new RSVP.defer(); - view.document.documentElement.style.padding = this.settings.padding; + // view.document.documentElement.style.padding = this.settings.padding; task.resolve(); return task.promise; }; diff --git a/lib/epubjs/view.js b/lib/epubjs/view.js index 02fc995..0c6b7af 100644 --- a/lib/epubjs/view.js +++ b/lib/epubjs/view.js @@ -29,9 +29,27 @@ EPUBJS.View.prototype.create = function(width, height) { return this.iframe; }; +EPUBJS.View.prototype.resize = function(width, height) { + + if(width){ + this.iframe.style.width = width + "px"; + } + + if(height){ + this.iframe.style.height = height + "px"; + } + + if (!this.resizing) { + this.resizing = true; + this.expand(); + } + +}; + EPUBJS.View.prototype.resized = function(e) { if (!this.resizing) { + console.log("resize"); this.expand(); } else { this.resizing = false; @@ -40,14 +58,14 @@ EPUBJS.View.prototype.resized = function(e) { }; EPUBJS.View.prototype.render = function(_request) { - return this.section.render(_request) - .then(function(contents){ - return this.load(contents); - }.bind(this)) - .then(this.display.bind(this)) - .then(function(){ - this.rendering.resolve(this); - }.bind(this)); + return this.section.render(_request) + .then(function(contents){ + return this.load(contents); + }.bind(this)) + .then(this.display.bind(this)) + .then(function(){ + this.rendering.resolve(this); + }.bind(this)); }; EPUBJS.View.prototype.load = function(contents) { @@ -98,15 +116,17 @@ EPUBJS.View.prototype.display = function(contents) { - if(!this.document.fonts || this.document.fonts.status !== "loading") { - this.expand(); - displaying.resolve(this); - } else { - this.document.fonts.onloading = function(){ - this.expand(); - displaying.resolve(this); - }.bind(this); - } + // if(!this.document.fonts || this.document.fonts.status !== "loading") { + // this.expand(); + // displaying.resolve(this); + // } else { + // this.document.fonts.onloading = function(){ + // this.expand(); + // displaying.resolve(this); + // }.bind(this); + // } + this.expand(); + displaying.resolve(this); // this.observer = this.observe(this.document.body);