diff --git a/dist/epub.js b/dist/epub.js index 90e162e..cab9078 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -3652,6 +3652,10 @@ EPUBJS.Infinite.prototype.start = function() { var firstScroll = true; this.container.addEventListener("scroll", function(e){ + + // this.top = this.container.scrollTop; + // this.left = this.container.scrollLeft; + if(!this.ignore) { this.scrolled = true; } else { @@ -5647,25 +5651,31 @@ EPUBJS.Rendition.prototype.afterDisplayed = function(currView){ EPUBJS.Rendition.prototype.afterDisplayedAbove = function(currView){ - var bounds, style, marginTopBottom, marginLeftRight; - var prevTop = this.container.scrollTop; - var prevLeft = this.container.scrollLeft; - - this.afterDisplayed(currView); + var bounds = currView.bounds(); //, style, marginTopBottom, marginLeftRight; + // var prevTop = this.container.scrollTop; + // var prevLeft = this.container.scrollLeft; if(currView.countered) return; - bounds = currView.bounds(); + // bounds = currView.bounds(); if(this.settings.axis === "vertical") { - this.infinite.scrollTo(0, prevTop + bounds.height, true) + this.infinite.scrollBy(0, bounds.height, true); } else { - this.infinite.scrollTo(prevLeft + bounds.width, 0, true); + this.infinite.scrollBy(bounds.width, 0, true); } - + // if(this.settings.axis === "vertical") { + // currView.countered = bounds.height - (currView.countered || 0); + // this.infinite.scrollTo(0, prevTop + bounds.height, true) + // } else { + // currView.countered = bounds.width - (currView.countered || 0); + // this.infinite.scrollTo(prevLeft + bounds.width, 0, true); + // } currView.countered = true; - this.removeShownListeners(currView); + // this.removeShownListeners(currView); + + this.afterDisplayed(currView); if(this.afterDisplayedAboveHook) this.afterDisplayedAboveHook(currView); @@ -5674,8 +5684,9 @@ EPUBJS.Rendition.prototype.afterDisplayedAbove = function(currView){ // Remove Previous Listeners if present EPUBJS.Rendition.prototype.removeShownListeners = function(view){ - view.off("shown", this.afterDisplayed); - view.off("shown", this.afterDisplayedAbove); + // view.off("shown", this.afterDisplayed); + // view.off("shown", this.afterDisplayedAbove); + view.onShown = function(){}; }; @@ -5685,7 +5696,8 @@ EPUBJS.Rendition.prototype.append = function(view){ this.container.appendChild(view.element); - view.on("shown", this.afterDisplayed.bind(this)); + // view.on("shown", this.afterDisplayed.bind(this)); + view.onShown = this.afterDisplayed.bind(this); // this.resizeView(view); }; @@ -5694,7 +5706,8 @@ EPUBJS.Rendition.prototype.prepend = function(view){ // view.prependTo(this.container); this.container.insertBefore(view.element, this.container.firstChild); - view.on("shown", this.afterDisplayedAbove.bind(this)); + view.onShown = this.afterDisplayedAbove.bind(this); + // view.on("shown", this.afterDisplayedAbove.bind(this)); // this.resizeView(view); @@ -5710,7 +5723,8 @@ EPUBJS.Rendition.prototype.fill = function(view){ this.container.appendChild(view.element); - view.on("shown", this.afterDisplayed.bind(this)); + // view.on("shown", this.afterDisplayed.bind(this)); + view.onShown = this.afterDisplayed.bind(this); }; @@ -6202,7 +6216,8 @@ EPUBJS.View = function(section) { this.element.style.height = 0; this.element.style.width = 0; this.element.style.overflow = "hidden"; - + + this.shown = false; this.rendered = false; @@ -6228,8 +6243,8 @@ EPUBJS.View.prototype.create = function(width, height) { this.resize(width, height); } - this.iframe.style.display = "none"; - this.iframe.style.visibility = "hidden"; + // this.iframe.style.display = "none"; + // this.iframe.style.visibility = "hidden"; this.element.appendChild(this.iframe); this.rendered = true; @@ -6237,18 +6252,23 @@ EPUBJS.View.prototype.create = function(width, height) { return this.iframe; }; +// TODO: minimize resizes EPUBJS.View.prototype.resize = function(width, height) { if(width){ if(this.iframe) { this.iframe.style.width = width + "px"; - this.element.style.width = width + "px"; + } + if(this.shown) { + this.element.style.width = height + "px"; } } if(height){ if(this.iframe) { this.iframe.style.height = height + "px"; + } + if(this.shown) { this.element.style.height = height + "px"; } } @@ -6334,7 +6354,7 @@ EPUBJS.View.prototype.afterLoad = function() { // Wait for fonts to load to finish if(this.document.fonts.status === "loading") { this.document.fonts.onloading = function(){ - // this.expand(); + this.expand(); }.bind(this); } @@ -6344,7 +6364,7 @@ EPUBJS.View.prototype.afterLoad = function() { }; -EPUBJS.View.prototype.expand = function(_defer, _count) { +EPUBJS.View.prototype.expand = function(_defer, _count, _func) { var bounds; var width, height; var expanding = _defer || new RSVP.defer(); @@ -6355,8 +6375,6 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { var count = _count || 1; var TIMEOUT = 10 * _count; - // console.log("expand", count, this.index) - // Flag Changes this.resizing = true; @@ -6375,11 +6393,15 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle? width = this.document.documentElement.scrollWidth; + console.log("expand", count, this.index, height, width) if(count <= MAX && (this.width != width || this.height != height)) { setTimeout(function(){ count += 1; - this.expand(expanding, count); + if(_func){ + _func(this); + } + this.expand(expanding, count, _func); }.bind(this), TIMEOUT); } else { @@ -6428,12 +6450,22 @@ EPUBJS.View.prototype.observe = function(target) { EPUBJS.View.prototype.show = function() { // this.iframe.style.display = "block"; + + this.style = window.getComputedStyle(this.element); + this.paddingTopBottom = parseInt(this.style.paddingTop) + parseInt(this.style.paddingBottom) || 0; + this.paddingLeftRight = parseInt(this.style.paddingLeft) + parseInt(this.style.paddingRight) || 0; + this.marginTopBottom = parseInt(this.style.marginTop) + parseInt(this.style.marginBottom) || 0; + this.marginLeftRight = parseInt(this.style.marginLeft) + parseInt(this.style.marginRight) || 0; + this.borderTopBottom = parseInt(this.style.borderTop) + parseInt(this.style.borderBottom) || 0; + this.borderLeftRight = parseInt(this.style.borderLeft) + parseInt(this.style.borderRight) || 0; + this.element.style.width = this.width + "px"; this.element.style.height = this.height + "px"; - this.iframe.style.display = "inline-block"; - this.iframe.style.visibility = "visible"; + // this.iframe.style.display = "inline-block"; + // this.iframe.style.visibility = "visible"; + this.onShown(this); this.trigger("shown", this); this.shown = true; @@ -6441,8 +6473,8 @@ EPUBJS.View.prototype.show = function() { }; EPUBJS.View.prototype.hide = function() { - this.iframe.style.display = "none"; - this.iframe.style.visibility = "hidden"; + // this.iframe.style.display = "none"; + // this.iframe.style.visibility = "hidden"; this.trigger("hidden"); }; @@ -6450,17 +6482,19 @@ EPUBJS.View.prototype.position = function() { return this.element.getBoundingClientRect(); }; -EPUBJS.View.prototype.bounds = function() { - var bounds = this.element.getBoundingClientRect(); - var style = window.getComputedStyle(this.element); - var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; - var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; - var borderTopBottom = parseInt(style.borderTop) + parseInt(style.borderBottom) || 0; - var borderLeftRight = parseInt(style.borderLeft) + parseInt(style.borderRight) || 0; +EPUBJS.View.prototype.onShown = function(view) { + // Stub, override with a custom functions +}; +EPUBJS.View.prototype.bounds = function() { + // var bounds = this.element.getBoundingClientRect(); + // var bounds = { + // width: this.element.offsetWidth, + // height: this.element.offsetHeight + // }; return { - height: bounds.height + marginTopBottom + borderTopBottom, - width: bounds.width + marginLeftRight + borderLeftRight + height: this.height + this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom, + width: this.width + this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight } }; diff --git a/dist/epub.min.js b/dist/epub.min.js index dd540df..a6821bb 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,3 +1,3 @@ -"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,i){e.Render[t]=i}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(t){var e,i;!function(){var t={},n={};e=function(e,i,n){t[e]={deps:i,callback:n}},i=function(e){function r(t){if("."!==t.charAt(0))return t;for(var i=t.split("/"),n=e.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[e])return n[e];if(n[e]={},!t[e])throw new Error("Could not find module "+e);for(var o,s=t[e],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[e]=o||p},i.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,i,n){"use strict";function r(){}function o(t){try{return t.then}catch(e){return x.error=e,x}}function s(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function a(t,e,i){b.async(function(t){var n=!1,r=s(i,e,function(i){n||(n=!0,e!==i?u(t,i):p(t,i))},function(e){n||(n=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,d(t,r))},t)}function h(t,e){t._onerror=null,e._state===U?p(t,e._result):t._state===J?d(t,e._result):f(e,void 0,function(i){e!==i?u(t,i):p(t,i)},function(e){d(t,e)})}function c(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===x?d(t,x.error):void 0===i?p(t,e):S(i)?a(t,e,i):p(t,e)}}function u(t,e){t===e?p(t,e):E(e)?c(t,e):p(t,e)}function l(t){t._onerror&&t._onerror(t._result),g(t)}function p(t,e){t._state===B&&(t._result=e,t._state=U,0===t._subscribers.length?b.instrument&&P("fulfilled",t):b.async(g,t))}function d(t,e){t._state===B&&(t._state=J,t._result=e,b.async(l,t))}function f(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+U]=i,r[o+J]=n,0===o&&t._state&&b.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(b.instrument&&P(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=l[t],i=l[t+1];e(i),l[t]=void 0,l[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){l[s]=t,l[s+1]=e,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)?e():c?i():u?n():r()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function i(t,e){return"onerror"===t?void r.on("error",e):2!==arguments.length?r[t]:void(r[t]=e)}var n=t["default"],r={instrument:!1};n.mixin(r),e.config=r,e.configure=i}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t){var e={};return e.promise=new i(function(t,i){e.resolve=t,e.reject=i},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,i){"use strict";function n(t,e,i){return t===l?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(t,e,i,n){this._instanceConstructor=t,this.promise=new t(a,n),this._abortOnReject=i,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.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=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,c=e.fulfill,u=e.subscribe,l=e.FULFILLED,p=e.REJECTED,d=e.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(t){return o(t)},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 t=this.length,e=this.promise,i=this._input,n=0;e._state===d&&t>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;s(t)?t.constructor===i&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(l,e,t))},r.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&t===p?h(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;u(t,void 0,function(t){i._settledAt(l,e,t)},function(t){i._settledAt(p,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function i(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,n){var r,o=i(this);r=o[t],r||(r=o[t]=[]),-1===e(r,n)&&r.push(n)},off:function(t,n){var r,o,s=i(this);return n?(r=s[t],o=e(r,n),void(-1!==o&&r.splice(o,1))):void(s[t]=[])},trigger:function(t,e){var n,r,o=i(this);if(n=o[t])for(var s=0;sa;a++)s[a]=e(t[a]);return n.all(s,i).then(function(e){for(var i=new Array(o),n=0,r=0;o>r;r++)e[r]&&(i[n]=t[r],n++);return i.length=n,i})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,i,n,r){"use strict";function o(t,e,i){this._superConstructor(t,e,!1,i)}var s=t["default"],a=e.makeSettledResult,h=i["default"],c=e["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(t,e){return new o(s,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,i,n){"use strict";{var r=t["default"],o=e["default"];i.ABORT_ON_REJECTION}n["default"]=function(t,e){return new o(r,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,i){"use strict";var n=t.config,r=e.now,o=[];i["default"]=function(t,e,i){1===o.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:r(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)s[a]=e(t[a]);return n.all(s,i)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=e.isArray;i["default"]=function(t,e){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||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),n.all(r).then(function(i){function r(n,r){function a(){for(var t=arguments.length,i=new Array(t),a=0;t>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)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,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(t,e){this._id=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),y!==t&&(v(t)||l(),this instanceof d||p(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),v=(n.objectOrFunction,n.isFunction),m=n.now,y=r.noop,w=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,S=r.invokeCallback,P=r.FULFILLED,b=o["default"],B=s["default"],U=a["default"],J=h["default"],x=c["default"],R="rsvp_"+m()+"-",C=0;u["default"]=d,d.cast=b,d.all=B,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(y,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===P&&t?f.async(function(){S(o,r,t,s)}):w(n,r,t,e),r},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return new i(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=i}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,i){"use strict";var n=t.isArray,r=(t.isFunction,t.isMaybeThenable,e.noop),o=e.resolve,s=e.reject,a=e.subscribe,h=e.PENDING;i["default"]=function(t,e){function i(t){o(l,t)}function c(t){s(l,t)}var u=this,l=new u(r,e);if(!n(t))return s(l,new TypeError("You must pass an array to race.")),l;for(var p=t.length,d=0;l._state===h&&p>d;d++)a(u.resolve(t[d]),void 0,i,c);return l}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.reject;e["default"]=function(t,e){var r=this,o=new r(i,e);return n(o,t),o}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.resolve;e["default"]=function(t,e){var r=this;if(t&&"object"==typeof t&&t.constructor===r)return t;var o=new r(i,e);return n(o,t),o}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function i(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=i,t.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var o=r;t.isArray=o;var s=Date.now||function(){return(new Date).getTime()};t.now=s;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("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(t,e,i,n,r,o,s,a,h,c,u,l,p,d,f,g,v){"use strict";function m(t,e){k.async(t,e)}function y(){k.on.apply(k,arguments)}function w(){k.off.apply(k,arguments)}var E=t["default"],S=e["default"],P=i["default"],b=n["default"],B=r["default"],U=o["default"],J=s["default"],x=a["default"],R=h["default"],C=c["default"],k=u.config,_=u.configure,T=l["default"],F=p["default"],I=d["default"],N=f["default"],V=g["default"];if(k.async=V,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var A=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var O in A)A.hasOwnProperty(O)&&y(O,A[O])}v.Promise=E,v.EventTarget=S,v.all=b,v.allSettled=B,v.race=U,v.hash=J,v.hashSettled=x,v.rethrow=R,v.defer=C,v.denodeify=P,v.configure=_,v.on=y,v.off=w,v.resolve=F,v.reject=I,v.async=m,v.map=T,v.filter=N}),t.RSVP=i("rsvp")}(self),EPUBJS.Book=function(t){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),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.url=t+i.directory,o.encoding=e.encoding,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),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(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Rendition(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.Continuous=function(){this.views=[],this.container=container,this.limit=limit||4},EPUBJS.Continuous.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element()),t.onDisplayed=function(){var t,e=this.views.indexOf(t),i=t.section.next();e+1===this.views.length&&i&&(t=new EPUBJS.View(i),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onDisplayed=function(){var t,e=(this.views.indexOf(t),t.section.prev());e&&(t=new EPUBJS.View(e),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.fill=function(t){this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=function(){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(e=new EPUBJS.View(n),this.append(e)),0===o&&r&&(i=new EPUBJS.View(r),this.append(i)),this.resizeView(t)}.bind(this)},EPUBJS.Continuous.prototype.insert=function(t,e){this.views.splice(e,0,t),e-1&&this.views.splice(e,1)},EPUBJS.Continuous.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(){{var t=this.container.getBoundingClientRect();(function(e){var i=e.bounds();i.bottom>=t.top&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?(console.log("visible",e.index),this.resizeView(e),this.display(e)):(console.log("off screen",e.index),e.destroy())}).bind(this)}this.views.forEach(this.isVisible)},EPUBJS.Continuous.prototype.displayView=function(t){return t.display(this.book.request).then(function(){return this.hooks.display.trigger(t)}.bind(this)).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return t.expand()}.bind(this)).then(function(){return this.rendering=!1,t.show(),this.trigger("rendered",section),t}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Continuous.prototype.resizeView=function(t){var e=this.container.getBoundingClientRect(),i=window.getComputedStyle(this.container),n={left:parseFloat(i["padding-left"])||0,right:parseFloat(i["padding-right"])||0,top:parseFloat(i["padding-top"])||0,bottom:parseFloat(i["padding-bottom"])||0},r=e.width-n.left-n.right,o=e.height-n.top-n.bottom,s=100,a=200;"vertical"===this.settings.axis?t.resize(r,s):t.resize(a,o)},EPUBJS.core={},EPUBJS.core.request=function(t,e,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==e?JSON.parse(this.response):"blob"==e?s?this.response:new Blob([this.response]):this.response,h.resolve(t)}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",t,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==e&&(c.responseType=a),"json"==e&&c.setRequestHeader("Accept","application/json"),"xml"==e&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(t){var e,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},o=t.indexOf("://"),s=t.indexOf("?"),a=t.indexOf("#");return-1!=a&&(r.fragment=t.slice(a+1),t=t.slice(0,a)),-1!=s&&(r.search=t.slice(s+1),t=t.slice(0,s),href=t),-1!=o?(r.protocol=t.slice(0,o),e=t.slice(o+3),n=e.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=e.slice(0,n),r.path=e.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=t,r.directory=EPUBJS.core.folder(t),r.base=r.directory),r.filename=t.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var i="";return i=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],i=t,n=function(t,i,n){return e.push({funcName:t,args:i,context:n}),e},r=function(){var t;e.length&&(t=e.shift(),i[t.funcName].apply(t.context||i,t.args))},o=function(){for(;e.length;)r()},s=function(){e=[]},a=function(){return e.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++er;r++)if("undefined"!=typeof document.body.style[e[r]+i])return e[r]+i;return t},EPUBJS.core.defaults=function(t){for(var e=1,i=arguments.length;i>e;e++){var n=arguments[e];for(var r in n)void 0===t[r]&&(t[r]=n[r])}return t},EPUBJS.core.insert=function(t,e,i){var n=EPUBJS.core.locationOf(t,e,i);return e.splice(n,0,t),n},EPUBJS.core.locationOf=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?h:(o=i(e[h],t),a-s===1?o>0?h:h+1:0===o?h:-1===o?EPUBJS.core.locationOf(t,e,i,h,a):EPUBJS.core.locationOf(t,e,i,s,h))},EPUBJS.core.indexOfSorted=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?-1:(o=i(e[h],t),a-s===1?0===o?h:-1:0===o?h:-1===o?EPUBJS.core.indexOfSorted(t,e,i,h,a):EPUBJS.core.indexOfSorted(t,e,i,s,h))},EPUBJS.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var i="";i+=2*(t.index+1),t.id&&(i+="["+t.id+"]"),e.push(i)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var i=this.pathTo(t),n=this.generatePathComponent(i);return n.length?"epubcfi("+e+"!"+n+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,i=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,i.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),i=e[1]?e[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,i,n,r,o,s,a,h,c,u={},l=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(u.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),i=this.getChapterComponent(t),n=this.getPathComponent(t)||"",r=this.getCharecterOffsetComponent(t),i&&(e=i.split("/")[2]||"")?(u.spinePos=parseInt(e)/2-1||0,s=e.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(t){var e;t&&(e=l(t),u.steps.push(e))}),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(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.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(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.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,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Infinite=function(t){this.container=t,this.windowHeight=window.innerHeight,this.tick=EPUBJS.core.requestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.tolerance=100,this.prevScrollTop=0,this.prevScrollLeft=0,t&&this.start()},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.ignore?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),scrollTop-this.prevScrollTop>this.tolerance&&this.forwards(),scrollTop-this.prevScrollTop<-this.tolerance&&this.backwards(),scrollLeft-this.prevScrollLeft>this.tolerance&&this.forwards(),scrollLeft-this.prevScrollLeft<-this.tolerance&&this.backwards(),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,this.scrolled=!1):(this.ignore=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(t){this.view=t,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,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(e),c=Math.floor(h/8),u=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+u,t.style.overflow="hidden",t.style.width=h+"px",t.style.height=i+"px",t.style[r]="horizontal",t.style[a]="auto",t.style[s]=h+"px",t.style[o]=u+"px",this.colWidth=h,this.gap=u,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(t){this.view=t,this.documentElement=t.document.documentElement,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i){var n=EPUBJS.core.prefixed("columnAxis"),r=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),s=EPUBJS.core.prefixed("columnFill"),a=2,h=Math.floor(t),c=h%2===0?h:h-1,u=Math.floor(c/8),l=i>=0?i:u%2===0?u:u-1,p=Math.floor((c-l)/a);return this.spreadWidth=(p+l)*a,this.view.document.documentElement.style.overflow="hidden",this.view.document.body.style.width=c+"px",this.view.document.body.style.height=e+"px",this.view.document.body.style[n]="horizontal",this.view.document.body.style[s]="auto",this.view.document.body.style[r]=l+"px",this.view.document.body.style[o]=p+"px",this.colWidth=p,this.gap=l,this.view.document.body.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:e}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(t){var e,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=t.querySelector("[name=viewport");return this.documentElement=t,s&&s.hasAttribute("content")&&(e=s.getAttribute("content"),i=e.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),t.style.width=n+"px"||"auto",t.style.height=r+"px"||"auto",t.style[o]="auto",t.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(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,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],e(a));n.unshift({id:h,href:u,label:p,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},EPUBJS.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(t,e,i){var n,r,o;return e&&!e.length&&(e=[e]),"function"==typeof t?(n=new RSVP.defer,r=n.promise,o={task:t,args:e,context:i,deferred:n,promise:r}):o={promise:t},this._q.push(o),o.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(t.context||this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):null},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Renderer=function(t,e){var i=e||{};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||"",offset:400},this.book=t,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(t){{var e=t||{},i=e.height!==!1?e.height:"100%",n=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(i=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(n=e.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,e.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(t,e){var i=t,n=e,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;t||(i=window.innerWidth),e||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(t){"vertical"===this.settings.axis?t.resize(s,0):t.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&t0&&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(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,i=e.promise;return"string"==typeof t&&(t=t.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(t);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,e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(t){var e,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 t?(i=new EPUBJS.View(t),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,t.index),e=i.render(this.book.request),e.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(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,i;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t=this.first(),e=t.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-e.height>100&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-e.height,!0):this.infinite.scrollTo(n-e.width,!0))),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,i;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t;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&&(t=this.last(),this.remove(t),this.container.scrollTop-this.first().bounds().height>100&&this.remove(t)),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return this.filling=!0,e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,i=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,i=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,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(t,e){for(var i=new RSVP.defer,n=t.document.querySelectorAll("a[href]"),r=function(t){var i=t.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?t.setAttribute("target","_blank"):0===i.indexOf("#")||(t.onclick=function(){return e.display(i),!1})},o=0;o=0;r--)if(t=this.views[r],e=t.bounds().top,e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Rendition.prototype.first=function(){return this.views[0]},EPUBJS.Rendition.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Rendition.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Rendition.prototype.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();i.bottom>=n.top-this.settings.offset&&!(i.top>n.bottom)&&i.right>=n.left&&!(i.left>n.right+this.settings.offset)?t.shown||this.rendering||(console.log("render",t.index),this.render(t)):t.shown&&(t.destroy(),console.log("destroy:",t.section.index))},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect();this.views.forEach(function(e){this.isVisible(e,t)}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=!0,e=0;e0?this.views[e-1].shown:!1,r=e+1=0;r--)if(t=this.views[r],e=t.bounds().top,e-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.displaying=new RSVP.defer,this.displayed=this.displaying.promise,this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.display="inline-block",this.element.style.height=0,this.element.style.width=0,this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1,this.observe=!1},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(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,(t||e)&&this.resize(t,e),this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.element.appendChild(this.iframe),this.rendered=!0,this.iframe)},EPUBJS.View.prototype.resize=function(t,e){t&&this.iframe&&(this.iframe.style.width=t+"px",this.element.style.width=t+"px"),e&&this.iframe&&(this.iframe.style.height=e+"px",this.element.style.height=e+"px"),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.iframe},EPUBJS.View.prototype.display=function(t){return this.shown=!0,this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.afterLoad.bind(this)).then(this.displaying.resolve.call(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.afterLoad=function(){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),"loading"===this.document.fonts.status&&(this.document.fonts.onloading=function(){}.bind(this)),this.observe&&(this.observer=this.observe(this.document.body))},EPUBJS.View.prototype.expand=function(t,e){var i,n,r,o=t||new RSVP.defer,s=o.promise,a=10,h=e||1,c=10*e;return this.resizing=!0,i=this.document.body.getBoundingClientRect(),!i||0===i.height&&0===i.width?(console.error("View not shown"),s):(r=i.height,n=this.document.documentElement.scrollWidth,a>=h&&(this.width!=n||this.height!=r)?setTimeout(function(){h+=1,this.expand(o,h)}.bind(this),c):o.resolve(),this.width=n,this.height=r,this.resize(n,r),s)},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.show=function(){this.element.style.width=this.width+"px",this.element.style.height=this.height+"px",this.iframe.style.display="inline-block",this.iframe.style.visibility="visible",this.trigger("shown",this),this.shown=!0},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.trigger("hidden")},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.bounds=function(){var t=this.element.getBoundingClientRect(),e=window.getComputedStyle(this.element),i=parseInt(e.marginTop)+parseInt(e.marginBottom)||0,n=parseInt(e.marginLeft)+parseInt(e.marginLeft)||0,r=parseInt(e.borderTop)+parseInt(e.borderBottom)||0,o=parseInt(e.borderLeft)+parseInt(e.borderRight)||0;return{height:t.height+i+r,width:t.width+n+o}},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.ViewManager=function(t){this.views=[],this.container=t},EPUBJS.ViewManager.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element())},EPUBJS.ViewManager.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element(),this.container.firstChild)},EPUBJS.ViewManager.prototype.insert=function(t,e){this.views.splice(e,0,t),ethis.last().index?(this.append(t),e=this.views.length):t.indexb.index?1:a.index-1&&this.views.splice(e,1)},EPUBJS.ViewManager.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.ViewManager.prototype.first=function(){return this.views[0]},EPUBJS.ViewManager.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.ViewManager.prototype.map=function(t){return this.views.map(t)}; \ No newline at end of file +"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,i){e.Render[t]=i}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(t){var e,i;!function(){var t={},n={};e=function(e,i,n){t[e]={deps:i,callback:n}},i=function(e){function r(t){if("."!==t.charAt(0))return t;for(var i=t.split("/"),n=e.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[e])return n[e];if(n[e]={},!t[e])throw new Error("Could not find module "+e);for(var o,s=t[e],a=s.deps,h=s.callback,c=[],u=0,p=a.length;p>u;u++)c.push("exports"===a[u]?o={}:i(r(a[u])));var l=h.apply(this,c);return n[e]=o||l},i.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,i,n){"use strict";function r(){}function o(t){try{return t.then}catch(e){return x.error=e,x}}function s(t,e,i,n){try{t.call(e,i,n)}catch(r){return r}}function a(t,e,i){b.async(function(t){var n=!1,r=s(i,e,function(i){n||(n=!0,e!==i?u(t,i):l(t,i))},function(e){n||(n=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!n&&r&&(n=!0,d(t,r))},t)}function h(t,e){t._onerror=null,e._state===U?l(t,e._result):t._state===J?d(t,e._result):f(e,void 0,function(i){e!==i?u(t,i):l(t,i)},function(e){d(t,e)})}function c(t,e){if(e instanceof t.constructor)h(t,e);else{var i=o(e);i===x?d(t,x.error):void 0===i?l(t,e):S(i)?a(t,e,i):l(t,e)}}function u(t,e){t===e?l(t,e):E(e)?c(t,e):l(t,e)}function p(t){t._onerror&&t._onerror(t._result),g(t)}function l(t,e){t._state===B&&(t._result=e,t._state=U,0===t._subscribers.length?b.instrument&&P("fulfilled",t):b.async(g,t))}function d(t,e){t._state===B&&(t._state=J,t._result=e,b.async(p,t))}function f(t,e,i,n){var r=t._subscribers,o=r.length;t._onerror=null,r[o]=e,r[o+U]=i,r[o+J]=n,0===o&&t._state&&b.async(g,t)}function g(t){var e=t._subscribers,i=t._state;if(b.instrument&&P(i===U?"fulfilled":"rejected",t),0!==e.length){for(var n,r,o=t._result,s=0;st;t+=2){var e=p[t],i=p[t+1];e(i),p[t]=void 0,p[t+1]=void 0}s=0}var s=0;t["default"]=function(t,e){p[s]=t,p[s+1]=e,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,p=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():c?i():u?n():r()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function i(t,e){return"onerror"===t?void r.on("error",e):2!==arguments.length?r[t]:void(r[t]=e)}var n=t["default"],r={instrument:!1};n.mixin(r),e.config=r,e.configure=i}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t){var e={};return e.promise=new i(function(t,i){e.resolve=t,e.reject=i},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,i){"use strict";function n(t,e,i){return t===p?{state:"fulfilled",value:i}:{state:"rejected",reason:i}}function r(t,e,i,n){this._instanceConstructor=t,this.promise=new t(a,n),this._abortOnReject=i,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.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=t.isArray,s=t.isMaybeThenable,a=e.noop,h=e.reject,c=e.fulfill,u=e.subscribe,p=e.FULFILLED,l=e.REJECTED,d=e.PENDING,f=!0;i.ABORT_ON_REJECTION=f,i.makeSettledResult=n,r.prototype._validateInput=function(t){return o(t)},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 t=this.length,e=this.promise,i=this._input,n=0;e._state===d&&t>n;n++)this._eachEntry(i[n],n)},r.prototype._eachEntry=function(t,e){var i=this._instanceConstructor;s(t)?t.constructor===i&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(i.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(p,e,t))},r.prototype._settledAt=function(t,e,i){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&t===l?h(n,i):this._result[e]=this._makeResult(t,e,i)),0===this._remaining&&c(n,this._result)},r.prototype._makeResult=function(t,e,i){return i},r.prototype._willSettleAt=function(t,e){var i=this;u(t,void 0,function(t){i._settledAt(p,e,t)},function(t){i._settledAt(l,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return i;return-1}function i(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,n){var r,o=i(this);r=o[t],r||(r=o[t]=[]),-1===e(r,n)&&r.push(n)},off:function(t,n){var r,o,s=i(this);return n?(r=s[t],o=e(r,n),void(-1!==o&&r.splice(o,1))):void(s[t]=[])},trigger:function(t,e){var n,r,o=i(this);if(n=o[t])for(var s=0;sa;a++)s[a]=e(t[a]);return n.all(s,i).then(function(e){for(var i=new Array(o),n=0,r=0;o>r;r++)e[r]&&(i[n]=t[r],n++);return i.length=n,i})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,i,n,r){"use strict";function o(t,e,i){this._superConstructor(t,e,!1,i)}var s=t["default"],a=e.makeSettledResult,h=i["default"],c=e["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(t,e){return new o(s,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,i,n){"use strict";{var r=t["default"],o=e["default"];i.ABORT_ON_REJECTION}n["default"]=function(t,e){return new o(r,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,i){"use strict";var n=t.config,r=e.now,o=[];i["default"]=function(t,e,i){1===o.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:i&&e._guidKey+i._id,label:e._label,timeStamp:r(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)s[a]=e(t[a]);return n.all(s,i)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,i){"use strict";var n=t["default"],r=e.isArray;i["default"]=function(t,e){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||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),n.all(r).then(function(i){function r(n,r){function a(){for(var t=arguments.length,i=new Array(t),a=0;t>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,p,l={},d=i.slice(1);for(p=0;pa;a++)o=i[a],this._eachEntry(o.entry,o.position)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,i,n,r,o,s,a,h,c,u){"use strict";function p(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function l(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(t,e){this._id=C++,this._label=e,this._subscribers=[],f.instrument&&g("created",this),y!==t&&(v(t)||p(),this instanceof d||l(),E(this,t))}var f=t.config,g=(e["default"],i["default"]),v=(n.objectOrFunction,n.isFunction),m=n.now,y=r.noop,w=(r.resolve,r.reject,r.fulfill,r.subscribe),E=r.initializePromise,S=r.invokeCallback,P=r.FULFILLED,b=o["default"],B=s["default"],U=a["default"],J=h["default"],x=c["default"],R="rsvp_"+m()+"-",C=0;u["default"]=d,d.cast=b,d.all=B,d.race=U,d.resolve=J,d.reject=x,d.prototype={constructor:d,_id:void 0,_guidKey:R,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,i){var n=this;n._onerror=null;var r=new this.constructor(y,i),o=n._state,s=n._result;return f.instrument&&g("chained",n,r),o===P&&t?f.async(function(){S(o,r,t,s)}):w(n,r,t,e),r},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var i=this.constructor;return this.then(function(e){return i.resolve(t()).then(function(){return e})},function(e){return i.resolve(t()).then(function(){throw e})},e)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return new i(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=i}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,i){"use strict";var n=t.isArray,r=(t.isFunction,t.isMaybeThenable,e.noop),o=e.resolve,s=e.reject,a=e.subscribe,h=e.PENDING;i["default"]=function(t,e){function i(t){o(p,t)}function c(t){s(p,t)}var u=this,p=new u(r,e);if(!n(t))return s(p,new TypeError("You must pass an array to race.")),p;for(var l=t.length,d=0;p._state===h&&l>d;d++)a(u.resolve(t[d]),void 0,i,c);return p}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.reject;e["default"]=function(t,e){var r=this,o=new r(i,e);return n(o,t),o}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var i=t.noop,n=t.resolve;e["default"]=function(t,e){var r=this;if(t&&"object"==typeof t&&t.constructor===r)return t;var o=new r(i,e);return n(o,t),o}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var i=t["default"];e["default"]=function(t,e){return i.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function i(t){return"function"==typeof t}function n(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=i,t.isMaybeThenable=n;var r;r=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var o=r;t.isArray=o;var s=Date.now||function(){return(new Date).getTime()};t.now=s;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("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(t,e,i,n,r,o,s,a,h,c,u,p,l,d,f,g,v){"use strict";function m(t,e){k.async(t,e)}function y(){k.on.apply(k,arguments)}function w(){k.off.apply(k,arguments)}var E=t["default"],S=e["default"],P=i["default"],b=n["default"],B=r["default"],U=o["default"],J=s["default"],x=a["default"],R=h["default"],C=c["default"],k=u.config,_=u.configure,T=p["default"],F=l["default"],I=d["default"],N=f["default"],V=g["default"];if(k.async=V,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var A=window.__PROMISE_INSTRUMENTATION__;_("instrument",!0);for(var L in A)A.hasOwnProperty(L)&&y(L,A[L])}v.Promise=E,v.EventTarget=S,v.all=b,v.allSettled=B,v.race=U,v.hash=J,v.hashSettled=x,v.rethrow=R,v.defer=C,v.denodeify=P,v.configure=_,v.on=y,v.off=w,v.resolve=F,v.reject=I,v.async=m,v.map=T,v.filter=N}),t.RSVP=i("rsvp")}(self),EPUBJS.Book=function(t){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),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,i,n,r=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.base:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,e.directory)):this.url=e.directory,i=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+s,i=this.request(this.containerUrl).then(function(t){return r.container(t)}).then(function(e){var i=EPUBJS.core.uri(e.packagePath);return o.packageUrl=t+e.packagePath,o.url=t+i.directory,o.encoding=e.encoding,o.request(o.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(t)})),i.then(function(t){o.unpack(t),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(t){console.error(t.message,t.stack),o.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,i=new EPUBJS.Parser;e.package=i.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Rendition(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.Continuous=function(){this.views=[],this.container=container,this.limit=limit||4},EPUBJS.Continuous.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element()),t.onDisplayed=function(){var t,e=this.views.indexOf(t),i=t.section.next();e+1===this.views.length&&i&&(t=new EPUBJS.View(i),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element,this.container.firstChild),t.onDisplayed=function(){var t,e=(this.views.indexOf(t),t.section.prev());e&&(t=new EPUBJS.View(e),this.append(t))}.bind(this),this.resizeView(t)},EPUBJS.Continuous.prototype.fill=function(t){this.views.length&&this.clear(),this.views.push(t),this.container.appendChild(t.element),t.onDisplayed=function(){var e,i,n=t.section.next(),r=t.section.prev(),o=this.views.indexOf(t);o+1===this.views.length&&n&&(e=new EPUBJS.View(n),this.append(e)),0===o&&r&&(i=new EPUBJS.View(r),this.append(i)),this.resizeView(t)}.bind(this)},EPUBJS.Continuous.prototype.insert=function(t,e){this.views.splice(e,0,t),e-1&&this.views.splice(e,1)},EPUBJS.Continuous.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Continuous.prototype.first=function(){return this.views[0]},EPUBJS.Continuous.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Continuous.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Continuous.prototype.check=function(){{var t=this.container.getBoundingClientRect();(function(e){var i=e.bounds();i.bottom>=t.top&&!(i.top>t.bottom)&&i.right>=t.left&&!(i.left>t.right)?(console.log("visible",e.index),this.resizeView(e),this.display(e)):(console.log("off screen",e.index),e.destroy())}).bind(this)}this.views.forEach(this.isVisible)},EPUBJS.Continuous.prototype.displayView=function(t){return t.display(this.book.request).then(function(){return this.hooks.display.trigger(t)}.bind(this)).then(function(){return this.hooks.replacements.trigger(t,this)}.bind(this)).then(function(){return t.expand()}.bind(this)).then(function(){return this.rendering=!1,t.show(),this.trigger("rendered",section),t}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))},EPUBJS.Continuous.prototype.resizeView=function(t){var e=this.container.getBoundingClientRect(),i=window.getComputedStyle(this.container),n={left:parseFloat(i["padding-left"])||0,right:parseFloat(i["padding-right"])||0,top:parseFloat(i["padding-top"])||0,bottom:parseFloat(i["padding-bottom"])||0},r=e.width-n.left-n.right,o=e.height-n.top-n.bottom,s=100,a=200;"vertical"===this.settings.axis?t.resize(r,s):t.resize(a,o)},EPUBJS.core={},EPUBJS.core.request=function(t,e,i,n){function r(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML?this.responseXML:(new DOMParser).parseFromString(this.response,"text/xml"):"json"==e?JSON.parse(this.response):"blob"==e?s?this.response:new Blob([this.response]):this.response,h.resolve(t)}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",t,!0);for(o in n)c.setRequestHeader(o,n[o]);return c.onreadystatechange=r,"blob"==e&&(c.responseType=a),"json"==e&&c.setRequestHeader("Accept","application/json"),"xml"==e&&c.overrideMimeType("text/xml"),c.send(),h.promise},EPUBJS.core.uri=function(t){var e,i,n,r={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},o=t.indexOf("://"),s=t.indexOf("?"),a=t.indexOf("#");return-1!=a&&(r.fragment=t.slice(a+1),t=t.slice(0,a)),-1!=s&&(r.search=t.slice(s+1),t=t.slice(0,s),href=t),-1!=o?(r.protocol=t.slice(0,o),e=t.slice(o+3),n=e.indexOf("/"),-1===n?(r.host=r.path,r.path=""):(r.host=e.slice(0,n),r.path=e.slice(n)),r.origin=r.protocol+"://"+r.host,r.directory=EPUBJS.core.folder(r.path),r.base=r.origin+r.directory):(r.path=t,r.directory=EPUBJS.core.folder(t),r.base=r.directory),r.filename=t.replace(r.base,""),i=r.filename.lastIndexOf("."),-1!=i&&(r.extension=r.filename.slice(i+1)),r},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var i="";return i=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],i=t,n=function(t,i,n){return e.push({funcName:t,args:i,context:n}),e},r=function(){var t;e.length&&(t=e.shift(),i[t.funcName].apply(t.context||i,t.args))},o=function(){for(;e.length;)r()},s=function(){e=[]},a=function(){return e.length};return{enqueue:n,dequeue:r,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:7&i|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,i=Object.keys(t),n=i.length,r=Array(n);++er;r++)if("undefined"!=typeof document.body.style[e[r]+i])return e[r]+i;return t},EPUBJS.core.defaults=function(t){for(var e=1,i=arguments.length;i>e;e++){var n=arguments[e];for(var r in n)void 0===t[r]&&(t[r]=n[r])}return t},EPUBJS.core.insert=function(t,e,i){var n=EPUBJS.core.locationOf(t,e,i);return e.splice(n,0,t),n},EPUBJS.core.locationOf=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?h:(o=i(e[h],t),a-s===1?o>0?h:h+1:0===o?h:-1===o?EPUBJS.core.locationOf(t,e,i,h,a):EPUBJS.core.locationOf(t,e,i,s,h))},EPUBJS.core.indexOfSorted=function(t,e,i,n,r){var o,s=n||0,a=r||e.length,h=parseInt(s+(a-s)/2);return i||(i=function(t,e){return t>e?1:e>t?-1:(t=e)?0:void 0}),0>=a-s?-1:(o=i(e[h],t),a-s===1?0===o?h:-1:0===o?h:-1===o?EPUBJS.core.indexOfSorted(t,e,i,h,a):EPUBJS.core.indexOfSorted(t,e,i,s,h))},EPUBJS.core.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,i){var n=parseInt(e),r=t+1,o="/"+r+"/";return o+=2*(n+1),i&&(o+="["+i+"]"),o},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var i="";i+=2*(t.index+1),t.id&&(i+="["+t.id+"]"),e.push(i)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var i=this.pathTo(t),n=this.generatePathComponent(i);return n.length?"epubcfi("+e+"!"+n+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,i=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,i.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return i},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),i=e[1]?e[1].split(":"):"";return i[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,i,n,r,o,s,a,h,c,u={},p=function(t){var e,i,n,r;return e="element",i=parseInt(t)/2-1,n=t.match(/\[(.*)\]/),n&&n[1]&&(r=n[1]),{type:e,index:i,id:r||!1}};return"string"!=typeof t?{spinePos:-1}:(u.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),i=this.getChapterComponent(t),n=this.getPathComponent(t)||"",r=this.getCharecterOffsetComponent(t),i&&(e=i.split("/")[2]||"")?(u.spinePos=parseInt(e)/2-1||0,s=e.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(t){var e;t&&(e=p(t),u.steps.push(e))}),c=parseInt(h),isNaN(c)||u.steps.push(c%2===0?p(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(t,e,i){var n,r,o,s,a=e||document,h=i||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),r=t.steps[t.steps.length-1],-1===t.spinePos?!1:(n=this.findParent(t,a))?(r&&"text"===r.type?(o=n.childNodes[r.index],t.characterOffset?(s=o.splitText(t.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(t){var e=t||document,i=e.createElement("span");return i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),i.classList.add("EPUBJS-CFI-MARKER"),i},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var i,n,r,o=e||document,s=o.getElementsByTagName("html")[0],a=Array.prototype.slice.call(s.children);if("string"==typeof t&&(t=this.parse(t)),n=t.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,t.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[i].index)return 1;if(t.steps[i].indexe.characterOffset?1:t.characterOffset=0?(o=r.length,t.characterOffseti?this.hooks[i].apply(this.context,r):void 0}.bind(this))):(t=n.promise,n.resolve()),t},EPUBJS.Infinite=function(t){this.container=t,this.windowHeight=window.innerHeight,this.tick=EPUBJS.core.requestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.tolerance=100,this.prevScrollTop=0,this.prevScrollLeft=0,t&&this.start()},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.ignore?(scrollTop=this.container.scrollTop,scrollLeft=this.container.scrollLeft,this.trigger("scroll",{top:scrollTop,left:scrollLeft}),scrollTop-this.prevScrollTop>this.tolerance&&this.forwards(),scrollTop-this.prevScrollTop<-this.tolerance&&this.backwards(),scrollLeft-this.prevScrollLeft>this.tolerance&&this.forwards(),scrollLeft-this.prevScrollLeft<-this.tolerance&&this.backwards(),this.prevScrollTop=scrollTop,this.prevScrollLeft=scrollLeft,this.scrolled=!1):(this.ignore=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scrollTo=function(t,e,i){i&&(this.ignore=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(t){this.view=t,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,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(e),c=Math.floor(h/8),u=n>=0?n:c%2===0?c:c-1;return this.documentElement=t,this.spreadWidth=h+u,t.style.overflow="hidden",t.style.width=h+"px",t.style.height=i+"px",t.style[r]="horizontal",t.style[a]="auto",t.style[s]=h+"px",t.style[o]=u+"px",this.colWidth=h,this.gap=u,{pageWidth:this.spreadWidth,pageHeight:i}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(t){this.view=t,this.documentElement=t.document.documentElement,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,i){var n=EPUBJS.core.prefixed("columnAxis"),r=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),s=EPUBJS.core.prefixed("columnFill"),a=2,h=Math.floor(t),c=h%2===0?h:h-1,u=Math.floor(c/8),p=i>=0?i:u%2===0?u:u-1,l=Math.floor((c-p)/a);return this.spreadWidth=(l+p)*a,this.view.document.documentElement.style.overflow="hidden",this.view.document.body.style.width=c+"px",this.view.document.body.style.height=e+"px",this.view.document.body.style[n]="horizontal",this.view.document.body.style[s]="auto",this.view.document.body.style[r]=p+"px",this.view.document.body.style[o]=l+"px",this.colWidth=l,this.gap=p,this.view.document.body.style.paddingRight=p+"px",{pageWidth:this.spreadWidth,pageHeight:e}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(t){var e,i,n,r,o=EPUBJS.core.prefixed("columnWidth"),s=t.querySelector("[name=viewport");return this.documentElement=t,s&&s.hasAttribute("content")&&(e=s.getAttribute("content"),i=e.split(","),i[0]&&(n=i[0].replace("width=","")),i[1]&&(r=i[1].replace("height=",""))),t.style.width=n+"px"||"auto",t.style.height=r+"px"||"auto",t.style[o]="auto",t.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(t,e){var i=this,n=new EPUBJS.Parser,r=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.navUrl,"xml").then(function(e){i.toc=n.nav(e),i.loaded(i.toc),t.resolve(i.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return r(i.ncxUrl,"xml").then(function(e){i.toc=n.ncx(e),i.loaded(i.toc),t.resolve(i.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,i;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(i=new RSVP.defer,i.resolve([]),e=i.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,i=0;i=0;s--){var a=r.snapshotItem(s),h=a.getAttribute("id")||!1,c=a.querySelector("content"),u=c.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=u.split("#"),f=(d[0],e(a));n.unshift({id:h,href:u,label:l,subitems:f,parent:i?i.getAttribute("id"):null})}return n}var i=t.querySelector("navMap");return i?e(i):[]},EPUBJS.Queue=function(t){this._q=[],this.context=t,this.tick=EPUBJS.core.requestAnimationFrame,this.running=!1},EPUBJS.Queue.prototype.enqueue=function(t,e,i){var n,r,o;return e&&!e.length&&(e=[e]),"function"==typeof t?(n=new RSVP.defer,r=n.promise,o={task:t,args:e,context:i,deferred:n,promise:r}):o={promise:t},this._q.push(o),o.promise},EPUBJS.Queue.prototype.dequeue=function(){var t,e;return this._q.length?(t=this._q.shift(),e=t.task,e?e.apply(t.context||this.context,t.args).then(function(){t.deferred.resolve.apply(t.context||this.context,arguments)}.bind(this)):t.promise):null},EPUBJS.Queue.prototype.flush=function(){for(;this._q.length;)this.dequeue()},EPUBJS.Queue.prototype.run=function(){!this.running&&this._q.length&&(this.running=!0,this.dequeue().then(function(){this.running=!1}.bind(this))),this.tick.call(window,this.run.bind(this))},EPUBJS.Queue.prototype.clear=function(){this._q=[]},EPUBJS.Queue.prototype.length=function(){return this._q.length},EPUBJS.Task=function(t){return function(){var e=arguments||[];return new RSVP.Promise(function(i){var n=function(t){i(t)};e.push(n),t.apply(this,e)}.bind(this))}},EPUBJS.Renderer=function(t,e){var i=e||{};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||"",offset:400},this.book=t,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(t){{var e=t||{},i=e.height!==!1?e.height:"100%",n=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(i=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(n=e.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,e.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(t,e){var i=t,n=e,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;t||(i=window.innerWidth),e||(n=window.innerHeight),this.trigger("resized",{width:this.width,height:this.height}),this.views.forEach(function(t){"vertical"===this.settings.axis?t.resize(s,0):t.resize(0,a)}.bind(this))},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&!this.filling&&!this.displaying&&t0&&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(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,i=e.promise;return"string"==typeof t&&(t=t.split("#")[0]),this.book.opened.then(function(){var i,n=this.book.spine.get(t);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,e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),i},EPUBJS.Renderer.prototype.render=function(t){var e,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 t?(i=new EPUBJS.View(t),"vertical"===this.settings.axis?i.create(s,0):i.create(0,a),this.insert(i,t.index),e=i.render(this.book.request),e.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(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,i;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t=this.first(),e=t.bounds(),i=(this.last().bounds(),this.container.scrollTop),n=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&this.container.scrollTop-e.height>100&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollTo(0,i-e.height,!0):this.infinite.scrollTo(n-e.width,!0))),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,i;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,i=this.book.spine.get(t),e=this.render(i),e.then(function(){var t;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&&(t=this.last(),this.remove(t),this.container.scrollTop-this.first().bounds().height>100&&this.remove(t)),this.rendering=!1}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return this.filling=!0,e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.filling=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,i=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,i=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,i.resolve(),i.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,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(t,e){for(var i=new RSVP.defer,n=t.document.querySelectorAll("a[href]"),r=function(t){var i=t.getAttribute("href"),n=new EPUBJS.core.uri(i);n.protocol?t.setAttribute("target","_blank"):0===i.indexOf("#")||(t.onclick=function(){return e.display(i),!1})},o=0;o=0;r--)if(t=this.views[r],e=t.bounds().top,e-1&&this.views.splice(e,1),this.container.removeChild(t.element),t.shown&&t.destroy(),t=null},EPUBJS.Rendition.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Rendition.prototype.first=function(){return this.views[0]},EPUBJS.Rendition.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Rendition.prototype.each=function(t){return this.views.forEach(t)},EPUBJS.Rendition.prototype.isVisible=function(t,e){var i=t.position(),n=e||this.container.getBoundingClientRect();i.bottom>=n.top-this.settings.offset&&!(i.top>n.bottom)&&i.right>=n.left&&!(i.left>n.right+this.settings.offset)?t.shown||this.rendering||(console.log("render",t.index),this.render(t)):t.shown&&(t.destroy(),console.log("destroy:",t.section.index))},EPUBJS.Rendition.prototype.check=function(){var t=this.container.getBoundingClientRect();this.views.forEach(function(e){this.isVisible(e,t)}.bind(this)),clearTimeout(this.trimTimeout),this.trimTimeout=setTimeout(function(){this.trim()}.bind(this),250)},EPUBJS.Rendition.prototype.trim=function(){for(var t=!0,e=0;e0?this.views[e-1].shown:!1,r=e+1=0;r--)if(t=this.views[r],e=t.bounds().top,e-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.displaying=new RSVP.defer,this.displayed=this.displaying.promise,this.section=t,this.index=t.index,this.element=document.createElement("div"),this.element.classList.add("epub-view"),this.element.style.display="inline-block",this.element.style.height=0,this.element.style.width=0,this.element.style.overflow="hidden",this.shown=!1,this.rendered=!1,this.observe=!1},EPUBJS.View.prototype.create=function(t,e){return this.iframe?this.iframe:(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,(t||e)&&this.resize(t,e),this.element.appendChild(this.iframe),this.rendered=!0,this.iframe)},EPUBJS.View.prototype.resize=function(t,e){t&&(this.iframe&&(this.iframe.style.width=t+"px"),this.shown&&(this.element.style.width=e+"px")),e&&(this.iframe&&(this.iframe.style.height=e+"px"),this.shown&&(this.element.style.height=e+"px")),this.resizing||(this.resizing=!0,this.iframe&&this.expand())},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.iframe},EPUBJS.View.prototype.display=function(t){return this.shown=!0,this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.afterLoad.bind(this)).then(this.displaying.resolve.call(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,i=e.promise;return this.document=this.iframe.contentDocument,this.document?(this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),i):(e.reject(new Error("No Document Available")),i)},EPUBJS.View.prototype.afterLoad=function(){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),"loading"===this.document.fonts.status&&(this.document.fonts.onloading=function(){this.expand()}.bind(this)),this.observe&&(this.observer=this.observe(this.document.body))},EPUBJS.View.prototype.expand=function(t,e,i){var n,r,o,s=t||new RSVP.defer,a=s.promise,h=10,c=e||1,u=10*e;return this.resizing=!0,n=this.document.body.getBoundingClientRect(),!n||0===n.height&&0===n.width?(console.error("View not shown"),a):(o=n.height,r=this.document.documentElement.scrollWidth,console.log("expand",c,this.index,o,r),h>=c&&(this.width!=r||this.height!=o)?setTimeout(function(){c+=1,i&&i(this),this.expand(s,c,i)}.bind(this),u):s.resolve(),this.width=r,this.height=o,this.resize(r,o),a)},EPUBJS.View.prototype.observe=function(t){var e=this,i=new MutationObserver(function(){e.expand()}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return i.observe(t,n),i},EPUBJS.View.prototype.show=function(){this.style=window.getComputedStyle(this.element),this.paddingTopBottom=parseInt(this.style.paddingTop)+parseInt(this.style.paddingBottom)||0,this.paddingLeftRight=parseInt(this.style.paddingLeft)+parseInt(this.style.paddingRight)||0,this.marginTopBottom=parseInt(this.style.marginTop)+parseInt(this.style.marginBottom)||0,this.marginLeftRight=parseInt(this.style.marginLeft)+parseInt(this.style.marginRight)||0,this.borderTopBottom=parseInt(this.style.borderTop)+parseInt(this.style.borderBottom)||0,this.borderLeftRight=parseInt(this.style.borderLeft)+parseInt(this.style.borderRight)||0,this.element.style.width=this.width+"px",this.element.style.height=this.height+"px",this.onShown(this),this.trigger("shown",this),this.shown=!0},EPUBJS.View.prototype.hide=function(){this.trigger("hidden")},EPUBJS.View.prototype.position=function(){return this.element.getBoundingClientRect()},EPUBJS.View.prototype.onShown=function(){},EPUBJS.View.prototype.bounds=function(){return{height:this.height+this.paddingTopBottom+this.marginTopBottom+this.borderTopBottom,width:this.width+this.paddingLeftRight+this.marginLeftRight+this.borderLeftRight}},EPUBJS.View.prototype.destroy=function(){this.iframe&&(this.element.removeChild(this.iframe),this.shown=!1,this.iframe=null)},RSVP.EventTarget.mixin(EPUBJS.View.prototype),EPUBJS.ViewManager=function(t){this.views=[],this.container=t},EPUBJS.ViewManager.prototype.append=function(t){this.views.push(t),this.container.appendChild(t.element())},EPUBJS.ViewManager.prototype.prepend=function(t){this.views.unshift(t),this.container.insertBefore(t.element(),this.container.firstChild)},EPUBJS.ViewManager.prototype.insert=function(t,e){this.views.splice(e,0,t),ethis.last().index?(this.append(t),e=this.views.length):t.indexb.index?1:a.index-1&&this.views.splice(e,1)},EPUBJS.ViewManager.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.ViewManager.prototype.first=function(){return this.views[0]},EPUBJS.ViewManager.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.ViewManager.prototype.map=function(t){return this.views.map(t)}; \ No newline at end of file diff --git a/lib/epubjs/infinite.js b/lib/epubjs/infinite.js index 68e17f6..4c4f89d 100644 --- a/lib/epubjs/infinite.js +++ b/lib/epubjs/infinite.js @@ -22,6 +22,10 @@ EPUBJS.Infinite.prototype.start = function() { var firstScroll = true; this.container.addEventListener("scroll", function(e){ + + // this.top = this.container.scrollTop; + // this.left = this.container.scrollLeft; + if(!this.ignore) { this.scrolled = true; } else { diff --git a/lib/epubjs/rendition.js b/lib/epubjs/rendition.js index 3a9e5d5..66eff29 100644 --- a/lib/epubjs/rendition.js +++ b/lib/epubjs/rendition.js @@ -282,25 +282,31 @@ EPUBJS.Rendition.prototype.afterDisplayed = function(currView){ EPUBJS.Rendition.prototype.afterDisplayedAbove = function(currView){ - var bounds, style, marginTopBottom, marginLeftRight; - var prevTop = this.container.scrollTop; - var prevLeft = this.container.scrollLeft; - - this.afterDisplayed(currView); + var bounds = currView.bounds(); //, style, marginTopBottom, marginLeftRight; + // var prevTop = this.container.scrollTop; + // var prevLeft = this.container.scrollLeft; if(currView.countered) return; - bounds = currView.bounds(); + // bounds = currView.bounds(); if(this.settings.axis === "vertical") { - this.infinite.scrollTo(0, prevTop + bounds.height, true) + this.infinite.scrollBy(0, bounds.height, true); } else { - this.infinite.scrollTo(prevLeft + bounds.width, 0, true); + this.infinite.scrollBy(bounds.width, 0, true); } - + // if(this.settings.axis === "vertical") { + // currView.countered = bounds.height - (currView.countered || 0); + // this.infinite.scrollTo(0, prevTop + bounds.height, true) + // } else { + // currView.countered = bounds.width - (currView.countered || 0); + // this.infinite.scrollTo(prevLeft + bounds.width, 0, true); + // } currView.countered = true; - this.removeShownListeners(currView); + // this.removeShownListeners(currView); + + this.afterDisplayed(currView); if(this.afterDisplayedAboveHook) this.afterDisplayedAboveHook(currView); @@ -309,8 +315,9 @@ EPUBJS.Rendition.prototype.afterDisplayedAbove = function(currView){ // Remove Previous Listeners if present EPUBJS.Rendition.prototype.removeShownListeners = function(view){ - view.off("shown", this.afterDisplayed); - view.off("shown", this.afterDisplayedAbove); + // view.off("shown", this.afterDisplayed); + // view.off("shown", this.afterDisplayedAbove); + view.onShown = function(){}; }; @@ -320,7 +327,8 @@ EPUBJS.Rendition.prototype.append = function(view){ this.container.appendChild(view.element); - view.on("shown", this.afterDisplayed.bind(this)); + // view.on("shown", this.afterDisplayed.bind(this)); + view.onShown = this.afterDisplayed.bind(this); // this.resizeView(view); }; @@ -329,7 +337,8 @@ EPUBJS.Rendition.prototype.prepend = function(view){ // view.prependTo(this.container); this.container.insertBefore(view.element, this.container.firstChild); - view.on("shown", this.afterDisplayedAbove.bind(this)); + view.onShown = this.afterDisplayedAbove.bind(this); + // view.on("shown", this.afterDisplayedAbove.bind(this)); // this.resizeView(view); @@ -345,7 +354,8 @@ EPUBJS.Rendition.prototype.fill = function(view){ this.container.appendChild(view.element); - view.on("shown", this.afterDisplayed.bind(this)); + // view.on("shown", this.afterDisplayed.bind(this)); + view.onShown = this.afterDisplayed.bind(this); }; diff --git a/lib/epubjs/view.js b/lib/epubjs/view.js index ccba4b8..42f19af 100644 --- a/lib/epubjs/view.js +++ b/lib/epubjs/view.js @@ -12,7 +12,8 @@ EPUBJS.View = function(section) { this.element.style.height = 0; this.element.style.width = 0; this.element.style.overflow = "hidden"; - + + this.shown = false; this.rendered = false; @@ -38,8 +39,8 @@ EPUBJS.View.prototype.create = function(width, height) { this.resize(width, height); } - this.iframe.style.display = "none"; - this.iframe.style.visibility = "hidden"; + // this.iframe.style.display = "none"; + // this.iframe.style.visibility = "hidden"; this.element.appendChild(this.iframe); this.rendered = true; @@ -47,18 +48,23 @@ EPUBJS.View.prototype.create = function(width, height) { return this.iframe; }; +// TODO: minimize resizes EPUBJS.View.prototype.resize = function(width, height) { if(width){ if(this.iframe) { this.iframe.style.width = width + "px"; - this.element.style.width = width + "px"; + } + if(this.shown) { + this.element.style.width = height + "px"; } } if(height){ if(this.iframe) { this.iframe.style.height = height + "px"; + } + if(this.shown) { this.element.style.height = height + "px"; } } @@ -144,7 +150,7 @@ EPUBJS.View.prototype.afterLoad = function() { // Wait for fonts to load to finish if(this.document.fonts.status === "loading") { this.document.fonts.onloading = function(){ - // this.expand(); + this.expand(); }.bind(this); } @@ -154,7 +160,7 @@ EPUBJS.View.prototype.afterLoad = function() { }; -EPUBJS.View.prototype.expand = function(_defer, _count) { +EPUBJS.View.prototype.expand = function(_defer, _count, _func) { var bounds; var width, height; var expanding = _defer || new RSVP.defer(); @@ -165,8 +171,6 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { var count = _count || 1; var TIMEOUT = 10 * _count; - // console.log("expand", count, this.index) - // Flag Changes this.resizing = true; @@ -185,11 +189,15 @@ EPUBJS.View.prototype.expand = function(_defer, _count) { height = bounds.height; //this.document.documentElement.scrollHeight; //window.getComputedStyle? width = this.document.documentElement.scrollWidth; + console.log("expand", count, this.index, height, width) if(count <= MAX && (this.width != width || this.height != height)) { setTimeout(function(){ count += 1; - this.expand(expanding, count); + if(_func){ + _func(this); + } + this.expand(expanding, count, _func); }.bind(this), TIMEOUT); } else { @@ -238,12 +246,22 @@ EPUBJS.View.prototype.observe = function(target) { EPUBJS.View.prototype.show = function() { // this.iframe.style.display = "block"; + + this.style = window.getComputedStyle(this.element); + this.paddingTopBottom = parseInt(this.style.paddingTop) + parseInt(this.style.paddingBottom) || 0; + this.paddingLeftRight = parseInt(this.style.paddingLeft) + parseInt(this.style.paddingRight) || 0; + this.marginTopBottom = parseInt(this.style.marginTop) + parseInt(this.style.marginBottom) || 0; + this.marginLeftRight = parseInt(this.style.marginLeft) + parseInt(this.style.marginRight) || 0; + this.borderTopBottom = parseInt(this.style.borderTop) + parseInt(this.style.borderBottom) || 0; + this.borderLeftRight = parseInt(this.style.borderLeft) + parseInt(this.style.borderRight) || 0; + this.element.style.width = this.width + "px"; this.element.style.height = this.height + "px"; - this.iframe.style.display = "inline-block"; - this.iframe.style.visibility = "visible"; + // this.iframe.style.display = "inline-block"; + // this.iframe.style.visibility = "visible"; + this.onShown(this); this.trigger("shown", this); this.shown = true; @@ -251,8 +269,8 @@ EPUBJS.View.prototype.show = function() { }; EPUBJS.View.prototype.hide = function() { - this.iframe.style.display = "none"; - this.iframe.style.visibility = "hidden"; + // this.iframe.style.display = "none"; + // this.iframe.style.visibility = "hidden"; this.trigger("hidden"); }; @@ -260,17 +278,19 @@ EPUBJS.View.prototype.position = function() { return this.element.getBoundingClientRect(); }; -EPUBJS.View.prototype.bounds = function() { - var bounds = this.element.getBoundingClientRect(); - var style = window.getComputedStyle(this.element); - var marginTopBottom = parseInt(style.marginTop) + parseInt(style.marginBottom) || 0; - var marginLeftRight = parseInt(style.marginLeft) + parseInt(style.marginLeft) || 0; - var borderTopBottom = parseInt(style.borderTop) + parseInt(style.borderBottom) || 0; - var borderLeftRight = parseInt(style.borderLeft) + parseInt(style.borderRight) || 0; +EPUBJS.View.prototype.onShown = function(view) { + // Stub, override with a custom functions +}; +EPUBJS.View.prototype.bounds = function() { + // var bounds = this.element.getBoundingClientRect(); + // var bounds = { + // width: this.element.offsetWidth, + // height: this.element.offsetHeight + // }; return { - height: bounds.height + marginTopBottom + borderTopBottom, - width: bounds.width + marginLeftRight + borderLeftRight + height: this.height + this.paddingTopBottom + this.marginTopBottom + this.borderTopBottom, + width: this.width + this.paddingLeftRight + this.marginLeftRight + this.borderLeftRight } }; diff --git a/package.json b/package.json index 13b9c3d..c1c132c 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "gulp-rename": "^1.2.0", "gulp-uglify": "^0.3.1", "gulp-util": "^3.0.0", - "gulp-webserver": "^0.9.0", "morgan": "^1.1.1", "optimist": "^0.6.1", "portfinder": "^0.2.1",