From f525d86fb1244d6ae49f33d1c1b3e65b1597c9b1 Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Sun, 29 Sep 2013 23:29:53 -0700 Subject: [PATCH] upgraded rsvp.js, small bug fixes --- Gruntfile.js | 34 +- build/epub.js | 1795 ++++++++++++++++++++++++++----------- build/epub.min.js | 4 +- build/hooks.js | 3 +- build/hooks.min.js | 2 +- demo/js/epub.min.js | 4 +- demo/js/hooks.min.js | 2 +- examples/basic-dev.html | 7 +- examples/contained.html | 2 +- hooks/default/endnotes.js | 3 +- libs/rsvp/rsvp.js | 871 +++++++++++++----- libs/rsvp/rsvp.min.js | 1 - src/book.js | 98 +- src/chapter.js | 6 +- src/core.js | 10 +- src/epubcfi.js | 4 +- src/renderer.js | 967 ++++++++++---------- src/replace.js | 16 +- src/unarchiver.js | 22 +- tests/core.js | 7 +- 20 files changed, 2488 insertions(+), 1370 deletions(-) delete mode 100644 libs/rsvp/rsvp.min.js diff --git a/Gruntfile.js b/Gruntfile.js index 722a7f2..d499ede 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,7 +8,7 @@ module.exports = function(grunt) { '<%= grunt.template.today("yyyy-mm-dd") %> */' }, concat : { - 'build/epub.js': ['', 'libs/rsvp/rsvp.min.js', 'src/*.js'], + 'build/epub.js': ['', 'libs/rsvp/rsvp.js', 'src/*.js'], 'build/reader.js': ['', 'reader/*.js'], 'build/hooks.js': ['', 'hooks/default/*.js'], 'demo/js/libs/fileStorage.min.js': 'libs/fileStorage/fileStorage.min.js', @@ -17,22 +17,22 @@ module.exports = function(grunt) { 'demo/js/libs/inflate.js': 'libs/zip/inflate.js' }, uglify: { - options: { - preserveComments: 'some' - }, - my_target: { - files: { - 'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'], - 'build/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'], - 'demo/js/reader.min.js': 'build/reader.js', - 'demo/js/hooks.min.js': 'build/hooks.js', - 'build/hooks.min.js': 'build/hooks.js', - 'demo/js/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'], - 'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js'], - 'build/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'], - 'build/libs/inflate.js': ['libs/zip/inflate.js'] - } - } + options: { + preserveComments: 'some' + }, + my_target: { + files: { + 'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'], + 'build/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'], + 'demo/js/reader.min.js': ['build/reader.js'], + 'demo/js/hooks.min.js': ['build/hooks.js'], + 'build/hooks.min.js': ['build/hooks.js'], + 'demo/js/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'], + 'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js'], + 'build/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'], + 'build/libs/inflate.js': ['libs/zip/inflate.js'] + } + } } }); diff --git a/build/epub.js b/build/epub.js index 3e452ff..ac0b831 100644 --- a/build/epub.js +++ b/build/epub.js @@ -1,5 +1,675 @@ -(function(e){"use strict";function v(e,n){t.async(function(){e.trigger("promise:resolved",{detail:n}),e.isResolved=!0,e.resolvedValue=n})}function m(e,n){t.async(function(){e.trigger("promise:failed",{detail:n}),e.isRejected=!0,e.rejectedValue=n})}function g(e){var t,n=[],r=new h,i=e.length;i===0&&r.resolve([]);var s=function(e){return function(t){o(e,t)}},o=function(e,t){n[e]=t,--i===0&&r.resolve(n)},u=function(e){r.reject(e)};for(t=0;t 2) { + resolve(Array.prototype.slice.call(arguments, 1)); + } else { + resolve(value); + } + }; + } + + function denodeify(nodeFunc) { + return function() { + var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject; + var thisArg = this; + + var promise = new Promise(function(nodeResolve, nodeReject) { + resolve = nodeResolve; + reject = nodeReject; + }); + + all(nodeArgs).then(function(nodeArgs) { + nodeArgs.push(makeNodeCallbackFor(resolve, reject)); + + try { + nodeFunc.apply(thisArg, nodeArgs); + } catch(e) { + reject(e); + } + }); + + return promise; + }; + } + + + __exports__.denodeify = denodeify; + }); +define("rsvp/promise", + ["rsvp/config","rsvp/events","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var config = __dependency1__.config; + var EventTarget = __dependency2__.EventTarget; + + function objectOrFunction(x) { + return isFunction(x) || (typeof x === "object" && x !== null); + } + + function isFunction(x){ + return typeof x === "function"; + } + + var Promise = function(resolver) { + var promise = this, + resolved = false; + + if (typeof resolver !== 'function') { + throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor'); + } + + if (!(promise instanceof Promise)) { + return new Promise(resolver); + } + + var resolvePromise = function(value) { + if (resolved) { return; } + resolved = true; + resolve(promise, value); + }; + + var rejectPromise = function(value) { + if (resolved) { return; } + resolved = true; + reject(promise, value); + }; + + this.on('promise:failed', function(event) { + this.trigger('error', { detail: event.detail }); + }, this); + + this.on('error', onerror); + + try { + resolver(resolvePromise, rejectPromise); + } catch(e) { + rejectPromise(e); + } + }; + + function onerror(event) { + if (config.onerror) { + config.onerror(event.detail); + } + } + + var invokeCallback = function(type, promise, callback, event) { + var hasCallback = isFunction(callback), + value, error, succeeded, failed; + + if (hasCallback) { + try { + value = callback(event.detail); + succeeded = true; + } catch(e) { + failed = true; + error = e; + } + } else { + value = event.detail; + succeeded = true; + } + + if (handleThenable(promise, value)) { + return; + } else if (hasCallback && succeeded) { + resolve(promise, value); + } else if (failed) { + reject(promise, error); + } else if (type === 'resolve') { + resolve(promise, value); + } else if (type === 'reject') { + reject(promise, value); + } + }; + + Promise.prototype = { + constructor: Promise, + + isRejected: undefined, + isFulfilled: undefined, + rejectedReason: undefined, + fulfillmentValue: undefined, + + then: function(done, fail) { + this.off('error', onerror); + + var thenPromise = new this.constructor(function() {}); + + if (this.isFulfilled) { + config.async(function(promise) { + invokeCallback('resolve', thenPromise, done, { detail: promise.fulfillmentValue }); + }, this); + } + + if (this.isRejected) { + config.async(function(promise) { + invokeCallback('reject', thenPromise, fail, { detail: promise.rejectedReason }); + }, this); + } + + this.on('promise:resolved', function(event) { + invokeCallback('resolve', thenPromise, done, event); + }); + + this.on('promise:failed', function(event) { + invokeCallback('reject', thenPromise, fail, event); + }); + + return thenPromise; + }, + + fail: function(fail) { + return this.then(null, fail); + } + }; + + EventTarget.mixin(Promise.prototype); + + function resolve(promise, value) { + if (promise === value) { + fulfill(promise, value); + } else if (!handleThenable(promise, value)) { + fulfill(promise, value); + } + } + + function handleThenable(promise, value) { + var then = null, + resolved; + + try { + if (promise === value) { + throw new TypeError("A promises callback cannot return that same promise."); + } + + if (objectOrFunction(value)) { + then = value.then; + + if (isFunction(then)) { + then.call(value, function(val) { + if (resolved) { return true; } + resolved = true; + + if (value !== val) { + resolve(promise, val); + } else { + fulfill(promise, val); + } + }, function(val) { + if (resolved) { return true; } + resolved = true; + + reject(promise, val); + }); + + return true; + } + } + } catch (error) { + reject(promise, error); + return true; + } + + return false; + } + + function fulfill(promise, value) { + config.async(function() { + promise.trigger('promise:resolved', { detail: value }); + promise.isFulfilled = true; + promise.fulfillmentValue = value; + }); + } + + function reject(promise, value) { + config.async(function() { + promise.trigger('promise:failed', { detail: value }); + promise.isRejected = true; + promise.rejectedReason = value; + }); + } + + + __exports__.Promise = Promise; + }); +define("rsvp/reject", + ["rsvp/promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__.Promise; + + function reject(reason) { + return new Promise(function (resolve, reject) { + reject(reason); + }); + } + + + __exports__.reject = reject; + }); +define("rsvp/resolve", + ["rsvp/promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__.Promise; + + function resolve(thenable) { + return new Promise(function(resolve, reject) { + resolve(thenable); + }); + } + + + __exports__.resolve = resolve; + }); +define("rsvp/rethrow", + ["exports"], + function(__exports__) { + "use strict"; + var local = (typeof global === "undefined") ? this : global; + + function rethrow(reason) { + local.setTimeout(function() { + throw reason; + }); + throw reason; + } + + + __exports__.rethrow = rethrow; + }); +define("rsvp", + ["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __exports__) { + "use strict"; + var EventTarget = __dependency1__.EventTarget; + var Promise = __dependency2__.Promise; + var denodeify = __dependency3__.denodeify; + var all = __dependency4__.all; + var hash = __dependency5__.hash; + var rethrow = __dependency6__.rethrow; + var defer = __dependency7__.defer; + var config = __dependency8__.config; + var resolve = __dependency9__.resolve; + var reject = __dependency10__.reject; + + function configure(name, value) { + config[name] = value; + } + + + __exports__.Promise = Promise; + __exports__.EventTarget = EventTarget; + __exports__.all = all; + __exports__.hash = hash; + __exports__.rethrow = rethrow; + __exports__.defer = defer; + __exports__.denodeify = denodeify; + __exports__.configure = configure; + __exports__.resolve = resolve; + __exports__.reject = reject; + }); +window.RSVP = requireModule("rsvp"); +})(window); var EPUBJS = EPUBJS || {}; EPUBJS.VERSION = "0.1.5"; @@ -121,14 +791,22 @@ EPUBJS.Book = function(options){ this.ready = { - manifest: new RSVP.Promise(), - spine: new RSVP.Promise(), - metadata: new RSVP.Promise(), - cover: new RSVP.Promise(), - toc: new RSVP.Promise() + manifest: new RSVP.defer(), + spine: new RSVP.defer(), + metadata: new RSVP.defer(), + cover: new RSVP.defer(), + toc: new RSVP.defer() }; - this.ready.all = RSVP.all(_.values(this.ready)); + this.readyPromises = [ + this.ready.manifest.promise, + this.ready.spine.promise, + this.ready.metadata.promise, + this.ready.cover.promise, + this.ready.toc.promise + ]; + + this.ready.all = RSVP.all(this.readyPromises); this.ready.all.then(this._ready); @@ -137,7 +815,8 @@ EPUBJS.Book = function(options){ this._rendering = false; this._displayQ = []; - this.opened = new RSVP.Promise(); + this.defer_opened = new RSVP.defer(); + this.opened = this.defer_opened.promise; // BookUrl is optional, but if present start loading process if(this.settings.bookPath) { this.open(this.settings.bookPath, this.settings.reload); @@ -209,7 +888,7 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){ } opened.then(function(){ - book.opened.resolve(); + book.defer_opened.resolve(); }); return opened; @@ -260,7 +939,7 @@ EPUBJS.Book.prototype.unpack = function(containerPath){ book.loadXml(book.settings.tocUrl). then(function(tocXml){ - return parse.toc(tocXml); // Grab Table of Contents + return parse.toc(tocXml); // Grab Table of Contents }).then(function(toc){ book.toc = book.contents.toc = toc; book.ready.toc.resolve(book.contents.toc); @@ -270,7 +949,7 @@ EPUBJS.Book.prototype.unpack = function(containerPath){ } }). - then(null, function(error) { + fail(function(error) { console.error(error); }); @@ -278,11 +957,11 @@ EPUBJS.Book.prototype.unpack = function(containerPath){ } EPUBJS.Book.prototype.getMetadata = function() { - return this.ready.metadata; + return this.ready.metadata.promise; } EPUBJS.Book.prototype.getToc = function() { - return this.ready.toc; + return this.ready.toc.promise; } /* Private Helpers */ @@ -320,10 +999,18 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){ fromRoot = bookPath[0] == "/", location = window.location, //-- Get URL orgin, try for native or combine - origin = location.origin || location.protocol + "//" + location.host; - + origin = location.origin || location.protocol + "//" + location.host, + baseTag = document.getElementsByTagName('base'), + base; + // if(bookPath[bookPath.length - 1] != "/") bookPath += "/"; + + //-- Check is Base tag is set + if(baseTag.length) { + base = baseTag[0].href; + } + //-- 1. Check if url is absolute if(absolute){ return bookPath; @@ -331,7 +1018,11 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){ //-- 2. Check if url starts with /, add base url if(!absolute && fromRoot){ - return origin + bookPath; + if(base) { + return base + bookPath; + } else { + return origin + bookPath; + } } //-- 3. Or find full path to url and add that @@ -339,10 +1030,15 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){ //-- go back if(bookPath.slice(0, 3) == "../"){ - return EPUBJS.core.resolveUrl(location.href, bookPath); + return EPUBJS.core.resolveUrl(base || location.pathname, bookPath); } - - return origin + EPUBJS.core.folder(location.pathname) + bookPath; + + if(base) { + return base + bookPath; + } else { + return origin + EPUBJS.core.folder(location.pathname) + bookPath; + } + } } @@ -468,11 +1164,13 @@ EPUBJS.Book.prototype.startDisplay = function(){ display = this.goto(this.settings.goto); }else if( this.settings.restore && this.settings.previousLocationCfi) { - + display = this.displayChapter(this.settings.previousLocationCfi); }else{ + display = this.displayChapter(this.spinePos); + } return display; @@ -482,7 +1180,7 @@ EPUBJS.Book.prototype.restore = function(reject){ var book = this, contentsKey = this.settings.bookPath + ":contents:" + this.settings.version, - promise = new RSVP.Promise(), + deferred = new RSVP.defer(), fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'], reject = reject || false, fromStore = localStorage.getItem(contentsKey); @@ -509,8 +1207,8 @@ EPUBJS.Book.prototype.restore = function(reject){ this.ready.metadata.resolve(this.metadata); this.ready.cover.resolve(this.cover); this.ready.toc.resolve(this.toc); - promise.resolve(); - return promise; + deferred.resolve(); + return deferred.promise; } @@ -538,14 +1236,8 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ pos = cfi.spinePos; } - - if(pos >= this.spine.length){ - // console.log("Reached End of Book"); - return false; - } - - if(pos < 0){ - // console.log("Reached Start of Book"); + if(pos < 0 || pos >= this.spine.length){ + console.error("Not A Valid Chapter"); return false; } @@ -620,19 +1312,26 @@ EPUBJS.Book.prototype.prevPage = function() { EPUBJS.Book.prototype.nextChapter = function() { this.spinePos++; - + if(this.spinePos > this.spine.length) return; + return this.displayChapter(this.spinePos); } EPUBJS.Book.prototype.prevChapter = function() { this.spinePos--; - + if(this.spinePos < 0) return; + return this.displayChapter(this.spinePos, true); } +EPUBJS.Book.prototype.gotoCfi = function(cfi){ + if(!this.isRendered) return this._enqueue("gotoCfi", arguments); + return this.displayChapter(cfi) +} + EPUBJS.Book.prototype.goto = function(url){ var split, chapter, section, absoluteURL, spinePos; - + var deferred = new RSVP.defer(); if(!this.isRendered) return this._enqueue("goto", arguments); split = url.split("#"), @@ -657,7 +1356,8 @@ EPUBJS.Book.prototype.goto = function(url){ }else{ //-- Only goto section if(section) this.render.section(section); - return new RSVP.Promise().resolve(this.currentChapter); + deferred.resolve(this.currentChapter); + return deferred.promise; } } @@ -866,7 +1566,7 @@ EPUBJS.Chapter.prototype.contents = function(store){ } EPUBJS.Chapter.prototype.url = function(store){ - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); if(store){ if(!this.tempUrl) { @@ -874,8 +1574,8 @@ EPUBJS.Chapter.prototype.url = function(store){ } return this.tempUrl; }else{ - promise.resolve(this.href); //-- this is less than ideal but keeps it a promise - return promise; + deferred.resolve(this.href); //-- this is less than ideal but keeps it a promise + return deferred.promise; } } @@ -917,7 +1617,7 @@ EPUBJS.core.request = function(url, type) { var supportsURL = window.URL; var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer"; - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); var xhr = new XMLHttpRequest(); @@ -962,14 +1662,14 @@ EPUBJS.core.request = function(url, type) { r = this.response; } - promise.resolve(r); + deferred.resolve(r); } - else { promise.reject(this); } + else { deferred.reject(this); } } }; - return promise; + return deferred.promise; }; // EPUBJS.core.loadXML = function(url, callback){ @@ -1084,7 +1784,7 @@ EPUBJS.core.toArray = function(obj) { EPUBJS.core.folder = function(url){ var slash = url.lastIndexOf('/'), - folder = url.slice(0, slash + 1); + folder = url.slice(0, slash + 1); if(slash == -1) folder = ''; @@ -1319,8 +2019,8 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { cfi.spinePos = (parseInt(cfi.chapter.split("/")[2]) / 2 - 1 ) || 0; chapId = cfi.chapter.match(/\[(.*)\]/); - - cfi.spineId = chapId[1] || false; + + cfi.spineId = chapId ? chapId[1] : false; path = cfi.fragment.split('/'); end = path[path.length-1]; @@ -1695,705 +2395,706 @@ EPUBJS.Parser.prototype.toc = function(tocXml){ EPUBJS.Renderer = function(book) { - this.el = book.element; - this.book = book; - - // this.settings = book.settings; - this.caches = {}; - - this.crossBrowserColumnCss(); - - this.epubcfi = new EPUBJS.EpubCFI(); - - this.initialize(); - this.listeners(); + this.el = book.element; + this.book = book; + + // this.settings = book.settings; + this.caches = {}; + + this.crossBrowserColumnCss(); + + this.epubcfi = new EPUBJS.EpubCFI(); + + this.initialize(); + this.listeners(); - //-- Renderer events for listening - /* - renderer:resized - renderer:chapterDisplayed - renderer:chapterUnloaded - */ + //-- Renderer events for listening + /* + renderer:resized + renderer:chapterDisplayed + renderer:chapterUnloaded + */ } //-- Build up any html needed EPUBJS.Renderer.prototype.initialize = function(){ - this.iframe = document.createElement('iframe'); - //this.iframe.id = "epubjs-iframe"; - this.iframe.scrolling = "no"; - - if(this.book.settings.width || this.book.settings.height){ - this.resizeIframe(false, this.book.settings.width || this.el.clientWidth, this.book.settings.height || this.el.clientHeight); - } else { - this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight); + this.iframe = document.createElement('iframe'); + //this.iframe.id = "epubjs-iframe"; + this.iframe.scrolling = "no"; + + if(this.book.settings.width || this.book.settings.height){ + this.resizeIframe(this.book.settings.width || this.el.clientWidth, this.book.settings.height || this.el.clientHeight); + } else { + // this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight); + this.resizeIframe('100%', '100%'); - this.on("renderer:resized", this.resizeIframe, this); - } - - - this.el.appendChild(this.iframe); + // this.on("renderer:resized", this.resizeIframe, this); + } + + this.el.appendChild(this.iframe); } //-- Listeners for browser events EPUBJS.Renderer.prototype.listeners = function(){ - this.resized = _.debounce(this.onResized.bind(this), 10); + + this.resized = _.throttle(this.onResized.bind(this), 10); - window.addEventListener("resize", this.resized, false); + // window.addEventListener("hashchange", book.route.bind(this), false); - // window.addEventListener("hashchange", book.route.bind(this), false); + this.book.registerHook("beforeChapterDisplay", this.replaceLinks.bind(this), true); - this.book.registerHook("beforeChapterDisplay", this.replaceLinks.bind(this), true); + if(this.determineStore()) { - if(this.determineStore()) { + this.book.registerHook("beforeChapterDisplay", [ + EPUBJS.replace.head, + EPUBJS.replace.resources, + EPUBJS.replace.svg + ], true); - this.book.registerHook("beforeChapterDisplay", [ - EPUBJS.replace.head, - EPUBJS.replace.resources, - EPUBJS.replace.svg - ], true); - - } + } } EPUBJS.Renderer.prototype.chapter = function(chapter){ - var renderer = this, - store = false; - - if(this.book.settings.contained) store = this.book.zip; - // if(this.settings.stored) store = this.storage; - - if(this.currentChapter) { - this.currentChapter.unload(); + var renderer = this, + store = false; + + if(this.book.settings.contained) store = this.book.zip; + // if(this.settings.stored) store = this.storage; + + if(this.currentChapter) { + this.currentChapter.unload(); - this.trigger("renderer:chapterUnloaded"); - this.book.trigger("renderer:chapterUnloaded"); - } - - this.currentChapter = chapter; - this.chapterPos = 1; - this.pageIds = {}; - this.leftPos = 0; - - this.currentChapterCfi = this.epubcfi.generateChapter(this.book.spineNodeIndex, chapter.spinePos, chapter.id); - this.visibileEl = false; + this.trigger("renderer:chapterUnloaded"); + this.book.trigger("renderer:chapterUnloaded"); + } + + this.currentChapter = chapter; + this.chapterPos = 1; + this.pageIds = {}; + this.leftPos = 0; + + this.currentChapterCfi = this.epubcfi.generateChapter(this.book.spineNodeIndex, chapter.spinePos, chapter.id); + this.visibileEl = false; - return chapter.url(store). - then(function(url) { - return renderer.setIframeSrc(url); - }); - + return chapter.url(store). + then(function(url) { + return renderer.setIframeSrc(url); + }); + } - - - - /* EPUBJS.Renderer.prototype.route = function(hash, callback){ - var location = window.location.hash.replace('#/', ''); - if(this.useHash && location.length && location != this.prevLocation){ - this.show(location, callback); - this.prevLocation = location; - return true; - } - return false; + var location = window.location.hash.replace('#/', ''); + if(this.useHash && location.length && location != this.prevLocation){ + this.show(location, callback); + this.prevLocation = location; + return true; + } + return false; } EPUBJS.Renderer.prototype.hideHashChanges = function(){ - this.useHash = false; + this.useHash = false; } */ -EPUBJS.Renderer.prototype.onResized = function(){ +EPUBJS.Renderer.prototype.onResized = function(e){ - var msg = { - width: this.el.clientWidth, - height: this.el.clientHeight - }; + var msg = { + width: this.iframe.clientWidth, + height: this.iframe.clientHeight + }; + + if(this.doc){ + this.reformat(); + } - this.trigger("renderer:resized", msg); - this.book.trigger("book:resized", msg); + this.trigger("renderer:resized", msg); + this.book.trigger("book:resized", msg); - this.reformat(); + + } EPUBJS.Renderer.prototype.reformat = function(){ - var renderer = this; - - //-- reformat - if(renderer.book.settings.fixedLayout) { - renderer.fixedLayout(); - } else { - renderer.formatSpread(); - } - - setTimeout(function(){ - - //-- re-calc number of pages - renderer.calcPages(); - - - //-- Go to current page after resize - if(renderer.currentLocationCfi){ - renderer.gotoCfiFragment(renderer.currentLocationCfi); - } - - }, 10); - - + var renderer = this; + + //-- reformat + if(renderer.book.settings.fixedLayout) { + renderer.fixedLayout(); + } else { + renderer.formatSpread(); + } + + setTimeout(function(){ + + //-- re-calc number of pages + renderer.calcPages(); + + + //-- Go to current page after resize + if(renderer.currentLocationCfi){ + renderer.gotoCfiFragment(renderer.currentLocationCfi); + } + + }, 10); + + } -EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){ - var width, height; +EPUBJS.Renderer.prototype.resizeIframe = function(width, height){ - //-- Can be resized by the window resize event, or by passed height - if(!e){ - width = cWidth; - height = cHeight; - }else{ - width = e.width; - height = e.height; - } + this.iframe.height = height; - this.iframe.height = height; + if(!isNaN(width) && width % 2 != 0){ + width += 1; //-- Prevent cutting off edges of text in columns + } - if(width % 2 != 0){ - width += 1; //-- Prevent cutting off edges of text in columns - } - - this.iframe.width = width; + this.iframe.width = width; + + this.onResized(); - } EPUBJS.Renderer.prototype.crossBrowserColumnCss = function(){ - - - EPUBJS.Renderer.columnAxis = EPUBJS.core.prefixed('columnAxis'); - EPUBJS.Renderer.columnGap = EPUBJS.core.prefixed('columnGap'); - EPUBJS.Renderer.columnWidth = EPUBJS.core.prefixed('columnWidth'); - EPUBJS.Renderer.transform = EPUBJS.core.prefixed('transform'); + + + EPUBJS.Renderer.columnAxis = EPUBJS.core.prefixed('columnAxis'); + EPUBJS.Renderer.columnGap = EPUBJS.core.prefixed('columnGap'); + EPUBJS.Renderer.columnWidth = EPUBJS.core.prefixed('columnWidth'); + EPUBJS.Renderer.transform = EPUBJS.core.prefixed('transform'); } EPUBJS.Renderer.prototype.setIframeSrc = function(url){ - var renderer = this, - promise = new RSVP.Promise(); + var renderer = this, + deferred = new RSVP.defer(); - this.visible(false); + this.visible(false); - this.iframe.src = url; + this.iframe.src = url; - this.iframe.onload = function() { - renderer.doc = renderer.iframe.contentDocument; - renderer.docEl = renderer.doc.documentElement; - renderer.bodyEl = renderer.doc.body; + this.iframe.onload = function() { + renderer.doc = renderer.iframe.contentDocument; + renderer.docEl = renderer.doc.documentElement; + renderer.bodyEl = renderer.doc.body; - renderer.applyStyles(); - - if(renderer.book.settings.fixedLayout) { - renderer.fixedLayout(); - } else { - renderer.formatSpread(); - } - + renderer.applyStyles(); + + if(renderer.book.settings.fixedLayout) { + renderer.fixedLayout(); + } else { + renderer.formatSpread(); + } + - //-- Trigger registered hooks before displaying - renderer.beforeDisplay(function(){ + //-- Trigger registered hooks before displaying + renderer.beforeDisplay(function(){ + var msg = renderer.currentChapter; + + renderer.calcPages(); + + deferred.resolve(renderer); - renderer.calcPages(); - - promise.resolve(renderer); + msg.cfi = renderer.currentLocationCfi = renderer.getPageCfi(); + + renderer.trigger("renderer:chapterDisplayed", msg); + renderer.book.trigger("renderer:chapterDisplayed", msg); - renderer.currentLocationCfi = renderer.getPageCfi(); + renderer.visible(true); - renderer.trigger("renderer:chapterDisplayed", renderer.currentChapter); - renderer.book.trigger("renderer:chapterDisplayed", renderer.currentChapter); + }); + + renderer.iframe.contentWindow.addEventListener("resize", renderer.resized, false); + + // that.afterLoaded(that); - renderer.visible(true); + + + } + - }); - - - // that.afterLoaded(that); - - - - } - - - - return promise; + + return deferred.promise; } EPUBJS.Renderer.prototype.formatSpread = function(){ - var divisor = 2, - cutoff = 800; + var divisor = 2, + cutoff = 800; - if(this.colWidth){ - this.OldcolWidth = this.colWidth; - this.OldspreadWidth = this.spreadWidth; + // if(this.colWidth){ + // this.OldcolWidth = this.colWidth; + // this.OldspreadWidth = this.spreadWidth; + // } + + //-- Check the width and decied on columns + //-- Todo: a better place for this? + this.elWidth = this.iframe.clientWidth; + if(this.elWidth % 2 != 0){ + this.elWidth -= 1; } - - //-- Check the width and decied on columns - //-- Todo: a better place for this? - this.elWidth = this.iframe.width; - - this.gap = this.gap || Math.ceil(this.elWidth / 8); - - if(this.elWidth < cutoff || !this.book.settings.spreads) { - this.spread = false; //-- Single Page - - divisor = 1; - this.colWidth = Math.floor(this.elWidth / divisor); - }else{ - this.spread = true; //-- Double Page - - this.colWidth = Math.floor((this.elWidth - this.gap) / divisor); - - /* - Was causing jumps, doesn't seem to be needed anymore - //-- Must be even for firefox - if(this.colWidth % 2 != 0){ - this.colWidth -= 1; - } - */ + + // this.gap = this.gap || Math.ceil(this.elWidth / 8); + this.gap = Math.ceil(this.elWidth / 8); + + if(this.gap % 2 != 0){ + this.gap += 1; } - - this.spreadWidth = (this.colWidth + this.gap) * divisor; - - // if(this.bodyEl) this.bodyEl.style.margin = 0; - // this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium"; - //-- Clear Margins - if(this.bodyEl) this.bodyEl.style.margin = "0"; - - this.docEl.style.overflow = "hidden"; + if(this.elWidth < cutoff || !this.book.settings.spreads) { + this.spread = false; //-- Single Page - this.docEl.style.width = this.elWidth; + divisor = 1; + this.colWidth = Math.floor(this.elWidth / divisor); + }else{ + this.spread = true; //-- Double Page - //-- Adjust height - this.docEl.style.height = this.iframe.height + "px"; + this.colWidth = Math.floor((this.elWidth - this.gap) / divisor); + + // - Was causing jumps, doesn't seem to be needed anymore + //-- Must be even for firefox + // if(this.colWidth % 2 != 0){ + // this.colWidth -= 1; + // } + + } - //-- Add columns - this.docEl.style[EPUBJS.Renderer.columnAxis] = "horizontal"; - this.docEl.style[EPUBJS.Renderer.columnGap] = this.gap+"px"; - this.docEl.style[EPUBJS.Renderer.columnWidth] = this.colWidth+"px"; + this.spreadWidth = (this.colWidth + this.gap) * divisor; + // if(this.bodyEl) this.bodyEl.style.margin = 0; + // this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium"; + + //-- Clear Margins + if(this.bodyEl) this.bodyEl.style.margin = "0"; + + this.docEl.style.overflow = "hidden"; + this.docEl.style.width = this.elWidth + "px"; - + //-- Adjust height + this.docEl.style.height = this.iframe.clientHeight + "px"; + + //-- Add columns + this.docEl.style[EPUBJS.Renderer.columnAxis] = "horizontal"; + this.docEl.style[EPUBJS.Renderer.columnGap] = this.gap+"px"; + this.docEl.style[EPUBJS.Renderer.columnWidth] = this.colWidth+"px"; + } EPUBJS.Renderer.prototype.fixedLayout = function(){ - this.paginated = false; + this.paginated = false; - this.elWidth = this.iframe.width; - this.docEl.style.width = this.elWidth; - // this.setLeft(0); + this.elWidth = this.iframe.width; + this.docEl.style.width = this.elWidth; + // this.setLeft(0); - this.docEl.style.width = this.elWidth; + this.docEl.style.width = this.elWidth; - //-- Adjust height - this.docEl.style.height = "auto"; + //-- Adjust height + this.docEl.style.height = "auto"; - //-- Remove columns - // this.docEl.style[EPUBJS.core.columnWidth] = "auto"; + //-- Remove columns + // this.docEl.style[EPUBJS.core.columnWidth] = "auto"; - //-- Scroll - this.docEl.style.overflow = "auto"; + //-- Scroll + this.docEl.style.overflow = "auto"; - // this.displayedPages = 1; + // this.displayedPages = 1; } EPUBJS.Renderer.prototype.setStyle = function(style, val, prefixed){ - if(prefixed) { - style = EPUBJS.core.prefixed(style); - } - - if(this.bodyEl) this.bodyEl.style[style] = val; + if(prefixed) { + style = EPUBJS.core.prefixed(style); + } + + if(this.bodyEl) this.bodyEl.style[style] = val; } EPUBJS.Renderer.prototype.removeStyle = function(style){ - - if(this.bodyEl) this.bodyEl.style[style] = ''; - + + if(this.bodyEl) this.bodyEl.style[style] = ''; + } EPUBJS.Renderer.prototype.applyStyles = function() { - var styles = this.book.settings.styles; + var styles = this.book.settings.styles; - for (style in styles) { - this.setStyle(style, styles[style]); - } + for (style in styles) { + this.setStyle(style, styles[style]); + } } EPUBJS.Renderer.prototype.gotoChapterEnd = function(){ - this.chapterEnd(); + this.chapterEnd(); } EPUBJS.Renderer.prototype.visible = function(bool){ - if(typeof(bool) == "undefined") { - return this.iframe.style.visibility; - } + if(typeof(bool) == "undefined") { + return this.iframe.style.visibility; + } - if(bool == true){ - this.iframe.style.visibility = "visible"; - }else if(bool == false){ - this.iframe.style.visibility = "hidden"; - } + if(bool == true){ + this.iframe.style.visibility = "visible"; + }else if(bool == false){ + this.iframe.style.visibility = "hidden"; + } } EPUBJS.Renderer.prototype.calcPages = function() { - - this.totalWidth = this.docEl.scrollWidth; - - this.displayedPages = Math.ceil(this.totalWidth / this.spreadWidth); + + this.totalWidth = this.docEl.scrollWidth; + + this.displayedPages = Math.ceil(this.totalWidth / this.spreadWidth); - this.currentChapter.pages = this.displayedPages; + this.currentChapter.pages = this.displayedPages; } EPUBJS.Renderer.prototype.nextPage = function(){ - if(this.chapterPos < this.displayedPages){ - this.chapterPos++; + if(this.chapterPos < this.displayedPages){ + this.chapterPos++; - this.leftPos += this.spreadWidth; + this.leftPos += this.spreadWidth; - this.setLeft(this.leftPos); + this.setLeft(this.leftPos); - this.currentLocationCfi = this.getPageCfi(); - - this.book.trigger("renderer:pageChanged", this.currentLocationCfi); + this.currentLocationCfi = this.getPageCfi(); + + this.book.trigger("renderer:pageChanged", this.currentLocationCfi); - return this.chapterPos; - }else{ - return false; - } + return this.chapterPos; + }else{ + return false; + } } EPUBJS.Renderer.prototype.prevPage = function(){ - if(this.chapterPos > 1){ - this.chapterPos--; + if(this.chapterPos > 1){ + this.chapterPos--; - this.leftPos -= this.spreadWidth; + this.leftPos -= this.spreadWidth; - this.setLeft(this.leftPos); + this.setLeft(this.leftPos); - this.currentLocationCfi = this.getPageCfi(); + this.currentLocationCfi = this.getPageCfi(); - this.book.trigger("renderer:pageChanged", this.currentLocationCfi); + this.book.trigger("renderer:pageChanged", this.currentLocationCfi); - return this.chapterPos; - }else{ - return false; - } + return this.chapterPos; + }else{ + return false; + } } EPUBJS.Renderer.prototype.chapterEnd = function(){ - this.page(this.displayedPages); + this.page(this.displayedPages); } EPUBJS.Renderer.prototype.setLeft = function(leftPos){ - // this.bodyEl.style.marginLeft = -leftPos + "px"; - // this.docEl.style.marginLeft = -leftPos + "px"; - // this.docEl.style[EPUBJS.Renderer.transform] = 'translate('+ (-leftPos) + 'px, 0)'; - this.doc.defaultView.scrollTo(leftPos, 0); + // this.bodyEl.style.marginLeft = -leftPos + "px"; + // this.docEl.style.marginLeft = -leftPos + "px"; + // this.docEl.style[EPUBJS.Renderer.transform] = 'translate('+ (-leftPos) + 'px, 0)'; + this.doc.defaultView.scrollTo(leftPos, 0); } EPUBJS.Renderer.prototype.determineStore = function(callback){ - if(this.book.fromStorage) { - - //-- Filesystem api links are relative, so no need to replace them - if(this.book.storage.getStorageType() == "filesystem") { - return false; - } - - return this.book.store; - - } else if(this.book.contained) { - - return this.book.zip; - - } else { - - return false; - - } + if(this.book.fromStorage) { + + //-- Filesystem api links are relative, so no need to replace them + if(this.book.storage.getStorageType() == "filesystem") { + return false; + } + + return this.book.store; + + } else if(this.book.contained) { + + return this.book.zip; + + } else { + + return false; + + } } EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){ - var items = this.doc.querySelectorAll(query), - resources = Array.prototype.slice.call(items), - count = resources.length, - after = function(result){ - count--; - if(progress) progress(result, count); - if(count <= 0 && finished) finished(true); - }; - - if(count === 0) { - finished(false); - return; - } + var items = this.doc.querySelectorAll(query), + resources = Array.prototype.slice.call(items), + count = resources.length, + after = function(result){ + count--; + if(progress) progress(result, count); + if(count <= 0 && finished) finished(true); + }; + + if(count === 0) { + finished(false); + return; + } - resources.forEach(function(item){ - - func(item, after); - - }.bind(this)); - + resources.forEach(function(item){ + + func(item, after); + + }.bind(this)); + } EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callback) { - var _oldUrls, - _newUrls = {}, - _store = this.determineStore(), - _cache = this.caches[query], - _contentsPath = this.book.settings.contentsPath, - _attr = attr, - progress = function(url, full, count) { - _newUrls[full] = url; - }, - finished = function(notempty) { - - if(callback) callback(); - - _.each(_oldUrls, function(url){ - _store.revokeUrl(url); - }); - - _cache = _newUrls; - }; + var _oldUrls, + _newUrls = {}, + _store = this.determineStore(), + _cache = this.caches[query], + _contentsPath = this.book.settings.contentsPath, + _attr = attr, + progress = function(url, full, count) { + _newUrls[full] = url; + }, + finished = function(notempty) { + + if(callback) callback(); + + _.each(_oldUrls, function(url){ + _store.revokeUrl(url); + }); + + _cache = _newUrls; + }; - if(!_store) return; + if(!_store) return; - if(!_cache) _cache = {}; - _oldUrls = _.clone(_cache); + if(!_cache) _cache = {}; + _oldUrls = _.clone(_cache); - this.replace(query, function(link, done){ + this.replace(query, function(link, done){ - var src = link.getAttribute(_attr), - full = EPUBJS.core.resolveUrl(_contentsPath, src), - replaceUrl = function(url) { - link.setAttribute(_attr, url); - link.onload = function(){ - done(url, full); - } - }; - - - if(full in _oldUrls){ - replaceUrl(_oldUrls[full]); - _newUrls[full] = _oldUrls[full]; - delete _oldUrls[full]; - }else{ - func(_store, full, replaceUrl, link); - } + var src = link.getAttribute(_attr), + full = EPUBJS.core.resolveUrl(_contentsPath, src), + replaceUrl = function(url) { + link.setAttribute(_attr, url); + link.onload = function(){ + done(url, full); + } + }; + + + if(full in _oldUrls){ + replaceUrl(_oldUrls[full]); + _newUrls[full] = _oldUrls[full]; + delete _oldUrls[full]; + }else{ + func(_store, full, replaceUrl, link); + } - }, finished, progress); + }, finished, progress); } //-- Replaces the relative links within the book to use our internal page changer EPUBJS.Renderer.prototype.replaceLinks = function(callback){ - - var renderer = this; + + var renderer = this; - this.replace("a[href]", function(link, done){ + this.replace("a[href]", function(link, done){ - var href = link.getAttribute("href"), - relative = href.search("://"), - fragment = href[0] == "#"; + var href = link.getAttribute("href"), + relative = href.search("://"), + fragment = href[0] == "#"; - if(relative != -1){ + if(relative != -1){ - link.setAttribute("target", "_blank"); + link.setAttribute("target", "_blank"); - }else{ + }else{ - link.onclick = function(){ - renderer.book.goto(href); - return false; - } - } + link.onclick = function(){ + renderer.book.goto(href); + return false; + } + } - done(); + done(); - }, callback); + }, callback); } EPUBJS.Renderer.prototype.page = function(pg){ - if(pg >= 1 && pg <= this.displayedPages){ - this.chapterPos = pg; - this.leftPos = this.spreadWidth * (pg-1); //-- pages start at 1 - this.setLeft(this.leftPos); - - this.currentLocationCfi = this.getPageCfi(); - - this.book.trigger("renderer:pageChanged", this.currentLocationCfi); - - // localStorage.setItem("chapterPos", pg); - return true; - } + if(pg >= 1 && pg <= this.displayedPages){ + this.chapterPos = pg; + this.leftPos = this.spreadWidth * (pg-1); //-- pages start at 1 + this.setLeft(this.leftPos); + + this.currentLocationCfi = this.getPageCfi(); + + this.book.trigger("renderer:pageChanged", this.currentLocationCfi); + + // localStorage.setItem("chapterPos", pg); + return true; + } - //-- Return false if page is greater than the total - return false; + //-- Return false if page is greater than the total + return false; } //-- Find a section by fragement id EPUBJS.Renderer.prototype.section = function(fragment){ - var el = this.doc.getElementById(fragment), - left, pg; + var el = this.doc.getElementById(fragment), + left, pg; - if(el){ - this.pageByElement(el); - } + if(el){ + this.pageByElement(el); + } } //-- Show the page containing an Element EPUBJS.Renderer.prototype.pageByElement = function(el){ - var left, pg; - if(!el) return; + var left, pg; + if(!el) return; - left = this.leftPos + el.getBoundingClientRect().left, //-- Calculate left offset compaired to scrolled position - pg = Math.floor(left / this.spreadWidth) + 1; //-- pages start at 1 - this.page(pg); + left = this.leftPos + el.getBoundingClientRect().left, //-- Calculate left offset compaired to scrolled position + pg = Math.floor(left / this.spreadWidth) + 1; //-- pages start at 1 + this.page(pg); } EPUBJS.Renderer.prototype.beforeDisplay = function(callback){ - this.book.triggerHooks("beforeChapterDisplay", callback.bind(this), this); + this.book.triggerHooks("beforeChapterDisplay", callback.bind(this), this); } EPUBJS.Renderer.prototype.walk = function(node) { - var r, - node, children, leng, - startNode = node, - prevNode, - stack = [startNode]; + var r, + node, children, leng, + startNode = node, + prevNode, + stack = [startNode]; - var STOP = 10000, ITER=0; + var STOP = 10000, ITER=0; - while(!r && stack.length) { + while(!r && stack.length) { - node = stack.shift(); - - if( this.isElementVisible(node) ) { - - r = node; - - } - - if(!r && node && node.childElementCount > 0){ - - children = node.children; - leng = children.length; - - - for (var i = 0; i < leng; i++) { - if(children[i] != prevNode) stack.push(children[i]); - } + node = stack.shift(); + + if( this.isElementVisible(node) ) { + + r = node; + + } + + if(!r && node && node.childElementCount > 0){ + + children = node.children; + if (children && children.length) { + leng = children.length ? children.length : 0; + } else { + return r; + } + + for (var i = 0; i < leng; i++) { + if(children[i] != prevNode) stack.push(children[i]); + } - } - - - if(!r && stack.length == 0 && startNode && startNode.parentNode !== null){ + } + + + if(!r && stack.length == 0 && startNode && startNode.parentNode !== null){ - stack.push(startNode.parentNode); - prevNode = startNode; - startNode = startNode.parentNode; - } - - - ITER++; - if(ITER > STOP) { - console.error("ENDLESS LOOP"); - break; - } - - } + stack.push(startNode.parentNode); + prevNode = startNode; + startNode = startNode.parentNode; + } + + + ITER++; + if(ITER > STOP) { + console.error("ENDLESS LOOP"); + break; + } + + } - return r; + return r; } EPUBJS.Renderer.prototype.getPageCfi = function(){ - var prevEl = this.visibileEl; - this.visibileEl = this.findFirstVisible(prevEl); - - if(!this.visibileEl.id) { - this.visibileEl.id = "EPUBJS-PAGE-" + this.chapterPos; - } - - this.pageIds[this.chapterPos] = this.visibileEl.id; - - - return this.epubcfi.generateFragment(this.visibileEl, this.currentChapterCfi); + var prevEl = this.visibileEl; + this.visibileEl = this.findFirstVisible(prevEl); + + if(!this.visibileEl.id) { + this.visibileEl.id = "EPUBJS-PAGE-" + this.chapterPos; + } + + this.pageIds[this.chapterPos] = this.visibileEl.id; + + + return this.epubcfi.generateFragment(this.visibileEl, this.currentChapterCfi); } EPUBJS.Renderer.prototype.gotoCfiFragment = function(cfi){ - var element; + var element; - if(_.isString(cfi)){ - cfi = this.epubcfi.parse(cfi); - } - - element = this.epubcfi.getElement(cfi, this.doc); + if(_.isString(cfi)){ + cfi = this.epubcfi.parse(cfi); + } + + element = this.epubcfi.getElement(cfi, this.doc); - this.pageByElement(element); + this.pageByElement(element); } EPUBJS.Renderer.prototype.findFirstVisible = function(startEl){ - var el = startEl || this.bodyEl, - found; - - found = this.walk(el); + var el = startEl || this.bodyEl, + found; + + found = this.walk(el); - if(found) { - return found; - }else{ - return startEl; - } - + if(found) { + return found; + }else{ + return startEl; + } + } EPUBJS.Renderer.prototype.isElementVisible = function(el){ - var left; - - if(el && typeof el.getBoundingClientRect === 'function'){ + var left; + + if(el && typeof el.getBoundingClientRect === 'function'){ - left = el.getBoundingClientRect().left; - - if( left >= 0 && - left < this.spreadWidth ) { - return true; - } - } - - return false; + left = el.getBoundingClientRect().left; + + if( left >= 0 && + left < this.spreadWidth ) { + return true; + } + } + + return false; } EPUBJS.Renderer.prototype.height = function(el){ - return this.docEl.offsetHeight; + return this.docEl.offsetHeight; } EPUBJS.Renderer.prototype.remove = function() { - window.removeEventListener("resize", this.resized); - this.el.removeChild(this.iframe); + this.iframe.contentWindow.removeEventListener("resize", this.resized); + this.el.removeChild(this.iframe); } @@ -2446,7 +3147,7 @@ EPUBJS.replace.links = function(_store, full, done, link){ } EPUBJS.replace.stylesheets = function(_store, full) { - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); if(!_store) return; @@ -2459,25 +3160,25 @@ EPUBJS.replace.stylesheets = function(_store, full) { var blob = new Blob([newText], { "type" : "text\/css" }), url = _URL.createObjectURL(blob); - promise.resolve(url); + deferred.resolve(url); }, function(e) {console.error(e)}); }); - return promise; + return deferred.promise; } EPUBJS.replace.cssUrls = function(_store, base, text){ - var promise = new RSVP.Promise(), + var deferred = new RSVP.defer(), promises = [], matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g); if(!_store) return; if(!matches){ - promise.resolve(text); - return promise; + deferred.resolve(text); + return deferred.promise; } matches.forEach(function(str){ @@ -2490,10 +3191,10 @@ EPUBJS.replace.cssUrls = function(_store, base, text){ }); RSVP.all(promises).then(function(){ - promise.resolve(text); + deferred.resolve(text); }); - return promise; + return deferred.promise; } EPUBJS.Unarchiver = function(url){ @@ -2526,13 +3227,13 @@ EPUBJS.Unarchiver.prototype.loadLib = function(callback){ } EPUBJS.Unarchiver.prototype.openZip = function(zipUrl, callback){ - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); var zipFs = this.zipFs; zipFs.importHttpContent(zipUrl, false, function() { - promise.resolve(zipFs); + deferred.resolve(zipFs); }, this.failed); - return promise + return deferred.promise; } // EPUBJS.Unarchiver.prototype.getXml = function(url){ @@ -2561,29 +3262,29 @@ EPUBJS.Unarchiver.prototype.getXml = function(url){ EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){ var unarchiver = this; - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); var entry = this.zipFs.find(url); var _URL = window.URL || window.webkitURL || window.mozURL; if(!entry) console.error(url); if(url in this.urlCache) { - promise.resolve(this.urlCache[url]); - return promise; + deferred.resolve(this.urlCache[url]); + return deferred.promise; } entry.getBlob(mime || zip.getMimeType(entry.name), function(blob){ var tempUrl = _URL.createObjectURL(blob); - promise.resolve(tempUrl); + deferred.resolve(tempUrl); unarchiver.urlCache[url] = tempUrl; }); - return promise; + return deferred.promise; } EPUBJS.Unarchiver.prototype.getText = function(url){ var unarchiver = this; - var promise = new RSVP.Promise(); + var deferred = new RSVP.defer(); var entry = this.zipFs.find(url); var _URL = window.URL || window.webkitURL || window.mozURL; @@ -2591,10 +3292,10 @@ EPUBJS.Unarchiver.prototype.getText = function(url){ entry.getText(function(text){ - promise.resolve(text); + deferred.resolve(text); }, null, null, 'ISO-8859-1'); - return promise; + return deferred.promise; } EPUBJS.Unarchiver.prototype.revokeUrl = function(url){ diff --git a/build/epub.min.js b/build/epub.min.js index 9c227bf..c8e6319 100644 --- a/build/epub.min.js +++ b/build/epub.min.js @@ -1,2 +1,2 @@ -!function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.push,h=d.slice,i=d.concat,j=e.toString,k=e.hasOwnProperty,l=d.forEach,m=d.map,n=d.reduce,o=d.reduceRight,p=d.filter,q=d.every,r=d.some,s=d.indexOf,t=d.lastIndexOf,u=Array.isArray,v=Object.keys,w=f.bind,x=function(a){return a instanceof x?a:this instanceof x?(this._wrapped=a,void 0):new x(a)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.4.4";var y=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.indexf;){var h=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}return f},x.toArray=function(a){return a?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){return null==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){return h.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:h.call(a,Math.max(a.length-b,0))},x.rest=x.tail=x.drop=function(a,b,c){return h.call(a,null==b||c?1:b)},x.compact=function(a){return x.filter(a,x.identity)};var D=function(a,b,c){return y(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){return D(a,b,[])},x.without=function(a){return x.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);var e=c?x.map(a,c,d):a,f=[],g=[];return y(e,function(c,d){(b?d&&g[g.length-1]===c:x.contains(g,c))||(g.push(c),f.push(a[d]))}),f},x.union=function(){return x.uniq(i.apply(d,arguments))},x.intersection=function(a){var b=h.call(arguments,1);return x.filter(x.uniq(a),function(a){return x.every(b,function(b){return x.indexOf(b,a)>=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);return c},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;return f},x.bind=function(a,b){if(a.bind===w&&w)return w.apply(a,h.call(arguments,1));var c=h.call(arguments,2);return function(){return a.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);return 0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){var c,d,e,f,g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)};return function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},x.debounce=function(a,b,c){var d,e;return function(){var f=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;return clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return 0>=a?b():function(){return 1>--a?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&(b[b.length]=c);return b},x.values=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push(a[c]);return b},x.pairs=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push([c,a[c]]);return b},x.invert=function(a){var b={};for(var c in a)x.has(a,c)&&(b[a[c]]=c);return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var E=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==b+"";case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;c.push(a),d.push(b);var g=0,h=!0;if("[object Array]"==e){if(g=a.length,h=g==b.length)for(;g--&&(h=E(a[g],b[g],c,d)););}else{var i=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&i instanceof i&&x.isFunction(k)&&k instanceof k))return!1;for(var l in a)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(l in b)if(x.has(b,l)&&!g--)break;h=!g}}return c.pop(),d.pop(),h};x.isEqual=function(a,b){return E(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var F={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};F.unescape=x.invert(F.escape);var G={escape:RegExp("["+x.keys(F.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(F.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(G[a],function(b){return F[a][b]})}}),x.result=function(a,b){if(null==a)return null;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),L.call(this,c.apply(x,a))}})};var H=0;x.uniqueId=function(a){var b=++H+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=RegExp([(c.escape||I).source,(c.interpolate||I).source,(c.evaluate||I).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(K,function(a){return"\\"+J[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var L=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return L.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),function(a){"use strict";function b(a,b){f.async(function(){a.trigger("promise:resolved",{detail:b}),a.isResolved=!0,a.resolvedValue=b})}function c(a,b){f.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedValue=b})}function d(a){var b,c=[],d=new p,e=a.length;0===e&&d.resolve([]);var f=function(a){return function(b){g(a,b)}},g=function(a,b){c[a]=b,0===--e&&d.resolve(c)},h=function(a){d.reject(a)};for(b=0;e>b;b++)a[b].then(f(b),h);return d}function e(a,b){f[a]=b}var f={},g="undefined"!=typeof window?window:{},h=g.MutationObserver||g.WebKitMutationObserver;if("undefined"!=typeof process&&"[object process]"==={}.toString.call(process))f.async=function(a,b){process.nextTick(function(){a.call(b)})};else if(h){var i=[],j=new h(function(){var a=i.slice();i=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),k=document.createElement("div");j.observe(k,{attributes:!0}),window.addEventListener("unload",function(){j.disconnect(),j=null}),f.async=function(a,b){i.push([a,b]),k.setAttribute("drainQueue","drainQueue")}}else f.async=function(a,b){setTimeout(function(){a.call(b)},1)};var l=function(a,b){this.type=a;for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c])},m=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c][0]===b)return c;return-1},n=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b},o={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a},on:function(a,b,c){var d,e,f=n(this);for(a=a.split(/\s+/),c=c||this;e=a.shift();)d=f[e],d||(d=f[e]=[]),-1===m(d,b)&&d.push([b,c])},off:function(a,b){var c,d,e,f=n(this);for(a=a.split(/\s+/);d=a.shift();)b?(c=f[d],e=m(c,b),-1!==e&&c.splice(e,1)):f[d]=[]},trigger:function(a,b){var c,d,e,f,g,h=n(this);if(c=h[a])for(var i=0,j=c.length;j>i;i++)d=c[i],e=d[0],f=d[1],"object"!=typeof b&&(b={detail:b}),g=new l(a,b),e.call(f,g)}},p=function(){this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this)},q=function(){},r=function(a,b,c,d){var e,f,g,h,i="function"==typeof c;if(i)try{e=c(d.detail),g=!0}catch(j){h=!0,f=j}else e=d.detail,g=!0;e&&"function"==typeof e.then?e.then(function(a){b.resolve(a)},function(a){b.reject(a)}):i&&g?b.resolve(e):h?b.reject(f):b[a](e)};p.prototype={then:function(a,b){var c=new p;return this.isResolved&&f.async(function(){r("resolve",c,a,{detail:this.resolvedValue})},this),this.isRejected&&f.async(function(){r("reject",c,b,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(b){r("resolve",c,a,b)}),this.on("promise:failed",function(a){r("reject",c,b,a)}),c},resolve:function(a){b(this,a),this.resolve=q,this.reject=q},reject:function(a){c(this,a),this.resolve=q,this.reject=q}},o.mixin(p.prototype),a.Promise=p,a.Event=l,a.EventTarget=o,a.all=d,a.configure=e}(window.RSVP={});var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",function(){var a=this,b=a.ePub||{},c=a.ePub=function(){var a,b;return arguments[0]&&"string"==typeof arguments[0]&&(a=arguments[0],arguments[1]&&"object"==typeof arguments[1]?(b=arguments[1],b.bookPath=a):b={bookPath:a}),arguments[0]&&"object"==typeof arguments[0]&&(b=arguments[0]),new EPUBJS.Book(b)};_.extend(c,{noConflict:function(){return a.ePub=b,this}}),"function"==typeof define&&define.amd?define(function(){return c}):"undefined"!=typeof module&&module.exports&&(module.exports=c)}(),EPUBJS.Book=function(a){this.settings=_.defaults(a||{},{bookPath:null,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,fixedLayout:!1,responsive:!0,version:1,restore:!1,reload:!1,"goto":!1,styles:{}}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),0!=this.settings.storage&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.Promise,spine:new RSVP.Promise,metadata:new RSVP.Promise,cover:new RSVP.Promise,toc:new RSVP.Promise},this.ready.all=RSVP.all(_.values(this.ready)),this.ready.all.then(this._ready),this._q=[],this.isRendered=!1,this._rendering=!1,this._displayQ=[],this.opened=new RSVP.Promise,this.settings.bookPath&&this.open(this.settings.bookPath,this.settings.reload),window.addEventListener("beforeunload",this.unload.bind(this),!1)},EPUBJS.Book.prototype.open=function(a,b){var c,d=this,e=this.isSaved(a);return this.settings.bookPath=a,this.bookUrl=this.urlFrom(a),e&&!b&&this.applySavedSettings(),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){return e&&d.settings.restore&&!b?d.restore():d.unpack()})):c=e&&this.settings.restore&&!b?this.restore():this.unpack(),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||c.then(d.storeOffline())),c.then(function(){d.opened.resolve()}),c},EPUBJS.Book.prototype.unpack=function(a){var b=this,c=new EPUBJS.Parser,a=a||"META-INF/container.xml";return b.loadXml(b.bookUrl+a).then(function(a){return c.container(a)}).then(function(a){return b.settings.contentsPath=b.bookUrl+a.basePath,b.settings.packageUrl=b.bookUrl+a.packagePath,b.loadXml(b.settings.packageUrl)}).then(function(a){return c.package(a,b.settings.contentsPath)}).then(function(a){b.contents=a,b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.cover=b.contents.cover=b.settings.contentsPath+a.coverPath,b.spineNodeIndex=b.contents.spineNodeIndex=a.spineNodeIndex,b.ready.manifest.resolve(b.contents.manifest),b.ready.spine.resolve(b.contents.spine),b.ready.metadata.resolve(b.contents.metadata),b.ready.cover.resolve(b.contents.cover),a.tocPath&&(b.settings.tocUrl=b.settings.contentsPath+a.tocPath,b.loadXml(b.settings.tocUrl).then(function(a){return c.toc(a)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)}))}).then(null,function(a){console.error(a)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a):this.settings.contained?this.zip.getXml(a):EPUBJS.core.request(a,"xml")},EPUBJS.Book.prototype.urlFrom=function(a){var b=-1!=a.search("://"),c="/"==a[0],d=window.location,e=d.origin||d.protocol+"//"+d.host;return b?a:!b&&c?e+a:b||c?void 0:"../"==a.slice(0,3)?EPUBJS.core.resolveUrl(d.href,a):e+EPUBJS.core.folder(d.pathname)+a},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=a.lastIndexOf("."),c=a.slice(b+1);return!c||"epub"!=c&&"zip"!=c?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=a+":"+this.settings.version,c=localStorage.getItem(b);return localStorage&&null!==c?!0:!1},EPUBJS.Book.prototype.removeSavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;localStorage.removeItem(a),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;return stored=JSON.parse(localStorage.getItem(a)),EPUBJS.VERSION!=stored.EPUBJSVERSION?!1:(this.settings=_.defaults(this.settings,stored),void 0)},EPUBJS.Book.prototype.saveSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(a,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.setItem(a,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.removeItem(a)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.render=new EPUBJS.Renderer(c),c._rendered(),c.startDisplay()},function(a){console.error(a)}),b.then(null,function(a){console.error(a)}),b},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.restore&&this.settings.goto?this.goto(this.settings.goto):this.settings.restore&&this.settings.previousLocationCfi?this.displayChapter(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b=this,c=this.settings.bookPath+":contents:"+this.settings.version,d=new RSVP.Promise,e=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],a=a||!1,f=localStorage.getItem(c);return this.settings.clearSaved&&(a=!0),a||"undefined"==f||"null"==f||(this.contents=JSON.parse(f),e.forEach(function(c){b[c]=b.contents[c],b[c]||(a=!0)})),!a&&f&&this.contents&&this.settings.contentsPath?(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),d.resolve(),d):this.open(this.settings.bookPath,!0)},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),e>=this.spine.length?!1:0>e?!1:(this.spinePos=e,this.chapter=new EPUBJS.Chapter(this.spine[e]),this._rendering=!0,c=f.render.chapter(this.chapter),d?c.then(function(b){b.currentLocationCfi=a,b.gotoCfiFragment(d)}):b&&c.then(function(a){a.gotoChapterEnd()}),this.settings.fromStorage||this.settings.contained||c.then(function(){f.preloadNextChapter()}),c.then(function(){var a;f._rendering=!1,f._displayQ.length&&(a=f._displayQ.unshift(),f.displayChapter.apply(f,a))}),c)):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.render.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.render.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.goto=function(a){var b,c,d,e,f;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=-1==c.search("://")?this.settings.contentsPath+c:c,f=this.spineIndexByURL[e],c||(f=this.chapter?this.chapter.spinePos:0),"number"!=typeof f?!1:this.chapter&&f==this.chapter.spinePos?(d&&this.render.section(d),(new RSVP.Promise).resolve(this.currentChapter)):this.displayChapter(f).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){return document.createElement("iframe"),this.spinePos>=this.spine.length?!1:(next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href),void 0)},EPUBJS.Book.prototype.storeOffline=function(){var a=this,b=_.values(this.manifest);return EPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){this.settings.styles[a]=b,this.render&&this.render.setStyle(a,b,c)},EPUBJS.Book.prototype.removeStyle=function(a){this.render&&this.render.removeStyle(a),delete this.settings.styles[a]},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&(this.saveSettings(),this.saveContents()),this.trigger("book:unload")},EPUBJS.Book.prototype.destroy=function(){window.removeEventListener("beforeunload",this.unload),this.currentChapter&&this.currentChapter.unload(),this.unload(),this.render&&this.render.remove()},EPUBJS.Book.prototype._enqueue=function(a,b){this._q.push({command:a,arguments:b})},EPUBJS.Book.prototype._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){var a=this;this.isRendered=!0,this.trigger("book:rendered"),this._q.forEach(function(b){a[b.command].apply(a,b.arguments)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;plugTypes=_.values(this.hooks);for(plugType in this.hooks)a=_.values(EPUBJS.Hooks[plugType]),a.forEach(function(a){b.registerHook(plugType,a)})},EPUBJS.Book.prototype.registerHook=function(a,b,c){var d=this;"undefined"!=typeof this.hooks[a]?"function"==typeof b?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?d.hooks[a].unshift(b):d.hooks[a].push(b)}):this.hooks[a]=[func]},EPUBJS.Book.prototype.triggerHooks=function(a,b,c){function d(){f--,0>=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,e.forEach(function(a){a(d,c)}),void 0)},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(a){this.href=a.href,this.id=a.id,this.spinePos=a.index,this.properties=a.properties,this.linear=a.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(a){return a?a.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.Promise;return a?(this.tempUrl||(this.tempUrl=a.getUrl(this.href)),this.tempUrl):(b.resolve(this.href),b)},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){return document.getElementById(a)},EPUBJS.core.getEls=function(a){return document.getElementsByClassName(a)},EPUBJS.core.request=function(a,b){function c(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var a;a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):"blob"==b?d?this.response:new Blob([this.response]):this.response,f.resolve(a)}else f.reject(this)}var d=window.URL,e=d?"blob":"arraybuffer",f=new RSVP.Promise,g=new XMLHttpRequest;return g.open("GET",a),g.onreadystatechange=c,"blob"==b&&(g.responseType=e),"json"==b&&g.setRequestHeader("Accept","application/json"),"xml"==b&&g.overrideMimeType("text/xml"),g.send(),f},EPUBJS.core.toArray=function(a){var b=[];for(member in a){var c;a.hasOwnProperty(member)&&(c=a[member],c.ident=member,b.push(c))}return b},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/"),c=a.slice(0,b+1);return-1==b&&(c=""),c},EPUBJS.core.dataURLToBlob=function(a){var b=";base64,";if(-1==a.indexOf(b)){var c=a.split(","),d=c[0].split(":")[1],e=c[1];return new Blob([e],{type:d})}for(var c=a.split(b),d=c[0].split(":")[1],e=window.atob(c[1]),f=e.length,g=new Uint8Array(f),h=0;f>h;++h)g[h]=e.charCodeAt(h);return new Blob([g],{type:d})},EPUBJS.core.addScript=function(a,b,c){var d,e;e=!1,d=document.createElement("script"),d.type="text/javascript",d.async=!1,d.src=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.addScripts=function(a,b,c){var d=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.loadScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){var d,e;e=!1,d=document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.prefixed=function(a){var b=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length,e=0;if("undefined"!=typeof document.body.style[a])return a;for(;d>e;e++)if("undefined"!=typeof document.body.style[b[e]+c])return b[e]+c;return a},EPUBJS.core.resolveUrl=function(a,b){var c,d,e=[],f=a.split("/");return f.pop(),d=b.split("/"),d.forEach(function(a){".."===a?f.pop():e.push(a)}),c=f.concat(e),c.join("/")},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapter=function(a,b,c){var b=parseInt(b),a=a+1,d="/"+a+"/";return d+=2*(b+1),c&&(d+="["+c+"]"),d+="!"},EPUBJS.EpubCFI.prototype.generateFragment=function(a,b){var c=this.pathTo(a),d=[];return b&&d.push(b),c.forEach(function(a){var b="";b+=2*(a.index+1),a.id&&"EPUBJS"!=a.id.slice(0,6)&&(b+="["+a.id+"]"),d.push(b)}),d.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(var b,c=[];a&&null!==a.parentNode;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;return c},EPUBJS.EpubCFI.prototype.getChapter=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getFragment=function(a){var b=a.split("!");return b[1]},EPUBJS.EpubCFI.prototype.getOffset=function(a){var b=a.split(":");return[b[0],b[1]]},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f={};return f.chapter=this.getChapter(a),f.fragment=this.getFragment(a),f.spinePos=parseInt(f.chapter.split("/")[2])/2-1||0,b=f.chapter.match(/\[(.*)\]/),f.spineId=b[1]||!1,c=f.fragment.split("/"),d=c[c.length-1],f.sections=[],parseInt(d)%2&&(e=this.getOffset(),f.text=parseInt(e[0]),f.character=parseInt(e[1]),c.pop()),c.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),f.sections.push({index:b,id:d||!1}))}),f},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,b=b||document,d=a.sections,e=b.getElementsByTagName("html")[0],f=Array.prototype.slice.call(e.children);for(d.shift();d.length>0;)c=d.shift(),c.id?e=b.getElementById(c.id):(e=f[c.index],f||console.error("No Kids",e)),e||console.error("No Element For",c),f=Array.prototype.slice.call(e.children);return e},EPUBJS.Events=function(a,b){return this.events={},this.el=b?b:document.createElement("div"),a.createEvent=this.createEvent,a.tell=this.tell,a.listen=this.listen,a.deafen=this.deafen,a.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(a){var b=new CustomEvent(a); -return this.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){var c;this.events[a]?c=this.events[a]:(console.warn("No event:",a,"defined yet, creating."),c=this.createEvent(a)),b&&(c.msg=b),this.el.dispatchEvent(c)},EPUBJS.Events.prototype.listen=function(a,b,c){return this.events[a]?(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1),void 0):(console.warn("No event:",a,"defined yet, creating."),this.createEvent(a),void 0)},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){function e(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(a){if(void 0===this[a]&&(this[a]={}),"object"!=typeof this[a])throw"Already registered: "+a;return this[a]}}}(),EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){var b=a.querySelector("rootfile"),c=b.getAttribute("full-path"),d=EPUBJS.core.folder(c);return{packagePath:c,basePath:d}},EPUBJS.Parser.prototype.package=function(a,b){var c=this;b&&(this.baseUrl=b);var d=a.querySelector("metadata"),e=a.querySelector("manifest"),f=a.querySelector("spine"),g=c.manifest(e),h=c.findTocPath(e),i=c.findCoverPath(e),j=Array.prototype.indexOf.call(f.parentNode.childNodes,f),k=c.spine(f,g),l={};return k.forEach(function(a){l[a.href]=a.index}),{metadata:c.metadata(d),spine:k,manifest:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}},EPUBJS.Parser.prototype.findTocPath=function(a){var b=a.querySelector("item[media-type='application/x-dtbncx+xml']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){var b=a.querySelector("item[properties='cover-image']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){var b={},c=this;return b.bookTitle=c.getElementText(a,"title"),b.creator=c.getElementText(a,"creator"),b.description=c.getElementText(a,"description"),b.pubdate=c.getElementText(a,"date"),b.publisher=c.getElementText(a,"publisher"),b.identifier=c.getElementText(a,"identifier"),b.language=c.getElementText(a,"language"),b.rights=c.getElementText(a,"rights"),b.modified_date=c.querySelectorText(a,"meta[property='dcterms:modified']"),b.layout=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.orientation=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.spread=c.querySelectorText(a,"meta[property='rendition:spread']"),b},EPUBJS.Parser.prototype.getElementText=function(a,b){var c,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);return d&&0!=d.length?(c=d[0],c.childNodes.length?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(a,b){var c=a.querySelector(b);return c&&c.childNodes.length?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){var b=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);return e.forEach(function(a){var d=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"";c[d]={href:b+e,type:f}}),c},EPUBJS.Parser.prototype.spine=function(a,b){var c=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d);return e.forEach(function(a,d){var e=a.getAttribute("idref"),f={id:e,linear:a.getAttribute("linear")||"",properties:a.getAttribute("properties")||"",href:b[e].href,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.toc=function(a){function b(a){var c,d=[],e=[],f=a.childNodes,g=Array.prototype.slice.call(f),h=g.length,i=h;if(0==h)return!1;for(;i--;)c=g[i],"navPoint"===c.nodeName&&e.push(c);return e.forEach(function(c){var e=c.getAttribute("id"),f=c.querySelector("content"),g=f.getAttribute("src"),h=(g.split("#"),c.querySelector("navLabel")),i=h.textContent?h.textContent:"",j=b(c);d.unshift({id:e,href:g,label:i,subitems:j,parent:a?a.getAttribute("id"):null})}),d}var c=a.querySelector("navMap");return b(c)},EPUBJS.Renderer=function(a){this.el=a.element,this.book=a,this.caches={},this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.iframe.scrolling="no",this.book.settings.width||this.book.settings.height?this.resizeIframe(!1,this.book.settings.width||this.el.clientWidth,this.book.settings.height||this.el.clientHeight):(this.resizeIframe(!1,this.el.clientWidth,this.el.clientHeight),this.on("renderer:resized",this.resizeIframe,this)),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.debounce(this.onResized.bind(this),10),window.addEventListener("resize",this.resized,!1),this.book.registerHook("beforeChapterDisplay",this.replaceLinks.bind(this),!0),this.determineStore()&&this.book.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Renderer.prototype.chapter=function(a){var b=this,c=!1;return this.book.settings.contained&&(c=this.book.zip),this.currentChapter&&(this.currentChapter.unload(),this.trigger("renderer:chapterUnloaded"),this.book.trigger("renderer:chapterUnloaded")),this.currentChapter=a,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,a.spinePos,a.id),this.visibileEl=!1,a.url(c).then(function(a){return b.setIframeSrc(a)})},EPUBJS.Renderer.prototype.onResized=function(){var a={width:this.el.clientWidth,height:this.el.clientHeight};this.trigger("renderer:resized",a),this.book.trigger("book:resized",a),this.reformat()},EPUBJS.Renderer.prototype.reformat=function(){var a=this;a.book.settings.fixedLayout?a.fixedLayout():a.formatSpread(),setTimeout(function(){a.calcPages(),a.currentLocationCfi&&a.gotoCfiFragment(a.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.resizeIframe=function(a,b,c){var d,e;a?(d=a.width,e=a.height):(d=b,e=c),this.iframe.height=e,0!=d%2&&(d+=1),this.iframe.width=d},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth"),EPUBJS.Renderer.transform=EPUBJS.core.prefixed("transform")},EPUBJS.Renderer.prototype.setIframeSrc=function(a){var b=this,c=new RSVP.Promise;return this.visible(!1),this.iframe.src=a,this.iframe.onload=function(){b.doc=b.iframe.contentDocument,b.docEl=b.doc.documentElement,b.bodyEl=b.doc.body,b.applyStyles(),b.book.settings.fixedLayout?b.fixedLayout():b.formatSpread(),b.beforeDisplay(function(){b.calcPages(),c.resolve(b),b.currentLocationCfi=b.getPageCfi(),b.trigger("renderer:chapterDisplayed",b.currentChapter),b.book.trigger("renderer:chapterDisplayed",b.currentChapter),b.visible(!0)})},c},EPUBJS.Renderer.prototype.formatSpread=function(){var a=2,b=800;this.colWidth&&(this.OldcolWidth=this.colWidth,this.OldspreadWidth=this.spreadWidth),this.elWidth=this.iframe.width,this.gap=this.gap||Math.ceil(this.elWidth/8),this.elWidth1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.setLeft=function(a){this.doc.defaultView.scrollTo(a,0)},EPUBJS.Renderer.prototype.determineStore=function(){return this.book.fromStorage?"filesystem"==this.book.storage.getStorageType()?!1:this.book.store:this.book.contained?this.book.zip:!1},EPUBJS.Renderer.prototype.replace=function(a,b,c,d){var e=this.doc.querySelectorAll(a),f=Array.prototype.slice.call(e),g=f.length,h=function(a){g--,d&&d(a,g),0>=g&&c&&c(!0)};return 0===g?(c(!1),void 0):(f.forEach(function(a){b(a,h)}.bind(this)),void 0)},EPUBJS.Renderer.prototype.replaceWithStored=function(a,b,c,d){var e,f={},g=this.determineStore(),h=this.caches[a],i=this.book.settings.contentsPath,j=b,k=function(a,b){f[b]=a},l=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(a,b){var d=a.getAttribute(j),h=EPUBJS.core.resolveUrl(i,d),k=function(c){a.setAttribute(j,c),a.onload=function(){b(c,h)}};h in e?(k(e[h]),f[h]=e[h],delete e[h]):c(g,h,k,a)},l,k))},EPUBJS.Renderer.prototype.replaceLinks=function(a){var b=this;this.replace("a[href]",function(a,c){var d=a.getAttribute("href"),e=d.search("://");"#"==d[0],-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return b.book.goto(d),!1},c()},a)},EPUBJS.Renderer.prototype.page=function(a){return a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.leftPos=this.spreadWidth*(a-1),this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b,c;a&&(b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.spreadWidth)+1,this.page(c))},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.book.triggerHooks("beforeChapterDisplay",a.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(a){for(var b,a,c,d,e,f=a,g=[f],h=1e4,i=0;!b&&g.length;){if(a=g.shift(),this.isElementVisible(a)&&(b=a),!b&&a&&a.childElementCount>0){c=a.children,d=c.length;for(var j=0;d>j;j++)c[j]!=e&&g.push(c[j])}if(!b&&0==g.length&&f&&null!==f.parentNode&&(g.push(f.parentNode),e=f,f=f.parentNode),i++,i>h){console.error("ENDLESS LOOP");break}}return b},EPUBJS.Renderer.prototype.getPageCfi=function(){var a=this.visibileEl;return this.visibileEl=this.findFirstVisible(a),this.visibileEl.id||(this.visibileEl.id="EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),b=this.epubcfi.getElement(a,this.doc),this.pageByElement(b)},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.bodyEl;return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.isElementVisible=function(a){var b;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect().left,b>=0&&be;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.indexf;){var h=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}return f},x.toArray=function(a){return a?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){return null==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){return h.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:h.call(a,Math.max(a.length-b,0))},x.rest=x.tail=x.drop=function(a,b,c){return h.call(a,null==b||c?1:b)},x.compact=function(a){return x.filter(a,x.identity)};var D=function(a,b,c){return y(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){return D(a,b,[])},x.without=function(a){return x.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);var e=c?x.map(a,c,d):a,f=[],g=[];return y(e,function(c,d){(b?d&&g[g.length-1]===c:x.contains(g,c))||(g.push(c),f.push(a[d]))}),f},x.union=function(){return x.uniq(i.apply(d,arguments))},x.intersection=function(a){var b=h.call(arguments,1);return x.filter(x.uniq(a),function(a){return x.every(b,function(b){return x.indexOf(b,a)>=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);return c},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;return f},x.bind=function(a,b){if(a.bind===w&&w)return w.apply(a,h.call(arguments,1));var c=h.call(arguments,2);return function(){return a.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);return 0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){var c,d,e,f,g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)};return function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},x.debounce=function(a,b,c){var d,e;return function(){var f=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;return clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return 0>=a?b():function(){return 1>--a?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&(b[b.length]=c);return b},x.values=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push(a[c]);return b},x.pairs=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push([c,a[c]]);return b},x.invert=function(a){var b={};for(var c in a)x.has(a,c)&&(b[a[c]]=c);return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var E=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==b+"";case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;c.push(a),d.push(b);var g=0,h=!0;if("[object Array]"==e){if(g=a.length,h=g==b.length)for(;g--&&(h=E(a[g],b[g],c,d)););}else{var i=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&i instanceof i&&x.isFunction(k)&&k instanceof k))return!1;for(var l in a)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(l in b)if(x.has(b,l)&&!g--)break;h=!g}}return c.pop(),d.pop(),h};x.isEqual=function(a,b){return E(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var F={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};F.unescape=x.invert(F.escape);var G={escape:RegExp("["+x.keys(F.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(F.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(G[a],function(b){return F[a][b]})}}),x.result=function(a,b){if(null==a)return null;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),L.call(this,c.apply(x,a))}})};var H=0;x.uniqueId=function(a){var b=++H+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=RegExp([(c.escape||I).source,(c.interpolate||I).source,(c.evaluate||I).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(K,function(a){return"\\"+J[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var L=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return L.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),function(){var a,b;!function(){var c={},d={};a=function(a,b,d){c[a]={deps:b,callback:d}},b=function(a){if(d[a])return d[a];d[a]={};var e=c[a];if(!e)throw new Error("Module '"+a+"' not found.");for(var f,g=e.deps,h=e.callback,i=[],j=0,k=g.length;k>j;j++)"exports"===g[j]?i.push(f={}):i.push(b(g[j]));var l=h.apply(this,i);return d[a]=f||l}}(),a("rsvp/all",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){if("[object Array]"!==Object.prototype.toString.call(a))throw new TypeError("You must pass an array to all.");return new d(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){g[a]=c,0===--h&&b(g)}var f,g=[],h=a.length;0===h&&b([]);for(var i=0;ic;c++)if(a[c][0]===b)return c;return-1},d=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b},e={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a},on:function(a,b,e){var f,g,h=d(this);for(a=a.split(/\s+/),e=e||this;g=a.shift();)f=h[g],f||(f=h[g]=[]),-1===c(f,b)&&f.push([b,e])},off:function(a,b){var e,f,g,h=d(this);for(a=a.split(/\s+/);f=a.shift();)b?(e=h[f],g=c(e,b),-1!==g&&e.splice(g,1)):h[f]=[]},trigger:function(a,c){var e,f,g,h,i,j=d(this);if(e=j[a])for(var k=0;k2?a(Array.prototype.slice.call(arguments,1)):a(d)}}function e(a){return function(){var b,c,e=Array.prototype.slice.call(arguments),h=this,i=new f(function(a,d){b=a,c=d});return g(e).then(function(e){e.push(d(b,c));try{a.apply(h,e)}catch(f){c(f)}}),i}}var f=a.Promise,g=b.all;c.denodeify=e}),a("rsvp/promise",["rsvp/config","rsvp/events","exports"],function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){k.onerror&&k.onerror(a.detail)}function g(a,b){a===b?i(a,b):h(a,b)||i(a,b)}function h(a,b){var c,f=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(d(b)&&(f=b.then,e(f)))return f.call(b,function(d){return c?!0:(c=!0,b!==d?g(a,d):i(a,d),void 0)},function(b){return c?!0:(c=!0,j(a,b),void 0)}),!0}catch(h){return j(a,h),!0}return!1}function i(a,b){k.async(function(){a.trigger("promise:resolved",{detail:b}),a.isFulfilled=!0,a.fulfillmentValue=b})}function j(a,b){k.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedReason=b})}var k=a.config,l=b.EventTarget,m=function(a){var b=this,c=!1;if("function"!=typeof a)throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor");if(!(b instanceof m))return new m(a);var d=function(a){c||(c=!0,g(b,a))},e=function(a){c||(c=!0,j(b,a))};this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this),this.on("error",f);try{a(d,e)}catch(h){e(h)}},n=function(a,b,c,d){var f,i,k,l,m=e(c);if(m)try{f=c(d.detail),k=!0}catch(n){l=!0,i=n}else f=d.detail,k=!0;h(b,f)||(m&&k?g(b,f):l?j(b,i):"resolve"===a?g(b,f):"reject"===a&&j(b,f))};m.prototype={constructor:m,isRejected:void 0,isFulfilled:void 0,rejectedReason:void 0,fulfillmentValue:void 0,then:function(a,b){this.off("error",f);var c=new this.constructor(function(){});return this.isFulfilled&&k.async(function(b){n("resolve",c,a,{detail:b.fulfillmentValue})},this),this.isRejected&&k.async(function(a){n("reject",c,b,{detail:a.rejectedReason})},this),this.on("promise:resolved",function(b){n("resolve",c,a,b)}),this.on("promise:failed",function(a){n("reject",c,b,a)}),c},fail:function(a){return this.then(null,a)}},l.mixin(m.prototype),c.Promise=m}),a("rsvp/reject",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){return new d(function(b,c){c(a)})}var d=a.Promise;b.reject=c}),a("rsvp/resolve",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){return new d(function(b){b(a)})}var d=a.Promise;b.resolve=c}),a("rsvp/rethrow",["exports"],function(a){"use strict";function b(a){throw c.setTimeout(function(){throw a}),a}var c="undefined"==typeof global?this:global;a.rethrow=b}),a("rsvp",["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"],function(a,b,c,d,e,f,g,h,i,j,k){"use strict";function l(a,b){t[a]=b}var m=a.EventTarget,n=b.Promise,o=c.denodeify,p=d.all,q=e.hash,r=f.rethrow,s=g.defer,t=h.config,u=i.resolve,v=j.reject;k.Promise=n,k.EventTarget=m,k.all=p,k.hash=q,k.rethrow=r,k.defer=s,k.denodeify=o,k.configure=l,k.resolve=u,k.reject=v}),window.RSVP=b("rsvp")}(window);var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",function(){var a=this,b=a.ePub||{},c=a.ePub=function(){var a,b;return arguments[0]&&"string"==typeof arguments[0]&&(a=arguments[0],arguments[1]&&"object"==typeof arguments[1]?(b=arguments[1],b.bookPath=a):b={bookPath:a}),arguments[0]&&"object"==typeof arguments[0]&&(b=arguments[0]),new EPUBJS.Book(b)};_.extend(c,{noConflict:function(){return a.ePub=b,this}}),"function"==typeof define&&define.amd?define(function(){return c}):"undefined"!=typeof module&&module.exports&&(module.exports=c)}(),EPUBJS.Book=function(a){this.settings=_.defaults(a||{},{bookPath:null,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,fixedLayout:!1,responsive:!0,version:1,restore:!1,reload:!1,"goto":!1,styles:{}}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),0!=this.settings.storage&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,toc:new RSVP.defer},this.readyPromises=[this.ready.manifest.promise,this.ready.spine.promise,this.ready.metadata.promise,this.ready.cover.promise,this.ready.toc.promise],this.ready.all=RSVP.all(this.readyPromises),this.ready.all.then(this._ready),this._q=[],this.isRendered=!1,this._rendering=!1,this._displayQ=[],this.defer_opened=new RSVP.defer,this.opened=this.defer_opened.promise,this.settings.bookPath&&this.open(this.settings.bookPath,this.settings.reload),window.addEventListener("beforeunload",this.unload.bind(this),!1)},EPUBJS.Book.prototype.open=function(a,b){var c,d=this,e=this.isSaved(a);return this.settings.bookPath=a,this.bookUrl=this.urlFrom(a),e&&!b&&this.applySavedSettings(),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){return e&&d.settings.restore&&!b?d.restore():d.unpack()})):c=e&&this.settings.restore&&!b?this.restore():this.unpack(),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||c.then(d.storeOffline())),c.then(function(){d.defer_opened.resolve()}),c},EPUBJS.Book.prototype.unpack=function(a){var b=this,c=new EPUBJS.Parser,a=a||"META-INF/container.xml";return b.loadXml(b.bookUrl+a).then(function(a){return c.container(a)}).then(function(a){return b.settings.contentsPath=b.bookUrl+a.basePath,b.settings.packageUrl=b.bookUrl+a.packagePath,b.loadXml(b.settings.packageUrl)}).then(function(a){return c.package(a,b.settings.contentsPath)}).then(function(a){b.contents=a,b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.cover=b.contents.cover=b.settings.contentsPath+a.coverPath,b.spineNodeIndex=b.contents.spineNodeIndex=a.spineNodeIndex,b.ready.manifest.resolve(b.contents.manifest),b.ready.spine.resolve(b.contents.spine),b.ready.metadata.resolve(b.contents.metadata),b.ready.cover.resolve(b.contents.cover),a.tocPath&&(b.settings.tocUrl=b.settings.contentsPath+a.tocPath,b.loadXml(b.settings.tocUrl).then(function(a){return c.toc(a)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)}))}).fail(function(a){console.error(a)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a):this.settings.contained?this.zip.getXml(a):EPUBJS.core.request(a,"xml")},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=-1!=a.search("://"),d="/"==a[0],e=window.location,f=e.origin||e.protocol+"//"+e.host,g=document.getElementsByTagName("base");return g.length&&(b=g[0].href),c?a:!c&&d?b?b+a:f+a:c||d?void 0:"../"==a.slice(0,3)?EPUBJS.core.resolveUrl(b||e.pathname,a):b?b+a:f+EPUBJS.core.folder(e.pathname)+a},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=a.lastIndexOf("."),c=a.slice(b+1);return!c||"epub"!=c&&"zip"!=c?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=a+":"+this.settings.version,c=localStorage.getItem(b);return localStorage&&null!==c?!0:!1},EPUBJS.Book.prototype.removeSavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;localStorage.removeItem(a),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;return stored=JSON.parse(localStorage.getItem(a)),EPUBJS.VERSION!=stored.EPUBJSVERSION?!1:(this.settings=_.defaults(this.settings,stored),void 0)},EPUBJS.Book.prototype.saveSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(a,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.setItem(a,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.removeItem(a)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.render=new EPUBJS.Renderer(c),c._rendered(),c.startDisplay()},function(a){console.error(a)}),b.then(null,function(a){console.error(a)}),b},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.restore&&this.settings.goto?this.goto(this.settings.goto):this.settings.restore&&this.settings.previousLocationCfi?this.displayChapter(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b=this,c=this.settings.bookPath+":contents:"+this.settings.version,d=new RSVP.defer,e=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],a=a||!1,f=localStorage.getItem(c);return this.settings.clearSaved&&(a=!0),a||"undefined"==f||"null"==f||(this.contents=JSON.parse(f),e.forEach(function(c){b[c]=b.contents[c],b[c]||(a=!0)})),!a&&f&&this.contents&&this.settings.contentsPath?(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),d.resolve(),d.promise):this.open(this.settings.bookPath,!0)},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),0>e||e>=this.spine.length?(console.error("Not A Valid Chapter"),!1):(this.spinePos=e,this.chapter=new EPUBJS.Chapter(this.spine[e]),this._rendering=!0,c=f.render.chapter(this.chapter),d?c.then(function(b){b.currentLocationCfi=a,b.gotoCfiFragment(d)}):b&&c.then(function(a){a.gotoChapterEnd()}),this.settings.fromStorage||this.settings.contained||c.then(function(){f.preloadNextChapter()}),c.then(function(){var a;f._rendering=!1,f._displayQ.length&&(a=f._displayQ.unshift(),f.displayChapter.apply(f,a))}),c)):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.render.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.render.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.spinePos>this.spine.length?void 0:this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.spinePos<0?void 0:this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.gotoCfi=function(a){return this.isRendered?this.displayChapter(a):this._enqueue("gotoCfi",arguments)},EPUBJS.Book.prototype.goto=function(a){var b,c,d,e,f,g=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=-1==c.search("://")?this.settings.contentsPath+c:c,f=this.spineIndexByURL[e],c||(f=this.chapter?this.chapter.spinePos:0),"number"!=typeof f?!1:this.chapter&&f==this.chapter.spinePos?(d&&this.render.section(d),g.resolve(this.currentChapter),g.promise):this.displayChapter(f).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){return document.createElement("iframe"),this.spinePos>=this.spine.length?!1:(next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href),void 0)},EPUBJS.Book.prototype.storeOffline=function(){var a=this,b=_.values(this.manifest);return EPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){this.settings.styles[a]=b,this.render&&this.render.setStyle(a,b,c)},EPUBJS.Book.prototype.removeStyle=function(a){this.render&&this.render.removeStyle(a),delete this.settings.styles[a]},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&(this.saveSettings(),this.saveContents()),this.trigger("book:unload")},EPUBJS.Book.prototype.destroy=function(){window.removeEventListener("beforeunload",this.unload),this.currentChapter&&this.currentChapter.unload(),this.unload(),this.render&&this.render.remove()},EPUBJS.Book.prototype._enqueue=function(a,b){this._q.push({command:a,arguments:b})},EPUBJS.Book.prototype._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){var a=this;this.isRendered=!0,this.trigger("book:rendered"),this._q.forEach(function(b){a[b.command].apply(a,b.arguments)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;plugTypes=_.values(this.hooks);for(plugType in this.hooks)a=_.values(EPUBJS.Hooks[plugType]),a.forEach(function(a){b.registerHook(plugType,a)})},EPUBJS.Book.prototype.registerHook=function(a,b,c){var d=this;"undefined"!=typeof this.hooks[a]?"function"==typeof b?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?d.hooks[a].unshift(b):d.hooks[a].push(b)}):this.hooks[a]=[func]},EPUBJS.Book.prototype.triggerHooks=function(a,b,c){function d(){f--,0>=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,e.forEach(function(a){a(d,c)}),void 0)},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(a){this.href=a.href,this.id=a.id,this.spinePos=a.index,this.properties=a.properties,this.linear=a.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(a){return a?a.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer;return a?(this.tempUrl||(this.tempUrl=a.getUrl(this.href)),this.tempUrl):(b.resolve(this.href),b.promise)},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){return document.getElementById(a)},EPUBJS.core.getEls=function(a){return document.getElementsByClassName(a)},EPUBJS.core.request=function(a,b){function c(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var a; +a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):"blob"==b?d?this.response:new Blob([this.response]):this.response,f.resolve(a)}else f.reject(this)}var d=window.URL,e=d?"blob":"arraybuffer",f=new RSVP.defer,g=new XMLHttpRequest;return g.open("GET",a),g.onreadystatechange=c,"blob"==b&&(g.responseType=e),"json"==b&&g.setRequestHeader("Accept","application/json"),"xml"==b&&g.overrideMimeType("text/xml"),g.send(),f.promise},EPUBJS.core.toArray=function(a){var b=[];for(member in a){var c;a.hasOwnProperty(member)&&(c=a[member],c.ident=member,b.push(c))}return b},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/"),c=a.slice(0,b+1);return-1==b&&(c=""),c},EPUBJS.core.dataURLToBlob=function(a){var b=";base64,";if(-1==a.indexOf(b)){var c=a.split(","),d=c[0].split(":")[1],e=c[1];return new Blob([e],{type:d})}for(var c=a.split(b),d=c[0].split(":")[1],e=window.atob(c[1]),f=e.length,g=new Uint8Array(f),h=0;f>h;++h)g[h]=e.charCodeAt(h);return new Blob([g],{type:d})},EPUBJS.core.addScript=function(a,b,c){var d,e;e=!1,d=document.createElement("script"),d.type="text/javascript",d.async=!1,d.src=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.addScripts=function(a,b,c){var d=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.loadScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){var d,e;e=!1,d=document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.prefixed=function(a){var b=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length,e=0;if("undefined"!=typeof document.body.style[a])return a;for(;d>e;e++)if("undefined"!=typeof document.body.style[b[e]+c])return b[e]+c;return a},EPUBJS.core.resolveUrl=function(a,b){var c,d,e=[],f=a.split("/");return f.pop(),d=b.split("/"),d.forEach(function(a){".."===a?f.pop():e.push(a)}),c=f.concat(e),c.join("/")},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapter=function(a,b,c){var b=parseInt(b),a=a+1,d="/"+a+"/";return d+=2*(b+1),c&&(d+="["+c+"]"),d+="!"},EPUBJS.EpubCFI.prototype.generateFragment=function(a,b){var c=this.pathTo(a),d=[];return b&&d.push(b),c.forEach(function(a){var b="";b+=2*(a.index+1),a.id&&"EPUBJS"!=a.id.slice(0,6)&&(b+="["+a.id+"]"),d.push(b)}),d.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(var b,c=[];a&&null!==a.parentNode;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;return c},EPUBJS.EpubCFI.prototype.getChapter=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getFragment=function(a){var b=a.split("!");return b[1]},EPUBJS.EpubCFI.prototype.getOffset=function(a){var b=a.split(":");return[b[0],b[1]]},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f={};return f.chapter=this.getChapter(a),f.fragment=this.getFragment(a),f.spinePos=parseInt(f.chapter.split("/")[2])/2-1||0,b=f.chapter.match(/\[(.*)\]/),f.spineId=b?b[1]:!1,c=f.fragment.split("/"),d=c[c.length-1],f.sections=[],parseInt(d)%2&&(e=this.getOffset(),f.text=parseInt(e[0]),f.character=parseInt(e[1]),c.pop()),c.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),f.sections.push({index:b,id:d||!1}))}),f},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,b=b||document,d=a.sections,e=b.getElementsByTagName("html")[0],f=Array.prototype.slice.call(e.children);for(d.shift();d.length>0;)c=d.shift(),c.id?e=b.getElementById(c.id):(e=f[c.index],f||console.error("No Kids",e)),e||console.error("No Element For",c),f=Array.prototype.slice.call(e.children);return e},EPUBJS.Events=function(a,b){return this.events={},this.el=b?b:document.createElement("div"),a.createEvent=this.createEvent,a.tell=this.tell,a.listen=this.listen,a.deafen=this.deafen,a.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(a){var b=new CustomEvent(a);return this.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){var c;this.events[a]?c=this.events[a]:(console.warn("No event:",a,"defined yet, creating."),c=this.createEvent(a)),b&&(c.msg=b),this.el.dispatchEvent(c)},EPUBJS.Events.prototype.listen=function(a,b,c){return this.events[a]?(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1),void 0):(console.warn("No event:",a,"defined yet, creating."),this.createEvent(a),void 0)},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){function e(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(a){if(void 0===this[a]&&(this[a]={}),"object"!=typeof this[a])throw"Already registered: "+a;return this[a]}}}(),EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){var b=a.querySelector("rootfile"),c=b.getAttribute("full-path"),d=EPUBJS.core.folder(c);return{packagePath:c,basePath:d}},EPUBJS.Parser.prototype.package=function(a,b){var c=this;b&&(this.baseUrl=b);var d=a.querySelector("metadata"),e=a.querySelector("manifest"),f=a.querySelector("spine"),g=c.manifest(e),h=c.findTocPath(e),i=c.findCoverPath(e),j=Array.prototype.indexOf.call(f.parentNode.childNodes,f),k=c.spine(f,g),l={};return k.forEach(function(a){l[a.href]=a.index}),{metadata:c.metadata(d),spine:k,manifest:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}},EPUBJS.Parser.prototype.findTocPath=function(a){var b=a.querySelector("item[media-type='application/x-dtbncx+xml']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){var b=a.querySelector("item[properties='cover-image']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){var b={},c=this;return b.bookTitle=c.getElementText(a,"title"),b.creator=c.getElementText(a,"creator"),b.description=c.getElementText(a,"description"),b.pubdate=c.getElementText(a,"date"),b.publisher=c.getElementText(a,"publisher"),b.identifier=c.getElementText(a,"identifier"),b.language=c.getElementText(a,"language"),b.rights=c.getElementText(a,"rights"),b.modified_date=c.querySelectorText(a,"meta[property='dcterms:modified']"),b.layout=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.orientation=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.spread=c.querySelectorText(a,"meta[property='rendition:spread']"),b},EPUBJS.Parser.prototype.getElementText=function(a,b){var c,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);return d&&0!=d.length?(c=d[0],c.childNodes.length?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(a,b){var c=a.querySelector(b);return c&&c.childNodes.length?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){var b=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);return e.forEach(function(a){var d=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"";c[d]={href:b+e,type:f}}),c},EPUBJS.Parser.prototype.spine=function(a,b){var c=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d);return e.forEach(function(a,d){var e=a.getAttribute("idref"),f={id:e,linear:a.getAttribute("linear")||"",properties:a.getAttribute("properties")||"",href:b[e].href,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.toc=function(a){function b(a){var c,d=[],e=[],f=a.childNodes,g=Array.prototype.slice.call(f),h=g.length,i=h;if(0==h)return!1;for(;i--;)c=g[i],"navPoint"===c.nodeName&&e.push(c);return e.forEach(function(c){var e=c.getAttribute("id"),f=c.querySelector("content"),g=f.getAttribute("src"),h=(g.split("#"),c.querySelector("navLabel")),i=h.textContent?h.textContent:"",j=b(c);d.unshift({id:e,href:g,label:i,subitems:j,parent:a?a.getAttribute("id"):null})}),d}var c=a.querySelector("navMap");return b(c)},EPUBJS.Renderer=function(a){this.el=a.element,this.book=a,this.caches={},this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.iframe.scrolling="no",this.book.settings.width||this.book.settings.height?this.resizeIframe(this.book.settings.width||this.el.clientWidth,this.book.settings.height||this.el.clientHeight):this.resizeIframe("100%","100%"),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.throttle(this.onResized.bind(this),10),this.book.registerHook("beforeChapterDisplay",this.replaceLinks.bind(this),!0),this.determineStore()&&this.book.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Renderer.prototype.chapter=function(a){var b=this,c=!1;return this.book.settings.contained&&(c=this.book.zip),this.currentChapter&&(this.currentChapter.unload(),this.trigger("renderer:chapterUnloaded"),this.book.trigger("renderer:chapterUnloaded")),this.currentChapter=a,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,a.spinePos,a.id),this.visibileEl=!1,a.url(c).then(function(a){return b.setIframeSrc(a)})},EPUBJS.Renderer.prototype.onResized=function(){var a={width:this.iframe.clientWidth,height:this.iframe.clientHeight};this.doc&&this.reformat(),this.trigger("renderer:resized",a),this.book.trigger("book:resized",a)},EPUBJS.Renderer.prototype.reformat=function(){var a=this;a.book.settings.fixedLayout?a.fixedLayout():a.formatSpread(),setTimeout(function(){a.calcPages(),a.currentLocationCfi&&a.gotoCfiFragment(a.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.resizeIframe=function(a,b){this.iframe.height=b,isNaN(a)||0==a%2||(a+=1),this.iframe.width=a,this.onResized()},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth"),EPUBJS.Renderer.transform=EPUBJS.core.prefixed("transform")},EPUBJS.Renderer.prototype.setIframeSrc=function(a){var b=this,c=new RSVP.defer;return this.visible(!1),this.iframe.src=a,this.iframe.onload=function(){b.doc=b.iframe.contentDocument,b.docEl=b.doc.documentElement,b.bodyEl=b.doc.body,b.applyStyles(),b.book.settings.fixedLayout?b.fixedLayout():b.formatSpread(),b.beforeDisplay(function(){var a=b.currentChapter;b.calcPages(),c.resolve(b),a.cfi=b.currentLocationCfi=b.getPageCfi(),b.trigger("renderer:chapterDisplayed",a),b.book.trigger("renderer:chapterDisplayed",a),b.visible(!0)}),b.iframe.contentWindow.addEventListener("resize",b.resized,!1)},c.promise},EPUBJS.Renderer.prototype.formatSpread=function(){var a=2,b=800;this.elWidth=this.iframe.clientWidth,0!=this.elWidth%2&&(this.elWidth-=1),this.gap=Math.ceil(this.elWidth/8),0!=this.gap%2&&(this.gap+=1),this.elWidth1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.setLeft=function(a){this.doc.defaultView.scrollTo(a,0)},EPUBJS.Renderer.prototype.determineStore=function(){return this.book.fromStorage?"filesystem"==this.book.storage.getStorageType()?!1:this.book.store:this.book.contained?this.book.zip:!1},EPUBJS.Renderer.prototype.replace=function(a,b,c,d){var e=this.doc.querySelectorAll(a),f=Array.prototype.slice.call(e),g=f.length,h=function(a){g--,d&&d(a,g),0>=g&&c&&c(!0)};return 0===g?(c(!1),void 0):(f.forEach(function(a){b(a,h)}.bind(this)),void 0)},EPUBJS.Renderer.prototype.replaceWithStored=function(a,b,c,d){var e,f={},g=this.determineStore(),h=this.caches[a],i=this.book.settings.contentsPath,j=b,k=function(a,b){f[b]=a},l=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(a,b){var d=a.getAttribute(j),h=EPUBJS.core.resolveUrl(i,d),k=function(c){a.setAttribute(j,c),a.onload=function(){b(c,h)}};h in e?(k(e[h]),f[h]=e[h],delete e[h]):c(g,h,k,a)},l,k))},EPUBJS.Renderer.prototype.replaceLinks=function(a){var b=this;this.replace("a[href]",function(a,c){var d=a.getAttribute("href"),e=d.search("://");"#"==d[0],-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return b.book.goto(d),!1},c()},a)},EPUBJS.Renderer.prototype.page=function(a){return a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.leftPos=this.spreadWidth*(a-1),this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b,c;a&&(b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.spreadWidth)+1,this.page(c))},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.book.triggerHooks("beforeChapterDisplay",a.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(a){for(var b,a,c,d,e,f=a,g=[f],h=1e4,i=0;!b&&g.length;){if(a=g.shift(),this.isElementVisible(a)&&(b=a),!b&&a&&a.childElementCount>0){if(c=a.children,!c||!c.length)return b;d=c.length?c.length:0;for(var j=0;d>j;j++)c[j]!=e&&g.push(c[j])}if(!b&&0==g.length&&f&&null!==f.parentNode&&(g.push(f.parentNode),e=f,f=f.parentNode),i++,i>h){console.error("ENDLESS LOOP");break}}return b},EPUBJS.Renderer.prototype.getPageCfi=function(){var a=this.visibileEl;return this.visibileEl=this.findFirstVisible(a),this.visibileEl.id||(this.visibileEl.id="EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),b=this.epubcfi.getElement(a,this.doc),this.pageByElement(b)},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.bodyEl;return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.isElementVisible=function(a){var b;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect().left,b>=0&&be/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()}; \ No newline at end of file +EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),b.replaceLinks.bind(this),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()}; \ No newline at end of file diff --git a/demo/js/epub.min.js b/demo/js/epub.min.js index 9c227bf..c8e6319 100644 --- a/demo/js/epub.min.js +++ b/demo/js/epub.min.js @@ -1,2 +1,2 @@ -!function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.push,h=d.slice,i=d.concat,j=e.toString,k=e.hasOwnProperty,l=d.forEach,m=d.map,n=d.reduce,o=d.reduceRight,p=d.filter,q=d.every,r=d.some,s=d.indexOf,t=d.lastIndexOf,u=Array.isArray,v=Object.keys,w=f.bind,x=function(a){return a instanceof x?a:this instanceof x?(this._wrapped=a,void 0):new x(a)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.4.4";var y=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.indexf;){var h=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}return f},x.toArray=function(a){return a?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){return null==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){return h.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:h.call(a,Math.max(a.length-b,0))},x.rest=x.tail=x.drop=function(a,b,c){return h.call(a,null==b||c?1:b)},x.compact=function(a){return x.filter(a,x.identity)};var D=function(a,b,c){return y(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){return D(a,b,[])},x.without=function(a){return x.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);var e=c?x.map(a,c,d):a,f=[],g=[];return y(e,function(c,d){(b?d&&g[g.length-1]===c:x.contains(g,c))||(g.push(c),f.push(a[d]))}),f},x.union=function(){return x.uniq(i.apply(d,arguments))},x.intersection=function(a){var b=h.call(arguments,1);return x.filter(x.uniq(a),function(a){return x.every(b,function(b){return x.indexOf(b,a)>=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);return c},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;return f},x.bind=function(a,b){if(a.bind===w&&w)return w.apply(a,h.call(arguments,1));var c=h.call(arguments,2);return function(){return a.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);return 0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){var c,d,e,f,g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)};return function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},x.debounce=function(a,b,c){var d,e;return function(){var f=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;return clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return 0>=a?b():function(){return 1>--a?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&(b[b.length]=c);return b},x.values=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push(a[c]);return b},x.pairs=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push([c,a[c]]);return b},x.invert=function(a){var b={};for(var c in a)x.has(a,c)&&(b[a[c]]=c);return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var E=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==b+"";case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;c.push(a),d.push(b);var g=0,h=!0;if("[object Array]"==e){if(g=a.length,h=g==b.length)for(;g--&&(h=E(a[g],b[g],c,d)););}else{var i=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&i instanceof i&&x.isFunction(k)&&k instanceof k))return!1;for(var l in a)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(l in b)if(x.has(b,l)&&!g--)break;h=!g}}return c.pop(),d.pop(),h};x.isEqual=function(a,b){return E(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var F={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};F.unescape=x.invert(F.escape);var G={escape:RegExp("["+x.keys(F.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(F.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(G[a],function(b){return F[a][b]})}}),x.result=function(a,b){if(null==a)return null;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),L.call(this,c.apply(x,a))}})};var H=0;x.uniqueId=function(a){var b=++H+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=RegExp([(c.escape||I).source,(c.interpolate||I).source,(c.evaluate||I).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(K,function(a){return"\\"+J[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var L=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return L.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),function(a){"use strict";function b(a,b){f.async(function(){a.trigger("promise:resolved",{detail:b}),a.isResolved=!0,a.resolvedValue=b})}function c(a,b){f.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedValue=b})}function d(a){var b,c=[],d=new p,e=a.length;0===e&&d.resolve([]);var f=function(a){return function(b){g(a,b)}},g=function(a,b){c[a]=b,0===--e&&d.resolve(c)},h=function(a){d.reject(a)};for(b=0;e>b;b++)a[b].then(f(b),h);return d}function e(a,b){f[a]=b}var f={},g="undefined"!=typeof window?window:{},h=g.MutationObserver||g.WebKitMutationObserver;if("undefined"!=typeof process&&"[object process]"==={}.toString.call(process))f.async=function(a,b){process.nextTick(function(){a.call(b)})};else if(h){var i=[],j=new h(function(){var a=i.slice();i=[],a.forEach(function(a){var b=a[0],c=a[1];b.call(c)})}),k=document.createElement("div");j.observe(k,{attributes:!0}),window.addEventListener("unload",function(){j.disconnect(),j=null}),f.async=function(a,b){i.push([a,b]),k.setAttribute("drainQueue","drainQueue")}}else f.async=function(a,b){setTimeout(function(){a.call(b)},1)};var l=function(a,b){this.type=a;for(var c in b)b.hasOwnProperty(c)&&(this[c]=b[c])},m=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c][0]===b)return c;return-1},n=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b},o={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a},on:function(a,b,c){var d,e,f=n(this);for(a=a.split(/\s+/),c=c||this;e=a.shift();)d=f[e],d||(d=f[e]=[]),-1===m(d,b)&&d.push([b,c])},off:function(a,b){var c,d,e,f=n(this);for(a=a.split(/\s+/);d=a.shift();)b?(c=f[d],e=m(c,b),-1!==e&&c.splice(e,1)):f[d]=[]},trigger:function(a,b){var c,d,e,f,g,h=n(this);if(c=h[a])for(var i=0,j=c.length;j>i;i++)d=c[i],e=d[0],f=d[1],"object"!=typeof b&&(b={detail:b}),g=new l(a,b),e.call(f,g)}},p=function(){this.on("promise:resolved",function(a){this.trigger("success",{detail:a.detail})},this),this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this)},q=function(){},r=function(a,b,c,d){var e,f,g,h,i="function"==typeof c;if(i)try{e=c(d.detail),g=!0}catch(j){h=!0,f=j}else e=d.detail,g=!0;e&&"function"==typeof e.then?e.then(function(a){b.resolve(a)},function(a){b.reject(a)}):i&&g?b.resolve(e):h?b.reject(f):b[a](e)};p.prototype={then:function(a,b){var c=new p;return this.isResolved&&f.async(function(){r("resolve",c,a,{detail:this.resolvedValue})},this),this.isRejected&&f.async(function(){r("reject",c,b,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(b){r("resolve",c,a,b)}),this.on("promise:failed",function(a){r("reject",c,b,a)}),c},resolve:function(a){b(this,a),this.resolve=q,this.reject=q},reject:function(a){c(this,a),this.resolve=q,this.reject=q}},o.mixin(p.prototype),a.Promise=p,a.Event=l,a.EventTarget=o,a.all=d,a.configure=e}(window.RSVP={});var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",function(){var a=this,b=a.ePub||{},c=a.ePub=function(){var a,b;return arguments[0]&&"string"==typeof arguments[0]&&(a=arguments[0],arguments[1]&&"object"==typeof arguments[1]?(b=arguments[1],b.bookPath=a):b={bookPath:a}),arguments[0]&&"object"==typeof arguments[0]&&(b=arguments[0]),new EPUBJS.Book(b)};_.extend(c,{noConflict:function(){return a.ePub=b,this}}),"function"==typeof define&&define.amd?define(function(){return c}):"undefined"!=typeof module&&module.exports&&(module.exports=c)}(),EPUBJS.Book=function(a){this.settings=_.defaults(a||{},{bookPath:null,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,fixedLayout:!1,responsive:!0,version:1,restore:!1,reload:!1,"goto":!1,styles:{}}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),0!=this.settings.storage&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.Promise,spine:new RSVP.Promise,metadata:new RSVP.Promise,cover:new RSVP.Promise,toc:new RSVP.Promise},this.ready.all=RSVP.all(_.values(this.ready)),this.ready.all.then(this._ready),this._q=[],this.isRendered=!1,this._rendering=!1,this._displayQ=[],this.opened=new RSVP.Promise,this.settings.bookPath&&this.open(this.settings.bookPath,this.settings.reload),window.addEventListener("beforeunload",this.unload.bind(this),!1)},EPUBJS.Book.prototype.open=function(a,b){var c,d=this,e=this.isSaved(a);return this.settings.bookPath=a,this.bookUrl=this.urlFrom(a),e&&!b&&this.applySavedSettings(),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){return e&&d.settings.restore&&!b?d.restore():d.unpack()})):c=e&&this.settings.restore&&!b?this.restore():this.unpack(),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||c.then(d.storeOffline())),c.then(function(){d.opened.resolve()}),c},EPUBJS.Book.prototype.unpack=function(a){var b=this,c=new EPUBJS.Parser,a=a||"META-INF/container.xml";return b.loadXml(b.bookUrl+a).then(function(a){return c.container(a)}).then(function(a){return b.settings.contentsPath=b.bookUrl+a.basePath,b.settings.packageUrl=b.bookUrl+a.packagePath,b.loadXml(b.settings.packageUrl)}).then(function(a){return c.package(a,b.settings.contentsPath)}).then(function(a){b.contents=a,b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.cover=b.contents.cover=b.settings.contentsPath+a.coverPath,b.spineNodeIndex=b.contents.spineNodeIndex=a.spineNodeIndex,b.ready.manifest.resolve(b.contents.manifest),b.ready.spine.resolve(b.contents.spine),b.ready.metadata.resolve(b.contents.metadata),b.ready.cover.resolve(b.contents.cover),a.tocPath&&(b.settings.tocUrl=b.settings.contentsPath+a.tocPath,b.loadXml(b.settings.tocUrl).then(function(a){return c.toc(a)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)}))}).then(null,function(a){console.error(a)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a):this.settings.contained?this.zip.getXml(a):EPUBJS.core.request(a,"xml")},EPUBJS.Book.prototype.urlFrom=function(a){var b=-1!=a.search("://"),c="/"==a[0],d=window.location,e=d.origin||d.protocol+"//"+d.host;return b?a:!b&&c?e+a:b||c?void 0:"../"==a.slice(0,3)?EPUBJS.core.resolveUrl(d.href,a):e+EPUBJS.core.folder(d.pathname)+a},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=a.lastIndexOf("."),c=a.slice(b+1);return!c||"epub"!=c&&"zip"!=c?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=a+":"+this.settings.version,c=localStorage.getItem(b);return localStorage&&null!==c?!0:!1},EPUBJS.Book.prototype.removeSavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;localStorage.removeItem(a),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;return stored=JSON.parse(localStorage.getItem(a)),EPUBJS.VERSION!=stored.EPUBJSVERSION?!1:(this.settings=_.defaults(this.settings,stored),void 0)},EPUBJS.Book.prototype.saveSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(a,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.setItem(a,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.removeItem(a)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.render=new EPUBJS.Renderer(c),c._rendered(),c.startDisplay()},function(a){console.error(a)}),b.then(null,function(a){console.error(a)}),b},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.restore&&this.settings.goto?this.goto(this.settings.goto):this.settings.restore&&this.settings.previousLocationCfi?this.displayChapter(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b=this,c=this.settings.bookPath+":contents:"+this.settings.version,d=new RSVP.Promise,e=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],a=a||!1,f=localStorage.getItem(c);return this.settings.clearSaved&&(a=!0),a||"undefined"==f||"null"==f||(this.contents=JSON.parse(f),e.forEach(function(c){b[c]=b.contents[c],b[c]||(a=!0)})),!a&&f&&this.contents&&this.settings.contentsPath?(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),d.resolve(),d):this.open(this.settings.bookPath,!0)},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),e>=this.spine.length?!1:0>e?!1:(this.spinePos=e,this.chapter=new EPUBJS.Chapter(this.spine[e]),this._rendering=!0,c=f.render.chapter(this.chapter),d?c.then(function(b){b.currentLocationCfi=a,b.gotoCfiFragment(d)}):b&&c.then(function(a){a.gotoChapterEnd()}),this.settings.fromStorage||this.settings.contained||c.then(function(){f.preloadNextChapter()}),c.then(function(){var a;f._rendering=!1,f._displayQ.length&&(a=f._displayQ.unshift(),f.displayChapter.apply(f,a))}),c)):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.render.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.render.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.goto=function(a){var b,c,d,e,f;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=-1==c.search("://")?this.settings.contentsPath+c:c,f=this.spineIndexByURL[e],c||(f=this.chapter?this.chapter.spinePos:0),"number"!=typeof f?!1:this.chapter&&f==this.chapter.spinePos?(d&&this.render.section(d),(new RSVP.Promise).resolve(this.currentChapter)):this.displayChapter(f).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){return document.createElement("iframe"),this.spinePos>=this.spine.length?!1:(next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href),void 0)},EPUBJS.Book.prototype.storeOffline=function(){var a=this,b=_.values(this.manifest);return EPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){this.settings.styles[a]=b,this.render&&this.render.setStyle(a,b,c)},EPUBJS.Book.prototype.removeStyle=function(a){this.render&&this.render.removeStyle(a),delete this.settings.styles[a]},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&(this.saveSettings(),this.saveContents()),this.trigger("book:unload")},EPUBJS.Book.prototype.destroy=function(){window.removeEventListener("beforeunload",this.unload),this.currentChapter&&this.currentChapter.unload(),this.unload(),this.render&&this.render.remove()},EPUBJS.Book.prototype._enqueue=function(a,b){this._q.push({command:a,arguments:b})},EPUBJS.Book.prototype._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){var a=this;this.isRendered=!0,this.trigger("book:rendered"),this._q.forEach(function(b){a[b.command].apply(a,b.arguments)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;plugTypes=_.values(this.hooks);for(plugType in this.hooks)a=_.values(EPUBJS.Hooks[plugType]),a.forEach(function(a){b.registerHook(plugType,a)})},EPUBJS.Book.prototype.registerHook=function(a,b,c){var d=this;"undefined"!=typeof this.hooks[a]?"function"==typeof b?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?d.hooks[a].unshift(b):d.hooks[a].push(b)}):this.hooks[a]=[func]},EPUBJS.Book.prototype.triggerHooks=function(a,b,c){function d(){f--,0>=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,e.forEach(function(a){a(d,c)}),void 0)},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(a){this.href=a.href,this.id=a.id,this.spinePos=a.index,this.properties=a.properties,this.linear=a.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(a){return a?a.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.Promise;return a?(this.tempUrl||(this.tempUrl=a.getUrl(this.href)),this.tempUrl):(b.resolve(this.href),b)},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){return document.getElementById(a)},EPUBJS.core.getEls=function(a){return document.getElementsByClassName(a)},EPUBJS.core.request=function(a,b){function c(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var a;a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):"blob"==b?d?this.response:new Blob([this.response]):this.response,f.resolve(a)}else f.reject(this)}var d=window.URL,e=d?"blob":"arraybuffer",f=new RSVP.Promise,g=new XMLHttpRequest;return g.open("GET",a),g.onreadystatechange=c,"blob"==b&&(g.responseType=e),"json"==b&&g.setRequestHeader("Accept","application/json"),"xml"==b&&g.overrideMimeType("text/xml"),g.send(),f},EPUBJS.core.toArray=function(a){var b=[];for(member in a){var c;a.hasOwnProperty(member)&&(c=a[member],c.ident=member,b.push(c))}return b},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/"),c=a.slice(0,b+1);return-1==b&&(c=""),c},EPUBJS.core.dataURLToBlob=function(a){var b=";base64,";if(-1==a.indexOf(b)){var c=a.split(","),d=c[0].split(":")[1],e=c[1];return new Blob([e],{type:d})}for(var c=a.split(b),d=c[0].split(":")[1],e=window.atob(c[1]),f=e.length,g=new Uint8Array(f),h=0;f>h;++h)g[h]=e.charCodeAt(h);return new Blob([g],{type:d})},EPUBJS.core.addScript=function(a,b,c){var d,e;e=!1,d=document.createElement("script"),d.type="text/javascript",d.async=!1,d.src=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.addScripts=function(a,b,c){var d=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.loadScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){var d,e;e=!1,d=document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.prefixed=function(a){var b=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length,e=0;if("undefined"!=typeof document.body.style[a])return a;for(;d>e;e++)if("undefined"!=typeof document.body.style[b[e]+c])return b[e]+c;return a},EPUBJS.core.resolveUrl=function(a,b){var c,d,e=[],f=a.split("/");return f.pop(),d=b.split("/"),d.forEach(function(a){".."===a?f.pop():e.push(a)}),c=f.concat(e),c.join("/")},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapter=function(a,b,c){var b=parseInt(b),a=a+1,d="/"+a+"/";return d+=2*(b+1),c&&(d+="["+c+"]"),d+="!"},EPUBJS.EpubCFI.prototype.generateFragment=function(a,b){var c=this.pathTo(a),d=[];return b&&d.push(b),c.forEach(function(a){var b="";b+=2*(a.index+1),a.id&&"EPUBJS"!=a.id.slice(0,6)&&(b+="["+a.id+"]"),d.push(b)}),d.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(var b,c=[];a&&null!==a.parentNode;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;return c},EPUBJS.EpubCFI.prototype.getChapter=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getFragment=function(a){var b=a.split("!");return b[1]},EPUBJS.EpubCFI.prototype.getOffset=function(a){var b=a.split(":");return[b[0],b[1]]},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f={};return f.chapter=this.getChapter(a),f.fragment=this.getFragment(a),f.spinePos=parseInt(f.chapter.split("/")[2])/2-1||0,b=f.chapter.match(/\[(.*)\]/),f.spineId=b[1]||!1,c=f.fragment.split("/"),d=c[c.length-1],f.sections=[],parseInt(d)%2&&(e=this.getOffset(),f.text=parseInt(e[0]),f.character=parseInt(e[1]),c.pop()),c.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),f.sections.push({index:b,id:d||!1}))}),f},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,b=b||document,d=a.sections,e=b.getElementsByTagName("html")[0],f=Array.prototype.slice.call(e.children);for(d.shift();d.length>0;)c=d.shift(),c.id?e=b.getElementById(c.id):(e=f[c.index],f||console.error("No Kids",e)),e||console.error("No Element For",c),f=Array.prototype.slice.call(e.children);return e},EPUBJS.Events=function(a,b){return this.events={},this.el=b?b:document.createElement("div"),a.createEvent=this.createEvent,a.tell=this.tell,a.listen=this.listen,a.deafen=this.deafen,a.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(a){var b=new CustomEvent(a); -return this.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){var c;this.events[a]?c=this.events[a]:(console.warn("No event:",a,"defined yet, creating."),c=this.createEvent(a)),b&&(c.msg=b),this.el.dispatchEvent(c)},EPUBJS.Events.prototype.listen=function(a,b,c){return this.events[a]?(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1),void 0):(console.warn("No event:",a,"defined yet, creating."),this.createEvent(a),void 0)},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){function e(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(a){if(void 0===this[a]&&(this[a]={}),"object"!=typeof this[a])throw"Already registered: "+a;return this[a]}}}(),EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){var b=a.querySelector("rootfile"),c=b.getAttribute("full-path"),d=EPUBJS.core.folder(c);return{packagePath:c,basePath:d}},EPUBJS.Parser.prototype.package=function(a,b){var c=this;b&&(this.baseUrl=b);var d=a.querySelector("metadata"),e=a.querySelector("manifest"),f=a.querySelector("spine"),g=c.manifest(e),h=c.findTocPath(e),i=c.findCoverPath(e),j=Array.prototype.indexOf.call(f.parentNode.childNodes,f),k=c.spine(f,g),l={};return k.forEach(function(a){l[a.href]=a.index}),{metadata:c.metadata(d),spine:k,manifest:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}},EPUBJS.Parser.prototype.findTocPath=function(a){var b=a.querySelector("item[media-type='application/x-dtbncx+xml']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){var b=a.querySelector("item[properties='cover-image']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){var b={},c=this;return b.bookTitle=c.getElementText(a,"title"),b.creator=c.getElementText(a,"creator"),b.description=c.getElementText(a,"description"),b.pubdate=c.getElementText(a,"date"),b.publisher=c.getElementText(a,"publisher"),b.identifier=c.getElementText(a,"identifier"),b.language=c.getElementText(a,"language"),b.rights=c.getElementText(a,"rights"),b.modified_date=c.querySelectorText(a,"meta[property='dcterms:modified']"),b.layout=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.orientation=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.spread=c.querySelectorText(a,"meta[property='rendition:spread']"),b},EPUBJS.Parser.prototype.getElementText=function(a,b){var c,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);return d&&0!=d.length?(c=d[0],c.childNodes.length?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(a,b){var c=a.querySelector(b);return c&&c.childNodes.length?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){var b=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);return e.forEach(function(a){var d=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"";c[d]={href:b+e,type:f}}),c},EPUBJS.Parser.prototype.spine=function(a,b){var c=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d);return e.forEach(function(a,d){var e=a.getAttribute("idref"),f={id:e,linear:a.getAttribute("linear")||"",properties:a.getAttribute("properties")||"",href:b[e].href,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.toc=function(a){function b(a){var c,d=[],e=[],f=a.childNodes,g=Array.prototype.slice.call(f),h=g.length,i=h;if(0==h)return!1;for(;i--;)c=g[i],"navPoint"===c.nodeName&&e.push(c);return e.forEach(function(c){var e=c.getAttribute("id"),f=c.querySelector("content"),g=f.getAttribute("src"),h=(g.split("#"),c.querySelector("navLabel")),i=h.textContent?h.textContent:"",j=b(c);d.unshift({id:e,href:g,label:i,subitems:j,parent:a?a.getAttribute("id"):null})}),d}var c=a.querySelector("navMap");return b(c)},EPUBJS.Renderer=function(a){this.el=a.element,this.book=a,this.caches={},this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.iframe.scrolling="no",this.book.settings.width||this.book.settings.height?this.resizeIframe(!1,this.book.settings.width||this.el.clientWidth,this.book.settings.height||this.el.clientHeight):(this.resizeIframe(!1,this.el.clientWidth,this.el.clientHeight),this.on("renderer:resized",this.resizeIframe,this)),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.debounce(this.onResized.bind(this),10),window.addEventListener("resize",this.resized,!1),this.book.registerHook("beforeChapterDisplay",this.replaceLinks.bind(this),!0),this.determineStore()&&this.book.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Renderer.prototype.chapter=function(a){var b=this,c=!1;return this.book.settings.contained&&(c=this.book.zip),this.currentChapter&&(this.currentChapter.unload(),this.trigger("renderer:chapterUnloaded"),this.book.trigger("renderer:chapterUnloaded")),this.currentChapter=a,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,a.spinePos,a.id),this.visibileEl=!1,a.url(c).then(function(a){return b.setIframeSrc(a)})},EPUBJS.Renderer.prototype.onResized=function(){var a={width:this.el.clientWidth,height:this.el.clientHeight};this.trigger("renderer:resized",a),this.book.trigger("book:resized",a),this.reformat()},EPUBJS.Renderer.prototype.reformat=function(){var a=this;a.book.settings.fixedLayout?a.fixedLayout():a.formatSpread(),setTimeout(function(){a.calcPages(),a.currentLocationCfi&&a.gotoCfiFragment(a.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.resizeIframe=function(a,b,c){var d,e;a?(d=a.width,e=a.height):(d=b,e=c),this.iframe.height=e,0!=d%2&&(d+=1),this.iframe.width=d},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth"),EPUBJS.Renderer.transform=EPUBJS.core.prefixed("transform")},EPUBJS.Renderer.prototype.setIframeSrc=function(a){var b=this,c=new RSVP.Promise;return this.visible(!1),this.iframe.src=a,this.iframe.onload=function(){b.doc=b.iframe.contentDocument,b.docEl=b.doc.documentElement,b.bodyEl=b.doc.body,b.applyStyles(),b.book.settings.fixedLayout?b.fixedLayout():b.formatSpread(),b.beforeDisplay(function(){b.calcPages(),c.resolve(b),b.currentLocationCfi=b.getPageCfi(),b.trigger("renderer:chapterDisplayed",b.currentChapter),b.book.trigger("renderer:chapterDisplayed",b.currentChapter),b.visible(!0)})},c},EPUBJS.Renderer.prototype.formatSpread=function(){var a=2,b=800;this.colWidth&&(this.OldcolWidth=this.colWidth,this.OldspreadWidth=this.spreadWidth),this.elWidth=this.iframe.width,this.gap=this.gap||Math.ceil(this.elWidth/8),this.elWidth1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.setLeft=function(a){this.doc.defaultView.scrollTo(a,0)},EPUBJS.Renderer.prototype.determineStore=function(){return this.book.fromStorage?"filesystem"==this.book.storage.getStorageType()?!1:this.book.store:this.book.contained?this.book.zip:!1},EPUBJS.Renderer.prototype.replace=function(a,b,c,d){var e=this.doc.querySelectorAll(a),f=Array.prototype.slice.call(e),g=f.length,h=function(a){g--,d&&d(a,g),0>=g&&c&&c(!0)};return 0===g?(c(!1),void 0):(f.forEach(function(a){b(a,h)}.bind(this)),void 0)},EPUBJS.Renderer.prototype.replaceWithStored=function(a,b,c,d){var e,f={},g=this.determineStore(),h=this.caches[a],i=this.book.settings.contentsPath,j=b,k=function(a,b){f[b]=a},l=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(a,b){var d=a.getAttribute(j),h=EPUBJS.core.resolveUrl(i,d),k=function(c){a.setAttribute(j,c),a.onload=function(){b(c,h)}};h in e?(k(e[h]),f[h]=e[h],delete e[h]):c(g,h,k,a)},l,k))},EPUBJS.Renderer.prototype.replaceLinks=function(a){var b=this;this.replace("a[href]",function(a,c){var d=a.getAttribute("href"),e=d.search("://");"#"==d[0],-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return b.book.goto(d),!1},c()},a)},EPUBJS.Renderer.prototype.page=function(a){return a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.leftPos=this.spreadWidth*(a-1),this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b,c;a&&(b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.spreadWidth)+1,this.page(c))},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.book.triggerHooks("beforeChapterDisplay",a.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(a){for(var b,a,c,d,e,f=a,g=[f],h=1e4,i=0;!b&&g.length;){if(a=g.shift(),this.isElementVisible(a)&&(b=a),!b&&a&&a.childElementCount>0){c=a.children,d=c.length;for(var j=0;d>j;j++)c[j]!=e&&g.push(c[j])}if(!b&&0==g.length&&f&&null!==f.parentNode&&(g.push(f.parentNode),e=f,f=f.parentNode),i++,i>h){console.error("ENDLESS LOOP");break}}return b},EPUBJS.Renderer.prototype.getPageCfi=function(){var a=this.visibileEl;return this.visibileEl=this.findFirstVisible(a),this.visibileEl.id||(this.visibileEl.id="EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),b=this.epubcfi.getElement(a,this.doc),this.pageByElement(b)},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.bodyEl;return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.isElementVisible=function(a){var b;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect().left,b>=0&&be;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.indexf;){var h=f+g>>>1;e>c.call(d,a[h])?f=h+1:g=h}return f},x.toArray=function(a){return a?x.isArray(a)?h.call(a):a.length===+a.length?x.map(a,x.identity):x.values(a):[]},x.size=function(a){return null==a?0:a.length===+a.length?a.length:x.keys(a).length},x.first=x.head=x.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:h.call(a,0,b)},x.initial=function(a,b,c){return h.call(a,0,a.length-(null==b||c?1:b))},x.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:h.call(a,Math.max(a.length-b,0))},x.rest=x.tail=x.drop=function(a,b,c){return h.call(a,null==b||c?1:b)},x.compact=function(a){return x.filter(a,x.identity)};var D=function(a,b,c){return y(a,function(a){x.isArray(a)?b?g.apply(c,a):D(a,b,c):c.push(a)}),c};x.flatten=function(a,b){return D(a,b,[])},x.without=function(a){return x.difference(a,h.call(arguments,1))},x.uniq=x.unique=function(a,b,c,d){x.isFunction(b)&&(d=c,c=b,b=!1);var e=c?x.map(a,c,d):a,f=[],g=[];return y(e,function(c,d){(b?d&&g[g.length-1]===c:x.contains(g,c))||(g.push(c),f.push(a[d]))}),f},x.union=function(){return x.uniq(i.apply(d,arguments))},x.intersection=function(a){var b=h.call(arguments,1);return x.filter(x.uniq(a),function(a){return x.every(b,function(b){return x.indexOf(b,a)>=0})})},x.difference=function(a){var b=i.apply(d,h.call(arguments,1));return x.filter(a,function(a){return!x.contains(b,a)})},x.zip=function(){for(var a=h.call(arguments),b=x.max(x.pluck(a,"length")),c=Array(b),d=0;b>d;d++)c[d]=x.pluck(a,""+d);return c},x.object=function(a,b){if(null==a)return{};for(var c={},d=0,e=a.length;e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c},x.indexOf=function(a,b,c){if(null==a)return-1;var d=0,e=a.length;if(c){if("number"!=typeof c)return d=x.sortedIndex(a,b),a[d]===b?d:-1;d=0>c?Math.max(0,e+c):c}if(s&&a.indexOf===s)return a.indexOf(b,c);for(;e>d;d++)if(a[d]===b)return d;return-1},x.lastIndexOf=function(a,b,c){if(null==a)return-1;var d=null!=c;if(t&&a.lastIndexOf===t)return d?a.lastIndexOf(b,c):a.lastIndexOf(b);for(var e=d?c:a.length;e--;)if(a[e]===b)return e;return-1},x.range=function(a,b,c){1>=arguments.length&&(b=a||0,a=0),c=arguments[2]||1;for(var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=Array(d);d>e;)f[e++]=a,a+=c;return f},x.bind=function(a,b){if(a.bind===w&&w)return w.apply(a,h.call(arguments,1));var c=h.call(arguments,2);return function(){return a.apply(b,c.concat(h.call(arguments)))}},x.partial=function(a){var b=h.call(arguments,1);return function(){return a.apply(this,b.concat(h.call(arguments)))}},x.bindAll=function(a){var b=h.call(arguments,1);return 0===b.length&&(b=x.functions(a)),y(b,function(b){a[b]=x.bind(a[b],a)}),a},x.memoize=function(a,b){var c={};return b||(b=x.identity),function(){var d=b.apply(this,arguments);return x.has(c,d)?c[d]:c[d]=a.apply(this,arguments)}},x.delay=function(a,b){var c=h.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)},x.defer=function(a){return x.delay.apply(x,[a,1].concat(h.call(arguments,1)))},x.throttle=function(a,b){var c,d,e,f,g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)};return function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},x.debounce=function(a,b,c){var d,e;return function(){var f=this,g=arguments,h=function(){d=null,c||(e=a.apply(f,g))},i=c&&!d;return clearTimeout(d),d=setTimeout(h,b),i&&(e=a.apply(f,g)),e}},x.once=function(a){var b,c=!1;return function(){return c?b:(c=!0,b=a.apply(this,arguments),a=null,b)}},x.wrap=function(a,b){return function(){var c=[a];return g.apply(c,arguments),b.apply(this,c)}},x.compose=function(){var a=arguments;return function(){for(var b=arguments,c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},x.after=function(a,b){return 0>=a?b():function(){return 1>--a?b.apply(this,arguments):void 0}},x.keys=v||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)x.has(a,c)&&(b[b.length]=c);return b},x.values=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push(a[c]);return b},x.pairs=function(a){var b=[];for(var c in a)x.has(a,c)&&b.push([c,a[c]]);return b},x.invert=function(a){var b={};for(var c in a)x.has(a,c)&&(b[a[c]]=c);return b},x.functions=x.methods=function(a){var b=[];for(var c in a)x.isFunction(a[c])&&b.push(c);return b.sort()},x.extend=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)a[c]=b[c]}),a},x.pick=function(a){var b={},c=i.apply(d,h.call(arguments,1));return y(c,function(c){c in a&&(b[c]=a[c])}),b},x.omit=function(a){var b={},c=i.apply(d,h.call(arguments,1));for(var e in a)x.contains(c,e)||(b[e]=a[e]);return b},x.defaults=function(a){return y(h.call(arguments,1),function(b){if(b)for(var c in b)null==a[c]&&(a[c]=b[c])}),a},x.clone=function(a){return x.isObject(a)?x.isArray(a)?a.slice():x.extend({},a):a},x.tap=function(a,b){return b(a),a};var E=function(a,b,c,d){if(a===b)return 0!==a||1/a==1/b;if(null==a||null==b)return a===b;a instanceof x&&(a=a._wrapped),b instanceof x&&(b=b._wrapped);var e=j.call(a);if(e!=j.call(b))return!1;switch(e){case"[object String]":return a==b+"";case"[object Number]":return a!=+a?b!=+b:0==a?1/a==1/b:a==+b;case"[object Date]":case"[object Boolean]":return+a==+b;case"[object RegExp]":return a.source==b.source&&a.global==b.global&&a.multiline==b.multiline&&a.ignoreCase==b.ignoreCase}if("object"!=typeof a||"object"!=typeof b)return!1;for(var f=c.length;f--;)if(c[f]==a)return d[f]==b;c.push(a),d.push(b);var g=0,h=!0;if("[object Array]"==e){if(g=a.length,h=g==b.length)for(;g--&&(h=E(a[g],b[g],c,d)););}else{var i=a.constructor,k=b.constructor;if(i!==k&&!(x.isFunction(i)&&i instanceof i&&x.isFunction(k)&&k instanceof k))return!1;for(var l in a)if(x.has(a,l)&&(g++,!(h=x.has(b,l)&&E(a[l],b[l],c,d))))break;if(h){for(l in b)if(x.has(b,l)&&!g--)break;h=!g}}return c.pop(),d.pop(),h};x.isEqual=function(a,b){return E(a,b,[],[])},x.isEmpty=function(a){if(null==a)return!0;if(x.isArray(a)||x.isString(a))return 0===a.length;for(var b in a)if(x.has(a,b))return!1;return!0},x.isElement=function(a){return!(!a||1!==a.nodeType)},x.isArray=u||function(a){return"[object Array]"==j.call(a)},x.isObject=function(a){return a===Object(a)},y(["Arguments","Function","String","Number","Date","RegExp"],function(a){x["is"+a]=function(b){return j.call(b)=="[object "+a+"]"}}),x.isArguments(arguments)||(x.isArguments=function(a){return!(!a||!x.has(a,"callee"))}),"function"!=typeof/./&&(x.isFunction=function(a){return"function"==typeof a}),x.isFinite=function(a){return isFinite(a)&&!isNaN(parseFloat(a))},x.isNaN=function(a){return x.isNumber(a)&&a!=+a},x.isBoolean=function(a){return a===!0||a===!1||"[object Boolean]"==j.call(a)},x.isNull=function(a){return null===a},x.isUndefined=function(a){return void 0===a},x.has=function(a,b){return k.call(a,b)},x.noConflict=function(){return a._=b,this},x.identity=function(a){return a},x.times=function(a,b,c){for(var d=Array(a),e=0;a>e;e++)d[e]=b.call(c,e);return d},x.random=function(a,b){return null==b&&(b=a,a=0),a+Math.floor(Math.random()*(b-a+1))};var F={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};F.unescape=x.invert(F.escape);var G={escape:RegExp("["+x.keys(F.escape).join("")+"]","g"),unescape:RegExp("("+x.keys(F.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(G[a],function(b){return F[a][b]})}}),x.result=function(a,b){if(null==a)return null;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),L.call(this,c.apply(x,a))}})};var H=0;x.uniqueId=function(a){var b=++H+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var I=/(.)^/,J={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},K=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=RegExp([(c.escape||I).source,(c.interpolate||I).source,(c.evaluate||I).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(K,function(a){return"\\"+J[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var L=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],L.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return L.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}.call(this),function(){var a,b;!function(){var c={},d={};a=function(a,b,d){c[a]={deps:b,callback:d}},b=function(a){if(d[a])return d[a];d[a]={};var e=c[a];if(!e)throw new Error("Module '"+a+"' not found.");for(var f,g=e.deps,h=e.callback,i=[],j=0,k=g.length;k>j;j++)"exports"===g[j]?i.push(f={}):i.push(b(g[j]));var l=h.apply(this,i);return d[a]=f||l}}(),a("rsvp/all",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){if("[object Array]"!==Object.prototype.toString.call(a))throw new TypeError("You must pass an array to all.");return new d(function(b,c){function d(a){return function(b){e(a,b)}}function e(a,c){g[a]=c,0===--h&&b(g)}var f,g=[],h=a.length;0===h&&b([]);for(var i=0;ic;c++)if(a[c][0]===b)return c;return-1},d=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b},e={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a},on:function(a,b,e){var f,g,h=d(this);for(a=a.split(/\s+/),e=e||this;g=a.shift();)f=h[g],f||(f=h[g]=[]),-1===c(f,b)&&f.push([b,e])},off:function(a,b){var e,f,g,h=d(this);for(a=a.split(/\s+/);f=a.shift();)b?(e=h[f],g=c(e,b),-1!==g&&e.splice(g,1)):h[f]=[]},trigger:function(a,c){var e,f,g,h,i,j=d(this);if(e=j[a])for(var k=0;k2?a(Array.prototype.slice.call(arguments,1)):a(d)}}function e(a){return function(){var b,c,e=Array.prototype.slice.call(arguments),h=this,i=new f(function(a,d){b=a,c=d});return g(e).then(function(e){e.push(d(b,c));try{a.apply(h,e)}catch(f){c(f)}}),i}}var f=a.Promise,g=b.all;c.denodeify=e}),a("rsvp/promise",["rsvp/config","rsvp/events","exports"],function(a,b,c){"use strict";function d(a){return e(a)||"object"==typeof a&&null!==a}function e(a){return"function"==typeof a}function f(a){k.onerror&&k.onerror(a.detail)}function g(a,b){a===b?i(a,b):h(a,b)||i(a,b)}function h(a,b){var c,f=null;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(d(b)&&(f=b.then,e(f)))return f.call(b,function(d){return c?!0:(c=!0,b!==d?g(a,d):i(a,d),void 0)},function(b){return c?!0:(c=!0,j(a,b),void 0)}),!0}catch(h){return j(a,h),!0}return!1}function i(a,b){k.async(function(){a.trigger("promise:resolved",{detail:b}),a.isFulfilled=!0,a.fulfillmentValue=b})}function j(a,b){k.async(function(){a.trigger("promise:failed",{detail:b}),a.isRejected=!0,a.rejectedReason=b})}var k=a.config,l=b.EventTarget,m=function(a){var b=this,c=!1;if("function"!=typeof a)throw new TypeError("You must pass a resolver function as the sole argument to the promise constructor");if(!(b instanceof m))return new m(a);var d=function(a){c||(c=!0,g(b,a))},e=function(a){c||(c=!0,j(b,a))};this.on("promise:failed",function(a){this.trigger("error",{detail:a.detail})},this),this.on("error",f);try{a(d,e)}catch(h){e(h)}},n=function(a,b,c,d){var f,i,k,l,m=e(c);if(m)try{f=c(d.detail),k=!0}catch(n){l=!0,i=n}else f=d.detail,k=!0;h(b,f)||(m&&k?g(b,f):l?j(b,i):"resolve"===a?g(b,f):"reject"===a&&j(b,f))};m.prototype={constructor:m,isRejected:void 0,isFulfilled:void 0,rejectedReason:void 0,fulfillmentValue:void 0,then:function(a,b){this.off("error",f);var c=new this.constructor(function(){});return this.isFulfilled&&k.async(function(b){n("resolve",c,a,{detail:b.fulfillmentValue})},this),this.isRejected&&k.async(function(a){n("reject",c,b,{detail:a.rejectedReason})},this),this.on("promise:resolved",function(b){n("resolve",c,a,b)}),this.on("promise:failed",function(a){n("reject",c,b,a)}),c},fail:function(a){return this.then(null,a)}},l.mixin(m.prototype),c.Promise=m}),a("rsvp/reject",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){return new d(function(b,c){c(a)})}var d=a.Promise;b.reject=c}),a("rsvp/resolve",["rsvp/promise","exports"],function(a,b){"use strict";function c(a){return new d(function(b){b(a)})}var d=a.Promise;b.resolve=c}),a("rsvp/rethrow",["exports"],function(a){"use strict";function b(a){throw c.setTimeout(function(){throw a}),a}var c="undefined"==typeof global?this:global;a.rethrow=b}),a("rsvp",["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"],function(a,b,c,d,e,f,g,h,i,j,k){"use strict";function l(a,b){t[a]=b}var m=a.EventTarget,n=b.Promise,o=c.denodeify,p=d.all,q=e.hash,r=f.rethrow,s=g.defer,t=h.config,u=i.resolve,v=j.reject;k.Promise=n,k.EventTarget=m,k.all=p,k.hash=q,k.rethrow=r,k.defer=s,k.denodeify=o,k.configure=l,k.resolve=u,k.reject=v}),window.RSVP=b("rsvp")}(window);var EPUBJS=EPUBJS||{};EPUBJS.VERSION="0.1.5",EPUBJS.plugins=EPUBJS.plugins||{},EPUBJS.filePath=EPUBJS.filePath||"/epubjs/",function(){var a=this,b=a.ePub||{},c=a.ePub=function(){var a,b;return arguments[0]&&"string"==typeof arguments[0]&&(a=arguments[0],arguments[1]&&"object"==typeof arguments[1]?(b=arguments[1],b.bookPath=a):b={bookPath:a}),arguments[0]&&"object"==typeof arguments[0]&&(b=arguments[0]),new EPUBJS.Book(b)};_.extend(c,{noConflict:function(){return a.ePub=b,this}}),"function"==typeof define&&define.amd?define(function(){return c}):"undefined"!=typeof module&&module.exports&&(module.exports=c)}(),EPUBJS.Book=function(a){this.settings=_.defaults(a||{},{bookPath:null,storage:!1,fromStorage:!1,saved:!1,online:!0,contained:!1,width:!1,height:!1,spreads:!0,fixedLayout:!1,responsive:!0,version:1,restore:!1,reload:!1,"goto":!1,styles:{}}),this.settings.EPUBJSVERSION=EPUBJS.VERSION,this.spinePos=0,this.stored=!1,this.hooks={beforeChapterDisplay:[]},this.getHooks(),this.online=this.settings.online||navigator.onLine,this.networkListeners(),0!=this.settings.storage&&(this.storage=new fileStorage.storage(this.settings.storage)),this.ready={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,toc:new RSVP.defer},this.readyPromises=[this.ready.manifest.promise,this.ready.spine.promise,this.ready.metadata.promise,this.ready.cover.promise,this.ready.toc.promise],this.ready.all=RSVP.all(this.readyPromises),this.ready.all.then(this._ready),this._q=[],this.isRendered=!1,this._rendering=!1,this._displayQ=[],this.defer_opened=new RSVP.defer,this.opened=this.defer_opened.promise,this.settings.bookPath&&this.open(this.settings.bookPath,this.settings.reload),window.addEventListener("beforeunload",this.unload.bind(this),!1)},EPUBJS.Book.prototype.open=function(a,b){var c,d=this,e=this.isSaved(a);return this.settings.bookPath=a,this.bookUrl=this.urlFrom(a),e&&!b&&this.applySavedSettings(),this.settings.contained||this.isContained(a)?(this.settings.contained=this.contained=!0,this.bookUrl="",c=this.unarchive(a).then(function(){return e&&d.settings.restore&&!b?d.restore():d.unpack()})):c=e&&this.settings.restore&&!b?this.restore():this.unpack(),this.online&&this.settings.storage&&!this.settings.contained&&(this.settings.stored||c.then(d.storeOffline())),c.then(function(){d.defer_opened.resolve()}),c},EPUBJS.Book.prototype.unpack=function(a){var b=this,c=new EPUBJS.Parser,a=a||"META-INF/container.xml";return b.loadXml(b.bookUrl+a).then(function(a){return c.container(a)}).then(function(a){return b.settings.contentsPath=b.bookUrl+a.basePath,b.settings.packageUrl=b.bookUrl+a.packagePath,b.loadXml(b.settings.packageUrl)}).then(function(a){return c.package(a,b.settings.contentsPath)}).then(function(a){b.contents=a,b.manifest=b.contents.manifest,b.spine=b.contents.spine,b.spineIndexByURL=b.contents.spineIndexByURL,b.metadata=b.contents.metadata,b.cover=b.contents.cover=b.settings.contentsPath+a.coverPath,b.spineNodeIndex=b.contents.spineNodeIndex=a.spineNodeIndex,b.ready.manifest.resolve(b.contents.manifest),b.ready.spine.resolve(b.contents.spine),b.ready.metadata.resolve(b.contents.metadata),b.ready.cover.resolve(b.contents.cover),a.tocPath&&(b.settings.tocUrl=b.settings.contentsPath+a.tocPath,b.loadXml(b.settings.tocUrl).then(function(a){return c.toc(a)}).then(function(a){b.toc=b.contents.toc=a,b.ready.toc.resolve(b.contents.toc)}))}).fail(function(a){console.error(a)})},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a):this.settings.contained?this.zip.getXml(a):EPUBJS.core.request(a,"xml")},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=-1!=a.search("://"),d="/"==a[0],e=window.location,f=e.origin||e.protocol+"//"+e.host,g=document.getElementsByTagName("base");return g.length&&(b=g[0].href),c?a:!c&&d?b?b+a:f+a:c||d?void 0:"../"==a.slice(0,3)?EPUBJS.core.resolveUrl(b||e.pathname,a):b?b+a:f+EPUBJS.core.folder(e.pathname)+a},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=a.lastIndexOf("."),c=a.slice(b+1);return!c||"epub"!=c&&"zip"!=c?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=a+":"+this.settings.version,c=localStorage.getItem(b);return localStorage&&null!==c?!0:!1},EPUBJS.Book.prototype.removeSavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;localStorage.removeItem(a),this.settings.stored=!1},EPUBJS.Book.prototype.applySavedSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;return stored=JSON.parse(localStorage.getItem(a)),EPUBJS.VERSION!=stored.EPUBJSVERSION?!1:(this.settings=_.defaults(this.settings,stored),void 0)},EPUBJS.Book.prototype.saveSettings=function(){var a=this.settings.bookPath+":"+this.settings.version;this.render&&(this.settings.previousLocationCfi=this.render.currentLocationCfi),localStorage.setItem(a,JSON.stringify(this.settings))},EPUBJS.Book.prototype.saveContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.setItem(a,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){var a=this.settings.bookPath+":contents:"+this.settings.version;localStorage.removeItem(a)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.render=new EPUBJS.Renderer(c),c._rendered(),c.startDisplay()},function(a){console.error(a)}),b.then(null,function(a){console.error(a)}),b},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.restore&&this.settings.goto?this.goto(this.settings.goto):this.settings.restore&&this.settings.previousLocationCfi?this.displayChapter(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b=this,c=this.settings.bookPath+":contents:"+this.settings.version,d=new RSVP.defer,e=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL"],a=a||!1,f=localStorage.getItem(c);return this.settings.clearSaved&&(a=!0),a||"undefined"==f||"null"==f||(this.contents=JSON.parse(f),e.forEach(function(c){b[c]=b.contents[c],b[c]||(a=!0)})),!a&&f&&this.contents&&this.settings.contentsPath?(this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),d.resolve(),d.promise):this.open(this.settings.bookPath,!0)},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),0>e||e>=this.spine.length?(console.error("Not A Valid Chapter"),!1):(this.spinePos=e,this.chapter=new EPUBJS.Chapter(this.spine[e]),this._rendering=!0,c=f.render.chapter(this.chapter),d?c.then(function(b){b.currentLocationCfi=a,b.gotoCfiFragment(d)}):b&&c.then(function(a){a.gotoChapterEnd()}),this.settings.fromStorage||this.settings.contained||c.then(function(){f.preloadNextChapter()}),c.then(function(){var a;f._rendering=!1,f._displayQ.length&&(a=f._displayQ.unshift(),f.displayChapter.apply(f,a))}),c)):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.render.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.render.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos++,this.spinePos>this.spine.length?void 0:this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.prevChapter=function(){return this.spinePos--,this.spinePos<0?void 0:this.displayChapter(this.spinePos,!0)},EPUBJS.Book.prototype.gotoCfi=function(a){return this.isRendered?this.displayChapter(a):this._enqueue("gotoCfi",arguments)},EPUBJS.Book.prototype.goto=function(a){var b,c,d,e,f,g=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=-1==c.search("://")?this.settings.contentsPath+c:c,f=this.spineIndexByURL[e],c||(f=this.chapter?this.chapter.spinePos:0),"number"!=typeof f?!1:this.chapter&&f==this.chapter.spinePos?(d&&this.render.section(d),g.resolve(this.currentChapter),g.promise):this.displayChapter(f).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){return document.createElement("iframe"),this.spinePos>=this.spine.length?!1:(next=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(next.href),void 0)},EPUBJS.Book.prototype.storeOffline=function(){var a=this,b=_.values(this.manifest);return EPUBJS.storage.batch(b).then(function(){a.settings.stored=!0,a.trigger("book:stored")})},EPUBJS.Book.prototype.availableOffline=function(){return this.settings.stored>0?!0:!1},EPUBJS.Book.prototype.setStyle=function(a,b,c){this.settings.styles[a]=b,this.render&&this.render.setStyle(a,b,c)},EPUBJS.Book.prototype.removeStyle=function(a){this.render&&this.render.removeStyle(a),delete this.settings.styles[a]},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&(this.saveSettings(),this.saveContents()),this.trigger("book:unload")},EPUBJS.Book.prototype.destroy=function(){window.removeEventListener("beforeunload",this.unload),this.currentChapter&&this.currentChapter.unload(),this.unload(),this.render&&this.render.remove()},EPUBJS.Book.prototype._enqueue=function(a,b){this._q.push({command:a,arguments:b})},EPUBJS.Book.prototype._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){var a=this;this.isRendered=!0,this.trigger("book:rendered"),this._q.forEach(function(b){a[b.command].apply(a,b.arguments)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;plugTypes=_.values(this.hooks);for(plugType in this.hooks)a=_.values(EPUBJS.Hooks[plugType]),a.forEach(function(a){b.registerHook(plugType,a)})},EPUBJS.Book.prototype.registerHook=function(a,b,c){var d=this;"undefined"!=typeof this.hooks[a]?"function"==typeof b?c?this.hooks[a].unshift(b):this.hooks[a].push(b):Array.isArray(b)&&b.forEach(function(b){c?d.hooks[a].unshift(b):d.hooks[a].push(b)}):this.hooks[a]=[func]},EPUBJS.Book.prototype.triggerHooks=function(a,b,c){function d(){f--,0>=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,e.forEach(function(a){a(d,c)}),void 0)},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),EPUBJS.Chapter=function(a){this.href=a.href,this.id=a.id,this.spinePos=a.index,this.properties=a.properties,this.linear=a.linear,this.pages=1},EPUBJS.Chapter.prototype.contents=function(a){return a?a.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer;return a?(this.tempUrl||(this.tempUrl=a.getUrl(this.href)),this.tempUrl):(b.resolve(this.href),b.promise)},EPUBJS.Chapter.prototype.setPages=function(a){this.pages=a},EPUBJS.Chapter.prototype.getPages=function(){return this.pages},EPUBJS.Chapter.prototype.getID=function(){return this.ID},EPUBJS.Chapter.prototype.unload=function(a){this.tempUrl&&a&&(a.revokeUrl(this.tempUrl),this.tempUrl=!1)};var EPUBJS=EPUBJS||{};EPUBJS.core={},EPUBJS.core.getEl=function(a){return document.getElementById(a)},EPUBJS.core.getEls=function(a){return document.getElementsByClassName(a)},EPUBJS.core.request=function(a,b){function c(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var a; +a="xml"==b?this.responseXML:"json"==b?JSON.parse(this.response):"blob"==b?d?this.response:new Blob([this.response]):this.response,f.resolve(a)}else f.reject(this)}var d=window.URL,e=d?"blob":"arraybuffer",f=new RSVP.defer,g=new XMLHttpRequest;return g.open("GET",a),g.onreadystatechange=c,"blob"==b&&(g.responseType=e),"json"==b&&g.setRequestHeader("Accept","application/json"),"xml"==b&&g.overrideMimeType("text/xml"),g.send(),f.promise},EPUBJS.core.toArray=function(a){var b=[];for(member in a){var c;a.hasOwnProperty(member)&&(c=a[member],c.ident=member,b.push(c))}return b},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/"),c=a.slice(0,b+1);return-1==b&&(c=""),c},EPUBJS.core.dataURLToBlob=function(a){var b=";base64,";if(-1==a.indexOf(b)){var c=a.split(","),d=c[0].split(":")[1],e=c[1];return new Blob([e],{type:d})}for(var c=a.split(b),d=c[0].split(":")[1],e=window.atob(c[1]),f=e.length,g=new Uint8Array(f),h=0;f>h;++h)g[h]=e.charCodeAt(h);return new Blob([g],{type:d})},EPUBJS.core.addScript=function(a,b,c){var d,e;e=!1,d=document.createElement("script"),d.type="text/javascript",d.async=!1,d.src=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.addScripts=function(a,b,c){var d=a.length,e=0,f=function(){e++,d==e?b&&b():EPUBJS.core.loadScript(a[e],f,c)};EPUBJS.core.addScript(a[e],f,c)},EPUBJS.core.addCss=function(a,b,c){var d,e;e=!1,d=document.createElement("link"),d.type="text/css",d.rel="stylesheet",d.href=a,d.onload=d.onreadystatechange=function(){e||this.readyState&&"complete"!=this.readyState||(e=!0,b&&b())},c=c||document.body,c.appendChild(d)},EPUBJS.core.prefixed=function(a){var b=["Webkit","Moz","O","ms"],c=a[0].toUpperCase()+a.slice(1),d=b.length,e=0;if("undefined"!=typeof document.body.style[a])return a;for(;d>e;e++)if("undefined"!=typeof document.body.style[b[e]+c])return b[e]+c;return a},EPUBJS.core.resolveUrl=function(a,b){var c,d,e=[],f=a.split("/");return f.pop(),d=b.split("/"),d.forEach(function(a){".."===a?f.pop():e.push(a)}),c=f.concat(e),c.join("/")},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapter=function(a,b,c){var b=parseInt(b),a=a+1,d="/"+a+"/";return d+=2*(b+1),c&&(d+="["+c+"]"),d+="!"},EPUBJS.EpubCFI.prototype.generateFragment=function(a,b){var c=this.pathTo(a),d=[];return b&&d.push(b),c.forEach(function(a){var b="";b+=2*(a.index+1),a.id&&"EPUBJS"!=a.id.slice(0,6)&&(b+="["+a.id+"]"),d.push(b)}),d.join("/")},EPUBJS.EpubCFI.prototype.pathTo=function(a){for(var b,c=[];a&&null!==a.parentNode;)b=a.parentNode.children,c.unshift({id:a.id,tagName:a.tagName,index:b?Array.prototype.indexOf.call(b,a):0}),a=a.parentNode;return c},EPUBJS.EpubCFI.prototype.getChapter=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getFragment=function(a){var b=a.split("!");return b[1]},EPUBJS.EpubCFI.prototype.getOffset=function(a){var b=a.split(":");return[b[0],b[1]]},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f={};return f.chapter=this.getChapter(a),f.fragment=this.getFragment(a),f.spinePos=parseInt(f.chapter.split("/")[2])/2-1||0,b=f.chapter.match(/\[(.*)\]/),f.spineId=b?b[1]:!1,c=f.fragment.split("/"),d=c[c.length-1],f.sections=[],parseInt(d)%2&&(e=this.getOffset(),f.text=parseInt(e[0]),f.character=parseInt(e[1]),c.pop()),c.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),f.sections.push({index:b,id:d||!1}))}),f},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,b=b||document,d=a.sections,e=b.getElementsByTagName("html")[0],f=Array.prototype.slice.call(e.children);for(d.shift();d.length>0;)c=d.shift(),c.id?e=b.getElementById(c.id):(e=f[c.index],f||console.error("No Kids",e)),e||console.error("No Element For",c),f=Array.prototype.slice.call(e.children);return e},EPUBJS.Events=function(a,b){return this.events={},this.el=b?b:document.createElement("div"),a.createEvent=this.createEvent,a.tell=this.tell,a.listen=this.listen,a.deafen=this.deafen,a.listenUntil=this.listenUntil,this},EPUBJS.Events.prototype.createEvent=function(a){var b=new CustomEvent(a);return this.events[a]=b,b},EPUBJS.Events.prototype.tell=function(a,b){var c;this.events[a]?c=this.events[a]:(console.warn("No event:",a,"defined yet, creating."),c=this.createEvent(a)),b&&(c.msg=b),this.el.dispatchEvent(c)},EPUBJS.Events.prototype.listen=function(a,b,c){return this.events[a]?(c?this.el.addEventListener(a,b.bind(c),!1):this.el.addEventListener(a,b,!1),void 0):(console.warn("No event:",a,"defined yet, creating."),this.createEvent(a),void 0)},EPUBJS.Events.prototype.deafen=function(a,b){this.el.removeEventListener(a,b,!1)},EPUBJS.Events.prototype.listenUntil=function(a,b,c,d){function e(){this.deafen(a,c),this.deafen(b,e)}this.listen(a,c,d),this.listen(b,e,this)},EPUBJS.Hooks=function(){"use strict";return{register:function(a){if(void 0===this[a]&&(this[a]={}),"object"!=typeof this[a])throw"Already registered: "+a;return this[a]}}}(),EPUBJS.Parser=function(a){this.baseUrl=a||""},EPUBJS.Parser.prototype.container=function(a){var b=a.querySelector("rootfile"),c=b.getAttribute("full-path"),d=EPUBJS.core.folder(c);return{packagePath:c,basePath:d}},EPUBJS.Parser.prototype.package=function(a,b){var c=this;b&&(this.baseUrl=b);var d=a.querySelector("metadata"),e=a.querySelector("manifest"),f=a.querySelector("spine"),g=c.manifest(e),h=c.findTocPath(e),i=c.findCoverPath(e),j=Array.prototype.indexOf.call(f.parentNode.childNodes,f),k=c.spine(f,g),l={};return k.forEach(function(a){l[a.href]=a.index}),{metadata:c.metadata(d),spine:k,manifest:g,tocPath:h,coverPath:i,spineNodeIndex:j,spineIndexByURL:l}},EPUBJS.Parser.prototype.findTocPath=function(a){var b=a.querySelector("item[media-type='application/x-dtbncx+xml']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.findCoverPath=function(a){var b=a.querySelector("item[properties='cover-image']");return b?b.getAttribute("href"):!1},EPUBJS.Parser.prototype.metadata=function(a){var b={},c=this;return b.bookTitle=c.getElementText(a,"title"),b.creator=c.getElementText(a,"creator"),b.description=c.getElementText(a,"description"),b.pubdate=c.getElementText(a,"date"),b.publisher=c.getElementText(a,"publisher"),b.identifier=c.getElementText(a,"identifier"),b.language=c.getElementText(a,"language"),b.rights=c.getElementText(a,"rights"),b.modified_date=c.querySelectorText(a,"meta[property='dcterms:modified']"),b.layout=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.orientation=c.querySelectorText(a,"meta[property='rendition:orientation']"),b.spread=c.querySelectorText(a,"meta[property='rendition:spread']"),b},EPUBJS.Parser.prototype.getElementText=function(a,b){var c,d=a.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",b);return d&&0!=d.length?(c=d[0],c.childNodes.length?c.childNodes[0].nodeValue:""):""},EPUBJS.Parser.prototype.querySelectorText=function(a,b){var c=a.querySelector(b);return c&&c.childNodes.length?c.childNodes[0].nodeValue:""},EPUBJS.Parser.prototype.manifest=function(a){var b=this.baseUrl,c={},d=a.querySelectorAll("item"),e=Array.prototype.slice.call(d);return e.forEach(function(a){var d=a.getAttribute("id"),e=a.getAttribute("href")||"",f=a.getAttribute("media-type")||"";c[d]={href:b+e,type:f}}),c},EPUBJS.Parser.prototype.spine=function(a,b){var c=[],d=a.getElementsByTagName("itemref"),e=Array.prototype.slice.call(d);return e.forEach(function(a,d){var e=a.getAttribute("idref"),f={id:e,linear:a.getAttribute("linear")||"",properties:a.getAttribute("properties")||"",href:b[e].href,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.toc=function(a){function b(a){var c,d=[],e=[],f=a.childNodes,g=Array.prototype.slice.call(f),h=g.length,i=h;if(0==h)return!1;for(;i--;)c=g[i],"navPoint"===c.nodeName&&e.push(c);return e.forEach(function(c){var e=c.getAttribute("id"),f=c.querySelector("content"),g=f.getAttribute("src"),h=(g.split("#"),c.querySelector("navLabel")),i=h.textContent?h.textContent:"",j=b(c);d.unshift({id:e,href:g,label:i,subitems:j,parent:a?a.getAttribute("id"):null})}),d}var c=a.querySelector("navMap");return b(c)},EPUBJS.Renderer=function(a){this.el=a.element,this.book=a,this.caches={},this.crossBrowserColumnCss(),this.epubcfi=new EPUBJS.EpubCFI,this.initialize(),this.listeners()},EPUBJS.Renderer.prototype.initialize=function(){this.iframe=document.createElement("iframe"),this.iframe.scrolling="no",this.book.settings.width||this.book.settings.height?this.resizeIframe(this.book.settings.width||this.el.clientWidth,this.book.settings.height||this.el.clientHeight):this.resizeIframe("100%","100%"),this.el.appendChild(this.iframe)},EPUBJS.Renderer.prototype.listeners=function(){this.resized=_.throttle(this.onResized.bind(this),10),this.book.registerHook("beforeChapterDisplay",this.replaceLinks.bind(this),!0),this.determineStore()&&this.book.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Renderer.prototype.chapter=function(a){var b=this,c=!1;return this.book.settings.contained&&(c=this.book.zip),this.currentChapter&&(this.currentChapter.unload(),this.trigger("renderer:chapterUnloaded"),this.book.trigger("renderer:chapterUnloaded")),this.currentChapter=a,this.chapterPos=1,this.pageIds={},this.leftPos=0,this.currentChapterCfi=this.epubcfi.generateChapter(this.book.spineNodeIndex,a.spinePos,a.id),this.visibileEl=!1,a.url(c).then(function(a){return b.setIframeSrc(a)})},EPUBJS.Renderer.prototype.onResized=function(){var a={width:this.iframe.clientWidth,height:this.iframe.clientHeight};this.doc&&this.reformat(),this.trigger("renderer:resized",a),this.book.trigger("book:resized",a)},EPUBJS.Renderer.prototype.reformat=function(){var a=this;a.book.settings.fixedLayout?a.fixedLayout():a.formatSpread(),setTimeout(function(){a.calcPages(),a.currentLocationCfi&&a.gotoCfiFragment(a.currentLocationCfi)},10)},EPUBJS.Renderer.prototype.resizeIframe=function(a,b){this.iframe.height=b,isNaN(a)||0==a%2||(a+=1),this.iframe.width=a,this.onResized()},EPUBJS.Renderer.prototype.crossBrowserColumnCss=function(){EPUBJS.Renderer.columnAxis=EPUBJS.core.prefixed("columnAxis"),EPUBJS.Renderer.columnGap=EPUBJS.core.prefixed("columnGap"),EPUBJS.Renderer.columnWidth=EPUBJS.core.prefixed("columnWidth"),EPUBJS.Renderer.transform=EPUBJS.core.prefixed("transform")},EPUBJS.Renderer.prototype.setIframeSrc=function(a){var b=this,c=new RSVP.defer;return this.visible(!1),this.iframe.src=a,this.iframe.onload=function(){b.doc=b.iframe.contentDocument,b.docEl=b.doc.documentElement,b.bodyEl=b.doc.body,b.applyStyles(),b.book.settings.fixedLayout?b.fixedLayout():b.formatSpread(),b.beforeDisplay(function(){var a=b.currentChapter;b.calcPages(),c.resolve(b),a.cfi=b.currentLocationCfi=b.getPageCfi(),b.trigger("renderer:chapterDisplayed",a),b.book.trigger("renderer:chapterDisplayed",a),b.visible(!0)}),b.iframe.contentWindow.addEventListener("resize",b.resized,!1)},c.promise},EPUBJS.Renderer.prototype.formatSpread=function(){var a=2,b=800;this.elWidth=this.iframe.clientWidth,0!=this.elWidth%2&&(this.elWidth-=1),this.gap=Math.ceil(this.elWidth/8),0!=this.gap%2&&(this.gap+=1),this.elWidth1?(this.chapterPos--,this.leftPos-=this.spreadWidth,this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),this.chapterPos):!1},EPUBJS.Renderer.prototype.chapterEnd=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.setLeft=function(a){this.doc.defaultView.scrollTo(a,0)},EPUBJS.Renderer.prototype.determineStore=function(){return this.book.fromStorage?"filesystem"==this.book.storage.getStorageType()?!1:this.book.store:this.book.contained?this.book.zip:!1},EPUBJS.Renderer.prototype.replace=function(a,b,c,d){var e=this.doc.querySelectorAll(a),f=Array.prototype.slice.call(e),g=f.length,h=function(a){g--,d&&d(a,g),0>=g&&c&&c(!0)};return 0===g?(c(!1),void 0):(f.forEach(function(a){b(a,h)}.bind(this)),void 0)},EPUBJS.Renderer.prototype.replaceWithStored=function(a,b,c,d){var e,f={},g=this.determineStore(),h=this.caches[a],i=this.book.settings.contentsPath,j=b,k=function(a,b){f[b]=a},l=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(a,b){var d=a.getAttribute(j),h=EPUBJS.core.resolveUrl(i,d),k=function(c){a.setAttribute(j,c),a.onload=function(){b(c,h)}};h in e?(k(e[h]),f[h]=e[h],delete e[h]):c(g,h,k,a)},l,k))},EPUBJS.Renderer.prototype.replaceLinks=function(a){var b=this;this.replace("a[href]",function(a,c){var d=a.getAttribute("href"),e=d.search("://");"#"==d[0],-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return b.book.goto(d),!1},c()},a)},EPUBJS.Renderer.prototype.page=function(a){return a>=1&&a<=this.displayedPages?(this.chapterPos=a,this.leftPos=this.spreadWidth*(a-1),this.setLeft(this.leftPos),this.currentLocationCfi=this.getPageCfi(),this.book.trigger("renderer:pageChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b,c;a&&(b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.spreadWidth)+1,this.page(c))},EPUBJS.Renderer.prototype.beforeDisplay=function(a){this.book.triggerHooks("beforeChapterDisplay",a.bind(this),this)},EPUBJS.Renderer.prototype.walk=function(a){for(var b,a,c,d,e,f=a,g=[f],h=1e4,i=0;!b&&g.length;){if(a=g.shift(),this.isElementVisible(a)&&(b=a),!b&&a&&a.childElementCount>0){if(c=a.children,!c||!c.length)return b;d=c.length?c.length:0;for(var j=0;d>j;j++)c[j]!=e&&g.push(c[j])}if(!b&&0==g.length&&f&&null!==f.parentNode&&(g.push(f.parentNode),e=f,f=f.parentNode),i++,i>h){console.error("ENDLESS LOOP");break}}return b},EPUBJS.Renderer.prototype.getPageCfi=function(){var a=this.visibileEl;return this.visibileEl=this.findFirstVisible(a),this.visibileEl.id||(this.visibileEl.id="EPUBJS-PAGE-"+this.chapterPos),this.pageIds[this.chapterPos]=this.visibileEl.id,this.epubcfi.generateFragment(this.visibileEl,this.currentChapterCfi)},EPUBJS.Renderer.prototype.gotoCfiFragment=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),b=this.epubcfi.getElement(a,this.doc),this.pageByElement(b)},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.bodyEl;return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.isElementVisible=function(a){var b;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect().left,b>=0&&be/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()}; \ No newline at end of file +EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),b.replaceLinks.bind(this),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()}; \ No newline at end of file diff --git a/examples/basic-dev.html b/examples/basic-dev.html index e4b1b68..cabadc8 100644 --- a/examples/basic-dev.html +++ b/examples/basic-dev.html @@ -49,13 +49,14 @@