diff --git a/dist/epub.js b/dist/epub.js index 0b0fd08..4b23f1a 100644 --- a/dist/epub.js +++ b/dist/epub.js @@ -4401,6 +4401,7 @@ EPUBJS.SpineItem.prototype.load = function(_request){ request(this.url, 'xml').then(function(xml){ var base; var directory = EPUBJS.core.folder(this.url); + this.document = xml; this.contents = xml.documentElement; @@ -4449,17 +4450,12 @@ EPUBJS.View.prototype.load = function(contents) { var loaded = loading.promise; this.document = this.iframe.contentDocument; - - // this.iframe.srcdoc = contents; - this.document.open(); - this.document.write(contents); - this.document.close(); - + this.iframe.onload = function(e) { this.window = this.iframe.contentWindow; this.window.addEventListener("resize", this.resized.bind(this), false); this.document = this.iframe.contentDocument; - + this.iframe.style.display = "block"; // Reset Body Styles @@ -4476,6 +4472,11 @@ EPUBJS.View.prototype.load = function(contents) { loading.resolve(this); this.loading.resolve(this); }.bind(this); + + // this.iframe.srcdoc = contents; + this.document.open(); + this.document.write(contents); + this.document.close(); return loaded; }; diff --git a/dist/epub.min.js b/dist/epub.min.js index c129d72..9b131fb 100644 --- a/dist/epub.min.js +++ b/dist/epub.min.js @@ -1,2 +1,2 @@ "undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(e){"use strict";var t=function(e){return new EPUBJS.Book(e)};t.Render={register:function(e,r){t.Render[e]=r}},"object"==typeof exports?(e.RSVP=require("rsvp"),module.exports=t):"function"==typeof define&&define.amd?define(t):e.ePub=t}(this),function(e){var t,r;!function(){var e={},n={};t=function(t,r,n){e[t]={deps:r,callback:n}},r=function(t){function i(e){if("."!==e.charAt(0))return e;for(var r=e.split("/"),n=t.split("/").slice(0,-1),i=0,o=r.length;o>i;i++){var s=r[i];if(".."===s)n.pop();else{if("."===s)continue;n.push(s)}}return n.join("/")}if(n[t])return n[t];if(n[t]={},!e[t])throw new Error("Could not find module "+t);for(var o,s=e[t],a=s.deps,u=s.callback,c=[],p=0,h=a.length;h>p;p++)c.push("exports"===a[p]?o={}:r(i(a[p])));var l=u.apply(this,c);return n[t]=o||l},r.entries=e}(),t("rsvp/-internal",["./utils","./instrument","./config","exports"],function(e,t,r,n){"use strict";function i(){}function o(e){try{return e.then}catch(t){return J.error=t,J}}function s(e,t,r,n){try{e.call(t,r,n)}catch(i){return i}}function a(e,t,r){w.async(function(e){var n=!1,i=s(r,t,function(r){n||(n=!0,t!==r?p(e,r):l(e,r))},function(t){n||(n=!0,f(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&i&&(n=!0,f(e,i))},e)}function u(e,t){e._onerror=null,t._state===x?l(e,t._result):e._state===U?f(e,t._result):d(t,void 0,function(r){t!==r?p(e,r):l(e,r)},function(t){f(e,t)})}function c(e,t){if(t instanceof e.constructor)u(e,t);else{var r=o(t);r===J?f(e,J.error):void 0===r?l(e,t):P(r)?a(e,t,r):l(e,t)}}function p(e,t){e===t?l(e,t):S(t)?c(e,t):l(e,t)}function h(e){e._onerror&&e._onerror(e._result),v(e)}function l(e,t){e._state===B&&(e._result=t,e._state=x,0===e._subscribers.length?w.instrument&&b("fulfilled",e):w.async(v,e))}function f(e,t){e._state===B&&(e._state=U,e._result=t,w.async(h,e))}function d(e,t,r,n){var i=e._subscribers,o=i.length;e._onerror=null,i[o]=t,i[o+x]=r,i[o+U]=n,0===o&&e._state&&w.async(v,e)}function v(e){var t=e._subscribers,r=e._state;if(w.instrument&&b(r===x?"fulfilled":"rejected",e),0!==t.length){for(var n,i,o=e._result,s=0;se;e+=2){var t=h[e],r=h[e+1];t(r),h[e]=void 0,h[e+1]=void 0}s=0}var s=0;e["default"]=function(e,t){h[s]=e,h[s+1]=t,s+=2,2===s&&a()};var a,u="undefined"!=typeof window?window:{},c=u.MutationObserver||u.WebKitMutationObserver,p="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,h=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?t():c?r():p?n():i()}),t("rsvp/config",["./events","exports"],function(e,t){"use strict";function r(e,t){return"onerror"===e?void i.on("error",t):2!==arguments.length?i[e]:void(i[e]=t)}var n=e["default"],i={instrument:!1};n.mixin(i),t.config=i,t.configure=r}),t("rsvp/defer",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e){var t={};return t.promise=new r(function(e,r){t.resolve=e,t.reject=r},e),t}}),t("rsvp/enumerator",["./utils","./-internal","exports"],function(e,t,r){"use strict";function n(e,t,r){return e===h?{state:"fulfilled",value:r}:{state:"rejected",reason:r}}function i(e,t,r,n){this._instanceConstructor=e,this.promise=new e(a,n),this._abortOnReject=r,this._validateInput(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._init(),0===this.length?c(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&c(this.promise,this._result))):u(this.promise,this._validationError())}var o=e.isArray,s=e.isMaybeThenable,a=t.noop,u=t.reject,c=t.fulfill,p=t.subscribe,h=t.FULFILLED,l=t.REJECTED,f=t.PENDING,d=!0;r.ABORT_ON_REJECTION=d,r.makeSettledResult=n,i.prototype._validateInput=function(e){return o(e)},i.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},i.prototype._init=function(){this._result=new Array(this.length)},r["default"]=i,i.prototype._enumerate=function(){for(var e=this.length,t=this.promise,r=this._input,n=0;t._state===f&&e>n;n++)this._eachEntry(r[n],n)},i.prototype._eachEntry=function(e,t){var r=this._instanceConstructor;s(e)?e.constructor===r&&e._state!==f?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(r.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(h,t,e))},i.prototype._settledAt=function(e,t,r){var n=this.promise;n._state===f&&(this._remaining--,this._abortOnReject&&e===l?u(n,r):this._result[t]=this._makeResult(e,t,r)),0===this._remaining&&c(n,this._result)},i.prototype._makeResult=function(e,t,r){return r},i.prototype._willSettleAt=function(e,t){var r=this;p(e,void 0,function(e){r._settledAt(h,t,e)},function(e){r._settledAt(l,t,e)})}}),t("rsvp/events",["exports"],function(e){"use strict";function t(e,t){for(var r=0,n=e.length;n>r;r++)if(e[r]===t)return r;return-1}function r(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}e["default"]={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,n){var i,o=r(this);i=o[e],i||(i=o[e]=[]),-1===t(i,n)&&i.push(n)},off:function(e,n){var i,o,s=r(this);return n?(i=s[e],o=t(i,n),void(-1!==o&&i.splice(o,1))):void(s[e]=[])},trigger:function(e,t){var n,i,o=r(this);if(n=o[e])for(var s=0;sa;a++)s[a]=t(e[a]);return n.all(s,r).then(function(t){for(var r=new Array(o),n=0,i=0;o>i;i++)t[i]&&(r[n]=e[i],n++);return r.length=n,r})})}}),t("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(e,t,r,n,i){"use strict";function o(e,t,r){this._superConstructor(e,t,!1,r)}var s=e["default"],a=t.makeSettledResult,u=r["default"],c=t["default"],p=n.o_create;o.prototype=p(u.prototype),o.prototype._superConstructor=c,o.prototype._makeResult=a,o.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},i["default"]=function(e,t){return new o(s,e,t).promise}}),t("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(e,t,r,n){"use strict";{var i=e["default"],o=t["default"];r.ABORT_ON_REJECTION}n["default"]=function(e,t){return new o(i,e,t).promise}}),t("rsvp/instrument",["./config","./utils","exports"],function(e,t,r){"use strict";var n=e.config,i=t.now,o=[];r["default"]=function(e,t,r){1===o.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:r&&t._guidKey+r._id,label:t._label,timeStamp:i(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;ta;a++)s[a]=t(e[a]);return n.all(s,r)})}}),t("rsvp/node",["./promise","./utils","exports"],function(e,t,r){"use strict";var n=e["default"],i=t.isArray;r["default"]=function(e,t){function r(){for(var r=arguments.length,i=new Array(r),a=0;r>a;a++)i[a]=arguments[a];var u;return o||s||!t?u=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),u=t),n.all(i).then(function(r){function i(n,i){function a(){for(var e=arguments.length,r=new Array(e),a=0;e>a;a++)r[a]=arguments[a];var u=r[0],c=r[1];if(u)i(u);else if(o)n(r.slice(1));else if(s){var p,h,l={},f=r.slice(1);for(h=0;ha;a++)o=r[a],this._eachEntry(o.entry,o.position)}}),t("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(e,t,r,n,i,o,s,a,u,c,p){"use strict";function h(){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 f(e,t){this._id=C++,this._label=t,this._subscribers=[],d.instrument&&v("created",this),y!==e&&(m(e)||h(),this instanceof f||l(),S(this,e))}var d=e.config,v=(t["default"],r["default"]),m=(n.objectOrFunction,n.isFunction),g=n.now,y=i.noop,E=(i.resolve,i.reject,i.fulfill,i.subscribe),S=i.initializePromise,P=i.invokeCallback,b=i.FULFILLED,w=o["default"],B=s["default"],x=a["default"],U=u["default"],J=c["default"],_="rsvp_"+g()+"-",C=0;p["default"]=f,f.cast=w,f.all=B,f.race=x,f.resolve=U,f.reject=J,f.prototype={constructor:f,_id:void 0,_guidKey:_,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(e){d.trigger("error",e)},then:function(e,t,r){var n=this;n._onerror=null;var i=new this.constructor(y,r),o=n._state,s=n._result;return d.instrument&&v("chained",n,i),o===b&&e?d.async(function(){P(o,i,e,s)}):E(n,i,e,t),i},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var r=this.constructor;return this.then(function(t){return r.resolve(e()).then(function(){return t})},function(t){return r.resolve(e()).then(function(){throw t})},t)}}}),t("rsvp/promise/all",["../enumerator","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return new r(this,e,!0,t).promise}}),t("rsvp/promise/cast",["./resolve","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=r}),t("rsvp/promise/race",["../utils","../-internal","exports"],function(e,t,r){"use strict";var n=e.isArray,i=(e.isFunction,e.isMaybeThenable,t.noop),o=t.resolve,s=t.reject,a=t.subscribe,u=t.PENDING;r["default"]=function(e,t){function r(e){o(h,e)}function c(e){s(h,e)}var p=this,h=new p(i,t);if(!n(e))return s(h,new TypeError("You must pass an array to race.")),h;for(var l=e.length,f=0;h._state===u&&l>f;f++)a(p.resolve(e[f]),void 0,r,c);return h}}),t("rsvp/promise/reject",["../-internal","exports"],function(e,t){"use strict";var r=e.noop,n=e.reject;t["default"]=function(e,t){var i=this,o=new i(r,t);return n(o,e),o}}),t("rsvp/promise/resolve",["../-internal","exports"],function(e,t){"use strict";var r=e.noop,n=e.resolve;t["default"]=function(e,t){var i=this;if(e&&"object"==typeof e&&e.constructor===i)return e;var o=new i(r,t);return n(o,e),o}}),t("rsvp/race",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.race(e,t)}}),t("rsvp/reject",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.reject(e,t)}}),t("rsvp/resolve",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.resolve(e,t)}}),t("rsvp/rethrow",["exports"],function(e){"use strict";e["default"]=function(e){throw setTimeout(function(){throw e}),e}}),t("rsvp/utils",["exports"],function(e){"use strict";function t(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}e.objectOrFunction=t,e.isFunction=r,e.isMaybeThenable=n;var i;i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var o=i;e.isArray=o;var s=Date.now||function(){return(new Date).getTime()};e.now=s;var a=Object.create||function(e){var t=function(){};return t.prototype=e,t};e.o_create=a}),t("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(e,t,r,n,i,o,s,a,u,c,p,h,l,f,d,v,m){"use strict";function g(e,t){k.async(e,t)}function y(){k.on.apply(k,arguments)}function E(){k.off.apply(k,arguments)}var S=e["default"],P=t["default"],b=r["default"],w=n["default"],B=i["default"],x=o["default"],U=s["default"],J=a["default"],_=u["default"],C=c["default"],k=p.config,R=p.configure,T=h["default"],N=l["default"],I=f["default"],F=d["default"],A=v["default"];if(k.async=A,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var O=window.__PROMISE_INSTRUMENTATION__;R("instrument",!0);for(var j in O)O.hasOwnProperty(j)&&y(j,O[j])}m.Promise=S,m.EventTarget=P,m.all=w,m.allSettled=B,m.race=x,m.hash=U,m.hashSettled=J,m.rethrow=_,m.defer=C,m.denodeify=b,m.configure=R,m.on=y,m.off=E,m.resolve=N,m.reject=I,m.async=g,m.map=T,m.filter=F}),e.RSVP=r("rsvp")}(self),EPUBJS.Book=function(e){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=void 0,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),e&&this.open(e)},EPUBJS.Book.prototype.open=function(e){var t,r,n,i=new EPUBJS.Parser,o=this,s="META-INF/container.xml";return t="object"==typeof e?e:EPUBJS.core.uri(e),"opf"===t.extension?(this.packageUrl=t.href,this.containerUrl="",t.origin?this.url=t.origin+"/"+t.directory:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,t.directory)):this.url=t.directory,r=this.request(this.packageUrl)):"epub"===t.extension||"zip"===t.extension?(this.archived=!0,this.url=""):t.extension||(this.containerUrl=e+s,r=this.request(this.containerUrl).then(function(e){return i.container(e)}).then(function(t){var r=EPUBJS.core.uri(t.packagePath);return o.packageUrl=e+t.packagePath,o.url=e+r.directory,o.encoding=t.encoding,o.request(o.packageUrl)}).catch(function(e){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),o.trigger("book:loadFailed",this.packageUrl||this.containerPath),o.opening.reject(e)})),r.then(function(e){o.unpack(e),o.loading.manifest.resolve(o.package.manifest),o.loading.metadata.resolve(o.package.metadata),o.loading.spine.resolve(o.spine),o.loading.cover.resolve(o.cover),this.isOpen=!0,o.opening.resolve(o)}).catch(function(e){console.error(e.message,e.stack),o.opening.reject(e)}),this.opened},EPUBJS.Book.prototype.unpack=function(e){var t=this,r=new EPUBJS.Parser;t.package=r.packageContents(e),t.package.baseUrl=t.url,t.spine=new EPUBJS.Spine(t.package,this.request),t.navigation=new EPUBJS.Navigation(t.package,this.request),t.navigation.load().then(function(e){t.toc=e,t.loading.navigation.resolve(t.toc)}),t.cover=t.url+t.package.coverPath},EPUBJS.Book.prototype.section=function(e){return this.spine.get(e)},EPUBJS.Book.prototype.renderTo=function(e,t){var r=new EPUBJS.Renderer(this,t);return r.attachTo(e),r},EPUBJS.Book.prototype.request=function(e){return this.archived?void 0:EPUBJS.core.request(e,"xml",this.credentials)},EPUBJS.Book.prototype.setCredentials=function(e){this.credentials=e},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(e){console.error(e.detail.message,e.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(e,t,r){function n(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var e;e="xml"==t?this.responseXML:"json"==t?JSON.parse(this.response):"blob"==t?i?this.response:new Blob([this.response]):this.response,s.resolve(e)}else s.reject({message:this.response,stack:(new Error).stack})}var i=window.URL,o=i?"blob":"arraybuffer",s=new RSVP.defer,a=new XMLHttpRequest,u=XMLHttpRequest.prototype;return"overrideMimeType"in u||Object.defineProperty(u,"overrideMimeType",{value:function(){}}),r&&(a.withCredentials=!0),a.open("GET",e,!0),a.onreadystatechange=n,"blob"==t&&(a.responseType=o),"json"==t&&a.setRequestHeader("Accept","application/json"),"xml"==t&&a.overrideMimeType("text/xml"),a.send(),s.promise},EPUBJS.core.uri=function(e){var t,r,n,i={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:e},o=e.indexOf("://"),s=e.indexOf("?"),a=e.indexOf("#");return-1!=a&&(i.fragment=e.slice(a+1),e=e.slice(0,a)),-1!=s&&(i.search=e.slice(s+1),e=e.slice(0,s),href=e),-1!=o?(i.protocol=e.slice(0,o),t=e.slice(o+3),n=t.indexOf("/"),-1===n?(i.host=i.path,i.path=""):(i.host=t.slice(0,n),i.path=t.slice(n)),i.origin=i.protocol+"://"+i.host,i.directory=EPUBJS.core.folder(i.path),i.base=i.origin+i.directory):(i.path=e,i.directory=EPUBJS.core.folder(e),i.base=i.directory),i.filename=e.replace(i.base,""),r=i.filename.lastIndexOf("."),-1!=r&&(i.extension=i.filename.slice(r+1)),i},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/");if(-1==t)var r="";return r=e.slice(0,t+1)},EPUBJS.core.queue=function(e){var t=[],r=e,n=function(e,r,n){return t.push({funcName:e,args:r,context:n}),t},i=function(){var e;t.length&&(e=t.shift(),r[e.funcName].apply(e.context||r,e.args))},o=function(){for(;t.length;)i()},s=function(){t=[]},a=function(){return t.length};return{enqueue:n,dequeue:i,flush:o,clear:s,length:a}},EPUBJS.core.isElement=function(e){return!(!e||1!=e.nodeType)},EPUBJS.core.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?r:7&r|8).toString(16)});return t},EPUBJS.core.values=function(e){for(var t=-1,r=Object.keys(e),n=r.length,i=Array(n);++t0;){if(r=n.shift(),"text"===r.type?(i=s.childNodes[r.index],s=i.parentNode||s):s=r.id?o.getElementById(r.id):a[r.index],"undefined"==typeof s)return console.error("No Element For",r,e.str),!1;a=Array.prototype.slice.call(s.children)}return s},EPUBJS.EpubCFI.prototype.compare=function(e,t){if("string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),"string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),e.spinePos>t.spinePos)return 1;if(e.spinePost.steps[r].index)return 1;if(e.steps[r].indext.characterOffset?1:e.characterOffset=0?(o=i.length,e.characterOffset=o&&t&&t()}var i,o;return"undefined"==typeof this.hooks[e]?!1:(i=this.hooks[e],o=i.length,0===o&&t&&t(),void i.forEach(function(e){e(n,r)}))},{register:function(e){if(void 0===EPUBJS.hooks[e]&&(EPUBJS.hooks[e]={}),"object"!=typeof EPUBJS.hooks[e])throw"Already registered: "+e;return EPUBJS.hooks[e]},mixin:function(t){for(var r in e.prototype)t[r]=e.prototype[r]}}}(),EPUBJS.Infinite=function(e,t){this.container=e,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=250,this.views=[],this.renderer=t,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){if(this.scrolled&&!this.displaying){var e=this.container.scrollTop,t=this.container.scrollHeight,r=e-this.prevScrollTop,n=this.container.getBoundingClientRect().height,i=n-(t-e)>-this.offset,o=e0?this.forwards():o&&0>r&&this.backwards(),this.prevScrollTop=e,this.scrolled=!1}this.tick.call(window,this.check.bind(this))},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=function(){},EPUBJS.Layout.prototype.reconcileLayoutSettings=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.forEach(function(e){var t,n,i=e.replace("rendition:",""),o=i.indexOf("-");-1!=o&&(t=i.slice(0,o),n=i.slice(o+1),r[t]=n)}),r},EPUBJS.Layout.prototype.determineLayout=function(e){var t=this.determineSpreads(this.minSpreadWidth),r=t?"ReflowableSpreads":"Reflowable",n=!1;return"pre-paginated"===e.layout&&(r="Fixed",n=!0,t=!1),"reflowable"===e.layout&&"none"===e.spread&&(r="Reflowable",n=!1,t=!1),"reflowable"===e.layout&&"both"===e.spread&&(r="ReflowableSpreads",n=!1,t=!0),this.spreads=t,this.render.scroll(n),this.trigger("renderer:spreads",t),r},EPUBJS.Layout.prototype.applyStyles=function(e){for(var t in e)for(var r in this.views)r.setStyle(t,e[t])},EPUBJS.Layout.prototype.setStyle=function(e,t,r){for(var n in this.views)n.setStyle(e,t,r)},EPUBJS.Layout.prototype.removeStyle=function(e){for(var t in this.views)t.removeStyle(e)},EPUBJS.Layout.prototype.applyHeadTags=function(e){for(var t in e)this.render.addHeadTag(t,e[t])},EPUBJS.Navigation=function(e,t){var r=this,n=new EPUBJS.Parser,i=t||EPUBJS.core.request;this.package=e,this.toc=[],this.tocByHref={},this.tocById={},e.navPath&&(this.navUrl=e.baseUrl+e.navPath,this.nav={},this.nav.load=function(){var e=new RSVP.defer,t=e.promise;return i(r.navUrl,"xml").then(function(t){r.toc=n.nav(t),r.loaded(r.toc),e.resolve(r.toc)}),t}),e.ncxPath&&(this.ncxUrl=e.baseUrl+e.ncxPath,this.ncx={},this.ncx.load=function(){var e=new RSVP.defer,t=e.promise;return i(r.ncxUrl,"xml").then(function(t){r.toc=n.ncx(t),r.loaded(r.toc),e.resolve(r.toc)}),t})},EPUBJS.Navigation.prototype.load=function(e){{var t;e||EPUBJS.core.request}return this.nav?t=this.nav.load():this.ncx&&(t=this.ncx.load()),t},EPUBJS.Navigation.prototype.loaded=function(e){for(var t,r=0;r=0;s--){var a=i.snapshotItem(s),u=a.getAttribute("id")||!1,c=a.querySelector("content"),p=c.getAttribute("src"),h=a.querySelector("navLabel"),l=h.textContent?h.textContent:"",f=p.split("#"),d=(f[0],t(a));n.unshift({id:u,href:p,label:l,subitems:d,parent:r?r.getAttribute("id"):null})}return n}var r=e.querySelector("navMap");return r?t(r):[]},EPUBJS.Renderer=function(e,t){var r=t||{};this.settings={hidden:r.hidden||!1,viewLimit:3,width:r.width||!1,height:r.height||!1},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},EPUBJS.Hooks.mixin(this),this.getHooks("beforeChapterDisplay"),this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height,hidden:!0}),this.rendering=!1,this.views=[],this.positions=[]},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},r=t.height?t.height+"px":"100%",n=t.width?t.width+"px":"100%";t.hidden||!1}return this.container=document.createElement("div"),this.infinite=new EPUBJS.Infinite(this.container,this),this.container.style.width=n,this.container.style.height=r,this.container.style.overflow="scroll",t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var r=e,n=t;e||(r=window.innerWidth),t||(n=window.innerHeight),this.container.style.width=r+"px",this.container.style.height=n+"px",this.trigger("resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.infinite.start(),this.infinite.on("forwards",this.forwards.bind(this)),this.infinite.on("backwards",this.backwards.bind(this)),void window.addEventListener("resize",this.onResized.bind(this),!1)):void console.error("Not an Element")},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,r=t.promise;return this.clear(),this.book.opened.then(function(){var r=this.book.spine.get(e),n=this.render(r);n.then(function(){this.fill(),t.resolve(this)}.bind(this))}.bind(this)),r},EPUBJS.Renderer.prototype.render=function(e){var t,r=new EPUBJS.View;return e?(t=e.render(),r.index=e.index,this.insert(r,e.index),t.then(function(e){return r.load(e)})):void t.reject()},EPUBJS.Renderer.prototype.forwards=function(){var e,t,r;return this.rendering||(console.log("going forwards"),e=this.last().index+1,e===this.book.spine.length)?void 0:(r=this.book.spine.get(e),t=this.render(r),this.rendering=!0,t.then(function(){console.log("last:",this.last().height),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,r;return this.rendering||(console.log("going backwards"),e=this.first().index-1,0>e)?void 0:(r=this.book.spine.get(e),t=this.render(r),this.rendering=!0,t.then(function(){this.rendering=!1,this.container.scrollTop+=this.first().height}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.backwards(),t=this.container.getBoundingClientRect().height;e&&e.then(function(){for(var e=this.last().bounds().bottom;t&&e&&t>e;)this.forwards()}.bind(this))},EPUBJS.Renderer.prototype.jump=function(e){this.views.push(e)},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().index>=0?this.append(e):t-this.last().index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.destroy=function(){},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Spine=function(e,t){this.items=e.spine,this.manifest=e.manifest,this.spineNodeIndex=e.spineNodeIndex,this.baseUrl=e.baseUrl||"",this.request=t,this.length=this.items.length,this.epubcfi=new EPUBJS.EpubCFI,this.spineItems=[],this.spineByHref={},this.spineById={},this.items.forEach(function(e,t){var r,n,i,o=this.epubcfi.generateChapterComponent(this.spineNodeIndex,e.index,e.idref),s=this.manifest[e.idref];s&&(r=s.href,n=this.baseUrl+r),i=new EPUBJS.SpineItem(e,r,n,o),this.spineItems.push(i),this.spineByHref[i.href]=t,this.spineById[i.idref]=t}.bind(this))},EPUBJS.Spine.prototype.get=function(e){var t=0;return!e||"number"!=typeof e&&isNaN(e)!==!1?e&&0===e.indexOf("#")?t=this.spineById[e.substring(1)]:e&&(t=this.spineByHref[e]):t=e,this.spineItems[t]},EPUBJS.SpineItem=function(e,t,r,n){this.idref=e.idref,this.linear=e.linear,this.properties=e.properties,this.index=e.index,this.href=t,this.url=r,this.cfiBase=n},EPUBJS.SpineItem.prototype.load=function(e){var t=e||this.request||EPUBJS.core.request,r=new RSVP.defer,n=r.promise;return this.contents?r.resolve(this.contents):t(this.url,"xml").then(function(e){EPUBJS.core.folder(this.url);this.document=e,this.contents=e.documentElement,this.replacements(this.document),r.resolve(this.contents)}.bind(this)),n},EPUBJS.SpineItem.prototype.replacements=function(e){var t=e.createElement("base");t.setAttribute("href",this.url),e.head.insertBefore(t,e.head.firstChild)},EPUBJS.SpineItem.prototype.render=function(){var e=new RSVP.defer,t=e.promise;return this.load().then(function(t){var r=new XMLSerializer,n=r.serializeToString(t);e.resolve(n)}),t},EPUBJS.SpineItem.prototype.find=function(){},EPUBJS.View=function(){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.loading=new RSVP.defer,this.loaded=this.loading.promise,this.iframe=this.create(),this.height,this.width},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,r=t.promise;return this.document=this.iframe.contentDocument,this.document.open(),this.document.write(e),this.document.close(),this.iframe.onload=function(){this.window=this.iframe.contentWindow,this.window.addEventListener("resize",this.resized.bind(this),!1),this.document=this.iframe.contentDocument,this.iframe.style.display="block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.layout(),this.layout(),this.iframe.style.visibility="visible",t.resolve(this),this.loading.resolve(this)}.bind(this),r},EPUBJS.View.prototype.unload=function(){},EPUBJS.View.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.width="100%",this.iframe.style.height="0",this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.layout()},EPUBJS.View.prototype.layout=function(){var e,t={},r=0,n=0;this.resizing=!0,t=this.document.body.getBoundingClientRect(),this.iframe.style.height=t.height+"px",this.iframe.style.width=t.width+"px",e=this.document.body.getBoundingClientRect(),n=e.height,r=e.width,this.width=r,this.height=n},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)}; \ No newline at end of file +},EPUBJS.Parser.prototype.packageContents=function(e){var t,r,n,i,o,s,a,u,c,p=this;return e?(t=e.querySelector("metadata"))?(r=e.querySelector("manifest"))?(n=e.querySelector("spine"))?(i=p.manifest(r),o=p.findNavPath(r),s=p.findNcxPath(r),a=p.findCoverPath(r),u=Array.prototype.indexOf.call(n.parentNode.childNodes,n),c=p.spine(n,i),{metadata:p.metadata(t),spine:c,manifest:i,navPath:o,ncxPath:s,coverPath:a,spineNodeIndex:u}):void console.error("No Spine Found"):void console.error("No Manifest Found"):void console.error("No Metadata Found"):void console.error("Package File Not Found")},EPUBJS.Parser.prototype.findNavPath=function(e){var t=e.querySelector("item[properties^='nav']");return t?t.getAttribute("href"):!1},EPUBJS.Parser.prototype.findNcxPath=function(e){var t=e.querySelector("item[media-type='application/x-dtbncx+xml']");return t?t.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(e){var t=e.querySelector("item[properties='cover-image']");return t?t.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(e){var t={},r=this;return t.title=r.getElementText(e,"title"),t.creator=r.getElementText(e,"creator"),t.description=r.getElementText(e,"description"),t.pubdate=r.getElementText(e,"date"),t.publisher=r.getElementText(e,"publisher"),t.identifier=r.getElementText(e,"identifier"),t.language=r.getElementText(e,"language"),t.rights=r.getElementText(e,"rights"),t.modified_date=r.querySelectorText(e,"meta[property='dcterms:modified']"),t.layout=r.querySelectorText(e,"meta[property='rendition:layout']"),t.orientation=r.querySelectorText(e,"meta[property='rendition:orientation']"),t.spread=r.querySelectorText(e,"meta[property='rendition:spread']"),t},EPUBJS.Parser.prototype.getElementText=function(e,t){var r,n=e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",t);return n&&0!==n.length?(r=n[0],r.childNodes.length?r.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(e,t){var r=e.querySelector(t);return r&&r.childNodes.length?r.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(e){var t={},r=e.querySelectorAll("item"),n=Array.prototype.slice.call(r);return n.forEach(function(e){var r=e.getAttribute("id"),n=e.getAttribute("href")||"",i=e.getAttribute("media-type")||"",o=e.getAttribute("properties")||"";t[r]={href:n,type:i,properties:o}}),t},EPUBJS.Parser.prototype.spine=function(e){var t=[],r=e.getElementsByTagName("itemref"),n=Array.prototype.slice.call(r);return n.forEach(function(e,r){var n=e.getAttribute("idref"),i=e.getAttribute("properties")||"",o=i.length?i.split(" "):[],s={idref:n,linear:e.getAttribute("linear")||"",properties:o,index:r};t.push(s)}),t},EPUBJS.Parser.prototype.nav=function(e){function t(e){var t=[];return Array.prototype.slice.call(e.childNodes).forEach(function(e){"ol"==e.tagName&&Array.prototype.slice.call(e.childNodes).forEach(function(e){"li"==e.tagName&&t.push(e)})}),t}function r(e){var t=null;return Array.prototype.slice.call(e.childNodes).forEach(function(e){("a"==e.tagName||"span"==e.tagName)&&(t=e)}),t}function n(e){var i=[],o=t(e),s=Array.prototype.slice.call(o),a=s.length;return 0===a?!1:(s.forEach(function(t){var o=t.getAttribute("id")||!1,s=r(t),a=s.getAttribute("href")||"",u=s.textContent||"",c=a.split("#"),p=(c[0],n(t));i.push({id:o,href:a,label:u,subitems:p,parent:e?e.getAttribute("id"):null})}),i)}var i=e.querySelector('nav[*|type="toc"]');return i?n(i):[]},EPUBJS.Parser.prototype.ncx=function(e){function t(r){var n=[],i=e.evaluate("*[local-name()='navPoint']",r,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),o=i.snapshotLength;if(0===o)return[];for(var s=o-1;s>=0;s--){var a=i.snapshotItem(s),u=a.getAttribute("id")||!1,c=a.querySelector("content"),p=c.getAttribute("src"),h=a.querySelector("navLabel"),l=h.textContent?h.textContent:"",f=p.split("#"),d=(f[0],t(a));n.unshift({id:u,href:p,label:l,subitems:d,parent:r?r.getAttribute("id"):null})}return n}var r=e.querySelector("navMap");return r?t(r):[]},EPUBJS.Renderer=function(e,t){var r=t||{};this.settings={hidden:r.hidden||!1,viewLimit:3,width:r.width||!1,height:r.height||!1},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},EPUBJS.Hooks.mixin(this),this.getHooks("beforeChapterDisplay"),this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height,hidden:!0}),this.rendering=!1,this.views=[],this.positions=[]},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},r=t.height?t.height+"px":"100%",n=t.width?t.width+"px":"100%";t.hidden||!1}return this.container=document.createElement("div"),this.infinite=new EPUBJS.Infinite(this.container,this),this.container.style.width=n,this.container.style.height=r,this.container.style.overflow="scroll",t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var r=e,n=t;e||(r=window.innerWidth),t||(n=window.innerHeight),this.container.style.width=r+"px",this.container.style.height=n+"px",this.trigger("resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.infinite.start(),this.infinite.on("forwards",this.forwards.bind(this)),this.infinite.on("backwards",this.backwards.bind(this)),void window.addEventListener("resize",this.onResized.bind(this),!1)):void console.error("Not an Element")},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,r=t.promise;return this.clear(),this.book.opened.then(function(){var r=this.book.spine.get(e),n=this.render(r);n.then(function(){this.fill(),t.resolve(this)}.bind(this))}.bind(this)),r},EPUBJS.Renderer.prototype.render=function(e){var t,r=new EPUBJS.View;return e?(t=e.render(),r.index=e.index,this.insert(r,e.index),t.then(function(e){return r.load(e)})):void t.reject()},EPUBJS.Renderer.prototype.forwards=function(){var e,t,r;return this.rendering||(console.log("going forwards"),e=this.last().index+1,e===this.book.spine.length)?void 0:(r=this.book.spine.get(e),t=this.render(r),this.rendering=!0,t.then(function(){console.log("last:",this.last().height),this.rendering=!1}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,r;return this.rendering||(console.log("going backwards"),e=this.first().index-1,0>e)?void 0:(r=this.book.spine.get(e),t=this.render(r),this.rendering=!0,t.then(function(){this.rendering=!1,this.container.scrollTop+=this.first().height}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.backwards(),t=this.container.getBoundingClientRect().height;e&&e.then(function(){for(var e=this.last().bounds().bottom;t&&e&&t>e;)this.forwards()}.bind(this))},EPUBJS.Renderer.prototype.jump=function(e){this.views.push(e)},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().index>=0?this.append(e):t-this.last().index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.destroy=function(){},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype),EPUBJS.Spine=function(e,t){this.items=e.spine,this.manifest=e.manifest,this.spineNodeIndex=e.spineNodeIndex,this.baseUrl=e.baseUrl||"",this.request=t,this.length=this.items.length,this.epubcfi=new EPUBJS.EpubCFI,this.spineItems=[],this.spineByHref={},this.spineById={},this.items.forEach(function(e,t){var r,n,i,o=this.epubcfi.generateChapterComponent(this.spineNodeIndex,e.index,e.idref),s=this.manifest[e.idref];s&&(r=s.href,n=this.baseUrl+r),i=new EPUBJS.SpineItem(e,r,n,o),this.spineItems.push(i),this.spineByHref[i.href]=t,this.spineById[i.idref]=t}.bind(this))},EPUBJS.Spine.prototype.get=function(e){var t=0;return!e||"number"!=typeof e&&isNaN(e)!==!1?e&&0===e.indexOf("#")?t=this.spineById[e.substring(1)]:e&&(t=this.spineByHref[e]):t=e,this.spineItems[t]},EPUBJS.SpineItem=function(e,t,r,n){this.idref=e.idref,this.linear=e.linear,this.properties=e.properties,this.index=e.index,this.href=t,this.url=r,this.cfiBase=n},EPUBJS.SpineItem.prototype.load=function(e){var t=e||this.request||EPUBJS.core.request,r=new RSVP.defer,n=r.promise;return this.contents?r.resolve(this.contents):t(this.url,"xml").then(function(e){EPUBJS.core.folder(this.url);this.document=e,this.contents=e.documentElement,this.replacements(this.document),r.resolve(this.contents)}.bind(this)),n},EPUBJS.SpineItem.prototype.replacements=function(e){var t=e.createElement("base");t.setAttribute("href",this.url),e.head.insertBefore(t,e.head.firstChild)},EPUBJS.SpineItem.prototype.render=function(){var e=new RSVP.defer,t=e.promise;return this.load().then(function(t){var r=new XMLSerializer,n=r.serializeToString(t);e.resolve(n)}),t},EPUBJS.SpineItem.prototype.find=function(){},EPUBJS.View=function(){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.loading=new RSVP.defer,this.loaded=this.loading.promise,this.iframe=this.create(),this.height,this.width},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,r=t.promise;return this.document=this.iframe.contentDocument,this.iframe.onload=function(){this.window=this.iframe.contentWindow,this.window.addEventListener("resize",this.resized.bind(this),!1),this.document=this.iframe.contentDocument,this.iframe.style.display="block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.layout(),this.layout(),this.iframe.style.visibility="visible",t.resolve(this),this.loading.resolve(this)}.bind(this),this.document.open(),this.document.write(e),this.document.close(),r},EPUBJS.View.prototype.unload=function(){},EPUBJS.View.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.width="100%",this.iframe.style.height="0",this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.layout()},EPUBJS.View.prototype.layout=function(){var e,t={},r=0,n=0;this.resizing=!0,t=this.document.body.getBoundingClientRect(),this.iframe.style.height=t.height+"px",this.iframe.style.width=t.width+"px",e=this.document.body.getBoundingClientRect(),n=e.height,r=e.width,this.width=r,this.height=n},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)}; \ No newline at end of file diff --git a/examples/toc.html b/examples/toc.html index c003ddd..253ffa7 100644 --- a/examples/toc.html +++ b/examples/toc.html @@ -66,7 +66,7 @@ var $prev = document.getElementById("prev"); var currentSectionIndex = 10; // Load the opf - var book = ePub("../books/moby-dick/OPS/package.opf"); + var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf"); var rendition = book.renderTo("viewer", {width: 600, height: 400}); var displayed = rendition.display(currentSectionIndex); diff --git a/lib/epubjs/spine.js b/lib/epubjs/spine.js index 5589b4b..96b1f32 100644 --- a/lib/epubjs/spine.js +++ b/lib/epubjs/spine.js @@ -73,6 +73,7 @@ EPUBJS.SpineItem.prototype.load = function(_request){ request(this.url, 'xml').then(function(xml){ var base; var directory = EPUBJS.core.folder(this.url); + this.document = xml; this.contents = xml.documentElement; diff --git a/lib/epubjs/view.js b/lib/epubjs/view.js index eaa94e4..749fd10 100644 --- a/lib/epubjs/view.js +++ b/lib/epubjs/view.js @@ -12,17 +12,12 @@ EPUBJS.View.prototype.load = function(contents) { var loaded = loading.promise; this.document = this.iframe.contentDocument; - - // this.iframe.srcdoc = contents; - this.document.open(); - this.document.write(contents); - this.document.close(); - + this.iframe.onload = function(e) { this.window = this.iframe.contentWindow; this.window.addEventListener("resize", this.resized.bind(this), false); this.document = this.iframe.contentDocument; - + this.iframe.style.display = "block"; // Reset Body Styles @@ -39,6 +34,11 @@ EPUBJS.View.prototype.load = function(contents) { loading.resolve(this); this.loading.resolve(this); }.bind(this); + + // this.iframe.srcdoc = contents; + this.document.open(); + this.document.write(contents); + this.document.close(); return loaded; };