diff --git a/Gruntfile.js b/Gruntfile.js index cd192c6..735b5fa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,7 +9,7 @@ module.exports = function(grunt) { }, concat : { 'build/epub.js': ['', 'libs/rsvp/rsvp.js', 'src/*.js'], - 'build/reader.js': ['', 'reader/reader.js'], + 'build/reader.js': ['', 'reader/reader.js', 'reader/controllers/*.js'], 'build/hooks.js': ['', 'hooks/default/*.js'], 'demo/js/libs/fileStorage.min.js': 'libs/fileStorage/fileStorage.min.js', 'demo/js/libs/loader_filesystem.min.js': 'libs/fileStorage/workers/loader_filesystem.min.js', diff --git a/build/epub.js b/build/epub.js index bcc95a1..703fa20 100644 --- a/build/epub.js +++ b/build/epub.js @@ -1777,6 +1777,8 @@ EPUBJS.Book = function(options){ this.settings = _.defaults(options || {}, { bookPath : null, + bookKey : null, + packageUrl : null, storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem' fromStorage : false, saved : false, @@ -1871,74 +1873,71 @@ EPUBJS.Book = function(options){ //-- Check bookUrl and start parsing book Assets or load them from storage EPUBJS.Book.prototype.open = function(bookPath, forceReload){ var book = this, - saved = this.isSaved(bookPath), - opened; - + epubpackage, + opened = new RSVP.defer(); + this.settings.bookPath = bookPath; - + //-- Get a absolute URL from the book path this.bookUrl = this.urlFrom(bookPath); - // console.log("saved", saved, !forceReload) - //-- Remove the previous settings and reload - if(saved){ - //-- Apply settings, keeping newer ones - this.applySavedSettings(); - } - if(this.settings.contained || this.isContained(bookPath)){ - this.settings.contained = this.contained = true; this.bookUrl = ''; // return; //-- TODO: this need to be fixed and tested before enabling - opened = this.unarchive(bookPath).then(function(){ + epubpackage = this.unarchive(bookPath). + then(function(){ + return this.loadPackage(); + }); - if(saved && book.settings.restore && !forceReload){ - return book.restore(); - }else{ - return book.unpack(); + } else { + epubpackage = this.loadPackage(); + } + + if(this.settings.restore && !forceReload){ + //-- Will load previous package json, or re-unpack if error + epubpackage.then(function(packageXml) { + var identifier = book.packageIdentifier(packageXml); + var restored = book.restore(identifier); + + if(!restored) { + book.unpack(packageXml); } - + opened.resolve(); + book.defer_opened.resolve(); }); - } else { - - if(saved && this.settings.restore && !forceReload){ - //-- Will load previous package json, or re-unpack if error - opened = this.restore(); - - }else{ - - //-- Get package information from epub opf - opened = this.unpack(); - - } + }else{ + //-- Get package information from epub opf + epubpackage.then(function(packageXml) { + book.unpack(packageXml); + opened.resolve(); + book.defer_opened.resolve(); + }); } - + //-- If there is network connection, store the books contents if(this.online && this.settings.storage && !this.settings.contained){ if(!this.settings.stored) opened.then(book.storeOffline()); } - - opened.then(function(){ - book.defer_opened.resolve(); - }); - return opened; + return opened.promise; }; -EPUBJS.Book.prototype.unpack = function(_containerPath){ +EPUBJS.Book.prototype.loadPackage = function(_containerPath){ var book = this, - parse = new EPUBJS.Parser(), - containerPath = _containerPath || "META-INF/container.xml"; - - //-- Return chain of promises - return book.loadXml(book.bookUrl + containerPath). + parse = new EPUBJS.Parser(), + containerPath = _containerPath || "META-INF/container.xml", + containerXml, + packageXml; + + if(!this.settings.packageUrl) { //-- provide the packageUrl to skip this step + packageXml = book.loadXml(book.bookUrl + containerPath). then(function(containerXml){ return parse.container(containerXml); // Container has path to content }). @@ -1946,58 +1945,74 @@ EPUBJS.Book.prototype.unpack = function(_containerPath){ book.settings.contentsPath = book.bookUrl + paths.basePath; book.settings.packageUrl = book.bookUrl + paths.packagePath; return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata - }). - then(function(packageXml){ - return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents - }). - then(function(contents){ - book.contents = contents; - book.manifest = book.contents.manifest; - book.spine = book.contents.spine; - book.spineIndexByURL = book.contents.spineIndexByURL; - book.metadata = book.contents.metadata; - - book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath; - - book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex; - - book.ready.manifest.resolve(book.contents.manifest); - book.ready.spine.resolve(book.contents.spine); - book.ready.metadata.resolve(book.contents.metadata); - book.ready.cover.resolve(book.contents.cover); - - //-- Adjust setting based on metadata - - //-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file - if(contents.navPath) { - book.settings.navUrl = book.settings.contentsPath + contents.navPath; - - book.loadXml(book.settings.navUrl). - then(function(navHtml){ - return parse.nav(navHtml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - } else if(contents.tocPath) { - book.settings.tocUrl = book.settings.contentsPath + contents.tocPath; - - book.loadXml(book.settings.tocUrl). - then(function(tocXml){ - return parse.toc(tocXml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - - } else { - book.ready.toc.resolve(false); - } }); + } else { + packageXml = book.loadXml(book.settings.packageUrl); + } + + return packageXml; +}; + +EPUBJS.Book.prototype.packageIdentifier = function(packageXml){ + var book = this, + parse = new EPUBJS.Parser(); + + return parse.identifier(packageXml); +}; + +EPUBJS.Book.prototype.unpack = function(packageXml){ + var book = this, + parse = new EPUBJS.Parser(); + + book.contents = parse.packageContents(packageXml, book.settings.contentsPath); // Extract info from contents + + book.manifest = book.contents.manifest; + book.spine = book.contents.spine; + book.spineIndexByURL = book.contents.spineIndexByURL; + book.metadata = book.contents.metadata; + book.setBookKey(book.metadata.identifier); + + book.cover = book.contents.cover = book.settings.contentsPath + book.contents.coverPath; + + book.spineNodeIndex = book.contents.spineNodeIndex; + + book.ready.manifest.resolve(book.contents.manifest); + book.ready.spine.resolve(book.contents.spine); + book.ready.metadata.resolve(book.contents.metadata); + book.ready.cover.resolve(book.contents.cover); + + //-- TODO: Adjust setting based on metadata + + //-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file + if(book.contents.navPath) { + book.settings.navUrl = book.settings.contentsPath + book.contents.navPath; + + book.loadXml(book.settings.navUrl). + then(function(navHtml){ + return parse.nav(navHtml, book.spineIndexByURL, book.spine); // Grab Table of Contents + }).then(function(toc){ + book.toc = book.contents.toc = toc; + book.ready.toc.resolve(book.contents.toc); + }, function(error) { + book.ready.toc.resolve(false); + }); + } else if(book.contents.tocPath) { + book.settings.tocUrl = book.settings.contentsPath + book.contents.tocPath; + + book.loadXml(book.settings.tocUrl). + then(function(tocXml){ + return parse.toc(tocXml, book.spineIndexByURL, book.spine); // Grab Table of Contents + }).then(function(toc){ + book.toc = book.contents.toc = toc; + book.ready.toc.resolve(book.contents.toc); + }, function(error) { + book.ready.toc.resolve(false); + }); + + } else { + book.ready.toc.resolve(false); + } + }; EPUBJS.Book.prototype.getMetadata = function() { @@ -2106,7 +2121,7 @@ EPUBJS.Book.prototype.unarchive = function(bookPath){ //-- Checks if url has a .epub or .zip extension EPUBJS.Book.prototype.isContained = function(bookUrl){ var dot = bookUrl.lastIndexOf('.'), - ext = bookUrl.slice(dot+1); + ext = bookUrl.slice(dot+1); if(ext && (ext == "epub" || ext == "zip")){ return true; @@ -2115,10 +2130,9 @@ EPUBJS.Book.prototype.isContained = function(bookUrl){ return false; }; -//-- Checks if the book setting can be retrieved from localStorage -EPUBJS.Book.prototype.isSaved = function(bookPath) { - var bookKey = bookPath + ":" + this.settings.version, - storedSettings = localStorage.getItem(bookKey); +//-- Checks if the book can be retrieved from localStorage +EPUBJS.Book.prototype.isSaved = function(bookKey) { + var storedSettings = localStorage.getItem(bookKey); if( !localStorage || storedSettings === null) { @@ -2128,48 +2142,27 @@ EPUBJS.Book.prototype.isSaved = function(bookPath) { } }; -//-- Remove save book settings -EPUBJS.Book.prototype.removeSavedSettings = function() { - var bookKey = this.settings.bookPath + ":" + this.settings.version; - - localStorage.removeItem(bookKey); - - this.settings.stored = false; //TODO: is this needed? -}; - -EPUBJS.Book.prototype.applySavedSettings = function() { - var bookKey = this.settings.bookPath + ":" + this.settings.version, - stored = JSON.parse(localStorage.getItem(bookKey)); - - if(EPUBJS.VERSION != stored.EPUBJSVERSION) return false; - this.settings = _.defaults(this.settings, stored); -}; - -EPUBJS.Book.prototype.saveSettings = function(){ - var bookKey = this.settings.bookPath + ":" + this.settings.version; - - if(this.render) { - this.settings.previousLocationCfi = this.render.currentLocationCfi; +EPUBJS.Book.prototype.setBookKey = function(identifier){ + if(!this.settings.bookKey) { + this.settings.bookKey = this.generateBookKey(identifier); } - - localStorage.setItem(bookKey, JSON.stringify(this.settings)); + return this.settings.bookKey; +}; +EPUBJS.Book.prototype.generateBookKey = function(identifier){ + return "epubjs:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; }; EPUBJS.Book.prototype.saveContents = function(){ - var contentsKey = this.settings.bookPath + ":contents:" + this.settings.version; - - localStorage.setItem(contentsKey, JSON.stringify(this.contents)); - + localStorage.setItem(this.settings.bookKey, JSON.stringify(this.contents)); }; EPUBJS.Book.prototype.removeSavedContents = function() { - var bookKey = this.settings.bookPath + ":contents:" + this.settings.version; - - localStorage.removeItem(bookKey); + localStorage.removeItem(this.settings.bookKey); }; + // EPUBJS.Book.prototype.chapterTitle = function(){ // return this.spine[this.spinePos].id; //-- TODO: clarify that this is returning title // } @@ -2220,14 +2213,13 @@ EPUBJS.Book.prototype.startDisplay = function(){ return display; }; -EPUBJS.Book.prototype.restore = function(_reject){ +EPUBJS.Book.prototype.restore = function(identifier){ var book = this, - contentsKey = this.settings.bookPath + ":contents:" + this.settings.version, - deferred = new RSVP.defer(), - fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'], - reject = _reject || false, - fromStore = localStorage.getItem(contentsKey); + fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'], + reject = false, + bookKey = this.setBookKey(identifier), + fromStore = localStorage.getItem(bookKey); if(this.settings.clearSaved) reject = true; @@ -2242,17 +2234,14 @@ EPUBJS.Book.prototype.restore = function(_reject){ } if(reject || !fromStore || !this.contents || !this.settings.contentsPath){ - // this.removeSavedSettings(); - return this.open(this.settings.bookPath, true); - + return false; }else{ 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); - deferred.resolve(); - return deferred.promise; + return true; } }; @@ -2280,15 +2269,15 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ } if(pos < 0 || pos >= this.spine.length){ - console.error("Not A Valid Chapter"); - return false; + console.warn("Not A Valid Location"); + pos = 0; + end = false; + cfi = false; } //-- Set the book's spine position this.spinePos = pos; - - //-- Create a new chapter this.chapter = new EPUBJS.Chapter(this.spine[pos]); @@ -2477,7 +2466,6 @@ EPUBJS.Book.prototype.removeStyle = function(style) { EPUBJS.Book.prototype.unload = function(){ if(this.settings.restore) { - this.saveSettings(); this.saveContents(); } @@ -2598,7 +2586,7 @@ RSVP.configure('instrument', true); //-- true | will logging out all RSVP reject // RSVP.on('chained', listener); // RSVP.on('fulfilled', listener); RSVP.on('rejected', function(event){ - console.error(event.detail, event.detail.message); + console.error(event.detail.message, event.detail.stack); }); EPUBJS.Chapter = function(spineObject){ @@ -2971,15 +2959,21 @@ EPUBJS.EpubCFI.prototype.getOffset = function(cfiStr) { EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { var cfi = {}, + chapSegment, chapId, path, end, text; cfi.chapter = this.getChapter(cfiStr); - + + chapSegment = parseInt(cfi.chapter.split("/")[2]) || false; + cfi.fragment = this.getFragment(cfiStr); - cfi.spinePos = (parseInt(cfi.chapter.split("/")[2]) / 2 - 1 ) || 0; + + if(!chapSegment || !cfi.fragment) return {spinePos: -1}; + + cfi.spinePos = (parseInt(chapSegment) / 2 - 1 ) || 0; chapId = cfi.chapter.match(/\[(.*)\]/); @@ -3154,19 +3148,24 @@ EPUBJS.Parser.prototype.container = function(containerXml){ }; }; -EPUBJS.Parser.prototype.package = function(packageXml, baseUrl){ +EPUBJS.Parser.prototype.identifier = function(packageXml){ + var metadataNode = packageXml.querySelector("metadata"); + return this.getElementText(metadataNode, "identifier"); +}; + +EPUBJS.Parser.prototype.packageContents = function(packageXml, baseUrl){ var parse = this; if(baseUrl) this.baseUrl = baseUrl; var metadataNode = packageXml.querySelector("metadata"), - manifestNode = packageXml.querySelector("manifest"), - spineNode = packageXml.querySelector("spine"); + manifestNode = packageXml.querySelector("manifest"), + spineNode = packageXml.querySelector("spine"); var manifest = parse.manifest(manifestNode), - navPath = parse.findNavPath(manifestNode), - tocPath = parse.findTocPath(manifestNode), - coverPath = parse.findCoverPath(manifestNode); + navPath = parse.findNavPath(manifestNode), + tocPath = parse.findTocPath(manifestNode), + coverPath = parse.findCoverPath(manifestNode); var spineNodeIndex = Array.prototype.indexOf.call(spineNode.parentNode.childNodes, spineNode); @@ -3210,7 +3209,7 @@ EPUBJS.Parser.prototype.findCoverPath = function(manifestNode){ //-- Expanded to match Readium web components EPUBJS.Parser.prototype.metadata = function(xml){ var metadata = {}, - p = this; + p = this; metadata.bookTitle = p.getElementText(xml, 'title'); metadata.creator = p.getElementText(xml, 'creator'); @@ -3261,7 +3260,7 @@ EPUBJS.Parser.prototype.querySelectorText = function(xml, q){ EPUBJS.Parser.prototype.manifest = function(manifestXml){ var baseUrl = this.baseUrl, - manifest = {}; + manifest = {}; //-- Turn items into an array var selected = manifestXml.querySelectorAll("item"), @@ -3270,9 +3269,9 @@ EPUBJS.Parser.prototype.manifest = function(manifestXml){ //-- Create an object with the id as key items.forEach(function(item){ var id = item.getAttribute('id'), - href = item.getAttribute('href') || '', - type = item.getAttribute('media-type') || '', - properties = item.getAttribute('properties') || ''; + href = item.getAttribute('href') || '', + type = item.getAttribute('media-type') || '', + properties = item.getAttribute('properties') || ''; manifest[id] = { 'href' : href, @@ -3291,7 +3290,7 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){ var spine = []; var selected = spineXml.getElementsByTagName("itemref"), - items = Array.prototype.slice.call(selected); + items = Array.prototype.slice.call(selected); //-- Add to array to mantain ordering and cross reference with manifest items.forEach(function(item, index){ @@ -3313,7 +3312,7 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){ EPUBJS.Parser.prototype.nav = function(navHtml, spineIndexByURL, bookSpine){ var navEl = navHtml.querySelector('nav'), //-- [*|type="toc"] * Doesn't seem to work - idCounter = 0; + idCounter = 0; if(!navEl) return []; @@ -3350,10 +3349,10 @@ EPUBJS.Parser.prototype.nav = function(navHtml, spineIndexByURL, bookSpine){ function getTOC(parent){ var list = [], - nodes = findListItems(parent), - items = Array.prototype.slice.call(nodes), - length = items.length, - node; + nodes = findListItems(parent), + items = Array.prototype.slice.call(nodes), + length = items.length, + node; if(length === 0) return false; @@ -3400,12 +3399,12 @@ EPUBJS.Parser.prototype.toc = function(tocXml, spineIndexByURL, bookSpine){ function getTOC(parent){ var list = [], - items = [], - nodes = parent.childNodes, - nodesArray = Array.prototype.slice.call(nodes), - length = nodesArray.length, - iter = length, - node; + items = [], + nodes = parent.childNodes, + nodesArray = Array.prototype.slice.call(nodes), + length = nodesArray.length, + iter = length, + node; if(length === 0) return false; @@ -3419,15 +3418,15 @@ EPUBJS.Parser.prototype.toc = function(tocXml, spineIndexByURL, bookSpine){ items.forEach(function(item){ var id = item.getAttribute('id') || false, - content = item.querySelector("content"), - src = content.getAttribute('src'), - navLabel = item.querySelector("navLabel"), - text = navLabel.textContent ? navLabel.textContent : "", - split = src.split("#"), - baseUrl = split[0], - spinePos = spineIndexByURL[baseUrl], - spineItem, - subitems = getTOC(item); + content = item.querySelector("content"), + src = content.getAttribute('src'), + navLabel = item.querySelector("navLabel"), + text = navLabel.textContent ? navLabel.textContent : "", + split = src.split("#"), + baseUrl = split[0], + spinePos = spineIndexByURL[baseUrl], + spineItem, + subitems = getTOC(item); if(!id) { if(spinePos) { diff --git a/build/epub.min.js b/build/epub.min.js index 0c138f1..65f690b 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){var b,c,d,e;!function(){var a={},f={};b=function(b,c,d){a[b]={deps:c,callback:d}},e=d=c=function(b){function d(a){if("."!==a.charAt(0))return a;for(var c=a.split("/"),d=b.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){var g=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}return d.join("/")}if(e._eak_seen=a,f[b])return f[b];if(f[b]={},!a[b])throw new Error("Could not find module "+b);for(var g,h=a[b],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)"exports"===i[l]?k.push(g={}):k.push(c(d(i[l])));var n=j.apply(this,k);return f[b]=g||n}}(),b("rsvp/all",["./promise","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=function(a,b){return c.all(a,b)}}),b("rsvp/asap",["exports"],function(a){"use strict";function b(){return function(){process.nextTick(e)}}function c(){var a=0,b=new h(e),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function d(){return function(){setTimeout(e,1)}}function e(){for(var a=0;ac;c++)if(a[c]===b)return c;return-1},c=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b};a["default"]={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a._promiseCallbacks=void 0,a},on:function(a,d){var e,f=c(this);e=f[a],e||(e=f[a]=[]),-1===b(e,d)&&e.push(d)},off:function(a,d){var e,f,g=c(this);return d?(e=g[a],f=b(e,d),-1!==f&&e.splice(f,1),void 0):(g[a]=[],void 0)},trigger:function(a,b){var d,e,f=c(this);if(d=f[a])for(var g=0;gb;b++)a[b]&&e.push(d[b]);return e})})}var f=a["default"],g=b["default"],h=c.isFunction,i=c.isArray;d["default"]=e}),b("rsvp/hash",["./promise","./utils","exports"],function(a,b,c){"use strict";var d=a["default"],e=b.isNonThenable,f=b.keysOf;c["default"]=function(a){return new d(function(b,c){function g(a){return function(c){k[a]=c,0===--m&&b(k)}}function h(a){m=0,c(a)}var i,j,k={},l=f(a),m=l.length;if(0===m)return b(k),void 0;for(var n=0;nd;d++)g.push(b(a[d]));return e(g,c)})}}),b("rsvp/node",["./promise","exports"],function(a,b){"use strict";function c(a,b){return function(c,d){c?b(c):arguments.length>2?a(e.call(arguments,1)):a(d)}}var d=a["default"],e=Array.prototype.slice;b["default"]=function(a,b){return function(){var f=e.call(arguments),g=this||b;return new d(function(b,e){d.all(f).then(function(d){try{d.push(c(b,e)),a.apply(g,d)}catch(f){e(f)}})})}}}),b("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(){}function l(a,b){if(!z(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof l))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=H++,this._label=b,this._subscribers=[],w.instrument&&x("created",this),k!==a&&m(a,this)}function m(a,b){function c(a){r(b,a)}function d(a){t(b,a)}try{a(c,d)}catch(e){d(e)}}function n(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+K]=c,e[f+L]=d}function o(a,b){var c,d,e=a._subscribers,f=a._detail;w.instrument&&x(b===K?"fulfilled":"rejected",a);for(var g=0;ge||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.getCurrentLocationCfi=function(){return this.isRendered?this.render.currentLocationCfi:!1},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=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=this.spineIndexByURL[c],c||(e=this.chapter?this.chapter.spinePos:0),"number"!=typeof e?!1:this.chapter&&e==this.chapter.spinePos?(d&&this.render.section(d),f.resolve(this.currentChapter),f.promise):this.displayChapter(e).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a;return this.spinePos>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(a.absolute),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,args: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.args)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;_.values(this.hooks);for(var c in this.hooks)a=_.values(EPUBJS.Hooks[c]),a.forEach(function(a){b.registerHook(c,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),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(a){console.error(a.detail,a.detail.message)}),EPUBJS.Chapter=function(a){this.href=a.href,this.absolute=a.url,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.absolute)),this.tempUrl):(b.resolve(this.absolute),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,h=XMLHttpRequest.prototype;return"overrideMimeType"in h||Object.defineProperty(h,"overrideMimeType",{value:function(){}}),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(var c in a){var d;a.hasOwnProperty(c)&&(d=a[c],d.ident=c,b.push(d))}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,c,d,e,f,g=";base64,";if(-1==a.indexOf(g))return b=a.split(","),c=b[0].split(":")[1],d=b[1],new Blob([d],{type:c});b=a.split(g),c=b[0].split(":")[1],d=window.atob(b[1]),e=d.length,f=new Uint8Array(e);for(var h=0;e>h;++h)f[h]=d.charCodeAt(h);return new Blob([f],{type:c})},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.addScript(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;if("undefined"!=typeof document.body.style[a])return a;for(var e=0;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 d=parseInt(b),e=a+1,f="/"+e+"/";return f+=2*(d+1),c&&(f+="["+c+"]"),f+="!"},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&&9!=a.parentNode.nodeType;)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){for(var c,d=b||document,e=a.sections,f=d.getElementsByTagName("html")[0],g=Array.prototype.slice.call(f.children);e.length>0;)c=e.shift(),c.id?f=d.getElementById(c.id):(f=g[c.index],g||console.error("No Kids",f)),f||console.error("No Element For",c),g=Array.prototype.slice.call(f.children);return f},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.findNavPath(e),i=c.findTocPath(e),j=c.findCoverPath(e),k=Array.prototype.indexOf.call(f.parentNode.childNodes,f),l=c.spine(f,g),m={};return l.forEach(function(a){m[a.href]=a.index}),{metadata:c.metadata(d),spine:l,manifest:g,navPath:h,tocPath:i,coverPath:j,spineNodeIndex:k,spineIndexByURL:m}},EPUBJS.Parser.prototype.findNavPath=function(a){var b=a.querySelector("item[properties^='nav']");return b?b.getAttribute("href"):!1},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")||"",g=a.getAttribute("properties")||"";c[d]={href:e,url:b+e,type:f,properties:g}}),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:b[e].properties||"",href:b[e].href,url:b[e].url,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.nav=function(a,b,c){function d(a){var b=[];return Array.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}function e(a){var b=null;return Array.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}function f(a){var g=[],i=d(a),j=Array.prototype.slice.call(i),k=j.length;return 0===k?!1:(j.forEach(function(d){var i,j=d.getAttribute("id")||!1,k=e(d),l=k.getAttribute("href")||"",m=k.textContent||"",n=l.split("#"),o=n[0],p=f(d),q=b[o];j||(q?(i=c[q],j=i.id):j="epubjs-autogen-toc-id-"+h++),d.setAttribute("id",j),g.push({id:j,href:l,label:m,subitems:p,parent:a?a.getAttribute("id"):null})}),g)}var g=a.querySelector("nav"),h=0;return g?f(g):[]},EPUBJS.Parser.prototype.toc=function(a,b,c){function d(a){var e,f=[],g=[],h=a.childNodes,i=Array.prototype.slice.call(h),j=i.length,k=j;if(0===j)return!1;for(;k--;)e=i[k],"navPoint"===e.nodeName&&g.push(e);return g.forEach(function(e){var g,h=e.getAttribute("id")||!1,i=e.querySelector("content"),j=i.getAttribute("src"),k=e.querySelector("navLabel"),l=k.textContent?k.textContent:"",m=j.split("#"),n=m[0],o=b[n],p=d(e);h||(o?(g=c[o],h=g.id):h="epubjs-autogen-toc-id-"+idCounter++),f.unshift({id:h,href:j,label:l,subitems:p,parent:a?a.getAttribute("id"):null})}),f}var e=a.querySelector("navMap");return e?d(e):[]},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,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(),0!=b.width&&0!=b.height&&b.left>=0&&b.lefte;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){var b,c,d,e;!function(){var a={},f={};b=function(b,c,d){a[b]={deps:c,callback:d}},e=d=c=function(b){function d(a){if("."!==a.charAt(0))return a;for(var c=a.split("/"),d=b.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){var g=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}return d.join("/")}if(e._eak_seen=a,f[b])return f[b];if(f[b]={},!a[b])throw new Error("Could not find module "+b);for(var g,h=a[b],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)"exports"===i[l]?k.push(g={}):k.push(c(d(i[l])));var n=j.apply(this,k);return f[b]=g||n}}(),b("rsvp/all",["./promise","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=function(a,b){return c.all(a,b)}}),b("rsvp/asap",["exports"],function(a){"use strict";function b(){return function(){process.nextTick(e)}}function c(){var a=0,b=new h(e),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function d(){return function(){setTimeout(e,1)}}function e(){for(var a=0;ac;c++)if(a[c]===b)return c;return-1},c=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b};a["default"]={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a._promiseCallbacks=void 0,a},on:function(a,d){var e,f=c(this);e=f[a],e||(e=f[a]=[]),-1===b(e,d)&&e.push(d)},off:function(a,d){var e,f,g=c(this);return d?(e=g[a],f=b(e,d),-1!==f&&e.splice(f,1),void 0):(g[a]=[],void 0)},trigger:function(a,b){var d,e,f=c(this);if(d=f[a])for(var g=0;gb;b++)a[b]&&e.push(d[b]);return e})})}var f=a["default"],g=b["default"],h=c.isFunction,i=c.isArray;d["default"]=e}),b("rsvp/hash",["./promise","./utils","exports"],function(a,b,c){"use strict";var d=a["default"],e=b.isNonThenable,f=b.keysOf;c["default"]=function(a){return new d(function(b,c){function g(a){return function(c){k[a]=c,0===--m&&b(k)}}function h(a){m=0,c(a)}var i,j,k={},l=f(a),m=l.length;if(0===m)return b(k),void 0;for(var n=0;nd;d++)g.push(b(a[d]));return e(g,c)})}}),b("rsvp/node",["./promise","exports"],function(a,b){"use strict";function c(a,b){return function(c,d){c?b(c):arguments.length>2?a(e.call(arguments,1)):a(d)}}var d=a["default"],e=Array.prototype.slice;b["default"]=function(a,b){return function(){var f=e.call(arguments),g=this||b;return new d(function(b,e){d.all(f).then(function(d){try{d.push(c(b,e)),a.apply(g,d)}catch(f){e(f)}})})}}}),b("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(){}function l(a,b){if(!z(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof l))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=H++,this._label=b,this._subscribers=[],w.instrument&&x("created",this),k!==a&&m(a,this)}function m(a,b){function c(a){r(b,a)}function d(a){t(b,a)}try{a(c,d)}catch(e){d(e)}}function n(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+K]=c,e[f+L]=d}function o(a,b){var c,d,e=a._subscribers,f=a._detail;w.instrument&&x(b===K?"fulfilled":"rejected",a);for(var g=0;ge||e>=this.spine.length)&&(console.warn("Not A Valid Location"),e=0,b=!1,d=!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.getCurrentLocationCfi=function(){return this.isRendered?this.render.currentLocationCfi:!1},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=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=this.spineIndexByURL[c],c||(e=this.chapter?this.chapter.spinePos:0),"number"!=typeof e?!1:this.chapter&&e==this.chapter.spinePos?(d&&this.render.section(d),f.resolve(this.currentChapter),f.promise):this.displayChapter(e).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a;return this.spinePos>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(a.absolute),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.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,args: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.args)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;_.values(this.hooks);for(var c in this.hooks)a=_.values(EPUBJS.Hooks[c]),a.forEach(function(a){b.registerHook(c,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),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(a){console.error(a.detail.message,a.detail.stack)}),EPUBJS.Chapter=function(a){this.href=a.href,this.absolute=a.url,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.absolute)),this.tempUrl):(b.resolve(this.absolute),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,h=XMLHttpRequest.prototype;return"overrideMimeType"in h||Object.defineProperty(h,"overrideMimeType",{value:function(){}}),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(var c in a){var d;a.hasOwnProperty(c)&&(d=a[c],d.ident=c,b.push(d))}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,c,d,e,f,g=";base64,";if(-1==a.indexOf(g))return b=a.split(","),c=b[0].split(":")[1],d=b[1],new Blob([d],{type:c});b=a.split(g),c=b[0].split(":")[1],d=window.atob(b[1]),e=d.length,f=new Uint8Array(e);for(var h=0;e>h;++h)f[h]=d.charCodeAt(h);return new Blob([f],{type:c})},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.addScript(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;if("undefined"!=typeof document.body.style[a])return a;for(var e=0;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 d=parseInt(b),e=a+1,f="/"+e+"/";return f+=2*(d+1),c&&(f+="["+c+"]"),f+="!"},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&&9!=a.parentNode.nodeType;)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,g={};return g.chapter=this.getChapter(a),b=parseInt(g.chapter.split("/")[2])||!1,g.fragment=this.getFragment(a),b&&g.fragment?(g.spinePos=parseInt(b)/2-1||0,c=g.chapter.match(/\[(.*)\]/),g.spineId=c?c[1]:!1,d=g.fragment.split("/"),e=d[d.length-1],g.sections=[],parseInt(e)%2&&(f=this.getOffset(),g.text=parseInt(f[0]),g.character=parseInt(f[1]),d.pop()),d.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),g.sections.push({index:b,id:d||!1}))}),g):{spinePos:-1}},EPUBJS.EpubCFI.prototype.getElement=function(a,b){for(var c,d=b||document,e=a.sections,f=d.getElementsByTagName("html")[0],g=Array.prototype.slice.call(f.children);e.length>0;)c=e.shift(),c.id?f=d.getElementById(c.id):(f=g[c.index],g||console.error("No Kids",f)),f||console.error("No Element For",c),g=Array.prototype.slice.call(f.children);return f},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.identifier=function(a){var b=a.querySelector("metadata");return this.getElementText(b,"identifier")},EPUBJS.Parser.prototype.packageContents=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.findNavPath(e),i=c.findTocPath(e),j=c.findCoverPath(e),k=Array.prototype.indexOf.call(f.parentNode.childNodes,f),l=c.spine(f,g),m={};return l.forEach(function(a){m[a.href]=a.index}),{metadata:c.metadata(d),spine:l,manifest:g,navPath:h,tocPath:i,coverPath:j,spineNodeIndex:k,spineIndexByURL:m}},EPUBJS.Parser.prototype.findNavPath=function(a){var b=a.querySelector("item[properties^='nav']");return b?b.getAttribute("href"):!1},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")||"",g=a.getAttribute("properties")||"";c[d]={href:e,url:b+e,type:f,properties:g}}),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:b[e].properties||"",href:b[e].href,url:b[e].url,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.nav=function(a,b,c){function d(a){var b=[];return Array.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}function e(a){var b=null;return Array.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}function f(a){var g=[],i=d(a),j=Array.prototype.slice.call(i),k=j.length;return 0===k?!1:(j.forEach(function(d){var i,j=d.getAttribute("id")||!1,k=e(d),l=k.getAttribute("href")||"",m=k.textContent||"",n=l.split("#"),o=n[0],p=f(d),q=b[o];j||(q?(i=c[q],j=i.id):j="epubjs-autogen-toc-id-"+h++),d.setAttribute("id",j),g.push({id:j,href:l,label:m,subitems:p,parent:a?a.getAttribute("id"):null})}),g)}var g=a.querySelector("nav"),h=0;return g?f(g):[]},EPUBJS.Parser.prototype.toc=function(a,b,c){function d(a){var e,f=[],g=[],h=a.childNodes,i=Array.prototype.slice.call(h),j=i.length,k=j;if(0===j)return!1;for(;k--;)e=i[k],"navPoint"===e.nodeName&&g.push(e);return g.forEach(function(e){var g,h=e.getAttribute("id")||!1,i=e.querySelector("content"),j=i.getAttribute("src"),k=e.querySelector("navLabel"),l=k.textContent?k.textContent:"",m=j.split("#"),n=m[0],o=b[n],p=d(e);h||(o?(g=c[o],h=g.id):h="epubjs-autogen-toc-id-"+idCounter++),f.unshift({id:h,href:j,label:l,subitems:p,parent:a?a.getAttribute("id"):null})}),f}var e=a.querySelector("navMap");return e?d(e):[]},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,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(),0!=b.width&&0!=b.height&&b.left>=0&&b.left -1 ) return; - var $title = $("#book-title"), - $author = $("#chapter-title"), - $dash = $("#title-seperator"); - - document.title = title+" – "+author; - - $title.html(title); - $author.html(author); - $dash.show(); + this.settings.bookmarks.push(cfi); + + this.trigger("reader:bookmarked", cfi); }; -EPUBJS.reader.ReaderView = function(book) { - var $main = $("#main"), - $divider = $("#divider"), - $loader = $("#loader"), - $next = $("#next"), - $prev = $("#prev"); +EPUBJS.Reader.prototype.removeBookmark = function(cfi) { + var bookmark = this.isBookmarked(cfi); + if(!bookmark === -1 ) return; - var slideIn = function() { - $main.removeClass("closed"); - }; - - var slideOut = function() { - $main.addClass("closed"); - }; - - var showLoader = function() { - $loader.show(); - }; - - var hideLoader = function() { - $loader.hide(); - }; - - var showDivider = function() { - $divider.addClass("show"); - }; - - var hideDivider = function() { - $divider.removeClass("show"); - }; - - var keylock = false; - - var arrowKeys = function(e) { - if(e.keyCode == 37) { - book.prevPage(); - $prev.addClass("active"); - - keylock = true; - setTimeout(function(){ - keylock = false; - $prev.removeClass("active"); - }, 100); - - e.preventDefault(); - } - if(e.keyCode == 39) { - book.nextPage(); - $next.addClass("active"); - - keylock = true; - setTimeout(function(){ - keylock = false; - $next.removeClass("active"); - }, 100); - - e.preventDefault(); - } - } - - document.addEventListener('keydown', arrowKeys, false); - - $next.on("click", function(e){ - book.nextPage(); - e.preventDefault(); - }); - - $prev.on("click", function(e){ - book.prevPage(); - e.preventDefault(); - }); - - //-- Hide the spinning loader - hideLoader(); - - //-- If the book is using spreads, show the divider - if(!book.single) { - showDivider(); - } - - return { - "slideOut" : slideOut, - "slideIn" : slideIn, - "showLoader" : showLoader, - "hideLoader" : hideLoader, - "showDivider" : showDivider, - "hideDivider" : hideDivider - }; + delete this.settings.bookmarks[bookmark]; }; -EPUBJS.reader.SidebarView = function(book) { - var reader = this; - - var $sidebar = $("#sidebar"), - $panels = $("#panels"); +EPUBJS.Reader.prototype.isBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks; - var activePanel = "TocView"; - - var changePanelTo = function(viewName) { - if(activePanel == viewName || typeof reader[viewName] === 'undefined' ) return; - reader[activePanel].hide(); - reader[viewName].show(); - activePanel = viewName; + return bookmarks.indexOf(cfi); +}; - $panels.find('.active').removeClass("active"); - $panels.find("#show-" + viewName ).addClass("active"); - }; +/* +EPUBJS.Reader.prototype.searchBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks, + len = bookmarks.length; + + for(var i = 0; i < len; i++) { + if (bookmarks[i]['cfi'] === cfi) return i; + } + return -1; +}; +*/ + +EPUBJS.Reader.prototype.clearBookmarks = function() { + this.settings.bookmarks = []; +}; + +//-- Settings +EPUBJS.Reader.prototype.setBookKey = function(identifier){ + if(!this.settings.bookKey) { + this.settings.bookKey = "epubjsreader:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; + } + return this.settings.bookKey; +}; + +//-- Checks if the book setting can be retrieved from localStorage +EPUBJS.Reader.prototype.isSaved = function(bookPath) { + var storedSettings = localStorage.getItem(this.settings.bookKey); + + if( !localStorage || + storedSettings === null) { + return false; + } else { + return true; + } +}; + +EPUBJS.Reader.prototype.removeSavedSettings = function() { + localStorage.removeItem(this.settings.bookKey); +}; + +EPUBJS.Reader.prototype.applySavedSettings = function() { + var stored = JSON.parse(localStorage.getItem(this.settings.bookKey)); + + if(stored) { + this.settings = _.defaults(this.settings, stored); + return true; + } else { + return false; + } +}; + +EPUBJS.Reader.prototype.saveSettings = function(){ + if(this.book) { + this.settings.previousLocationCfi = this.book.getCurrentLocationCfi(); + } + + localStorage.setItem(this.settings.bookKey, JSON.stringify(this.settings)); +}; + +EPUBJS.Reader.prototype.unload = function(){ + if(this.settings.restore) { + this.saveSettings(); + } +}; + +//-- Enable binding events to reader +RSVP.EventTarget.mixin(EPUBJS.Reader.prototype); +EPUBJS.reader.BookmarksController = function() { + var book = this.book; + + var $bookmarks = $("#bookmarksView"), + $list = $bookmarks.find("#bookmarks"); + + var docfrag = document.createDocumentFragment(); var show = function() { - reader.sidebarOpen = true; - reader.ReaderView.slideOut(); - $sidebar.addClass("open"); - } - + $bookmarks.show(); + }; + var hide = function() { - reader.sidebarOpen = false; - reader.ReaderView.slideIn(); - $sidebar.removeClass("open"); - } + $bookmarks.hide(); + }; - $panels.find(".show_view").on("click", function(event) { - var view = $(this).data("view"); + var createBookmarkItem = function(cfi) { + var listitem = document.createElement("li"), + link = document.createElement("a"); + + listitem.classList.add('list_item'); - changePanelTo(view); - event.preventDefault(); + //-- TODO: Parse Cfi + link.textContent = cfi; + link.href = cfi; + + link.classList.add('bookmark_link'); + + link.addEventListener("click", function(event){ + var cfi = this.getAttribute('href'); + book.gotoCfi(cfi); + event.preventDefault(); + }, false); + + listitem.appendChild(link); + return listitem; + }; + + this.settings.bookmarks.forEach(function(cfi) { + var bookmark = createBookmarkItem(cfi); + docfrag.appendChild(bookmark); }); + $list.append(docfrag); + + + + this.on("reader:bookmarked", function(cfi) { + var item = createBookmarkItem(cfi); + $list.append(item); + }); + return { - 'show' : show, - 'hide' : hide, - 'activePanel' : activePanel, - 'changePanelTo' : changePanelTo + "show" : show, + "hide" : hide }; }; - -EPUBJS.reader.ControlsView = function(book) { +EPUBJS.reader.ControlsController = function(book) { var reader = this; var $store = $("#store"), @@ -226,7 +241,7 @@ EPUBJS.reader.ControlsView = function(book) { $slider = $("#slider"), $main = $("#main"), $sidebar = $("#sidebar"), - $settings = $("#settings"), + $settings = $("#setting"), $bookmark = $("#bookmark"); var goOnline = function() { @@ -244,67 +259,256 @@ EPUBJS.reader.ControlsView = function(book) { $slider.on("click", function () { if(reader.sidebarOpen) { - reader.SidebarView.hide(); + reader.SidebarController.hide(); $slider.addClass("icon-menu"); $slider.removeClass("icon-right"); } else { - reader.SidebarView.show(); + reader.SidebarController.show(); $slider.addClass("icon-right"); $slider.removeClass("icon-menu"); } }); - + $fullscreen.on("click", function() { screenfull.toggle($('#container')[0]); $fullscreenicon.toggle(); $cancelfullscreenicon.toggle(); }); - + $settings.on("click", function() { - reader.SettingsView.show(); + reader.SettingsController.show(); }); $bookmark.on("click", function() { $bookmark.addClass("icon-bookmark"); $bookmark.removeClass("icon-bookmark-empty"); - console.log(reader.book.getCurrentLocationCfi()); + reader.addBookmark(reader.book.getCurrentLocationCfi()); }); book.on('renderer:pageChanged', function(cfi){ - //-- TODO: Check if bookmarked - $bookmark - .removeClass("icon-bookmark") - .addClass("icon-bookmark-empty"); + //-- Check if bookmarked + var bookmarked = reader.isBookmarked(cfi); + + if(bookmarked === -1) { //-- Not bookmarked + $bookmark + .removeClass("icon-bookmark") + .addClass("icon-bookmark-empty"); + } else { //-- Bookmarked + $bookmark + .addClass("icon-bookmark") + .removeClass("icon-bookmark-empty"); + } + }); return { - + }; }; +EPUBJS.reader.MetaController = function(meta) { + var title = meta.bookTitle, + author = meta.creator; -EPUBJS.reader.TocView = function(toc) { + var $title = $("#book-title"), + $author = $("#chapter-title"), + $dash = $("#title-seperator"); + + document.title = title+" – "+author; + + $title.html(title); + $author.html(author); + $dash.show(); +}; +EPUBJS.reader.ReaderController = function(book) { + var $main = $("#main"), + $divider = $("#divider"), + $loader = $("#loader"), + $next = $("#next"), + $prev = $("#prev"); + + var slideIn = function() { + $main.removeClass("closed"); + }; + + var slideOut = function() { + $main.addClass("closed"); + }; + + var showLoader = function() { + $loader.show(); + hideDivider(); + }; + + var hideLoader = function() { + $loader.hide(); + + //-- If the book is using spreads, show the divider + if(!book.single) { + showDivider(); + } + }; + + var showDivider = function() { + $divider.addClass("show"); + }; + + var hideDivider = function() { + $divider.removeClass("show"); + }; + + var keylock = false; + + var arrowKeys = function(e) { + if(e.keyCode == 37) { + book.prevPage(); + $prev.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $prev.removeClass("active"); + }, 100); + + e.preventDefault(); + } + if(e.keyCode == 39) { + book.nextPage(); + $next.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $next.removeClass("active"); + }, 100); + + e.preventDefault(); + } + } + + document.addEventListener('keydown', arrowKeys, false); + + $next.on("click", function(e){ + book.nextPage(); + e.preventDefault(); + }); + + $prev.on("click", function(e){ + book.prevPage(); + e.preventDefault(); + }); + + return { + "slideOut" : slideOut, + "slideIn" : slideIn, + "showLoader" : showLoader, + "hideLoader" : hideLoader, + "showDivider" : showDivider, + "hideDivider" : hideDivider + }; +}; +EPUBJS.reader.SettingsController = function() { var book = this.book; + + var $settings = $("#settings-modal"), + $overlay = $(".overlay"); + + var show = function() { + $settings.addClass("md-show"); + }; + + var hide = function() { + $settings.removeClass("md-show"); + }; + + $settings.find(".closer").on("click", function() { + hide(); + }); + + $overlay.on("click", function() { + hide(); + }); + + return { + "show" : show, + "hide" : hide + }; +}; +EPUBJS.reader.SidebarController = function(book) { + var reader = this; + + var $sidebar = $("#sidebar"), + $panels = $("#panels"); + + var activePanel = "Toc"; + + var changePanelTo = function(viewName) { + var controllerName = viewName + "Controller"; + + if(activePanel == viewName || typeof reader[controllerName] === 'undefined' ) return; + reader[activePanel+ "Controller"].hide(); + reader[controllerName].show(); + activePanel = viewName; + + $panels.find('.active').removeClass("active"); + $panels.find("#show-" + viewName ).addClass("active"); + }; + var getActivePanel = function() { + return activePanel; + }; + + var show = function() { + reader.sidebarOpen = true; + reader.ReaderController.slideOut(); + $sidebar.addClass("open"); + } + + var hide = function() { + reader.sidebarOpen = false; + reader.ReaderController.slideIn(); + $sidebar.removeClass("open"); + } + + $panels.find(".show_view").on("click", function(event) { + var view = $(this).data("view"); + + changePanelTo(view); + event.preventDefault(); + }); + + return { + 'show' : show, + 'hide' : hide, + 'getActivePanel' : getActivePanel, + 'changePanelTo' : changePanelTo + }; +}; +EPUBJS.reader.TocController = function(toc) { + var book = this.book; + var $list = $("#tocView"), docfrag = document.createDocumentFragment(); - + var currentChapter = false; - + var generateTocItems = function(toc, level) { var container = document.createElement("ul"); - + if(!level) level = 1; toc.forEach(function(chapter) { var listitem = document.createElement("li"), link = document.createElement("a"); toggle = document.createElement("a"); + var subitems; - + listitem.id = "toc-"+chapter.id; + listitem.classList.add('list_item'); link.textContent = chapter.label; link.href = chapter.href; + link.classList.add('toc_link'); listitem.appendChild(link); @@ -313,27 +517,27 @@ EPUBJS.reader.TocView = function(toc) { level++; subitems = generateTocItems(chapter.subitems, level); toggle.classList.add('toc_toggle'); - + listitem.insertBefore(toggle, link); listitem.appendChild(subitems); } - - + + container.appendChild(listitem); - + }); - + return container; }; - + var onShow = function() { $list.show(); }; - + var onHide = function() { $list.hide(); }; - + var chapterChange = function(e) { var id = e.id, $item = $list.find("#toc-"+id), @@ -341,24 +545,24 @@ EPUBJS.reader.TocView = function(toc) { $open = $list.find('.openChapter'); if($item.length){ - + if($item != $current && $item.has(currentChapter).length > 0) { $current.removeClass("currentChapter"); } - + $item.addClass("currentChapter"); - + // $open.removeClass("openChapter"); $item.parents('li').addClass("openChapter"); } }; - + book.on('renderer:chapterDisplayed', chapterChange); var tocitems = generateTocItems(toc); - + docfrag.appendChild(tocitems); - + $list.append(docfrag); $list.find(".toc_link").on("click", function(event){ var url = this.getAttribute('href'); @@ -366,20 +570,20 @@ EPUBJS.reader.TocView = function(toc) { //-- Provide the Book with the url to show // The Url must be found in the books manifest book.goto(url); - + $list.find(".currentChapter") .addClass("openChapter") .removeClass("currentChapter"); - + $(this).parent('li').addClass("currentChapter"); - + event.preventDefault(); }); $list.find(".toc_toggle").on("click", function(event){ var $el = $(this).parent('li'), open = $el.hasClass("openChapter"); - + if(open){ $el.removeClass("openChapter"); } else { @@ -387,28 +591,9 @@ EPUBJS.reader.TocView = function(toc) { } event.preventDefault(); }); - + return { "show" : onShow, "hide" : onHide }; }; - -EPUBJS.reader.SettingsView = function() { - var book = this.book; - - var $settings = $("#settingsPanel"); - - var onShow = function() { - $settings.show(); - }; - - var onHide = function() { - $settings.hide(); - }; - - return { - "show" : onShow, - "hide" : onHide - }; -}; \ No newline at end of file diff --git a/demo/css/main.css b/demo/css/main.css index 61e5e1e..4e46054 100755 --- a/demo/css/main.css +++ b/demo/css/main.css @@ -260,7 +260,8 @@ input:-moz-placeholder { margin: -33px 0 0 -33px; } -#tocView { +#tocView, +#bookmarksView { overflow-x: hidden; overflow-y: hidden; width: 300px; @@ -273,21 +274,24 @@ input:-moz-placeholder { -#sidebar.open #tocView { +#sidebar.open #tocView, +#sidebar.open #bookmarksView { overflow-y: auto; visibility: visible; -webkit-transition: visibility 0 ease 0; -moz-transition: visibility 0 ease 0; } -#tocView > ul{ +#tocView > ul, +#bookmarksView > ul { margin-top: 15px; margin-bottom: 50px; padding-left: 20px; display: block; } -#tocView li { +#tocView li, +#bookmarksView li { margin-bottom:10px; width: 225px; font-family: Georgia, "Times New Roman", Times, serif; @@ -301,37 +305,37 @@ input:-moz-placeholder { list-style: none; } -#tocView a { +.list_item a { color: #AAA; text-decoration: none; } -#tocView a.chapter { +.list_item a.chapter { font-size: 1em; } -#tocView a.section { +.list_item a.section { font-size: .8em; } -#tocView li.currentChapter > a, -#tocView li a:hover { +.list_item.currentChapter > a, +.list_item a:hover { color: #f1f1f1 } /* #tocView li.openChapter > a, */ -#tocView li a:hover { +.list_item a:hover { color: #E2E2E2; } -#tocView li ul { +.list_item ul { padding-left:10px; margin-top: 8px; display: none; } -#tocView li.currentChapter > ul, -#tocView li.openChapter > ul { +.list_item.currentChapter > ul, +.list_item.openChapter > ul { display: block; } diff --git a/demo/dev.html b/demo/dev.html index e04d3ea..f5d2b9f 100755 --- a/demo/dev.html +++ b/demo/dev.html @@ -66,6 +66,13 @@ + + + + + + + @@ -80,10 +87,10 @@
@@ -91,9 +98,9 @@
    -
    +
    +
      -
      diff --git a/demo/index.html b/demo/index.html index b80affb..469f4fe 100755 --- a/demo/index.html +++ b/demo/index.html @@ -54,10 +54,10 @@
      @@ -65,9 +65,9 @@
        -
        +
        +
          -
          @@ -94,5 +94,15 @@
          + +
          diff --git a/demo/js/epub.min.js b/demo/js/epub.min.js index 0c138f1..65f690b 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){var b,c,d,e;!function(){var a={},f={};b=function(b,c,d){a[b]={deps:c,callback:d}},e=d=c=function(b){function d(a){if("."!==a.charAt(0))return a;for(var c=a.split("/"),d=b.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){var g=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}return d.join("/")}if(e._eak_seen=a,f[b])return f[b];if(f[b]={},!a[b])throw new Error("Could not find module "+b);for(var g,h=a[b],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)"exports"===i[l]?k.push(g={}):k.push(c(d(i[l])));var n=j.apply(this,k);return f[b]=g||n}}(),b("rsvp/all",["./promise","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=function(a,b){return c.all(a,b)}}),b("rsvp/asap",["exports"],function(a){"use strict";function b(){return function(){process.nextTick(e)}}function c(){var a=0,b=new h(e),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function d(){return function(){setTimeout(e,1)}}function e(){for(var a=0;ac;c++)if(a[c]===b)return c;return-1},c=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b};a["default"]={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a._promiseCallbacks=void 0,a},on:function(a,d){var e,f=c(this);e=f[a],e||(e=f[a]=[]),-1===b(e,d)&&e.push(d)},off:function(a,d){var e,f,g=c(this);return d?(e=g[a],f=b(e,d),-1!==f&&e.splice(f,1),void 0):(g[a]=[],void 0)},trigger:function(a,b){var d,e,f=c(this);if(d=f[a])for(var g=0;gb;b++)a[b]&&e.push(d[b]);return e})})}var f=a["default"],g=b["default"],h=c.isFunction,i=c.isArray;d["default"]=e}),b("rsvp/hash",["./promise","./utils","exports"],function(a,b,c){"use strict";var d=a["default"],e=b.isNonThenable,f=b.keysOf;c["default"]=function(a){return new d(function(b,c){function g(a){return function(c){k[a]=c,0===--m&&b(k)}}function h(a){m=0,c(a)}var i,j,k={},l=f(a),m=l.length;if(0===m)return b(k),void 0;for(var n=0;nd;d++)g.push(b(a[d]));return e(g,c)})}}),b("rsvp/node",["./promise","exports"],function(a,b){"use strict";function c(a,b){return function(c,d){c?b(c):arguments.length>2?a(e.call(arguments,1)):a(d)}}var d=a["default"],e=Array.prototype.slice;b["default"]=function(a,b){return function(){var f=e.call(arguments),g=this||b;return new d(function(b,e){d.all(f).then(function(d){try{d.push(c(b,e)),a.apply(g,d)}catch(f){e(f)}})})}}}),b("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(){}function l(a,b){if(!z(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof l))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=H++,this._label=b,this._subscribers=[],w.instrument&&x("created",this),k!==a&&m(a,this)}function m(a,b){function c(a){r(b,a)}function d(a){t(b,a)}try{a(c,d)}catch(e){d(e)}}function n(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+K]=c,e[f+L]=d}function o(a,b){var c,d,e=a._subscribers,f=a._detail;w.instrument&&x(b===K?"fulfilled":"rejected",a);for(var g=0;ge||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.getCurrentLocationCfi=function(){return this.isRendered?this.render.currentLocationCfi:!1},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=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=this.spineIndexByURL[c],c||(e=this.chapter?this.chapter.spinePos:0),"number"!=typeof e?!1:this.chapter&&e==this.chapter.spinePos?(d&&this.render.section(d),f.resolve(this.currentChapter),f.promise):this.displayChapter(e).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a;return this.spinePos>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(a.absolute),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,args: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.args)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;_.values(this.hooks);for(var c in this.hooks)a=_.values(EPUBJS.Hooks[c]),a.forEach(function(a){b.registerHook(c,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),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(a){console.error(a.detail,a.detail.message)}),EPUBJS.Chapter=function(a){this.href=a.href,this.absolute=a.url,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.absolute)),this.tempUrl):(b.resolve(this.absolute),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,h=XMLHttpRequest.prototype;return"overrideMimeType"in h||Object.defineProperty(h,"overrideMimeType",{value:function(){}}),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(var c in a){var d;a.hasOwnProperty(c)&&(d=a[c],d.ident=c,b.push(d))}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,c,d,e,f,g=";base64,";if(-1==a.indexOf(g))return b=a.split(","),c=b[0].split(":")[1],d=b[1],new Blob([d],{type:c});b=a.split(g),c=b[0].split(":")[1],d=window.atob(b[1]),e=d.length,f=new Uint8Array(e);for(var h=0;e>h;++h)f[h]=d.charCodeAt(h);return new Blob([f],{type:c})},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.addScript(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;if("undefined"!=typeof document.body.style[a])return a;for(var e=0;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 d=parseInt(b),e=a+1,f="/"+e+"/";return f+=2*(d+1),c&&(f+="["+c+"]"),f+="!"},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&&9!=a.parentNode.nodeType;)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){for(var c,d=b||document,e=a.sections,f=d.getElementsByTagName("html")[0],g=Array.prototype.slice.call(f.children);e.length>0;)c=e.shift(),c.id?f=d.getElementById(c.id):(f=g[c.index],g||console.error("No Kids",f)),f||console.error("No Element For",c),g=Array.prototype.slice.call(f.children);return f},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.findNavPath(e),i=c.findTocPath(e),j=c.findCoverPath(e),k=Array.prototype.indexOf.call(f.parentNode.childNodes,f),l=c.spine(f,g),m={};return l.forEach(function(a){m[a.href]=a.index}),{metadata:c.metadata(d),spine:l,manifest:g,navPath:h,tocPath:i,coverPath:j,spineNodeIndex:k,spineIndexByURL:m}},EPUBJS.Parser.prototype.findNavPath=function(a){var b=a.querySelector("item[properties^='nav']");return b?b.getAttribute("href"):!1},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")||"",g=a.getAttribute("properties")||"";c[d]={href:e,url:b+e,type:f,properties:g}}),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:b[e].properties||"",href:b[e].href,url:b[e].url,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.nav=function(a,b,c){function d(a){var b=[];return Array.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}function e(a){var b=null;return Array.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}function f(a){var g=[],i=d(a),j=Array.prototype.slice.call(i),k=j.length;return 0===k?!1:(j.forEach(function(d){var i,j=d.getAttribute("id")||!1,k=e(d),l=k.getAttribute("href")||"",m=k.textContent||"",n=l.split("#"),o=n[0],p=f(d),q=b[o];j||(q?(i=c[q],j=i.id):j="epubjs-autogen-toc-id-"+h++),d.setAttribute("id",j),g.push({id:j,href:l,label:m,subitems:p,parent:a?a.getAttribute("id"):null})}),g)}var g=a.querySelector("nav"),h=0;return g?f(g):[]},EPUBJS.Parser.prototype.toc=function(a,b,c){function d(a){var e,f=[],g=[],h=a.childNodes,i=Array.prototype.slice.call(h),j=i.length,k=j;if(0===j)return!1;for(;k--;)e=i[k],"navPoint"===e.nodeName&&g.push(e);return g.forEach(function(e){var g,h=e.getAttribute("id")||!1,i=e.querySelector("content"),j=i.getAttribute("src"),k=e.querySelector("navLabel"),l=k.textContent?k.textContent:"",m=j.split("#"),n=m[0],o=b[n],p=d(e);h||(o?(g=c[o],h=g.id):h="epubjs-autogen-toc-id-"+idCounter++),f.unshift({id:h,href:j,label:l,subitems:p,parent:a?a.getAttribute("id"):null})}),f}var e=a.querySelector("navMap");return e?d(e):[]},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,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(),0!=b.width&&0!=b.height&&b.left>=0&&b.lefte;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){var b,c,d,e;!function(){var a={},f={};b=function(b,c,d){a[b]={deps:c,callback:d}},e=d=c=function(b){function d(a){if("."!==a.charAt(0))return a;for(var c=a.split("/"),d=b.split("/").slice(0,-1),e=0,f=c.length;f>e;e++){var g=c[e];if(".."===g)d.pop();else{if("."===g)continue;d.push(g)}}return d.join("/")}if(e._eak_seen=a,f[b])return f[b];if(f[b]={},!a[b])throw new Error("Could not find module "+b);for(var g,h=a[b],i=h.deps,j=h.callback,k=[],l=0,m=i.length;m>l;l++)"exports"===i[l]?k.push(g={}):k.push(c(d(i[l])));var n=j.apply(this,k);return f[b]=g||n}}(),b("rsvp/all",["./promise","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=function(a,b){return c.all(a,b)}}),b("rsvp/asap",["exports"],function(a){"use strict";function b(){return function(){process.nextTick(e)}}function c(){var a=0,b=new h(e),c=document.createTextNode("");return b.observe(c,{characterData:!0}),function(){c.data=a=++a%2}}function d(){return function(){setTimeout(e,1)}}function e(){for(var a=0;ac;c++)if(a[c]===b)return c;return-1},c=function(a){var b=a._promiseCallbacks;return b||(b=a._promiseCallbacks={}),b};a["default"]={mixin:function(a){return a.on=this.on,a.off=this.off,a.trigger=this.trigger,a._promiseCallbacks=void 0,a},on:function(a,d){var e,f=c(this);e=f[a],e||(e=f[a]=[]),-1===b(e,d)&&e.push(d)},off:function(a,d){var e,f,g=c(this);return d?(e=g[a],f=b(e,d),-1!==f&&e.splice(f,1),void 0):(g[a]=[],void 0)},trigger:function(a,b){var d,e,f=c(this);if(d=f[a])for(var g=0;gb;b++)a[b]&&e.push(d[b]);return e})})}var f=a["default"],g=b["default"],h=c.isFunction,i=c.isArray;d["default"]=e}),b("rsvp/hash",["./promise","./utils","exports"],function(a,b,c){"use strict";var d=a["default"],e=b.isNonThenable,f=b.keysOf;c["default"]=function(a){return new d(function(b,c){function g(a){return function(c){k[a]=c,0===--m&&b(k)}}function h(a){m=0,c(a)}var i,j,k={},l=f(a),m=l.length;if(0===m)return b(k),void 0;for(var n=0;nd;d++)g.push(b(a[d]));return e(g,c)})}}),b("rsvp/node",["./promise","exports"],function(a,b){"use strict";function c(a,b){return function(c,d){c?b(c):arguments.length>2?a(e.call(arguments,1)):a(d)}}var d=a["default"],e=Array.prototype.slice;b["default"]=function(a,b){return function(){var f=e.call(arguments),g=this||b;return new d(function(b,e){d.all(f).then(function(d){try{d.push(c(b,e)),a.apply(g,d)}catch(f){e(f)}})})}}}),b("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(){}function l(a,b){if(!z(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof l))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=H++,this._label=b,this._subscribers=[],w.instrument&&x("created",this),k!==a&&m(a,this)}function m(a,b){function c(a){r(b,a)}function d(a){t(b,a)}try{a(c,d)}catch(e){d(e)}}function n(a,b,c,d){var e=a._subscribers,f=e.length;e[f]=b,e[f+K]=c,e[f+L]=d}function o(a,b){var c,d,e=a._subscribers,f=a._detail;w.instrument&&x(b===K?"fulfilled":"rejected",a);for(var g=0;ge||e>=this.spine.length)&&(console.warn("Not A Valid Location"),e=0,b=!1,d=!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.getCurrentLocationCfi=function(){return this.isRendered?this.render.currentLocationCfi:!1},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=new RSVP.defer;return this.isRendered?(b=a.split("#"),c=b[0],d=b[1]||!1,e=this.spineIndexByURL[c],c||(e=this.chapter?this.chapter.spinePos:0),"number"!=typeof e?!1:this.chapter&&e==this.chapter.spinePos?(d&&this.render.section(d),f.resolve(this.currentChapter),f.promise):this.displayChapter(e).then(function(){d&&this.render.section(d)}.bind(this))):this._enqueue("goto",arguments)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a;return this.spinePos>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[this.spinePos+1]),EPUBJS.core.request(a.absolute),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.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,args: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.args)})},EPUBJS.Book.prototype.getHooks=function(){var a,b=this;_.values(this.hooks);for(var c in this.hooks)a=_.values(EPUBJS.Hooks[c]),a.forEach(function(a){b.registerHook(c,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),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(a){console.error(a.detail.message,a.detail.stack)}),EPUBJS.Chapter=function(a){this.href=a.href,this.absolute=a.url,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.absolute)),this.tempUrl):(b.resolve(this.absolute),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,h=XMLHttpRequest.prototype;return"overrideMimeType"in h||Object.defineProperty(h,"overrideMimeType",{value:function(){}}),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(var c in a){var d;a.hasOwnProperty(c)&&(d=a[c],d.ident=c,b.push(d))}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,c,d,e,f,g=";base64,";if(-1==a.indexOf(g))return b=a.split(","),c=b[0].split(":")[1],d=b[1],new Blob([d],{type:c});b=a.split(g),c=b[0].split(":")[1],d=window.atob(b[1]),e=d.length,f=new Uint8Array(e);for(var h=0;e>h;++h)f[h]=d.charCodeAt(h);return new Blob([f],{type:c})},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.addScript(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;if("undefined"!=typeof document.body.style[a])return a;for(var e=0;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 d=parseInt(b),e=a+1,f="/"+e+"/";return f+=2*(d+1),c&&(f+="["+c+"]"),f+="!"},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&&9!=a.parentNode.nodeType;)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,g={};return g.chapter=this.getChapter(a),b=parseInt(g.chapter.split("/")[2])||!1,g.fragment=this.getFragment(a),b&&g.fragment?(g.spinePos=parseInt(b)/2-1||0,c=g.chapter.match(/\[(.*)\]/),g.spineId=c?c[1]:!1,d=g.fragment.split("/"),e=d[d.length-1],g.sections=[],parseInt(e)%2&&(f=this.getOffset(),g.text=parseInt(f[0]),g.character=parseInt(f[1]),d.pop()),d.forEach(function(a){var b,c,d;a&&(b=parseInt(a)/2-1,c=a.match(/\[(.*)\]/),c&&c[1]&&(d=c[1]),g.sections.push({index:b,id:d||!1}))}),g):{spinePos:-1}},EPUBJS.EpubCFI.prototype.getElement=function(a,b){for(var c,d=b||document,e=a.sections,f=d.getElementsByTagName("html")[0],g=Array.prototype.slice.call(f.children);e.length>0;)c=e.shift(),c.id?f=d.getElementById(c.id):(f=g[c.index],g||console.error("No Kids",f)),f||console.error("No Element For",c),g=Array.prototype.slice.call(f.children);return f},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.identifier=function(a){var b=a.querySelector("metadata");return this.getElementText(b,"identifier")},EPUBJS.Parser.prototype.packageContents=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.findNavPath(e),i=c.findTocPath(e),j=c.findCoverPath(e),k=Array.prototype.indexOf.call(f.parentNode.childNodes,f),l=c.spine(f,g),m={};return l.forEach(function(a){m[a.href]=a.index}),{metadata:c.metadata(d),spine:l,manifest:g,navPath:h,tocPath:i,coverPath:j,spineNodeIndex:k,spineIndexByURL:m}},EPUBJS.Parser.prototype.findNavPath=function(a){var b=a.querySelector("item[properties^='nav']");return b?b.getAttribute("href"):!1},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")||"",g=a.getAttribute("properties")||"";c[d]={href:e,url:b+e,type:f,properties:g}}),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:b[e].properties||"",href:b[e].href,url:b[e].url,index:d};c.push(f)}),c},EPUBJS.Parser.prototype.nav=function(a,b,c){function d(a){var b=[];return Array.prototype.slice.call(a.childNodes).forEach(function(a){"ol"==a.tagName&&Array.prototype.slice.call(a.childNodes).forEach(function(a){"li"==a.tagName&&b.push(a)})}),b}function e(a){var b=null;return Array.prototype.slice.call(a.childNodes).forEach(function(a){("a"==a.tagName||"span"==a.tagName)&&(b=a)}),b}function f(a){var g=[],i=d(a),j=Array.prototype.slice.call(i),k=j.length;return 0===k?!1:(j.forEach(function(d){var i,j=d.getAttribute("id")||!1,k=e(d),l=k.getAttribute("href")||"",m=k.textContent||"",n=l.split("#"),o=n[0],p=f(d),q=b[o];j||(q?(i=c[q],j=i.id):j="epubjs-autogen-toc-id-"+h++),d.setAttribute("id",j),g.push({id:j,href:l,label:m,subitems:p,parent:a?a.getAttribute("id"):null})}),g)}var g=a.querySelector("nav"),h=0;return g?f(g):[]},EPUBJS.Parser.prototype.toc=function(a,b,c){function d(a){var e,f=[],g=[],h=a.childNodes,i=Array.prototype.slice.call(h),j=i.length,k=j;if(0===j)return!1;for(;k--;)e=i[k],"navPoint"===e.nodeName&&g.push(e);return g.forEach(function(e){var g,h=e.getAttribute("id")||!1,i=e.querySelector("content"),j=i.getAttribute("src"),k=e.querySelector("navLabel"),l=k.textContent?k.textContent:"",m=j.split("#"),n=m[0],o=b[n],p=d(e);h||(o?(g=c[o],h=g.id):h="epubjs-autogen-toc-id-"+idCounter++),f.unshift({id:h,href:j,label:l,subitems:p,parent:a?a.getAttribute("id"):null})}),f}var e=a.querySelector("navMap");return e?d(e):[]},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,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(),0!=b.width&&0!=b.height&&b.left>=0&&b.left0&&f.removeClass("currentChapter"),d.addClass("currentChapter"),d.parents("li").addClass("openChapter"))};b.on("renderer:chapterDisplayed",i);var j=f(a);return d.appendChild(j),c.append(d),c.find(".toc_link").on("click",function(a){var d=this.getAttribute("href");b.goto(d),c.find(".currentChapter").addClass("openChapter").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter"),a.preventDefault()}),c.find(".toc_toggle").on("click",function(a){var b=$(this).parent("li"),c=b.hasClass("openChapter");c?b.removeClass("openChapter"):b.addClass("openChapter"),a.preventDefault()}),{show:g,hide:h}},EPUBJS.reader.SettingsView=function(){this.book;var a=$("#settingsPanel"),b=function(){a.show()},c=function(){a.hide()};return{show:b,hide:c}}; \ No newline at end of file +EPUBJS.reader={},EPUBJS.reader.plugins={},function(a){var b=a.ePubReader||{},c=a.ePubReader=function(a,b){return new EPUBJS.Reader(a,b)};_.extend(c,{noConflict:function(){return a.ePubReader=b,this}}),"function"==typeof define&&define.amd?define(function(){return Reader}):"undefined"!=typeof module&&module.exports&&(module.exports=c)}(window),EPUBJS.Reader=function(a,b){var c,d=this;this.settings=_.defaults(b||{},{restore:!0,bookmarks:null}),this.setBookKey(a),this.settings.restore&&this.isSaved()&&this.applySavedSettings(),this.book=c=new EPUBJS.Book({bookPath:a,restore:this.settings.restore,previousLocationCfi:this.settings.previousLocationCfi}),this.offline=!1,this.sidebarOpen=!1,this.settings.bookmarks||(this.settings.bookmarks=[]),c.renderTo("viewer"),d.ReaderController=EPUBJS.reader.ReaderController.call(d,c),d.SettingsController=EPUBJS.reader.SettingsController.call(d,c),d.ControlsController=EPUBJS.reader.ControlsController.call(d,c),d.SidebarController=EPUBJS.reader.SidebarController.call(d,c),d.BookmarksController=EPUBJS.reader.BookmarksController.call(d,c);for(var e in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(e)&&(d[e]=EPUBJS.reader.plugins[e].call(d,c));return c.ready.all.then(function(){d.ReaderController.hideLoader()}),c.getMetadata().then(function(a){d.MetaController=EPUBJS.reader.MetaController.call(d,a)}),c.getToc().then(function(a){d.TocController=EPUBJS.reader.TocController.call(d,a)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),this},EPUBJS.Reader.prototype.addBookmark=function(a){var b=this.isBookmarked(a);b>-1||(this.settings.bookmarks.push(a),this.trigger("reader:bookmarked",a))},EPUBJS.Reader.prototype.removeBookmark=function(a){var b=this.isBookmarked(a);-1!==!b&&delete this.settings.bookmarks[b]},EPUBJS.Reader.prototype.isBookmarked=function(a){var b=this.settings.bookmarks;return b.indexOf(a)},EPUBJS.Reader.prototype.clearBookmarks=function(){this.settings.bookmarks=[]},EPUBJS.Reader.prototype.setBookKey=function(a){return this.settings.bookKey||(this.settings.bookKey="epubjsreader:"+EPUBJS.VERSION+":"+window.location.host+":"+a),this.settings.bookKey},EPUBJS.Reader.prototype.isSaved=function(){var a=localStorage.getItem(this.settings.bookKey);return localStorage&&null!==a?!0:!1},EPUBJS.Reader.prototype.removeSavedSettings=function(){localStorage.removeItem(this.settings.bookKey)},EPUBJS.Reader.prototype.applySavedSettings=function(){var a=JSON.parse(localStorage.getItem(this.settings.bookKey));return a?(this.settings=_.defaults(this.settings,a),!0):!1},EPUBJS.Reader.prototype.saveSettings=function(){this.book&&(this.settings.previousLocationCfi=this.book.getCurrentLocationCfi()),localStorage.setItem(this.settings.bookKey,JSON.stringify(this.settings))},EPUBJS.Reader.prototype.unload=function(){this.settings.restore&&this.saveSettings()},RSVP.EventTarget.mixin(EPUBJS.Reader.prototype),EPUBJS.reader.BookmarksController=function(){var a=this.book,b=$("#bookmarksView"),c=b.find("#bookmarks"),d=document.createDocumentFragment(),e=function(){b.show()},f=function(){b.hide()},g=function(b){var c=document.createElement("li"),d=document.createElement("a");return c.classList.add("list_item"),d.textContent=b,d.href=b,d.classList.add("bookmark_link"),d.addEventListener("click",function(b){var c=this.getAttribute("href");a.gotoCfi(c),b.preventDefault()},!1),c.appendChild(d),c};return this.settings.bookmarks.forEach(function(a){var b=g(a);d.appendChild(b)}),c.append(d),this.on("reader:bookmarked",function(a){var b=g(a);c.append(b)}),{show:e,hide:f}},EPUBJS.reader.ControlsController=function(a){var b=this,c=($("#store"),$("#fullscreen")),d=$("#fullscreenicon"),e=$("#cancelfullscreenicon"),f=$("#slider"),g=($("#main"),$("#sidebar"),$("#setting")),h=$("#bookmark"),i=function(){b.offline=!1},j=function(){b.offline=!0};return a.on("book:online",i),a.on("book:offline",j),f.on("click",function(){b.sidebarOpen?(b.SidebarController.hide(),f.addClass("icon-menu"),f.removeClass("icon-right")):(b.SidebarController.show(),f.addClass("icon-right"),f.removeClass("icon-menu"))}),c.on("click",function(){screenfull.toggle($("#container")[0]),d.toggle(),e.toggle()}),g.on("click",function(){b.SettingsController.show()}),h.on("click",function(){h.addClass("icon-bookmark"),h.removeClass("icon-bookmark-empty"),b.addBookmark(b.book.getCurrentLocationCfi())}),a.on("renderer:pageChanged",function(a){var c=b.isBookmarked(a);-1===c?h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):h.addClass("icon-bookmark").removeClass("icon-bookmark-empty")}),{}},EPUBJS.reader.MetaController=function(a){var b=a.bookTitle,c=a.creator,d=$("#book-title"),e=$("#chapter-title"),f=$("#title-seperator");document.title=b+" – "+c,d.html(b),e.html(c),f.show()},EPUBJS.reader.ReaderController=function(a){var b=$("#main"),c=$("#divider"),d=$("#loader"),e=$("#next"),f=$("#prev"),g=function(){b.removeClass("closed")},h=function(){b.addClass("closed")},i=function(){d.show(),l()},j=function(){d.hide(),a.single||k()},k=function(){c.addClass("show")},l=function(){c.removeClass("show")},m=!1,n=function(b){37==b.keyCode&&(a.prevPage(),f.addClass("active"),m=!0,setTimeout(function(){m=!1,f.removeClass("active")},100),b.preventDefault()),39==b.keyCode&&(a.nextPage(),e.addClass("active"),m=!0,setTimeout(function(){m=!1,e.removeClass("active")},100),b.preventDefault())};return document.addEventListener("keydown",n,!1),e.on("click",function(b){a.nextPage(),b.preventDefault()}),f.on("click",function(b){a.prevPage(),b.preventDefault()}),{slideOut:h,slideIn:g,showLoader:i,hideLoader:j,showDivider:k,hideDivider:l}},EPUBJS.reader.SettingsController=function(){this.book;var a=$("#settings-modal"),b=$(".overlay"),c=function(){a.addClass("md-show")},d=function(){a.removeClass("md-show")};return a.find(".closer").on("click",function(){d()}),b.on("click",function(){d()}),{show:c,hide:d}},EPUBJS.reader.SidebarController=function(){var a=this,b=$("#sidebar"),c=$("#panels"),d="Toc",e=function(b){var e=b+"Controller";d!=b&&"undefined"!=typeof a[e]&&(a[d+"Controller"].hide(),a[e].show(),d=b,c.find(".active").removeClass("active"),c.find("#show-"+b).addClass("active"))},f=function(){return d},g=function(){a.sidebarOpen=!0,a.ReaderController.slideOut(),b.addClass("open")},h=function(){a.sidebarOpen=!1,a.ReaderController.slideIn(),b.removeClass("open")};return c.find(".show_view").on("click",function(a){var b=$(this).data("view");e(b),a.preventDefault()}),{show:g,hide:h,getActivePanel:f,changePanelTo:e}},EPUBJS.reader.TocController=function(a){var b=this.book,c=$("#tocView"),d=document.createDocumentFragment(),e=!1,f=function(a,b){var c=document.createElement("ul");return b||(b=1),a.forEach(function(a){var d=document.createElement("li"),e=document.createElement("a");toggle=document.createElement("a");var g;d.id="toc-"+a.id,d.classList.add("list_item"),e.textContent=a.label,e.href=a.href,e.classList.add("toc_link"),d.appendChild(e),a.subitems&&(b++,g=f(a.subitems,b),toggle.classList.add("toc_toggle"),d.insertBefore(toggle,e),d.appendChild(g)),c.appendChild(d)}),c},g=function(){c.show()},h=function(){c.hide()},i=function(a){var b=a.id,d=c.find("#toc-"+b),f=c.find(".currentChapter");c.find(".openChapter"),d.length&&(d!=f&&d.has(e).length>0&&f.removeClass("currentChapter"),d.addClass("currentChapter"),d.parents("li").addClass("openChapter"))};b.on("renderer:chapterDisplayed",i);var j=f(a);return d.appendChild(j),c.append(d),c.find(".toc_link").on("click",function(a){var d=this.getAttribute("href");b.goto(d),c.find(".currentChapter").addClass("openChapter").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter"),a.preventDefault()}),c.find(".toc_toggle").on("click",function(a){var b=$(this).parent("li"),c=b.hasClass("openChapter");c?b.removeClass("openChapter"):b.addClass("openChapter"),a.preventDefault()}),{show:g,hide:h}}; \ No newline at end of file diff --git a/examples/search.html b/examples/search.html index 62b0778..c2bfa72 100755 --- a/examples/search.html +++ b/examples/search.html @@ -31,51 +31,26 @@ } }; - - - - - - - - - - - + - - - - - - - - - - - - - - + + - - - - - + + - + - + - + @@ -83,10 +58,10 @@
          @@ -94,9 +69,9 @@
            -
            +
            +
              -
              @@ -123,5 +98,14 @@
              + +
              diff --git a/reader/controllers/bookmarks_controller.js b/reader/controllers/bookmarks_controller.js new file mode 100644 index 0000000..43daf66 --- /dev/null +++ b/reader/controllers/bookmarks_controller.js @@ -0,0 +1,57 @@ +EPUBJS.reader.BookmarksController = function() { + var book = this.book; + + var $bookmarks = $("#bookmarksView"), + $list = $bookmarks.find("#bookmarks"); + + var docfrag = document.createDocumentFragment(); + + var show = function() { + $bookmarks.show(); + }; + + var hide = function() { + $bookmarks.hide(); + }; + + var createBookmarkItem = function(cfi) { + var listitem = document.createElement("li"), + link = document.createElement("a"); + + listitem.classList.add('list_item'); + + //-- TODO: Parse Cfi + link.textContent = cfi; + link.href = cfi; + + link.classList.add('bookmark_link'); + + link.addEventListener("click", function(event){ + var cfi = this.getAttribute('href'); + book.gotoCfi(cfi); + event.preventDefault(); + }, false); + + listitem.appendChild(link); + return listitem; + }; + + this.settings.bookmarks.forEach(function(cfi) { + var bookmark = createBookmarkItem(cfi); + docfrag.appendChild(bookmark); + }); + + $list.append(docfrag); + + + + this.on("reader:bookmarked", function(cfi) { + var item = createBookmarkItem(cfi); + $list.append(item); + }); + + return { + "show" : show, + "hide" : hide + }; +}; \ No newline at end of file diff --git a/reader/controllers/controls_controller.js b/reader/controllers/controls_controller.js new file mode 100644 index 0000000..66c85aa --- /dev/null +++ b/reader/controllers/controls_controller.js @@ -0,0 +1,74 @@ +EPUBJS.reader.ControlsController = function(book) { + var reader = this; + + var $store = $("#store"), + $fullscreen = $("#fullscreen"), + $fullscreenicon = $("#fullscreenicon"), + $cancelfullscreenicon = $("#cancelfullscreenicon"), + $slider = $("#slider"), + $main = $("#main"), + $sidebar = $("#sidebar"), + $settings = $("#setting"), + $bookmark = $("#bookmark"); + + var goOnline = function() { + reader.offline = false; + // $store.attr("src", $icon.data("save")); + }; + + var goOffline = function() { + reader.offline = true; + // $store.attr("src", $icon.data("saved")); + }; + + book.on("book:online", goOnline); + book.on("book:offline", goOffline); + + $slider.on("click", function () { + if(reader.sidebarOpen) { + reader.SidebarController.hide(); + $slider.addClass("icon-menu"); + $slider.removeClass("icon-right"); + } else { + reader.SidebarController.show(); + $slider.addClass("icon-right"); + $slider.removeClass("icon-menu"); + } + }); + + $fullscreen.on("click", function() { + screenfull.toggle($('#container')[0]); + $fullscreenicon.toggle(); + $cancelfullscreenicon.toggle(); + }); + + $settings.on("click", function() { + reader.SettingsController.show(); + }); + + $bookmark.on("click", function() { + $bookmark.addClass("icon-bookmark"); + $bookmark.removeClass("icon-bookmark-empty"); + reader.addBookmark(reader.book.getCurrentLocationCfi()); + }); + + book.on('renderer:pageChanged', function(cfi){ + //-- Check if bookmarked + var bookmarked = reader.isBookmarked(cfi); + + if(bookmarked === -1) { //-- Not bookmarked + $bookmark + .removeClass("icon-bookmark") + .addClass("icon-bookmark-empty"); + } else { //-- Bookmarked + $bookmark + .addClass("icon-bookmark") + .removeClass("icon-bookmark-empty"); + } + + }); + + return { + + }; +}; \ No newline at end of file diff --git a/reader/controllers/meta_controller.js b/reader/controllers/meta_controller.js new file mode 100644 index 0000000..0a5c5ac --- /dev/null +++ b/reader/controllers/meta_controller.js @@ -0,0 +1,14 @@ +EPUBJS.reader.MetaController = function(meta) { + var title = meta.bookTitle, + author = meta.creator; + + var $title = $("#book-title"), + $author = $("#chapter-title"), + $dash = $("#title-seperator"); + + document.title = title+" – "+author; + + $title.html(title); + $author.html(author); + $dash.show(); +}; \ No newline at end of file diff --git a/reader/controllers/reader_controller.js b/reader/controllers/reader_controller.js new file mode 100644 index 0000000..aac20d8 --- /dev/null +++ b/reader/controllers/reader_controller.js @@ -0,0 +1,87 @@ +EPUBJS.reader.ReaderController = function(book) { + var $main = $("#main"), + $divider = $("#divider"), + $loader = $("#loader"), + $next = $("#next"), + $prev = $("#prev"); + + var slideIn = function() { + $main.removeClass("closed"); + }; + + var slideOut = function() { + $main.addClass("closed"); + }; + + var showLoader = function() { + $loader.show(); + hideDivider(); + }; + + var hideLoader = function() { + $loader.hide(); + + //-- If the book is using spreads, show the divider + if(!book.single) { + showDivider(); + } + }; + + var showDivider = function() { + $divider.addClass("show"); + }; + + var hideDivider = function() { + $divider.removeClass("show"); + }; + + var keylock = false; + + var arrowKeys = function(e) { + if(e.keyCode == 37) { + book.prevPage(); + $prev.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $prev.removeClass("active"); + }, 100); + + e.preventDefault(); + } + if(e.keyCode == 39) { + book.nextPage(); + $next.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $next.removeClass("active"); + }, 100); + + e.preventDefault(); + } + } + + document.addEventListener('keydown', arrowKeys, false); + + $next.on("click", function(e){ + book.nextPage(); + e.preventDefault(); + }); + + $prev.on("click", function(e){ + book.prevPage(); + e.preventDefault(); + }); + + return { + "slideOut" : slideOut, + "slideIn" : slideIn, + "showLoader" : showLoader, + "hideLoader" : hideLoader, + "showDivider" : showDivider, + "hideDivider" : hideDivider + }; +}; \ No newline at end of file diff --git a/reader/controllers/settings_controller.js b/reader/controllers/settings_controller.js new file mode 100644 index 0000000..8a22182 --- /dev/null +++ b/reader/controllers/settings_controller.js @@ -0,0 +1,27 @@ +EPUBJS.reader.SettingsController = function() { + var book = this.book; + + var $settings = $("#settings-modal"), + $overlay = $(".overlay"); + + var show = function() { + $settings.addClass("md-show"); + }; + + var hide = function() { + $settings.removeClass("md-show"); + }; + + $settings.find(".closer").on("click", function() { + hide(); + }); + + $overlay.on("click", function() { + hide(); + }); + + return { + "show" : show, + "hide" : hide + }; +}; \ No newline at end of file diff --git a/reader/controllers/sidebar_controller.js b/reader/controllers/sidebar_controller.js new file mode 100644 index 0000000..80317c3 --- /dev/null +++ b/reader/controllers/sidebar_controller.js @@ -0,0 +1,50 @@ +EPUBJS.reader.SidebarController = function(book) { + var reader = this; + + var $sidebar = $("#sidebar"), + $panels = $("#panels"); + + var activePanel = "Toc"; + + var changePanelTo = function(viewName) { + var controllerName = viewName + "Controller"; + + if(activePanel == viewName || typeof reader[controllerName] === 'undefined' ) return; + reader[activePanel+ "Controller"].hide(); + reader[controllerName].show(); + activePanel = viewName; + + $panels.find('.active').removeClass("active"); + $panels.find("#show-" + viewName ).addClass("active"); + }; + + var getActivePanel = function() { + return activePanel; + }; + + var show = function() { + reader.sidebarOpen = true; + reader.ReaderController.slideOut(); + $sidebar.addClass("open"); + } + + var hide = function() { + reader.sidebarOpen = false; + reader.ReaderController.slideIn(); + $sidebar.removeClass("open"); + } + + $panels.find(".show_view").on("click", function(event) { + var view = $(this).data("view"); + + changePanelTo(view); + event.preventDefault(); + }); + + return { + 'show' : show, + 'hide' : hide, + 'getActivePanel' : getActivePanel, + 'changePanelTo' : changePanelTo + }; +}; \ No newline at end of file diff --git a/reader/controllers/toc_controller.js b/reader/controllers/toc_controller.js new file mode 100644 index 0000000..5dd303e --- /dev/null +++ b/reader/controllers/toc_controller.js @@ -0,0 +1,114 @@ +EPUBJS.reader.TocController = function(toc) { + var book = this.book; + + var $list = $("#tocView"), + docfrag = document.createDocumentFragment(); + + var currentChapter = false; + + var generateTocItems = function(toc, level) { + var container = document.createElement("ul"); + + if(!level) level = 1; + + toc.forEach(function(chapter) { + var listitem = document.createElement("li"), + link = document.createElement("a"); + toggle = document.createElement("a"); + + var subitems; + + listitem.id = "toc-"+chapter.id; + listitem.classList.add('list_item'); + + link.textContent = chapter.label; + link.href = chapter.href; + + link.classList.add('toc_link'); + + listitem.appendChild(link); + + if(chapter.subitems) { + level++; + subitems = generateTocItems(chapter.subitems, level); + toggle.classList.add('toc_toggle'); + + listitem.insertBefore(toggle, link); + listitem.appendChild(subitems); + } + + + container.appendChild(listitem); + + }); + + return container; + }; + + var onShow = function() { + $list.show(); + }; + + var onHide = function() { + $list.hide(); + }; + + var chapterChange = function(e) { + var id = e.id, + $item = $list.find("#toc-"+id), + $current = $list.find(".currentChapter"), + $open = $list.find('.openChapter'); + + if($item.length){ + + if($item != $current && $item.has(currentChapter).length > 0) { + $current.removeClass("currentChapter"); + } + + $item.addClass("currentChapter"); + + // $open.removeClass("openChapter"); + $item.parents('li').addClass("openChapter"); + } + }; + + book.on('renderer:chapterDisplayed', chapterChange); + + var tocitems = generateTocItems(toc); + + docfrag.appendChild(tocitems); + + $list.append(docfrag); + $list.find(".toc_link").on("click", function(event){ + var url = this.getAttribute('href'); + + //-- Provide the Book with the url to show + // The Url must be found in the books manifest + book.goto(url); + + $list.find(".currentChapter") + .addClass("openChapter") + .removeClass("currentChapter"); + + $(this).parent('li').addClass("currentChapter"); + + event.preventDefault(); + }); + + $list.find(".toc_toggle").on("click", function(event){ + var $el = $(this).parent('li'), + open = $el.hasClass("openChapter"); + + if(open){ + $el.removeClass("openChapter"); + } else { + $el.addClass("openChapter"); + } + event.preventDefault(); + }); + + return { + "show" : onShow, + "hide" : onHide + }; +}; diff --git a/reader/app.js b/reader/old/app.js similarity index 100% rename from reader/app.js rename to reader/old/app.js diff --git a/reader/utils.js b/reader/old/utils.js similarity index 100% rename from reader/utils.js rename to reader/old/utils.js diff --git a/reader/search.js b/reader/plugins/search.js similarity index 88% rename from reader/search.js rename to reader/plugins/search.js index 2e231ee..8e5b3b2 100644 --- a/reader/search.js +++ b/reader/plugins/search.js @@ -18,12 +18,11 @@ EPUBJS.reader.search.request = function(q, callback) { }); }; -EPUBJS.reader.plugins.SearchView = function(Book) { +EPUBJS.reader.plugins.SearchController = function(Book) { var reader = this; var $searchBox = $("#searchBox"), $searchResults = $("#searchResults"), - $tocView = $("#tocView"), $searchView = $("#searchView"), iframeDoc; @@ -103,9 +102,8 @@ EPUBJS.reader.plugins.SearchView = function(Book) { //-- SearchBox is empty or cleared if(q == '') { $searchResults.empty(); - - if(reader.SidebarView.activePanel != "SearchView") { - reader.SidebarView.changePanelTo("TocView"); + if(reader.SidebarController.getActivePanel() == "Search") { + reader.SidebarController.changePanelTo("Toc"); } $(iframeDoc).find('body').unhighlight(); @@ -113,9 +111,7 @@ EPUBJS.reader.plugins.SearchView = function(Book) { return; } - if(reader.SidebarView.activePanel != "SearchView") { - reader.SidebarView.changePanelTo("SearchView"); - } + reader.SidebarController.changePanelTo("Search"); e.preventDefault(); }); diff --git a/reader/reader.js b/reader/reader.js index ad1f43f..4fc24da 100644 --- a/reader/reader.js +++ b/reader/reader.js @@ -1,5 +1,5 @@ EPUBJS.reader = {}; -EPUBJS.reader.plugins = {}; //-- Attach extra view as plugins (like search?) +EPUBJS.reader.plugins = {}; //-- Attach extra Controllers as plugins (like search?) (function(root) { @@ -26,398 +26,151 @@ EPUBJS.reader.plugins = {}; //-- Attach extra view as plugins (like search?) })(window); -EPUBJS.Reader = function(path, options) { +EPUBJS.Reader = function(path, _options) { var reader = this; - var settings = _.defaults(options || {}, { - restore: true + var book; + + this.settings = _.defaults(_options || {}, { + restore: true, + bookmarks: null + }); + + this.setBookKey(path); //-- This could be username + path or any unique string + + if(this.settings.restore && this.isSaved()) { + this.applySavedSettings(); + } + + this.book = book = new EPUBJS.Book({ + bookPath: path, + restore: this.settings.restore, + previousLocationCfi: this.settings.previousLocationCfi }); - var book = this.book = ePub(path, settings); - this.settings = settings; this.offline = false; this.sidebarOpen = false; + if(!this.settings.bookmarks) { + this.settings.bookmarks = []; + } book.renderTo("viewer"); - reader.SettingsView = EPUBJS.reader.SettingsView.call(reader, book); - reader.ControlsView = EPUBJS.reader.ControlsView.call(reader, book); - reader.SidebarView = EPUBJS.reader.SidebarView.call(reader, book); + reader.ReaderController = EPUBJS.reader.ReaderController.call(reader, book); + reader.SettingsController = EPUBJS.reader.SettingsController.call(reader, book); + reader.ControlsController = EPUBJS.reader.ControlsController.call(reader, book); + reader.SidebarController = EPUBJS.reader.SidebarController.call(reader, book); + reader.BookmarksController = EPUBJS.reader.BookmarksController.call(reader, book); + + // Call Plugins + for(var plugin in EPUBJS.reader.plugins) { + if(EPUBJS.reader.plugins.hasOwnProperty(plugin)) { + reader[plugin] = EPUBJS.reader.plugins[plugin].call(reader, book); + } + } book.ready.all.then(function() { - reader.ReaderView = EPUBJS.reader.ReaderView.call(reader, book); - - // Call Plugins - for(var plugin in EPUBJS.reader.plugins) { - if(EPUBJS.reader.plugins.hasOwnProperty(plugin)) { - reader[plugin] = EPUBJS.reader.plugins[plugin].call(reader, book); - } - } - + reader.ReaderController.hideLoader(); }); book.getMetadata().then(function(meta) { - reader.MetaView = EPUBJS.reader.MetaView.call(reader, meta); + reader.MetaController = EPUBJS.reader.MetaController.call(reader, meta); }); book.getToc().then(function(toc) { - reader.TocView = EPUBJS.reader.TocView.call(reader, toc); + reader.TocController = EPUBJS.reader.TocController.call(reader, toc); }); - + + window.addEventListener("beforeunload", this.unload.bind(this), false); + return this; }; -EPUBJS.reader.MetaView = function(meta) { - var title = meta.bookTitle, - author = meta.creator; +EPUBJS.Reader.prototype.addBookmark = function(cfi) { + var present = this.isBookmarked(cfi); + if(present > -1 ) return; - var $title = $("#book-title"), - $author = $("#chapter-title"), - $dash = $("#title-seperator"); - - document.title = title+" – "+author; - - $title.html(title); - $author.html(author); - $dash.show(); + this.settings.bookmarks.push(cfi); + + this.trigger("reader:bookmarked", cfi); }; -EPUBJS.reader.ReaderView = function(book) { - var $main = $("#main"), - $divider = $("#divider"), - $loader = $("#loader"), - $next = $("#next"), - $prev = $("#prev"); +EPUBJS.Reader.prototype.removeBookmark = function(cfi) { + var bookmark = this.isBookmarked(cfi); + if(!bookmark === -1 ) return; - var slideIn = function() { - $main.removeClass("closed"); - }; - - var slideOut = function() { - $main.addClass("closed"); - }; - - var showLoader = function() { - $loader.show(); - }; - - var hideLoader = function() { - $loader.hide(); - }; - - var showDivider = function() { - $divider.addClass("show"); - }; - - var hideDivider = function() { - $divider.removeClass("show"); - }; - - var keylock = false; - - var arrowKeys = function(e) { - if(e.keyCode == 37) { - book.prevPage(); - $prev.addClass("active"); - - keylock = true; - setTimeout(function(){ - keylock = false; - $prev.removeClass("active"); - }, 100); - - e.preventDefault(); - } - if(e.keyCode == 39) { - book.nextPage(); - $next.addClass("active"); - - keylock = true; - setTimeout(function(){ - keylock = false; - $next.removeClass("active"); - }, 100); - - e.preventDefault(); - } - } - - document.addEventListener('keydown', arrowKeys, false); - - $next.on("click", function(e){ - book.nextPage(); - e.preventDefault(); - }); - - $prev.on("click", function(e){ - book.prevPage(); - e.preventDefault(); - }); - - //-- Hide the spinning loader - hideLoader(); - - //-- If the book is using spreads, show the divider - if(!book.single) { - showDivider(); - } - - return { - "slideOut" : slideOut, - "slideIn" : slideIn, - "showLoader" : showLoader, - "hideLoader" : hideLoader, - "showDivider" : showDivider, - "hideDivider" : hideDivider - }; + delete this.settings.bookmarks[bookmark]; }; -EPUBJS.reader.SidebarView = function(book) { - var reader = this; +EPUBJS.Reader.prototype.isBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks; + + return bookmarks.indexOf(cfi); +}; - var $sidebar = $("#sidebar"), - $panels = $("#panels"); +/* +EPUBJS.Reader.prototype.searchBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks, + len = bookmarks.length; - var activePanel = "TocView"; - - var changePanelTo = function(viewName) { - if(activePanel == viewName || typeof reader[viewName] === 'undefined' ) return; - reader[activePanel].hide(); - reader[viewName].show(); - activePanel = viewName; + for(var i = 0; i < len; i++) { + if (bookmarks[i]['cfi'] === cfi) return i; + } + return -1; +}; +*/ - $panels.find('.active').removeClass("active"); - $panels.find("#show-" + viewName ).addClass("active"); - }; - - var show = function() { - reader.sidebarOpen = true; - reader.ReaderView.slideOut(); - $sidebar.addClass("open"); +EPUBJS.Reader.prototype.clearBookmarks = function() { + this.settings.bookmarks = []; +}; + +//-- Settings +EPUBJS.Reader.prototype.setBookKey = function(identifier){ + if(!this.settings.bookKey) { + this.settings.bookKey = "epubjsreader:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; } - - var hide = function() { - reader.sidebarOpen = false; - reader.ReaderView.slideIn(); - $sidebar.removeClass("open"); + return this.settings.bookKey; +}; + +//-- Checks if the book setting can be retrieved from localStorage +EPUBJS.Reader.prototype.isSaved = function(bookPath) { + var storedSettings = localStorage.getItem(this.settings.bookKey); + + if( !localStorage || + storedSettings === null) { + return false; + } else { + return true; } - - $panels.find(".show_view").on("click", function(event) { - var view = $(this).data("view"); +}; + +EPUBJS.Reader.prototype.removeSavedSettings = function() { + localStorage.removeItem(this.settings.bookKey); +}; + +EPUBJS.Reader.prototype.applySavedSettings = function() { + var stored = JSON.parse(localStorage.getItem(this.settings.bookKey)); - changePanelTo(view); - event.preventDefault(); - }); - - return { - 'show' : show, - 'hide' : hide, - 'activePanel' : activePanel, - 'changePanelTo' : changePanelTo - }; -}; - -EPUBJS.reader.ControlsView = function(book) { - var reader = this; - - var $store = $("#store"), - $fullscreen = $("#fullscreen"), - $fullscreenicon = $("#fullscreenicon"), - $cancelfullscreenicon = $("#cancelfullscreenicon"), - $slider = $("#slider"), - $main = $("#main"), - $sidebar = $("#sidebar"), - $settings = $("#setting"), - $bookmark = $("#bookmark"); - - var goOnline = function() { - reader.offline = false; - // $store.attr("src", $icon.data("save")); - }; - - var goOffline = function() { - reader.offline = true; - // $store.attr("src", $icon.data("saved")); - }; - - book.on("book:online", goOnline); - book.on("book:offline", goOffline); - - $slider.on("click", function () { - if(reader.sidebarOpen) { - reader.SidebarView.hide(); - $slider.addClass("icon-menu"); - $slider.removeClass("icon-right"); + if(stored) { + this.settings = _.defaults(this.settings, stored); + return true; } else { - reader.SidebarView.show(); - $slider.addClass("icon-right"); - $slider.removeClass("icon-menu"); + return false; } - }); - - $fullscreen.on("click", function() { - screenfull.toggle($('#container')[0]); - $fullscreenicon.toggle(); - $cancelfullscreenicon.toggle(); - }); - - $settings.on("click", function() { - reader.SettingsView.show(); - }); - - $bookmark.on("click", function() { - $bookmark.addClass("icon-bookmark"); - $bookmark.removeClass("icon-bookmark-empty"); - console.log(reader.book.getCurrentLocationCfi()); - }); - - book.on('renderer:pageChanged', function(cfi){ - //-- TODO: Check if bookmarked - $bookmark - .removeClass("icon-bookmark") - .addClass("icon-bookmark-empty"); - }); - - return { - - }; }; -EPUBJS.reader.TocView = function(toc) { - var book = this.book; - - var $list = $("#tocView"), - docfrag = document.createDocumentFragment(); - - var currentChapter = false; - - var generateTocItems = function(toc, level) { - var container = document.createElement("ul"); - - if(!level) level = 1; +EPUBJS.Reader.prototype.saveSettings = function(){ + if(this.book) { + this.settings.previousLocationCfi = this.book.getCurrentLocationCfi(); + } - toc.forEach(function(chapter) { - var listitem = document.createElement("li"), - link = document.createElement("a"); - toggle = document.createElement("a"); - var subitems; - - listitem.id = "toc-"+chapter.id; - - link.textContent = chapter.label; - link.href = chapter.href; - link.classList.add('toc_link'); - - listitem.appendChild(link); - - if(chapter.subitems) { - level++; - subitems = generateTocItems(chapter.subitems, level); - toggle.classList.add('toc_toggle'); - - listitem.insertBefore(toggle, link); - listitem.appendChild(subitems); - } - - - container.appendChild(listitem); - - }); - - return container; - }; - - var onShow = function() { - $list.show(); - }; - - var onHide = function() { - $list.hide(); - }; - - var chapterChange = function(e) { - var id = e.id, - $item = $list.find("#toc-"+id), - $current = $list.find(".currentChapter"), - $open = $list.find('.openChapter'); - - if($item.length){ - - if($item != $current && $item.has(currentChapter).length > 0) { - $current.removeClass("currentChapter"); - } - - $item.addClass("currentChapter"); - - // $open.removeClass("openChapter"); - $item.parents('li').addClass("openChapter"); - } - }; - - book.on('renderer:chapterDisplayed', chapterChange); - - var tocitems = generateTocItems(toc); - - docfrag.appendChild(tocitems); - - $list.append(docfrag); - $list.find(".toc_link").on("click", function(event){ - var url = this.getAttribute('href'); - - //-- Provide the Book with the url to show - // The Url must be found in the books manifest - book.goto(url); - - $list.find(".currentChapter") - .addClass("openChapter") - .removeClass("currentChapter"); - - $(this).parent('li').addClass("currentChapter"); - - event.preventDefault(); - }); - - $list.find(".toc_toggle").on("click", function(event){ - var $el = $(this).parent('li'), - open = $el.hasClass("openChapter"); - - if(open){ - $el.removeClass("openChapter"); - } else { - $el.addClass("openChapter"); - } - event.preventDefault(); - }); - - return { - "show" : onShow, - "hide" : onHide - }; + localStorage.setItem(this.settings.bookKey, JSON.stringify(this.settings)); }; -EPUBJS.reader.SettingsView = function() { - var book = this.book; +EPUBJS.Reader.prototype.unload = function(){ + if(this.settings.restore) { + this.saveSettings(); + } +}; - var $settings = $("#settings-modal"), - $overlay = $(".overlay"); - - var show = function() { - $settings.addClass("md-show"); - }; - - var hide = function() { - $settings.removeClass("md-show"); - }; - - $settings.find(".closer").on("click", function() { - hide(); - }); - - $overlay.on("click", function() { - hide(); - }); - - return { - "show" : show, - "hide" : hide - }; -}; \ No newline at end of file +//-- Enable binding events to reader +RSVP.EventTarget.mixin(EPUBJS.Reader.prototype); \ No newline at end of file diff --git a/src/book.js b/src/book.js index 944ac4b..20b3e56 100644 --- a/src/book.js +++ b/src/book.js @@ -4,6 +4,8 @@ EPUBJS.Book = function(options){ this.settings = _.defaults(options || {}, { bookPath : null, + bookKey : null, + packageUrl : null, storage: false, //-- true (auto) or false (none) | override: 'ram', 'websqldatabase', 'indexeddb', 'filesystem' fromStorage : false, saved : false, @@ -98,74 +100,71 @@ EPUBJS.Book = function(options){ //-- Check bookUrl and start parsing book Assets or load them from storage EPUBJS.Book.prototype.open = function(bookPath, forceReload){ var book = this, - saved = this.isSaved(bookPath), - opened; - + epubpackage, + opened = new RSVP.defer(); + this.settings.bookPath = bookPath; - + //-- Get a absolute URL from the book path this.bookUrl = this.urlFrom(bookPath); - // console.log("saved", saved, !forceReload) - //-- Remove the previous settings and reload - if(saved){ - //-- Apply settings, keeping newer ones - this.applySavedSettings(); - } - if(this.settings.contained || this.isContained(bookPath)){ - this.settings.contained = this.contained = true; this.bookUrl = ''; // return; //-- TODO: this need to be fixed and tested before enabling - opened = this.unarchive(bookPath).then(function(){ + epubpackage = this.unarchive(bookPath). + then(function(){ + return this.loadPackage(); + }); - if(saved && book.settings.restore && !forceReload){ - return book.restore(); - }else{ - return book.unpack(); + } else { + epubpackage = this.loadPackage(); + } + + if(this.settings.restore && !forceReload){ + //-- Will load previous package json, or re-unpack if error + epubpackage.then(function(packageXml) { + var identifier = book.packageIdentifier(packageXml); + var restored = book.restore(identifier); + + if(!restored) { + book.unpack(packageXml); } - + opened.resolve(); + book.defer_opened.resolve(); }); - } else { - - if(saved && this.settings.restore && !forceReload){ - //-- Will load previous package json, or re-unpack if error - opened = this.restore(); - - }else{ - - //-- Get package information from epub opf - opened = this.unpack(); - - } + }else{ + //-- Get package information from epub opf + epubpackage.then(function(packageXml) { + book.unpack(packageXml); + opened.resolve(); + book.defer_opened.resolve(); + }); } - + //-- If there is network connection, store the books contents if(this.online && this.settings.storage && !this.settings.contained){ if(!this.settings.stored) opened.then(book.storeOffline()); } - - opened.then(function(){ - book.defer_opened.resolve(); - }); - return opened; + return opened.promise; }; -EPUBJS.Book.prototype.unpack = function(_containerPath){ +EPUBJS.Book.prototype.loadPackage = function(_containerPath){ var book = this, - parse = new EPUBJS.Parser(), - containerPath = _containerPath || "META-INF/container.xml"; - - //-- Return chain of promises - return book.loadXml(book.bookUrl + containerPath). + parse = new EPUBJS.Parser(), + containerPath = _containerPath || "META-INF/container.xml", + containerXml, + packageXml; + + if(!this.settings.packageUrl) { //-- provide the packageUrl to skip this step + packageXml = book.loadXml(book.bookUrl + containerPath). then(function(containerXml){ return parse.container(containerXml); // Container has path to content }). @@ -173,58 +172,74 @@ EPUBJS.Book.prototype.unpack = function(_containerPath){ book.settings.contentsPath = book.bookUrl + paths.basePath; book.settings.packageUrl = book.bookUrl + paths.packagePath; return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata - }). - then(function(packageXml){ - return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents - }). - then(function(contents){ - book.contents = contents; - book.manifest = book.contents.manifest; - book.spine = book.contents.spine; - book.spineIndexByURL = book.contents.spineIndexByURL; - book.metadata = book.contents.metadata; - - book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath; - - book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex; - - book.ready.manifest.resolve(book.contents.manifest); - book.ready.spine.resolve(book.contents.spine); - book.ready.metadata.resolve(book.contents.metadata); - book.ready.cover.resolve(book.contents.cover); - - //-- Adjust setting based on metadata - - //-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file - if(contents.navPath) { - book.settings.navUrl = book.settings.contentsPath + contents.navPath; - - book.loadXml(book.settings.navUrl). - then(function(navHtml){ - return parse.nav(navHtml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - } else if(contents.tocPath) { - book.settings.tocUrl = book.settings.contentsPath + contents.tocPath; - - book.loadXml(book.settings.tocUrl). - then(function(tocXml){ - return parse.toc(tocXml, book.spineIndexByURL, book.spine); // Grab Table of Contents - }).then(function(toc){ - book.toc = book.contents.toc = toc; - book.ready.toc.resolve(book.contents.toc); - }, function(error) { - book.ready.toc.resolve(false); - }); - - } else { - book.ready.toc.resolve(false); - } }); + } else { + packageXml = book.loadXml(book.settings.packageUrl); + } + + return packageXml; +}; + +EPUBJS.Book.prototype.packageIdentifier = function(packageXml){ + var book = this, + parse = new EPUBJS.Parser(); + + return parse.identifier(packageXml); +}; + +EPUBJS.Book.prototype.unpack = function(packageXml){ + var book = this, + parse = new EPUBJS.Parser(); + + book.contents = parse.packageContents(packageXml, book.settings.contentsPath); // Extract info from contents + + book.manifest = book.contents.manifest; + book.spine = book.contents.spine; + book.spineIndexByURL = book.contents.spineIndexByURL; + book.metadata = book.contents.metadata; + book.setBookKey(book.metadata.identifier); + + book.cover = book.contents.cover = book.settings.contentsPath + book.contents.coverPath; + + book.spineNodeIndex = book.contents.spineNodeIndex; + + book.ready.manifest.resolve(book.contents.manifest); + book.ready.spine.resolve(book.contents.spine); + book.ready.metadata.resolve(book.contents.metadata); + book.ready.cover.resolve(book.contents.cover); + + //-- TODO: Adjust setting based on metadata + + //-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file + if(book.contents.navPath) { + book.settings.navUrl = book.settings.contentsPath + book.contents.navPath; + + book.loadXml(book.settings.navUrl). + then(function(navHtml){ + return parse.nav(navHtml, book.spineIndexByURL, book.spine); // Grab Table of Contents + }).then(function(toc){ + book.toc = book.contents.toc = toc; + book.ready.toc.resolve(book.contents.toc); + }, function(error) { + book.ready.toc.resolve(false); + }); + } else if(book.contents.tocPath) { + book.settings.tocUrl = book.settings.contentsPath + book.contents.tocPath; + + book.loadXml(book.settings.tocUrl). + then(function(tocXml){ + return parse.toc(tocXml, book.spineIndexByURL, book.spine); // Grab Table of Contents + }).then(function(toc){ + book.toc = book.contents.toc = toc; + book.ready.toc.resolve(book.contents.toc); + }, function(error) { + book.ready.toc.resolve(false); + }); + + } else { + book.ready.toc.resolve(false); + } + }; EPUBJS.Book.prototype.getMetadata = function() { @@ -333,7 +348,7 @@ EPUBJS.Book.prototype.unarchive = function(bookPath){ //-- Checks if url has a .epub or .zip extension EPUBJS.Book.prototype.isContained = function(bookUrl){ var dot = bookUrl.lastIndexOf('.'), - ext = bookUrl.slice(dot+1); + ext = bookUrl.slice(dot+1); if(ext && (ext == "epub" || ext == "zip")){ return true; @@ -342,10 +357,9 @@ EPUBJS.Book.prototype.isContained = function(bookUrl){ return false; }; -//-- Checks if the book setting can be retrieved from localStorage -EPUBJS.Book.prototype.isSaved = function(bookPath) { - var bookKey = bookPath + ":" + this.settings.version, - storedSettings = localStorage.getItem(bookKey); +//-- Checks if the book can be retrieved from localStorage +EPUBJS.Book.prototype.isSaved = function(bookKey) { + var storedSettings = localStorage.getItem(bookKey); if( !localStorage || storedSettings === null) { @@ -355,48 +369,27 @@ EPUBJS.Book.prototype.isSaved = function(bookPath) { } }; -//-- Remove save book settings -EPUBJS.Book.prototype.removeSavedSettings = function() { - var bookKey = this.settings.bookPath + ":" + this.settings.version; - - localStorage.removeItem(bookKey); - - this.settings.stored = false; //TODO: is this needed? -}; - -EPUBJS.Book.prototype.applySavedSettings = function() { - var bookKey = this.settings.bookPath + ":" + this.settings.version, - stored = JSON.parse(localStorage.getItem(bookKey)); - - if(EPUBJS.VERSION != stored.EPUBJSVERSION) return false; - this.settings = _.defaults(this.settings, stored); -}; - -EPUBJS.Book.prototype.saveSettings = function(){ - var bookKey = this.settings.bookPath + ":" + this.settings.version; - - if(this.render) { - this.settings.previousLocationCfi = this.render.currentLocationCfi; +EPUBJS.Book.prototype.setBookKey = function(identifier){ + if(!this.settings.bookKey) { + this.settings.bookKey = this.generateBookKey(identifier); } - - localStorage.setItem(bookKey, JSON.stringify(this.settings)); + return this.settings.bookKey; +}; +EPUBJS.Book.prototype.generateBookKey = function(identifier){ + return "epubjs:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; }; EPUBJS.Book.prototype.saveContents = function(){ - var contentsKey = this.settings.bookPath + ":contents:" + this.settings.version; - - localStorage.setItem(contentsKey, JSON.stringify(this.contents)); - + localStorage.setItem(this.settings.bookKey, JSON.stringify(this.contents)); }; EPUBJS.Book.prototype.removeSavedContents = function() { - var bookKey = this.settings.bookPath + ":contents:" + this.settings.version; - - localStorage.removeItem(bookKey); + localStorage.removeItem(this.settings.bookKey); }; + // EPUBJS.Book.prototype.chapterTitle = function(){ // return this.spine[this.spinePos].id; //-- TODO: clarify that this is returning title // } @@ -447,14 +440,13 @@ EPUBJS.Book.prototype.startDisplay = function(){ return display; }; -EPUBJS.Book.prototype.restore = function(_reject){ +EPUBJS.Book.prototype.restore = function(identifier){ var book = this, - contentsKey = this.settings.bookPath + ":contents:" + this.settings.version, - deferred = new RSVP.defer(), - fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'], - reject = _reject || false, - fromStore = localStorage.getItem(contentsKey); + fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'], + reject = false, + bookKey = this.setBookKey(identifier), + fromStore = localStorage.getItem(bookKey); if(this.settings.clearSaved) reject = true; @@ -469,17 +461,14 @@ EPUBJS.Book.prototype.restore = function(_reject){ } if(reject || !fromStore || !this.contents || !this.settings.contentsPath){ - // this.removeSavedSettings(); - return this.open(this.settings.bookPath, true); - + return false; }else{ 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); - deferred.resolve(); - return deferred.promise; + return true; } }; @@ -507,15 +496,15 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ } if(pos < 0 || pos >= this.spine.length){ - console.error("Not A Valid Chapter"); - return false; + console.warn("Not A Valid Location"); + pos = 0; + end = false; + cfi = false; } //-- Set the book's spine position this.spinePos = pos; - - //-- Create a new chapter this.chapter = new EPUBJS.Chapter(this.spine[pos]); @@ -704,7 +693,6 @@ EPUBJS.Book.prototype.removeStyle = function(style) { EPUBJS.Book.prototype.unload = function(){ if(this.settings.restore) { - this.saveSettings(); this.saveContents(); } @@ -825,5 +813,5 @@ RSVP.configure('instrument', true); //-- true | will logging out all RSVP reject // RSVP.on('chained', listener); // RSVP.on('fulfilled', listener); RSVP.on('rejected', function(event){ - console.error(event.detail, event.detail.message); + console.error(event.detail.message, event.detail.stack); }); diff --git a/src/epubcfi.js b/src/epubcfi.js index 4a6e14e..463f88e 100644 --- a/src/epubcfi.js +++ b/src/epubcfi.js @@ -85,15 +85,21 @@ EPUBJS.EpubCFI.prototype.getOffset = function(cfiStr) { EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { var cfi = {}, + chapSegment, chapId, path, end, text; cfi.chapter = this.getChapter(cfiStr); - + + chapSegment = parseInt(cfi.chapter.split("/")[2]) || false; + cfi.fragment = this.getFragment(cfiStr); - cfi.spinePos = (parseInt(cfi.chapter.split("/")[2]) / 2 - 1 ) || 0; + + if(!chapSegment || !cfi.fragment) return {spinePos: -1}; + + cfi.spinePos = (parseInt(chapSegment) / 2 - 1 ) || 0; chapId = cfi.chapter.match(/\[(.*)\]/); diff --git a/src/parser.js b/src/parser.js index aaec2e5..6c77f2f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -16,19 +16,24 @@ EPUBJS.Parser.prototype.container = function(containerXml){ }; }; -EPUBJS.Parser.prototype.package = function(packageXml, baseUrl){ +EPUBJS.Parser.prototype.identifier = function(packageXml){ + var metadataNode = packageXml.querySelector("metadata"); + return this.getElementText(metadataNode, "identifier"); +}; + +EPUBJS.Parser.prototype.packageContents = function(packageXml, baseUrl){ var parse = this; if(baseUrl) this.baseUrl = baseUrl; var metadataNode = packageXml.querySelector("metadata"), - manifestNode = packageXml.querySelector("manifest"), - spineNode = packageXml.querySelector("spine"); + manifestNode = packageXml.querySelector("manifest"), + spineNode = packageXml.querySelector("spine"); var manifest = parse.manifest(manifestNode), - navPath = parse.findNavPath(manifestNode), - tocPath = parse.findTocPath(manifestNode), - coverPath = parse.findCoverPath(manifestNode); + navPath = parse.findNavPath(manifestNode), + tocPath = parse.findTocPath(manifestNode), + coverPath = parse.findCoverPath(manifestNode); var spineNodeIndex = Array.prototype.indexOf.call(spineNode.parentNode.childNodes, spineNode); @@ -72,7 +77,7 @@ EPUBJS.Parser.prototype.findCoverPath = function(manifestNode){ //-- Expanded to match Readium web components EPUBJS.Parser.prototype.metadata = function(xml){ var metadata = {}, - p = this; + p = this; metadata.bookTitle = p.getElementText(xml, 'title'); metadata.creator = p.getElementText(xml, 'creator'); @@ -123,7 +128,7 @@ EPUBJS.Parser.prototype.querySelectorText = function(xml, q){ EPUBJS.Parser.prototype.manifest = function(manifestXml){ var baseUrl = this.baseUrl, - manifest = {}; + manifest = {}; //-- Turn items into an array var selected = manifestXml.querySelectorAll("item"), @@ -132,9 +137,9 @@ EPUBJS.Parser.prototype.manifest = function(manifestXml){ //-- Create an object with the id as key items.forEach(function(item){ var id = item.getAttribute('id'), - href = item.getAttribute('href') || '', - type = item.getAttribute('media-type') || '', - properties = item.getAttribute('properties') || ''; + href = item.getAttribute('href') || '', + type = item.getAttribute('media-type') || '', + properties = item.getAttribute('properties') || ''; manifest[id] = { 'href' : href, @@ -153,7 +158,7 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){ var spine = []; var selected = spineXml.getElementsByTagName("itemref"), - items = Array.prototype.slice.call(selected); + items = Array.prototype.slice.call(selected); //-- Add to array to mantain ordering and cross reference with manifest items.forEach(function(item, index){ @@ -175,7 +180,7 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){ EPUBJS.Parser.prototype.nav = function(navHtml, spineIndexByURL, bookSpine){ var navEl = navHtml.querySelector('nav'), //-- [*|type="toc"] * Doesn't seem to work - idCounter = 0; + idCounter = 0; if(!navEl) return []; @@ -212,10 +217,10 @@ EPUBJS.Parser.prototype.nav = function(navHtml, spineIndexByURL, bookSpine){ function getTOC(parent){ var list = [], - nodes = findListItems(parent), - items = Array.prototype.slice.call(nodes), - length = items.length, - node; + nodes = findListItems(parent), + items = Array.prototype.slice.call(nodes), + length = items.length, + node; if(length === 0) return false; @@ -262,12 +267,12 @@ EPUBJS.Parser.prototype.toc = function(tocXml, spineIndexByURL, bookSpine){ function getTOC(parent){ var list = [], - items = [], - nodes = parent.childNodes, - nodesArray = Array.prototype.slice.call(nodes), - length = nodesArray.length, - iter = length, - node; + items = [], + nodes = parent.childNodes, + nodesArray = Array.prototype.slice.call(nodes), + length = nodesArray.length, + iter = length, + node; if(length === 0) return false; @@ -281,15 +286,15 @@ EPUBJS.Parser.prototype.toc = function(tocXml, spineIndexByURL, bookSpine){ items.forEach(function(item){ var id = item.getAttribute('id') || false, - content = item.querySelector("content"), - src = content.getAttribute('src'), - navLabel = item.querySelector("navLabel"), - text = navLabel.textContent ? navLabel.textContent : "", - split = src.split("#"), - baseUrl = split[0], - spinePos = spineIndexByURL[baseUrl], - spineItem, - subitems = getTOC(item); + content = item.querySelector("content"), + src = content.getAttribute('src'), + navLabel = item.querySelector("navLabel"), + text = navLabel.textContent ? navLabel.textContent : "", + split = src.split("#"), + baseUrl = split[0], + spinePos = spineIndexByURL[baseUrl], + spineItem, + subitems = getTOC(item); if(!id) { if(spinePos) {