diff --git a/build/epub.js b/build/epub.js index ab6c490..103c169 100644 --- a/build/epub.js +++ b/build/epub.js @@ -1851,6 +1851,7 @@ EPUBJS.Book = function(options){ this.ready.toc.promise ]; + this.pageList = []; this.pagination = new EPUBJS.Pagination(); this.pageListReady = this.ready.pageList.promise; @@ -1858,10 +1859,15 @@ EPUBJS.Book = function(options){ this.ready.all.then(this._ready.bind(this)); - this._q = []; + // Queue for methods used before rendering this.isRendered = false; + this._q = EPUBJS.core.queue(this); + // Queue for rendering this._rendering = false; - this._displayQ = []; + this._displayQ = EPUBJS.core.queue(this); + // Queue for going to another location + this._moving = false; + this._gotoQ = EPUBJS.core.queue(this); /** * Creates a new renderer. @@ -2025,8 +2031,8 @@ EPUBJS.Book.prototype.unpack = function(packageXml){ then(function(navHtml){ return parse.pageList(navHtml, book.spineIndexByURL, book.spine); }).then(function(pageList){ - book.pageList = book.contents.pageList = pageList; if(pageList.length) { + book.pageList = book.contents.pageList = pageList; book.pagination.process(book.pageList); book.ready.pageList.resolve(book.pageList); } @@ -2063,6 +2069,9 @@ EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) { hiddenEl = document.createElement("div"); hiddenEl.style.visibility = "hidden"; + hiddenEl.style.overflow = "hidden"; + hiddenEl.style.width = "0"; + hiddenEl.style.height = "0"; this.element.appendChild(hiddenEl); renderer.initialize(hiddenEl, width, height); @@ -2090,8 +2099,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){ spinePos = next; chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); - pager.displayChapter(chapter, this.globalLayoutProperties).then(function(){ - var nextPage = pager.nextPage(); + pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ + var nextPage = true;//pager.nextPage(); // Page though the entire chapter while (nextPage) { nextPage = pager.nextPage(); @@ -2144,10 +2153,7 @@ EPUBJS.Book.prototype.loadPagination = function(pagelistJSON) { if(pageList && pageList.length) { this.pageList = pageList; this.pagination.process(this.pageList); - // Wait for book contents to load before resolving - this.ready.all.then(function(){ - this.ready.pageList.resolve(this.pageList); - }.bind(this)); + this.ready.pageList.resolve(this.pageList); } return this.pageList; }; @@ -2201,8 +2207,23 @@ EPUBJS.Book.prototype.listenToRenderer = function(renderer){ "page": page, "percentage": percent }); + + // TODO: Add event for first and last page. + // (though last is going to be hard, since it could be several reflowed pages long) } }.bind(this)); + + renderer.on("render:loaded", this.loadChange.bind(this)); +}; + +// Listens for load events from the Renderer and checks against the current chapter +// Prevents the Render from loading a different chapter when back button is pressed +EPUBJS.Book.prototype.loadChange = function(url){ + var uri = EPUBJS.core.uri(url); + if(this.currentChapter && uri.path != this.currentChapter.absolute){ + console.warn("Miss Match", uri.path, this.currentChapter.absolute); + this.goto(uri.filename); + } }; EPUBJS.Book.prototype.unlistenToRenderer = function(renderer){ @@ -2392,18 +2413,28 @@ EPUBJS.Book.prototype.restore = function(identifier){ }; -EPUBJS.Book.prototype.displayChapter = function(chap, end){ +EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){ var book = this, render, cfi, pos, - store; - - if(!this.isRendered) return this._enqueue("displayChapter", arguments); + store, + defer = deferred || new RSVP.defer(); + if(!this.isRendered) { + this._q.enqueue("displayChapter", arguments); + // Reject for now. TODO: pass promise to queue + defer.reject({ + message : "Rendering", + stack : new Error().stack + }); + return defer.promise; + } + if(this._rendering) { - this._displayQ.push(arguments); - return; + // Pass along the current defer + this._displayQ.enqueue("displayChapter", [chap, end, defer]); + return defer.promise; } if(_.isNumber(chap)){ @@ -2434,10 +2465,16 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ render.then(function(chapter){ // chapter.currentLocationCfi = chap; chapter.gotoCfi(cfi); + defer.resolve(book.renderer); }); } else if(end) { render.then(function(chapter){ chapter.lastPage(); + defer.resolve(book.renderer); + }); + } else { + render.then(function(){ + defer.resolve(book.renderer); }); } @@ -2452,21 +2489,17 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ //-- Clear render queue render.then(function(){ var inwait; - book._rendering = false; - if(book._displayQ.length) { - inwait = book._displayQ.shift(); - book.displayChapter.apply(book, inwait); - } - + book._displayQ.dequeue(); }); - return render; + + return defer.promise; }; EPUBJS.Book.prototype.nextPage = function(){ var next; - if(!this.isRendered) return this._enqueue("nextPage", arguments); + if(!this.isRendered) return this._q.enqueue("nextPage", arguments); next = this.renderer.nextPage(); @@ -2478,7 +2511,7 @@ EPUBJS.Book.prototype.nextPage = function(){ EPUBJS.Book.prototype.prevPage = function() { var prev; - if(!this.isRendered) return this._enqueue("prevPage", arguments); + if(!this.isRendered) return this._q.enqueue("prevPage", arguments); prev = this.renderer.prevPage(); @@ -2511,28 +2544,48 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() { return this.renderer.currentLocationCfi; }; -EPUBJS.Book.prototype.gotoCfi = function(cfiString){ +EPUBJS.Book.prototype.goto = function(target){ + + if(typeof target === "number"){ + return this.gotoPage(target); + } else if(target.indexOf("epubcfi(") === 0) { + return this.gotoCfi(target); + } else if(target.indexOf("%") === target.length-1) { + return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); + } else { + return this.gotoHref(target); + } + +}; + +EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){ var cfi, spinePos, spineItem, rendered, - deferred; + deferred = defer || new RSVP.defer(); if(!this.isRendered) { this.settings.previousLocationCfi = cfiString; return false; } + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]); + return false; + } cfi = new EPUBJS.EpubCFI(cfiString); spinePos = cfi.spinePos; spineItem = this.spine[spinePos]; - deferred = new RSVP.defer(); - + promise = deferred.promise; + this._moving = true; //-- If same chapter only stay on current chapter if(this.currentChapter && this.spinePos === spinePos){ this.renderer.gotoCfi(cfi); - deferred.resolve(this.currentChapter); - return deferred.promise; + this._moving = false; + deferred.resolve(this.renderer.currentLocationCfi); } else { if(!spineItem || spinePos == -1) { @@ -2547,24 +2600,35 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString){ render = this.renderer.displayChapter(this.currentChapter, this.globalLayoutProperties); render.then(function(rendered){ - rendered.gotoCfi(cfi); - }); + rendered.gotoCfi(cfi); + this._moving = false; + deferred.resolve(rendered.currentLocationCfi); + }.bind(this)); } - - return render; } + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return promise; }; -EPUBJS.Book.prototype.goto = function(url){ +EPUBJS.Book.prototype.gotoHref = function(url, defer){ var split, chapter, section, absoluteURL, spinePos; - var deferred = new RSVP.defer(); - //if(!this.isRendered) return this._enqueue("goto", arguments); + var deferred = defer || new RSVP.defer(); + if(!this.isRendered) { this.settings.goto = url; - return; + return false; } - + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoHref", [url, deferred]); + return false; + } + split = url.split("#"); chapter = split[0]; section = split[1] || false; @@ -2582,14 +2646,34 @@ EPUBJS.Book.prototype.goto = function(url){ if(!this.currentChapter || spinePos != this.currentChapter.spinePos){ //-- Load new chapter if different than current return this.displayChapter(spinePos).then(function(){ - if(section) this.render.section(section); - }.bind(this)); + if(section){ + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); + }.bind(this)); }else{ //-- Only goto section - if(section) this.render.section(section); - deferred.resolve(this.currentChapter); - return deferred.promise; + if(section) { + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); } + + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return deferred.promise; +}; + +EPUBJS.Book.prototype.gotoPage = function(pg){ + var cfi = this.pagination.cfiFromPage(pg); + return this.gotoCfi(cfi); +}; + +EPUBJS.Book.prototype.gotoPercentage = function(percent){ + var pg = this.pagination.pageFromPercentage(percent); + return this.gotoCfi(pg); }; EPUBJS.Book.prototype.preloadNextChapter = function() { @@ -2649,7 +2733,7 @@ EPUBJS.Book.prototype.fromStorage = function(stored) { */ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { - if(!this.isRendered) return this._enqueue("setStyle", arguments); + if(!this.isRendered) return this._q.enqueue("setStyle", arguments); this.settings.styles[style] = val; @@ -2658,14 +2742,14 @@ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { }; EPUBJS.Book.prototype.removeStyle = function(style) { - if(!this.isRendered) return this._enqueue("removeStyle", arguments); + if(!this.isRendered) return this._q.enqueue("removeStyle", arguments); this.renderer.removeStyle(style); this.renderer.reformat(); delete this.settings.styles[style]; }; EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) { - if(!this.isRendered) return this._enqueue("addHeadTag", arguments); + if(!this.isRendered) return this._q.enqueue("addHeadTag", arguments); this.settings.headTags[tag] = attrs; }; @@ -2708,15 +2792,6 @@ EPUBJS.Book.prototype.destroy = function() { }; -EPUBJS.Book.prototype._enqueue = function(command, args) { - - this._q.push({ - 'command': command, - 'args': args - }); - -}; - EPUBJS.Book.prototype._ready = function() { this.trigger("book:ready"); @@ -2729,21 +2804,18 @@ EPUBJS.Book.prototype._rendered = function(err) { this.isRendered = true; this.trigger("book:rendered"); - this._q.forEach(function(item){ - book[item.command].apply(book, item.args); - }); - + this._q.flush(); }; EPUBJS.Book.prototype.applyStyles = function(callback){ - if(!this.isRendered) return this._enqueue("applyStyles", arguments); + if(!this.isRendered) return this._q.enqueue("applyStyles", arguments); this.renderer.applyStyles(this.settings.styles); callback(); }; EPUBJS.Book.prototype.applyHeadTags = function(callback){ - if(!this.isRendered) return this._enqueue("applyHeadTags", arguments); + if(!this.isRendered) return this._q.enqueue("applyHeadTags", arguments); this.renderer.applyHeadTags(this.settings.headTags); callback(); }; @@ -2751,7 +2823,7 @@ EPUBJS.Book.prototype.applyHeadTags = function(callback){ EPUBJS.Book.prototype._registerReplacements = function(renderer){ renderer.registerHook("beforeChapterDisplay", this.applyStyles.bind(this), true); renderer.registerHook("beforeChapterDisplay", this.applyHeadTags.bind(this), true); - renderer.registerHook("beforeChapterDisplay", EPUBJS.replace.hrefs, true); + renderer.registerHook("beforeChapterDisplay", EPUBJS.replace.hrefs.bind(this), true); if(this._needsAssetReplacement()) { @@ -3222,6 +3294,47 @@ EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); } }; + +EPUBJS.core.queue = function(_scope){ + var _q = []; + var scope = _scope; + // Add an item to the queue + var enqueue = function(funcName, args, context) { + _q.push({ + "funcName" : funcName, + "args" : args, + "context" : context + }); + return _q; + }; + // Run one item + var dequeue = function(){ + var inwait; + if(_q.length) { + inwait = _q.shift(); + // Defer to any current tasks + setTimeout(function(){ + scope[inwait.funcName].apply(inwait.context || scope, inwait.args); + }, 0); + } + }; + // Run All + var flush = function(){ + while(_q.length) { + dequeue(); + } + }; + // Clear all items in wait + var clear = function(){ + _q = []; + }; + return { + "enqueue" : enqueue, + "dequeue" : dequeue, + "flush" : flush, + "clear" : clear + }; +}; EPUBJS.EpubCFI = function(cfiStr){ if(cfiStr) return this.parse(cfiStr); }; @@ -3247,10 +3360,7 @@ EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) { var segment = ''; segment += (part.index + 1) * 2; - if(part.id && part.id.slice(0, 6) === "EPUBJS") { - //-- ignore internal @EPUBJS ids for - return; - } else if(part.id) { + if(part.id) { segment += "[" + part.id + "]"; } @@ -3263,8 +3373,13 @@ EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) { EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) { var steps = this.pathTo(element); var path = this.generatePathComponent(steps); - - return "epubcfi(" + chapter + "!" + path + "/1:0)"; + if(!path.length) { + // Start of Chapter + return "epubcfi(" + chapter + ")"; + } else { + // First Text Node + return "epubcfi(" + chapter + "!" + path + "/1:0)"; + } }; EPUBJS.EpubCFI.prototype.pathTo = function(node) { @@ -3320,18 +3435,18 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { end, text; + cfi.str = cfiStr; + if(cfiStr.indexOf("epubcfi(") === 0) { // Remove intial epubcfi( and ending ) cfiStr = cfiStr.slice(8, cfiStr.length-1); } - - chapterComponent = this.getChapterComponent(cfiStr); - pathComponent = this.getPathComponent(cfiStr); + pathComponent = this.getPathComponent(cfiStr) || ''; charecterOffsetComponent = this.getCharecterOffsetComponent(cfiStr); // Make sure this is a valid cfi or return - if(!chapterComponent.length || !pathComponent.length) { + if(!chapterComponent) { return {spinePos: -1}; } @@ -3393,8 +3508,83 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { return cfi; }; +EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) { + var doc = _doc || document; + var marker = _marker || this.createMarker(doc); + var parent; + var lastStep; + var text; + var split; + + if(typeof cfi === 'string') { + cfi = this.parse(cfi); + } + // Get the terminal step + lastStep = cfi.steps[cfi.steps.length-1]; -EPUBJS.EpubCFI.prototype.getElement = function(cfi, _doc) { + // check spinePos + if(cfi.spinePos === -1) { + // Not a valid CFI + return false; + } + + // Find the CFI elements parent + parent = this.findParent(cfi, doc); + + if(!parent) { + // CFI didn't return an element + // Maybe it isnt in the current chapter? + return false; + } + + if(lastStep && lastStep.type === "text") { + text = parent.childNodes[lastStep.index]; + if(cfi.characterOffset){ + split = text.splitText(); + marker.classList.add("EPUBJS-CFI-SPLIT"); + parent.insertBefore(marker, split); + } else { + parent.insertBefore(marker, text); + } + } else { + parent.insertBefore(marker, parent.firstChild); + } + + return marker; +}; + +EPUBJS.EpubCFI.prototype.createMarker = function(_doc) { + var doc = _doc || document; + var element = doc.createElement('span'); + element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid(); + element.classList.add("EPUBJS-CFI-MARKER"); + + return element; +}; + +EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) { + var doc = _doc || document; + // var id = marker.id; + + // Remove only elements added as markers + if(marker.classList.contains("EPUBJS-CFI-MARKER")){ + marker.parentElement.removeChild(marker); + } + + // Cleanup textnodes + if(marker.classList.contains("EPUBJS-CFI-SPLIT")){ + nextSib = marker.nextSibling; + prevSib = marker.previousSibling; + if(nextSib.nodeType === 3 && prevSib.nodeType === 3){ + prevSib.innerText += nextSib.innerText; + marker.parentElement.removeChild(nextSib); + } + marker.parentElement.removeChild(marker); + } + +}; + +EPUBJS.EpubCFI.prototype.findParent = function(cfi, _doc) { var doc = _doc || document, element = doc.getElementsByTagName('html')[0], children = Array.prototype.slice.call(element.children), @@ -3405,38 +3595,30 @@ EPUBJS.EpubCFI.prototype.getElement = function(cfi, _doc) { cfi = this.parse(cfi); } - sections = cfi.steps; - + sections = cfi.steps.slice(0); // Clone steps array + if(!sections.length) { + return doc.getElementsByTagName('body')[0]; + } + while(sections && sections.length > 0) { part = sections.shift(); - - // Wrap text elements in a span and return that new element + // Find textNodes Parent if(part.type === "text") { text = element.childNodes[part.index]; - element = doc.createElement('span'); - element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid(); - - if(cfi.characterOffset) { - textBegin = doc.createTextNode(text.textContent.slice(0, cfi.characterOffset)); - textEnd = doc.createTextNode(text.textContent.slice(cfi.characterOffset)); - text.parentNode.insertBefore(textEnd, text); - text.parentNode.insertBefore(element, textEnd); - text.parentNode.insertBefore(textBegin, element); - text.parentNode.removeChild(text); - } else { - text.parentNode.insertBefore(element, text); - } - // sort cut to find element by id + element = text.parentNode || element; + // Find element by id if present } else if(part.id){ element = doc.getElementById(part.id); - // find element in parent + // Find element in parent }else{ - if(!children) console.error("No Kids", element); element = children[part.index]; } - - - if(!element) console.error("No Element For", part, cfi); + // Element can't be found + if(typeof element === "undefined") { + console.error("No Element For", part, cfi.str); + return false; + } + // Get current element children and continue through steps children = Array.prototype.slice.call(element.children); } @@ -3682,7 +3864,7 @@ EPUBJS.Layout.Reflowable.prototype.calculatePages = function() { this.documentElement.style.width = "auto"; //-- reset width for calculations totalWidth = this.documentElement.scrollWidth; displayedPages = Math.round(totalWidth / this.spreadWidth); -// console.log(totalWidth, this.spreadWidth) + return { displayedPages : displayedPages, pageCount : displayedPages @@ -3799,11 +3981,12 @@ EPUBJS.Layout.Fixed.prototype.calculatePages = function(){ }; }; EPUBJS.Pagination = function(pageList) { - this.pageList = pageList; this.pages = []; this.locations = []; - this.epubcfi = new EPUBJS.EpubCFI(); + if(pageList && pageList.length) { + this.process(pageList); + } }; EPUBJS.Pagination.prototype.process = function(pageList){ @@ -3811,14 +3994,15 @@ EPUBJS.Pagination.prototype.process = function(pageList){ this.pages.push(item.page); this.locations.push(item.cfi); }, this); - + + this.pageList = pageList; this.firstPage = parseInt(this.pages[0]); this.lastPage = parseInt(this.pages[this.pages.length-1]); this.totalPages = this.lastPage - this.firstPage; }; EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){ - var pg; + var pg = -1; // check if the cfi is in the location list var index = this.locations.indexOf(cfi); if(index != -1 && index < (this.pages.length-1) ) { @@ -3832,12 +4016,11 @@ EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){ // Add the new page in so that the locations and page array match up this.pages.splice(index, 0, pg); } - return pg; }; EPUBJS.Pagination.prototype.cfiFromPage = function(pg){ - var cfi; + var cfi = -1; // check that pg is an int if(typeof pg != "number"){ pg = parseInt(pg); @@ -3869,18 +4052,6 @@ EPUBJS.Pagination.prototype.percentageFromCfi = function(cfi){ var percentage = this.percentageFromPage(pg); return percentage; }; - -// TODO: move these -EPUBJS.Book.prototype.gotoPage = function(pg){ - var cfi = this.pagination.cfiFromPage(pg); - this.gotoCfi(cfi); -}; - -EPUBJS.Book.prototype.gotoPercentage = function(percent){ - var pg = this.pagination.pageFromPercentage(percent); - this.gotoCfi(pg); -}; - EPUBJS.Parser = function(baseUrl){ this.baseUrl = baseUrl || ''; }; @@ -4344,7 +4515,11 @@ EPUBJS.Render.Iframe.prototype.create = function(){ this.iframe = document.createElement('iframe'); this.iframe.id = "epubjs-iframe:" + EPUBJS.core.uuid(); this.iframe.scrolling = "no"; + this.iframe.seamless = "seamless"; + // Back up if seamless isn't supported + this.iframe.style.border = "none"; + this.iframe.addEventListener("load", this.loaded.bind(this), false); return this.iframe; }; @@ -4357,9 +4532,11 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ var render = this, deferred = new RSVP.defer(); - this.leftPos = 0; this.iframe.src = url; - + + // Reset the scroll position + render.leftPos = 0; + if(this.window) { this.unload(); } @@ -4373,12 +4550,12 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ render.window = render.iframe.contentWindow; render.window.addEventListener("resize", render.resized.bind(render), false); - + //-- Clear Margins if(render.bodyEl) { render.bodyEl.style.margin = "0"; } - + deferred.resolve(render.docEl); }; @@ -4392,6 +4569,12 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ return deferred.promise; }; + +EPUBJS.Render.Iframe.prototype.loaded = function(v){ + var url = this.iframe.contentWindow.location.href; + this.trigger("render:loaded", url); +}; + // Resize the iframe to the given width and height EPUBJS.Render.Iframe.prototype.resize = function(width, height){ var iframeBox; @@ -4489,13 +4672,15 @@ EPUBJS.Render.Iframe.prototype.getBaseElement = function(){ // Checks if an element is on the screen EPUBJS.Render.Iframe.prototype.isElementVisible = function(el){ var rect; + var left; if(el && typeof el.getBoundingClientRect === 'function'){ rect = el.getBoundingClientRect(); + left = rect.left; //+ rect.width; if( rect.width !== 0 && rect.height !== 0 && // Element not visible - rect.left >= 0 && - rect.left < this.pageWidth ) { + left >= 0 && + left < this.pageWidth ) { return true; } } @@ -4516,6 +4701,9 @@ EPUBJS.Render.Iframe.prototype.scroll = function(bool){ EPUBJS.Render.Iframe.prototype.unload = function(){ this.window.removeEventListener("resize", this.resized); }; + +//-- Enable binding events to Render +RSVP.EventTarget.mixin(EPUBJS.Render.Iframe.prototype); EPUBJS.Renderer = function(renderMethod) { // Dom events to listen for this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"]; @@ -4530,6 +4718,9 @@ EPUBJS.Renderer = function(renderMethod) { console.error("Not a Valid Rendering Method"); } + // Listen for load events + this.render.on("render:loaded", this.loaded.bind(this)); + // Cached for replacement urls from storage this.caches = {}; @@ -4638,9 +4829,9 @@ EPUBJS.Renderer.prototype.load = function(url){ this.visible(false); - loaded = this.render.load(url); + render = this.render.load(url); - loaded.then(function(contents) { + render.then(function(contents) { var formated; this.contents = contents; @@ -4654,6 +4845,7 @@ EPUBJS.Renderer.prototype.load = function(url){ this.render.window.addEventListener("resize", this.resized, false); } + this.addEventListeners(); this.addSelectionListeners(); @@ -4679,6 +4871,13 @@ EPUBJS.Renderer.prototype.load = function(url){ return deferred.promise; }; +EPUBJS.Renderer.prototype.loaded = function(url){ + this.trigger("render:loaded", url); + // var uri = EPUBJS.core.uri(url); + // var relative = uri.path.replace(book.bookUrl, ''); + // console.log(url, uri, relative); +}; + /** * Reconciles the current chapters layout properies with * the global layout properities. @@ -4707,8 +4906,7 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){ settings[property] = value; } }); - - return settings; + return settings; }; /** @@ -4769,7 +4967,7 @@ EPUBJS.Renderer.prototype.reformat = function(){ pages = renderer.layout.calculatePages(); renderer.updatePages(pages); - + // Give the css styles time to update clearTimeout(this.timeoutTillCfi); this.timeoutTillCfi = setTimeout(function(){ @@ -4840,7 +5038,6 @@ EPUBJS.Renderer.prototype.page = function(pg){ this.currentLocationCfi = this.getPageCfi(); this.trigger("renderer:locationChanged", this.currentLocationCfi); - return true; } //-- Return false if page is greater than the total @@ -4893,7 +5090,20 @@ EPUBJS.Renderer.prototype.section = function(fragment){ }; -// Walk the node tree from an element to the root +EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) { + var children = node.childNodes; + var leng = children.length; + + if(leng && + children[0] && // First Child + children[0].nodeType === 3 && // This is a textNodes + children[0].textContent.trim().length) { // With non whitespace or return charecters + return true; + } + return false; +}; + +// Walk the node tree from a start element to next visible element EPUBJS.Renderer.prototype.walk = function(node) { var r, children, leng, startNode = node, @@ -4905,7 +5115,7 @@ EPUBJS.Renderer.prototype.walk = function(node) { while(!r && stack.length) { node = stack.shift(); - if( this.render.isElementVisible(node) ) { + if( this.render.isElementVisible(node) && this.firstElementisTextNode(node)) { r = node; } @@ -4916,8 +5126,8 @@ EPUBJS.Renderer.prototype.walk = function(node) { } else { return r; } - for (var i = 0; i < leng; i++) { - if(children[i] != prevNode) stack.push(children[i]); + for (var i = leng-1; i >= 0; i--) { + if(children[i] != prevNode) stack.unshift(children[i]); } } @@ -4949,13 +5159,19 @@ EPUBJS.Renderer.prototype.getPageCfi = function(prevEl){ // Goto a cfi position in the current chapter EPUBJS.Renderer.prototype.gotoCfi = function(cfi){ var element; + var pg; if(_.isString(cfi)){ cfi = this.epubcfi.parse(cfi); } - element = this.epubcfi.getElement(cfi, this.doc); - this.pageByElement(element); + marker = this.epubcfi.addMarker(cfi, this.doc); + if(marker) { + pg = this.render.getPageNumberByElement(marker); + // Must Clean up Marker before going to page + this.epubcfi.removeMarker(marker, this.doc); + this.page(pg); + } }; // Walk nodes until a visible element is found @@ -5188,12 +5404,12 @@ EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callba //-- Enable binding events to Renderer RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype); - var EPUBJS = EPUBJS || {}; EPUBJS.replace = {}; //-- Replaces the relative links within the book to use our internal page changer EPUBJS.replace.hrefs = function(callback, renderer){ + var book = this; var replacments = function(link, done){ var href = link.getAttribute("href"), relative = href.search("://"), @@ -5206,7 +5422,7 @@ EPUBJS.replace.hrefs = function(callback, renderer){ }else{ link.onclick = function(){ - renderer.book.goto(href); + book.goto(href); return false; }; diff --git a/build/epub.min.js b/build/epub.min.js index b8029f0..3bf10db 100644 --- a/build/epub.min.js +++ b/build/epub.min.js @@ -1,3 +1,3 @@ -(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;g=h?e.resolve():(g=c,b=new EPUBJS.Chapter(this.spine[g],this.store),d.displayChapter(b,this.globalLayoutProperties).then(function(){for(var a=d.nextPage();a;)a=d.nextPage();j(e)})),e.promise}.bind(this);j().then(function(){d.remove(),this.element.removeChild(e),f.resolve(c)}.bind(this))}return d.on("renderer:locationChanged",function(a){i+=1,c.push({cfi:a,page:i})}),f.promise},EPUBJS.Book.prototype.generatePagination=function(a,b){var c,d=this;return this.ready.spine.promise.then(function(){c=d.generatePageList(a,b).then(function(a){d.pageList=d.contents.pageList=a,d.pagination.process(a),d.ready.pageList.resolve(d.pageList)})}),c},EPUBJS.Book.prototype.loadPagination=function(a){var b=JSON.parse(a);return b&&b.length&&(this.pageList=b,this.pagination.process(this.pageList),this.ready.all.then(function(){this.ready.pageList.resolve(this.pageList)}.bind(this))),this.pageList},EPUBJS.Book.prototype.getPageList=function(){return this.ready.pageList.promise},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.listenToRenderer=function(a){var b=this;a.Events.forEach(function(c){a.on(c,function(a){b.trigger(c,a)})}),a.on("renderer:locationChanged",function(a){var b,c;this.pageList.length>0&&(b=this.pagination.pageFromCfi(a),c=this.pagination.percentageFromPage(b),this.trigger("book:pageChanged",{page:b,percentage:c}))}.bind(this))},EPUBJS.Book.prototype.unlistenToRenderer=function(a){a.Events.forEach(function(b){a.off(b)})},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a,this.settings.encoding):this.settings.contained?this.zip.getXml(a,this.settings.encoding):EPUBJS.core.request(a,"xml",this.settings.withCredentials)},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=EPUBJS.core.uri(a),d=c.protocol,e="/"==c.path[0],f=window.location,g=f.origin||f.protocol+"//"+f.host,h=document.getElementsByTagName("base");return h.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void 0:EPUBJS.core.resolveUrl(b||f.pathname,c.path)},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=localStorage.getItem(a); -return localStorage&&null!==b?!0:!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){localStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){localStorage.removeItem(this.settings.bookKey)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){var i=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,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),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),(0>e||e>=this.spine.length)&&(console.warn("Not A Valid Location"),e=0,b=!1,d=!1),this.spinePos=e,this.currentChapter=new EPUBJS.Chapter(this.spine[e],this.store),this._rendering=!0,c=f.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),d?c.then(function(a){a.gotoCfi(d)}):b&&c.then(function(a){a.lastPage()}),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.shift(),f.displayChapter.apply(f,a))}),c):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.renderer.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.renderer.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos0?(this.spinePos-=1,this.displayChapter(this.spinePos,!0)):(this.trigger("book:atStart"),void 0)},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){return this.isRendered?this.renderer.currentLocationCfi:!1},EPUBJS.Book.prototype.gotoCfi=function(a){var b,c,d,e;return this.isRendered?(b=new EPUBJS.EpubCFI(a),c=b.spinePos,d=this.spine[c],e=new RSVP.defer,this.currentChapter&&this.spinePos===c?(this.renderer.gotoCfi(b),e.resolve(this.currentChapter),e.promise):(d&&-1!=c||(c=0,d=this.spine[c]),this.currentChapter=new EPUBJS.Chapter(d,this.store),this.currentChapter&&(this.spinePos=c,render=this.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),render.then(function(a){a.gotoCfi(b)})),render)):(this.settings.previousLocationCfi=a,!1)},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.currentChapter?this.currentChapter.spinePos:0),"number"!=typeof e?!1:this.currentChapter&&e==this.currentChapter.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.settings.goto=a,void 0)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a,b=this.spinePos+1;return b>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[b]),a&&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){return this.isRendered?(this.settings.styles[a]=b,this.renderer.setStyle(a,b,c),this.renderer.reformat(),void 0):this._enqueue("setStyle",arguments)},EPUBJS.Book.prototype.removeStyle=function(a){return this.isRendered?(this.renderer.removeStyle(a),this.renderer.reformat(),delete this.settings.styles[a],void 0):this._enqueue("removeStyle",arguments)},EPUBJS.Book.prototype.addHeadTag=function(a,b){return this.isRendered?(this.settings.headTags[a]=b,void 0):this._enqueue("addHeadTag",arguments)},EPUBJS.Book.prototype.useSpreads=function(a){console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"),a===!1?this.forceSingle(!0):this.forceSingle(!1)},EPUBJS.Book.prototype.forceSingle=function(a){this.renderer.forceSingle(a),this.isRendered&&this.renderer.reformat()},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&this.saveContents(),this.unlistenToRenderer(this.renderer),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.applyStyles=function(a){return this.isRendered?(this.renderer.applyStyles(this.settings.styles),a(),void 0):this._enqueue("applyStyles",arguments)},EPUBJS.Book.prototype.applyHeadTags=function(a){return this.isRendered?(this.renderer.applyHeadTags(this.settings.headTags),a(),void 0):this._enqueue("applyHeadTags",arguments)},EPUBJS.Book.prototype._registerReplacements=function(a){a.registerHook("beforeChapterDisplay",this.applyStyles.bind(this),!0),a.registerHook("beforeChapterDisplay",this.applyHeadTags.bind(this),!0),a.registerHook("beforeChapterDisplay",EPUBJS.replace.hrefs,!0),this._needsAssetReplacement()&&a.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Book.prototype._needsAssetReplacement=function(){return this.settings.fromStorage?"filesystem"==this.storage.getStorageType()?!1:!0:this.settings.contained?!0:!1},EPUBJS.Book.prototype.parseLayoutProperties=function(a){var b=this.layoutOveride&&this.layoutOveride.layout||a.layout||"reflowable",c=this.layoutOveride&&this.layoutOveride.spread||a.spread||"auto",d=this.layoutOveride&&this.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},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,b){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b},EPUBJS.Chapter.prototype.contents=function(a){var b=a||this.store;return b?b.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer,c=a||this.store;return c?(this.tempUrl||(this.tempUrl=c.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,c){function d(){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?e?this.response:new Blob([this.response]):this.response,g.resolve(a)}else g.reject({message:this.response,stack:(new Error).stack})}var e=window.URL,f=e?"blob":"arraybuffer",g=new RSVP.defer,h=new XMLHttpRequest,i=XMLHttpRequest.prototype;return"overrideMimeType"in i||Object.defineProperty(i,"overrideMimeType",{value:function(){}}),c&&(h.withCredentials=!0),h.open("GET",a,!0),h.onreadystatechange=d,"blob"==b&&(h.responseType=f),"json"==b&&h.setRequestHeader("Accept","application/json"),"xml"==b&&h.overrideMimeType("text/xml"),h.send(),g.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.uri=function(a){var b,c,d,e={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:a},f=a.indexOf("://"),g=a.indexOf("?"),h=a.indexOf("#");return-1!=h&&(e.fragment=a.slice(h+1),a=a.slice(0,h)),-1!=g&&(e.search=a.slice(g+1),a=a.slice(0,g)),-1!=f?(e.protocol=a.slice(0,f),b=a.slice(f+3),d=b.indexOf("/"),-1===d?(e.host=e.path,e.path=""):(e.host=b.slice(0,d),e.path=b.slice(d)),e.origin=e.protocol+"://"+e.host,e.directory=EPUBJS.core.folder(e.path),e.base=e.origin+e.directory):(e.path=a,e.directory=EPUBJS.core.folder(a),e.base=e.directory),e.filename=a.replace(e.base,""),c=e.filename.lastIndexOf("."),-1!=c&&(e.extension=e.filename.slice(c+1)),e},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/");if(-1==b)var c="";return c=a.slice(0,b+1)},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=EPUBJS.core.uri(b),g=a.split("/");return f.host?b:(g.pop(),d=b.split("/"),d.forEach(function(a){".."===a?g.pop():e.push(a)}),c=g.concat(e),c.join("/"))},EPUBJS.core.uuid=function(){var a=(new Date).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});return b},EPUBJS.core.insert=function(a,b,c){var d=EPUBJS.core.locationOf(a,b,c);return b.splice(d+1,0,a),d+1},EPUBJS.core.locationOf=function(a,b,c,d,e){var f=d||0,g=e||b.length,h=parseInt(f+(g-f)/2);return c||(c=function(a,b){return a>b?1:b>a?-1:(a=b)?0:void 0}),1>=g-f||0===c(b[h],a)?h:-1===c(b[h],a)?EPUBJS.core.locationOf(a,b,c,h,g):EPUBJS.core.locationOf(a,b,c,f,h)},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=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.generatePathComponent=function(a){var b=[];return a.forEach(function(a){var c="";c+=2*(a.index+1),a.id&&"EPUBJS"===a.id.slice(0,6)||(a.id&&(c+="["+a.id+"]"),b.push(c))}),b.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(a,b){var c=this.pathTo(a),d=this.generatePathComponent(c);return"epubcfi("+b+"!"+d+"/1:0)"},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.getChapterComponent=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(a){var b=a.split("!"),c=b[1]?b[1].split(":"):"";return c[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(a){var b=a.split(":");return b[1]||""},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f,g,h,i,j={};return 0===a.indexOf("epubcfi(")&&(a=a.slice(8,a.length-1)),c=this.getChapterComponent(a),d=this.getPathComponent(a),e=this.getCharecterOffsetComponent(a),c.length&&d.length?(b=c.split("/")[2]||"")?(j.spinePos=parseInt(b)/2-1||0,g=b.match(/\[(.*)\]/),j.spineId=g?g[1]:!1,-1!=d.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=d.split("/"),i=h[h.length-1],j.steps=[],h.forEach(function(a){var b,c,d,g;a&&(parseInt(a)%2?(b="text",c=parseInt(a)-1):(b="element",c=parseInt(a)/2-1,d=a.match(/\[(.*)\]/),d&&d[1]&&(g=d[1])),j.steps.push({type:b,index:c,id:g||!1}),f=e.match(/\[(.*)\]/),f&&f[1]?(j.characterOffset=parseInt(e.split("[")[0]),j.textLocationAssertion=f[1]):j.characterOffset=parseInt(e))}),j):{spinePos:-1}:{spinePos:-1}},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,d,e,f,g,h=b||document,i=h.getElementsByTagName("html")[0],j=Array.prototype.slice.call(i.children);for("string"==typeof a&&(a=this.parse(a)),d=a.steps;d&&d.length>0;)c=d.shift(),"text"===c.type?(e=i.childNodes[c.index],i=h.createElement("span"),i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),a.characterOffset?(f=h.createTextNode(e.textContent.slice(0,a.characterOffset)),g=h.createTextNode(e.textContent.slice(a.characterOffset)),e.parentNode.insertBefore(g,e),e.parentNode.insertBefore(i,g),e.parentNode.insertBefore(f,i),e.parentNode.removeChild(e)):e.parentNode.insertBefore(i,e)):c.id?i=h.getElementById(c.id):(j||console.error("No Kids",i),i=j[c.index]),i||console.error("No Element For",c,a),j=Array.prototype.slice.call(i.children);return i},EPUBJS.EpubCFI.prototype.compare=function(a,b){if("string"==typeof a&&(a=new EPUBJS.EpubCFI(a)),"string"==typeof b&&(b=new EPUBJS.EpubCFI(b)),a.spinePos>b.spinePos)return 1;if(a.spinePosb.steps[c].index)return 1;if(a.steps[c].indexb.characterOffset?1:a.characterOffset=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,0===f&&b&&b(),e.forEach(function(a){a(d,c)}),void 0)},{register:function(a){if(void 0===EPUBJS.hooks[a]&&(EPUBJS.hooks[a]={}),"object"!=typeof EPUBJS.hooks[a])throw"Already registered: "+a;return EPUBJS.hooks[a]},mixin:function(b){for(var c in a.prototype)b[c]=a.prototype[c]}}}(),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=b%2===0?b:Math.floor(b)-1,h=Math.ceil(g/8),i=h%2===0?h:h-1;return this.documentElement=a,this.spreadWidth=g+i,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=i+"px",a.style[f]=g+"px",a.style.width=g+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var a,b;return this.documentElement.style.width="auto",a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth),{displayedPages:b,pageCount:b}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=2,h=b%2===0?b:Math.floor(b)-1,i=Math.ceil(h/8),j=i%2===0?i:i-1,k=Math.floor((h-j)/g);return this.documentElement=a,this.spreadWidth=(k+j)*g,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=j+"px",a.style[f]=k+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth);return this.documentElement.style.width=a+this.spreadWidth+"px",{displayedPages:b,pageCount:2*b}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(a){var b,c,d,e,f=EPUBJS.core.prefixed("columnWidth"),g=a.querySelector("[name=viewport");return this.documentElement=a,g&&g.hasAttribute("content")&&(b=g.getAttribute("content"),c=b.split(","),c[0]&&(d=c[0].replace("width=","")),c[1]&&(e=c[1].replace("height=",""))),a.style.width=d+"px"||"auto",a.style.height=e+"px"||"auto",a.style[f]="auto",a.style.overflow="auto",{pageWidth:d,pageHeight:e}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Pagination=function(a){this.pageList=a,this.pages=[],this.locations=[],this.epubcfi=new EPUBJS.EpubCFI},EPUBJS.Pagination.prototype.process=function(a){a.forEach(function(a){this.pages.push(a.page),this.locations.push(a.cfi)},this),this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage},EPUBJS.Pagination.prototype.pageFromCfi=function(a){var b,c=this.locations.indexOf(a);return-1!=c&&c1?g[1]:!1;i&&d.push({cfi:i,packageUrl:h,page:f})}),d)}var e=a.querySelector('nav[*|type="page-list"]');return e?d(e):[]},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a){var b=this,c=new RSVP.defer;return this.leftPos=0,this.iframe.src=a,this.window&&this.unload(),this.iframe.onload=function(){b.document=b.iframe.contentDocument,b.docEl=b.document.documentElement,b.headEl=b.document.head,b.bodyEl=b.document.body,b.window=b.iframe.contentWindow,b.window.addEventListener("resize",b.resized.bind(b),!1),b.bodyEl&&(b.bodyEl.style.margin="0"),c.resolve(b.docEl)},this.iframe.onerror=function(a){c.reject({message:"Error Loading Contents: "+a,stack:(new Error).stack})},c.promise},EPUBJS.Render.Iframe.prototype.resize=function(a,b){this.iframe&&(this.iframe.height=b,isNaN(a)||a%2===0||(a+=1),this.iframe.width=a,this.width=this.iframe.getBoundingClientRect().width||a,this.height=this.iframe.getBoundingClientRect().height||b)},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){return this.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){return this.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b){var c=document.createElement(a);for(var d in b)c[d]=b[d];this.headEl&&this.headEl.appendChild(c)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){var b,c;if(a)return b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){return this.bodyEl},EPUBJS.Render.Iframe.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&&a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.nextPage=function(){var a=this.chapterPos+1;return a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(this.visibileEl),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.page(this.chapterPos-1)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b;a&&(b=this.render.getPageNumberByElement(a),this.page(b))},EPUBJS.Renderer.prototype.lastPage=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},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.render.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(a){return this.visibileEl=this.findFirstVisible(a),this.epubcfi.generateCfiFromElement(this.visibileEl,this.currentChapter.cfiBase)},EPUBJS.Renderer.prototype.gotoCfi=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.render.getBaseElement();return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.onResized=function(){var a;this.width=this.container.clientWidth,this.height=this.container.clientHeight,a=this.determineSpreads(this.minSpreadWidth),a!=this.spreads&&(this.spreads=a,this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=new EPUBJS.Layout[this.layoutMethod]),this.contents&&this.reformat(),this.trigger("renderer:resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.addEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.addEventListener(a,this.triggerEvent.bind(this),!1)},this)},EPUBJS.Renderer.prototype.removeEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.removeEventListener(a,this.triggerEvent,!1)},this)},EPUBJS.Renderer.prototype.triggerEvent=function(a){this.trigger("renderer:"+a.type,a)},EPUBJS.Renderer.prototype.addSelectionListeners=function(){this.render.document.addEventListener("selectionchange",this.onSelectionChange.bind(this),!1),this.render.window.addEventListener("mouseup",this.onMouseUp.bind(this),!1)},EPUBJS.Renderer.prototype.removeSelectionListeners=function(){this.doc.removeEventListener("selectionchange",this.onSelectionChange,!1),this.render.window.removeEventListener("mouseup",this.onMouseUp,!1)},EPUBJS.Renderer.prototype.onSelectionChange=function(){this.highlighted=!0},EPUBJS.Renderer.prototype.onMouseUp=function(){var a;this.highlighted&&(a=this.render.window.getSelection(),this.trigger("renderer:selected",a),this.highlighted=!1)},EPUBJS.Renderer.prototype.setMinSpreadWidth=function(a){this.minSpreadWidth=a,this.spreads=this.determineSpreads(a)},EPUBJS.Renderer.prototype.determineSpreads=function(a){return this.isForcedSingle||!a||this.width=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.currentChapter.store,h=this.caches[a],i=EPUBJS.core.uri(this.currentChapter.absolute),j=i.base,k=b,l=2e3,m=function(a,b){f[b]=a},n=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(b,d){var h=b.getAttribute(k),i=EPUBJS.core.resolveUrl(j,h),m=function(c){var e;b.onload=function(){clearTimeout(e),d(c,i)},b.onerror=function(a){clearTimeout(e),d(c,i),console.error(a)},"image"==a&&b.setAttribute("externalResourcesRequired","true"),"link[href]"==a&&d(c,i),b.setAttribute(k,c),e=setTimeout(function(){d(c,i)},l)};i in e?(m(e[i]),f[i]=e[i],delete e[i]):c(g,i,m,b)},n,m))},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);var EPUBJS=EPUBJS||{};EPUBJS.replace={},EPUBJS.replace.hrefs=function(a,b){var c=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()};b.replace("a[href]",c,a)},EPUBJS.replace.head=function(a,b){b.replaceWithStored("link[href]","href",EPUBJS.replace.links,a)},EPUBJS.replace.resources=function(a,b){b.replaceWithStored("[src]","src",EPUBJS.replace.srcs,a)},EPUBJS.replace.svg=function(a,b){b.replaceWithStored("image","xlink:href",function(a,b,c){a.getUrl(b).then(c)},a)},EPUBJS.replace.srcs=function(a,b,c){a.getUrl(b).then(c)},EPUBJS.replace.links=function(a,b,c,d){"stylesheet"===d.getAttribute("rel")?EPUBJS.replace.stylesheets(a,b).then(function(a,b){setTimeout(function(){c(a,b)},5)}):a.getUrl(b).then(c)},EPUBJS.replace.stylesheets=function(a,b){var c=new RSVP.defer;if(a)return a.getText(b).then(function(d){EPUBJS.replace.cssUrls(a,b,d).then(function(a){var b=window.URL||window.webkitURL||window.mozURL,d=new Blob([a],{type:"text/css"}),e=b.createObjectURL(d);c.resolve(e)},function(a){console.error(a)})}),c.promise},EPUBJS.replace.cssUrls=function(a,b,c){var d=new RSVP.defer,e=[],f=c.match(/url\(\'?\"?([^\'|^\"|^\)]*)\'?\"?\)/g);if(a)return f?(f.forEach(function(d){var f=EPUBJS.core.resolveUrl(b,d.replace(/url\(|[|\)|\'|\"]/g,"")),g=a.getUrl(f).then(function(a){c=c.replace(d,'url("'+a+'")')});e.push(g)}),RSVP.all(e).then(function(){d.resolve(c)}),d.promise):(d.resolve(c),d.promise)},EPUBJS.Unarchiver=function(a){return this.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=new zip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeof zip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){var b=new RSVP.defer,c=this.zipFs;return c.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b.promise},EPUBJS.Unarchiver.prototype.getXml=function(a,b){return this.getText(a,b).then(function(a){var b=new DOMParser;return b.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){var c=this,d=new RSVP.defer,e=window.decodeURIComponent(a),f=this.zipFs.find(e),g=window.URL||window.webkitURL||window.mozURL;return f?a in this.urlCache?(d.resolve(this.urlCache[a]),d.promise):(f.getBlob(b||zip.getMimeType(f.name),function(b){var e=g.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d.promise):(d.reject({message:"File not found in the epub: "+a,stack:(new Error).stack}),d.promise)},EPUBJS.Unarchiver.prototype.getText=function(a,b){{var c=new RSVP.defer,d=window.decodeURIComponent(a),e=this.zipFs.find(d);window.URL||window.webkitURL||window.mozURL}return e||console.error("No entry found",a),e.getText(function(a){c.resolve(a)},null,null,b||"UTF-8"),c.promise},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){var b=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];c&&b.revokeObjectURL(c)},EPUBJS.Unarchiver.prototype.failed=function(a){console.error(a)},EPUBJS.Unarchiver.prototype.afterSaved=function(){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(a){function b(){f--,0===f&&e.afterSaved()}var c=0,d=20,e=this,f=a.length;a.forEach(function(a){setTimeout(function(a){e.saveEntryFileToStorage(a,b)},c,a),c+=d}),console.log("time",c)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(a,b){a.getData(new zip.BlobWriter,function(c){EPUBJS.storage.save(a.filename,c,b)})}; \ No newline at end of file +(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;g=h?e.resolve():(g=c,b=new EPUBJS.Chapter(this.spine[g],this.store),d.displayChapter(b,this.globalLayoutProperties).then(function(){for(var a=!0;a;)a=d.nextPage();j(e)})),e.promise}.bind(this);j().then(function(){d.remove(),this.element.removeChild(e),f.resolve(c)}.bind(this))}return d.on("renderer:locationChanged",function(a){i+=1,c.push({cfi:a,page:i})}),f.promise},EPUBJS.Book.prototype.generatePagination=function(a,b){var c,d=this;return this.ready.spine.promise.then(function(){c=d.generatePageList(a,b).then(function(a){d.pageList=d.contents.pageList=a,d.pagination.process(a),d.ready.pageList.resolve(d.pageList)})}),c},EPUBJS.Book.prototype.loadPagination=function(a){var b=JSON.parse(a);return b&&b.length&&(this.pageList=b,this.pagination.process(this.pageList),this.ready.pageList.resolve(this.pageList)),this.pageList},EPUBJS.Book.prototype.getPageList=function(){return this.ready.pageList.promise},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.listenToRenderer=function(a){var b=this;a.Events.forEach(function(c){a.on(c,function(a){b.trigger(c,a)})}),a.on("renderer:locationChanged",function(a){var b,c;this.pageList.length>0&&(b=this.pagination.pageFromCfi(a),c=this.pagination.percentageFromPage(b),this.trigger("book:pageChanged",{page:b,percentage:c}))}.bind(this)),a.on("render:loaded",this.loadChange.bind(this))},EPUBJS.Book.prototype.loadChange=function(a){var b=EPUBJS.core.uri(a);this.currentChapter&&b.path!=this.currentChapter.absolute&&(console.warn("Miss Match",b.path,this.currentChapter.absolute),this.goto(b.filename))},EPUBJS.Book.prototype.unlistenToRenderer=function(a){a.Events.forEach(function(b){a.off(b)})},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a,this.settings.encoding):this.settings.contained?this.zip.getXml(a,this.settings.encoding):EPUBJS.core.request(a,"xml",this.settings.withCredentials)},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=EPUBJS.core.uri(a),d=c.protocol,e="/"==c.path[0],f=window.location,g=f.origin||f.protocol+"//"+f.host,h=document.getElementsByTagName("base");return h.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void 0:EPUBJS.core.resolveUrl(b||f.pathname,c.path) +},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=localStorage.getItem(a);return localStorage&&null!==b?!0:!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){localStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){localStorage.removeItem(this.settings.bookKey)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){var i=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,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),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b,c){var d,e,f,g=this,h=c||new RSVP.defer;return this.isRendered?this._rendering?(this._displayQ.enqueue("displayChapter",[a,b,h]),h.promise):(_.isNumber(a)?f=a:(e=new EPUBJS.EpubCFI(a),f=e.spinePos),(0>f||f>=this.spine.length)&&(console.warn("Not A Valid Location"),f=0,b=!1,e=!1),this.spinePos=f,this.currentChapter=new EPUBJS.Chapter(this.spine[f],this.store),this._rendering=!0,d=g.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),e?d.then(function(a){a.gotoCfi(e),h.resolve(g.renderer)}):b?d.then(function(a){a.lastPage(),h.resolve(g.renderer)}):d.then(function(){h.resolve(g.renderer)}),this.settings.fromStorage||this.settings.contained||d.then(function(){g.preloadNextChapter()}),d.then(function(){g._rendering=!1,g._displayQ.dequeue()}),h.promise):(this._q.enqueue("displayChapter",arguments),h.reject({message:"Rendering",stack:(new Error).stack}),h.promise)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.renderer.nextPage(),a?void 0:this.nextChapter()):this._q.enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.renderer.prevPage(),a?void 0:this.prevChapter()):this._q.enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos0?(this.spinePos-=1,this.displayChapter(this.spinePos,!0)):(this.trigger("book:atStart"),void 0)},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){return this.isRendered?this.renderer.currentLocationCfi:!1},EPUBJS.Book.prototype.goto=function(a){return"number"==typeof a?this.gotoPage(a):0===a.indexOf("epubcfi(")?this.gotoCfi(a):a.indexOf("%")===a.length-1?this.gotoPercentage(parseInt(a.substring(0,a.length-1))):this.gotoHref(a)},EPUBJS.Book.prototype.gotoCfi=function(a,b){var c,d,e,f=b||new RSVP.defer;return this.isRendered?this._moving?(this._gotoQ.enqueue("gotoCfi",[a,f]),!1):(c=new EPUBJS.EpubCFI(a),d=c.spinePos,e=this.spine[d],promise=f.promise,this._moving=!0,this.currentChapter&&this.spinePos===d?(this.renderer.gotoCfi(c),this._moving=!1,f.resolve(this.renderer.currentLocationCfi)):(e&&-1!=d||(d=0,e=this.spine[d]),this.currentChapter=new EPUBJS.Chapter(e,this.store),this.currentChapter&&(this.spinePos=d,render=this.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),render.then(function(a){a.gotoCfi(c),this._moving=!1,f.resolve(a.currentLocationCfi)}.bind(this)))),promise.then(function(){this._gotoQ.dequeue()}.bind(this)),promise):(this.settings.previousLocationCfi=a,!1)},EPUBJS.Book.prototype.gotoHref=function(a,b){var c,d,e,f,g=b||new RSVP.defer;return this.isRendered?this._moving?(this._gotoQ.enqueue("gotoHref",[a,g]),!1):(c=a.split("#"),d=c[0],e=c[1]||!1,f=this.spineIndexByURL[d],d||(f=this.currentChapter?this.currentChapter.spinePos:0),"number"!=typeof f?!1:this.currentChapter&&f==this.currentChapter.spinePos?(e&&this.render.section(e),g.resolve(this.renderer.currentLocationCfi),promise.then(function(){this._gotoQ.dequeue()}.bind(this)),g.promise):this.displayChapter(f).then(function(){e&&this.render.section(e),g.resolve(this.renderer.currentLocationCfi)}.bind(this))):(this.settings.goto=a,!1)},EPUBJS.Book.prototype.gotoPage=function(a){var b=this.pagination.cfiFromPage(a);return this.gotoCfi(b)},EPUBJS.Book.prototype.gotoPercentage=function(a){var b=this.pagination.pageFromPercentage(a);return this.gotoCfi(b)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a,b=this.spinePos+1;return b>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[b]),a&&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){return this.isRendered?(this.settings.styles[a]=b,this.renderer.setStyle(a,b,c),this.renderer.reformat(),void 0):this._q.enqueue("setStyle",arguments)},EPUBJS.Book.prototype.removeStyle=function(a){return this.isRendered?(this.renderer.removeStyle(a),this.renderer.reformat(),delete this.settings.styles[a],void 0):this._q.enqueue("removeStyle",arguments)},EPUBJS.Book.prototype.addHeadTag=function(a,b){return this.isRendered?(this.settings.headTags[a]=b,void 0):this._q.enqueue("addHeadTag",arguments)},EPUBJS.Book.prototype.useSpreads=function(a){console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"),a===!1?this.forceSingle(!0):this.forceSingle(!1)},EPUBJS.Book.prototype.forceSingle=function(a){this.renderer.forceSingle(a),this.isRendered&&this.renderer.reformat()},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&this.saveContents(),this.unlistenToRenderer(this.renderer),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._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){this.isRendered=!0,this.trigger("book:rendered"),this._q.flush()},EPUBJS.Book.prototype.applyStyles=function(a){return this.isRendered?(this.renderer.applyStyles(this.settings.styles),a(),void 0):this._q.enqueue("applyStyles",arguments)},EPUBJS.Book.prototype.applyHeadTags=function(a){return this.isRendered?(this.renderer.applyHeadTags(this.settings.headTags),a(),void 0):this._q.enqueue("applyHeadTags",arguments)},EPUBJS.Book.prototype._registerReplacements=function(a){a.registerHook("beforeChapterDisplay",this.applyStyles.bind(this),!0),a.registerHook("beforeChapterDisplay",this.applyHeadTags.bind(this),!0),a.registerHook("beforeChapterDisplay",EPUBJS.replace.hrefs.bind(this),!0),this._needsAssetReplacement()&&a.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Book.prototype._needsAssetReplacement=function(){return this.settings.fromStorage?"filesystem"==this.storage.getStorageType()?!1:!0:this.settings.contained?!0:!1},EPUBJS.Book.prototype.parseLayoutProperties=function(a){var b=this.layoutOveride&&this.layoutOveride.layout||a.layout||"reflowable",c=this.layoutOveride&&this.layoutOveride.spread||a.spread||"auto",d=this.layoutOveride&&this.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},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,b){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b},EPUBJS.Chapter.prototype.contents=function(a){var b=a||this.store;return b?b.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer,c=a||this.store;return c?(this.tempUrl||(this.tempUrl=c.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,c){function d(){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?e?this.response:new Blob([this.response]):this.response,g.resolve(a)}else g.reject({message:this.response,stack:(new Error).stack})}var e=window.URL,f=e?"blob":"arraybuffer",g=new RSVP.defer,h=new XMLHttpRequest,i=XMLHttpRequest.prototype;return"overrideMimeType"in i||Object.defineProperty(i,"overrideMimeType",{value:function(){}}),c&&(h.withCredentials=!0),h.open("GET",a,!0),h.onreadystatechange=d,"blob"==b&&(h.responseType=f),"json"==b&&h.setRequestHeader("Accept","application/json"),"xml"==b&&h.overrideMimeType("text/xml"),h.send(),g.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.uri=function(a){var b,c,d,e={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:a},f=a.indexOf("://"),g=a.indexOf("?"),h=a.indexOf("#");return-1!=h&&(e.fragment=a.slice(h+1),a=a.slice(0,h)),-1!=g&&(e.search=a.slice(g+1),a=a.slice(0,g)),-1!=f?(e.protocol=a.slice(0,f),b=a.slice(f+3),d=b.indexOf("/"),-1===d?(e.host=e.path,e.path=""):(e.host=b.slice(0,d),e.path=b.slice(d)),e.origin=e.protocol+"://"+e.host,e.directory=EPUBJS.core.folder(e.path),e.base=e.origin+e.directory):(e.path=a,e.directory=EPUBJS.core.folder(a),e.base=e.directory),e.filename=a.replace(e.base,""),c=e.filename.lastIndexOf("."),-1!=c&&(e.extension=e.filename.slice(c+1)),e},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/");if(-1==b)var c="";return c=a.slice(0,b+1)},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=EPUBJS.core.uri(b),g=a.split("/");return f.host?b:(g.pop(),d=b.split("/"),d.forEach(function(a){".."===a?g.pop():e.push(a)}),c=g.concat(e),c.join("/"))},EPUBJS.core.uuid=function(){var a=(new Date).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});return b},EPUBJS.core.insert=function(a,b,c){var d=EPUBJS.core.locationOf(a,b,c);return b.splice(d+1,0,a),d+1},EPUBJS.core.locationOf=function(a,b,c,d,e){var f=d||0,g=e||b.length,h=parseInt(f+(g-f)/2);return c||(c=function(a,b){return a>b?1:b>a?-1:(a=b)?0:void 0}),1>=g-f||0===c(b[h],a)?h:-1===c(b[h],a)?EPUBJS.core.locationOf(a,b,c,h,g):EPUBJS.core.locationOf(a,b,c,f,h)},EPUBJS.core.queue=function(a){var b=[],c=a,d=function(a,c,d){return b.push({funcName:a,args:c,context:d}),b},e=function(){var a;b.length&&(a=b.shift(),setTimeout(function(){c[a.funcName].apply(a.context||c,a.args)},0))},f=function(){for(;b.length;)e()},g=function(){b=[]};return{enqueue:d,dequeue:e,flush:f,clear:g}},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=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.generatePathComponent=function(a){var b=[];return a.forEach(function(a){var c="";c+=2*(a.index+1),a.id&&(c+="["+a.id+"]"),b.push(c)}),b.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(a,b){var c=this.pathTo(a),d=this.generatePathComponent(c);return d.length?"epubcfi("+b+"!"+d+"/1:0)":"epubcfi("+b+")"},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.getChapterComponent=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(a){var b=a.split("!"),c=b[1]?b[1].split(":"):"";return c[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(a){var b=a.split(":");return b[1]||""},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f,g,h,i,j={};return j.str=a,0===a.indexOf("epubcfi(")&&(a=a.slice(8,a.length-1)),c=this.getChapterComponent(a),d=this.getPathComponent(a)||"",e=this.getCharecterOffsetComponent(a),c?(b=c.split("/")[2]||"")?(j.spinePos=parseInt(b)/2-1||0,g=b.match(/\[(.*)\]/),j.spineId=g?g[1]:!1,-1!=d.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=d.split("/"),i=h[h.length-1],j.steps=[],h.forEach(function(a){var b,c,d,g;a&&(parseInt(a)%2?(b="text",c=parseInt(a)-1):(b="element",c=parseInt(a)/2-1,d=a.match(/\[(.*)\]/),d&&d[1]&&(g=d[1])),j.steps.push({type:b,index:c,id:g||!1}),f=e.match(/\[(.*)\]/),f&&f[1]?(j.characterOffset=parseInt(e.split("[")[0]),j.textLocationAssertion=f[1]):j.characterOffset=parseInt(e))}),j):{spinePos:-1}:{spinePos:-1}},EPUBJS.EpubCFI.prototype.addMarker=function(a,b,c){var d,e,f,g,h=b||document,i=c||this.createMarker(h);return"string"==typeof a&&(a=this.parse(a)),e=a.steps[a.steps.length-1],-1===a.spinePos?!1:(d=this.findParent(a,h))?(e&&"text"===e.type?(f=d.childNodes[e.index],a.characterOffset?(g=f.splitText(),i.classList.add("EPUBJS-CFI-SPLIT"),d.insertBefore(i,g)):d.insertBefore(i,f)):d.insertBefore(i,d.firstChild),i):!1},EPUBJS.EpubCFI.prototype.createMarker=function(a){var b=a||document,c=b.createElement("span");return c.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),c.classList.add("EPUBJS-CFI-MARKER"),c},EPUBJS.EpubCFI.prototype.removeMarker=function(a,b){a.classList.contains("EPUBJS-CFI-MARKER")&&a.parentElement.removeChild(a),a.classList.contains("EPUBJS-CFI-SPLIT")&&(nextSib=a.nextSibling,prevSib=a.previousSibling,3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.innerText+=nextSib.innerText,a.parentElement.removeChild(nextSib)),a.parentElement.removeChild(a))},EPUBJS.EpubCFI.prototype.findParent=function(a,b){var c,d,e,f=b||document,g=f.getElementsByTagName("html")[0],h=Array.prototype.slice.call(g.children);if("string"==typeof a&&(a=this.parse(a)),d=a.steps.slice(0),!d.length)return f.getElementsByTagName("body")[0];for(;d&&d.length>0;){if(c=d.shift(),"text"===c.type?(e=g.childNodes[c.index],g=e.parentNode||g):g=c.id?f.getElementById(c.id):h[c.index],"undefined"==typeof g)return console.error("No Element For",c,a.str),!1;h=Array.prototype.slice.call(g.children)}return g},EPUBJS.EpubCFI.prototype.compare=function(a,b){if("string"==typeof a&&(a=new EPUBJS.EpubCFI(a)),"string"==typeof b&&(b=new EPUBJS.EpubCFI(b)),a.spinePos>b.spinePos)return 1;if(a.spinePosb.steps[c].index)return 1;if(a.steps[c].indexb.characterOffset?1:a.characterOffset=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,0===f&&b&&b(),e.forEach(function(a){a(d,c)}),void 0)},{register:function(a){if(void 0===EPUBJS.hooks[a]&&(EPUBJS.hooks[a]={}),"object"!=typeof EPUBJS.hooks[a])throw"Already registered: "+a;return EPUBJS.hooks[a]},mixin:function(b){for(var c in a.prototype)b[c]=a.prototype[c]}}}(),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=b%2===0?b:Math.floor(b)-1,h=Math.ceil(g/8),i=h%2===0?h:h-1;return this.documentElement=a,this.spreadWidth=g+i,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=i+"px",a.style[f]=g+"px",a.style.width=g+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var a,b;return this.documentElement.style.width="auto",a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth),{displayedPages:b,pageCount:b}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=2,h=b%2===0?b:Math.floor(b)-1,i=Math.ceil(h/8),j=i%2===0?i:i-1,k=Math.floor((h-j)/g);return this.documentElement=a,this.spreadWidth=(k+j)*g,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=j+"px",a.style[f]=k+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth);return this.documentElement.style.width=a+this.spreadWidth+"px",{displayedPages:b,pageCount:2*b}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(a){var b,c,d,e,f=EPUBJS.core.prefixed("columnWidth"),g=a.querySelector("[name=viewport");return this.documentElement=a,g&&g.hasAttribute("content")&&(b=g.getAttribute("content"),c=b.split(","),c[0]&&(d=c[0].replace("width=","")),c[1]&&(e=c[1].replace("height=",""))),a.style.width=d+"px"||"auto",a.style.height=e+"px"||"auto",a.style[f]="auto",a.style.overflow="auto",{pageWidth:d,pageHeight:e}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Pagination=function(a){this.pages=[],this.locations=[],this.epubcfi=new EPUBJS.EpubCFI,a&&a.length&&this.process(a)},EPUBJS.Pagination.prototype.process=function(a){a.forEach(function(a){this.pages.push(a.page),this.locations.push(a.cfi)},this),this.pageList=a,this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage},EPUBJS.Pagination.prototype.pageFromCfi=function(a){var b=-1,c=this.locations.indexOf(a);return-1!=c&&c1?g[1]:!1;i&&d.push({cfi:i,packageUrl:h,page:f})}),d)}var e=a.querySelector('nav[*|type="page-list"]');return e?d(e):[]},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.addEventListener("load",this.loaded.bind(this),!1),this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a){var b=this,c=new RSVP.defer;return this.iframe.src=a,b.leftPos=0,this.window&&this.unload(),this.iframe.onload=function(){b.document=b.iframe.contentDocument,b.docEl=b.document.documentElement,b.headEl=b.document.head,b.bodyEl=b.document.body,b.window=b.iframe.contentWindow,b.window.addEventListener("resize",b.resized.bind(b),!1),b.bodyEl&&(b.bodyEl.style.margin="0"),c.resolve(b.docEl)},this.iframe.onerror=function(a){c.reject({message:"Error Loading Contents: "+a,stack:(new Error).stack})},c.promise},EPUBJS.Render.Iframe.prototype.loaded=function(){var a=this.iframe.contentWindow.location.href;this.trigger("render:loaded",a)},EPUBJS.Render.Iframe.prototype.resize=function(a,b){this.iframe&&(this.iframe.height=b,isNaN(a)||a%2===0||(a+=1),this.iframe.width=a,this.width=this.iframe.getBoundingClientRect().width||a,this.height=this.iframe.getBoundingClientRect().height||b)},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){return this.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){return this.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b){var c=document.createElement(a);for(var d in b)c[d]=b[d];this.headEl&&this.headEl.appendChild(c)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){var b,c;if(a)return b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){return this.bodyEl},EPUBJS.Render.Iframe.prototype.isElementVisible=function(a){var b,c;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect(),c=b.left,0!==b.width&&0!==b.height&&c>=0&&c=1&&a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.nextPage=function(){var a=this.chapterPos+1;return a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(this.visibileEl),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.page(this.chapterPos-1)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b;a&&(b=this.render.getPageNumberByElement(a),this.page(b))},EPUBJS.Renderer.prototype.lastPage=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.firstElementisTextNode=function(a){var b=a.childNodes,c=b.length;return c&&b[0]&&3===b[0].nodeType&&b[0].textContent.trim().length?!0:!1},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.render.isElementVisible(a)&&this.firstElementisTextNode(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=d-1;j>=0;j--)c[j]!=e&&g.unshift(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(a){return this.visibileEl=this.findFirstVisible(a),this.epubcfi.generateCfiFromElement(this.visibileEl,this.currentChapter.cfiBase)},EPUBJS.Renderer.prototype.gotoCfi=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),marker=this.epubcfi.addMarker(a,this.doc),marker&&(b=this.render.getPageNumberByElement(marker),this.epubcfi.removeMarker(marker,this.doc),this.page(b))},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.render.getBaseElement();return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.onResized=function(){var a;this.width=this.container.clientWidth,this.height=this.container.clientHeight,a=this.determineSpreads(this.minSpreadWidth),a!=this.spreads&&(this.spreads=a,this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=new EPUBJS.Layout[this.layoutMethod]),this.contents&&this.reformat(),this.trigger("renderer:resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.addEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.addEventListener(a,this.triggerEvent.bind(this),!1)},this)},EPUBJS.Renderer.prototype.removeEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.removeEventListener(a,this.triggerEvent,!1)},this)},EPUBJS.Renderer.prototype.triggerEvent=function(a){this.trigger("renderer:"+a.type,a)},EPUBJS.Renderer.prototype.addSelectionListeners=function(){this.render.document.addEventListener("selectionchange",this.onSelectionChange.bind(this),!1),this.render.window.addEventListener("mouseup",this.onMouseUp.bind(this),!1)},EPUBJS.Renderer.prototype.removeSelectionListeners=function(){this.doc.removeEventListener("selectionchange",this.onSelectionChange,!1),this.render.window.removeEventListener("mouseup",this.onMouseUp,!1)},EPUBJS.Renderer.prototype.onSelectionChange=function(){this.highlighted=!0},EPUBJS.Renderer.prototype.onMouseUp=function(){var a;this.highlighted&&(a=this.render.window.getSelection(),this.trigger("renderer:selected",a),this.highlighted=!1)},EPUBJS.Renderer.prototype.setMinSpreadWidth=function(a){this.minSpreadWidth=a,this.spreads=this.determineSpreads(a)},EPUBJS.Renderer.prototype.determineSpreads=function(a){return this.isForcedSingle||!a||this.width=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.currentChapter.store,h=this.caches[a],i=EPUBJS.core.uri(this.currentChapter.absolute),j=i.base,k=b,l=2e3,m=function(a,b){f[b]=a},n=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(b,d){var h=b.getAttribute(k),i=EPUBJS.core.resolveUrl(j,h),m=function(c){var e;b.onload=function(){clearTimeout(e),d(c,i)},b.onerror=function(a){clearTimeout(e),d(c,i),console.error(a)},"image"==a&&b.setAttribute("externalResourcesRequired","true"),"link[href]"==a&&d(c,i),b.setAttribute(k,c),e=setTimeout(function(){d(c,i)},l)};i in e?(m(e[i]),f[i]=e[i],delete e[i]):c(g,i,m,b)},n,m))},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);var EPUBJS=EPUBJS||{};EPUBJS.replace={},EPUBJS.replace.hrefs=function(a,b){var c=this,d=function(a,b){{var d=a.getAttribute("href"),e=d.search("://");"#"==d[0]}-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return c.goto(d),!1},b()};b.replace("a[href]",d,a)},EPUBJS.replace.head=function(a,b){b.replaceWithStored("link[href]","href",EPUBJS.replace.links,a)},EPUBJS.replace.resources=function(a,b){b.replaceWithStored("[src]","src",EPUBJS.replace.srcs,a)},EPUBJS.replace.svg=function(a,b){b.replaceWithStored("image","xlink:href",function(a,b,c){a.getUrl(b).then(c)},a)},EPUBJS.replace.srcs=function(a,b,c){a.getUrl(b).then(c)},EPUBJS.replace.links=function(a,b,c,d){"stylesheet"===d.getAttribute("rel")?EPUBJS.replace.stylesheets(a,b).then(function(a,b){setTimeout(function(){c(a,b)},5)}):a.getUrl(b).then(c)},EPUBJS.replace.stylesheets=function(a,b){var c=new RSVP.defer;if(a)return a.getText(b).then(function(d){EPUBJS.replace.cssUrls(a,b,d).then(function(a){var b=window.URL||window.webkitURL||window.mozURL,d=new Blob([a],{type:"text/css"}),e=b.createObjectURL(d);c.resolve(e)},function(a){console.error(a)})}),c.promise},EPUBJS.replace.cssUrls=function(a,b,c){var d=new RSVP.defer,e=[],f=c.match(/url\(\'?\"?([^\'|^\"|^\)]*)\'?\"?\)/g);if(a)return f?(f.forEach(function(d){var f=EPUBJS.core.resolveUrl(b,d.replace(/url\(|[|\)|\'|\"]/g,"")),g=a.getUrl(f).then(function(a){c=c.replace(d,'url("'+a+'")')});e.push(g)}),RSVP.all(e).then(function(){d.resolve(c)}),d.promise):(d.resolve(c),d.promise)},EPUBJS.Unarchiver=function(a){return this.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=new zip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeof zip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){var b=new RSVP.defer,c=this.zipFs;return c.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b.promise},EPUBJS.Unarchiver.prototype.getXml=function(a,b){return this.getText(a,b).then(function(a){var b=new DOMParser;return b.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){var c=this,d=new RSVP.defer,e=window.decodeURIComponent(a),f=this.zipFs.find(e),g=window.URL||window.webkitURL||window.mozURL;return f?a in this.urlCache?(d.resolve(this.urlCache[a]),d.promise):(f.getBlob(b||zip.getMimeType(f.name),function(b){var e=g.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d.promise):(d.reject({message:"File not found in the epub: "+a,stack:(new Error).stack}),d.promise)},EPUBJS.Unarchiver.prototype.getText=function(a,b){{var c=new RSVP.defer,d=window.decodeURIComponent(a),e=this.zipFs.find(d);window.URL||window.webkitURL||window.mozURL}return e||console.error("No entry found",a),e.getText(function(a){c.resolve(a)},null,null,b||"UTF-8"),c.promise},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){var b=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];c&&b.revokeObjectURL(c)},EPUBJS.Unarchiver.prototype.failed=function(a){console.error(a)},EPUBJS.Unarchiver.prototype.afterSaved=function(){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(a){function b(){f--,0===f&&e.afterSaved()}var c=0,d=20,e=this,f=a.length;a.forEach(function(a){setTimeout(function(a){e.saveEntryFileToStorage(a,b)},c,a),c+=d}),console.log("time",c)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(a,b){a.getData(new zip.BlobWriter,function(c){EPUBJS.storage.save(a.filename,c,b)})}; \ No newline at end of file diff --git a/build/epub_no_underscore.js b/build/epub_no_underscore.js index 45028c0..3ba3bbe 100644 --- a/build/epub_no_underscore.js +++ b/build/epub_no_underscore.js @@ -1850,6 +1850,7 @@ EPUBJS.Book = function(options){ this.ready.toc.promise ]; + this.pageList = []; this.pagination = new EPUBJS.Pagination(); this.pageListReady = this.ready.pageList.promise; @@ -1857,10 +1858,15 @@ EPUBJS.Book = function(options){ this.ready.all.then(this._ready.bind(this)); - this._q = []; + // Queue for methods used before rendering this.isRendered = false; + this._q = EPUBJS.core.queue(this); + // Queue for rendering this._rendering = false; - this._displayQ = []; + this._displayQ = EPUBJS.core.queue(this); + // Queue for going to another location + this._moving = false; + this._gotoQ = EPUBJS.core.queue(this); /** * Creates a new renderer. @@ -2024,8 +2030,8 @@ EPUBJS.Book.prototype.unpack = function(packageXml){ then(function(navHtml){ return parse.pageList(navHtml, book.spineIndexByURL, book.spine); }).then(function(pageList){ - book.pageList = book.contents.pageList = pageList; if(pageList.length) { + book.pageList = book.contents.pageList = pageList; book.pagination.process(book.pageList); book.ready.pageList.resolve(book.pageList); } @@ -2062,6 +2068,9 @@ EPUBJS.Book.prototype.createHiddenRender = function(renderer, _width, _height) { hiddenEl = document.createElement("div"); hiddenEl.style.visibility = "hidden"; + hiddenEl.style.overflow = "hidden"; + hiddenEl.style.width = "0"; + hiddenEl.style.height = "0"; this.element.appendChild(hiddenEl); renderer.initialize(hiddenEl, width, height); @@ -2089,8 +2098,8 @@ EPUBJS.Book.prototype.generatePageList = function(width, height){ spinePos = next; chapter = new EPUBJS.Chapter(this.spine[spinePos], this.store); - pager.displayChapter(chapter, this.globalLayoutProperties).then(function(){ - var nextPage = pager.nextPage(); + pager.displayChapter(chapter, this.globalLayoutProperties).then(function(chap){ + var nextPage = true;//pager.nextPage(); // Page though the entire chapter while (nextPage) { nextPage = pager.nextPage(); @@ -2143,10 +2152,7 @@ EPUBJS.Book.prototype.loadPagination = function(pagelistJSON) { if(pageList && pageList.length) { this.pageList = pageList; this.pagination.process(this.pageList); - // Wait for book contents to load before resolving - this.ready.all.then(function(){ - this.ready.pageList.resolve(this.pageList); - }.bind(this)); + this.ready.pageList.resolve(this.pageList); } return this.pageList; }; @@ -2200,8 +2206,23 @@ EPUBJS.Book.prototype.listenToRenderer = function(renderer){ "page": page, "percentage": percent }); + + // TODO: Add event for first and last page. + // (though last is going to be hard, since it could be several reflowed pages long) } }.bind(this)); + + renderer.on("render:loaded", this.loadChange.bind(this)); +}; + +// Listens for load events from the Renderer and checks against the current chapter +// Prevents the Render from loading a different chapter when back button is pressed +EPUBJS.Book.prototype.loadChange = function(url){ + var uri = EPUBJS.core.uri(url); + if(this.currentChapter && uri.path != this.currentChapter.absolute){ + console.warn("Miss Match", uri.path, this.currentChapter.absolute); + this.goto(uri.filename); + } }; EPUBJS.Book.prototype.unlistenToRenderer = function(renderer){ @@ -2391,18 +2412,28 @@ EPUBJS.Book.prototype.restore = function(identifier){ }; -EPUBJS.Book.prototype.displayChapter = function(chap, end){ +EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){ var book = this, render, cfi, pos, - store; - - if(!this.isRendered) return this._enqueue("displayChapter", arguments); + store, + defer = deferred || new RSVP.defer(); + if(!this.isRendered) { + this._q.enqueue("displayChapter", arguments); + // Reject for now. TODO: pass promise to queue + defer.reject({ + message : "Rendering", + stack : new Error().stack + }); + return defer.promise; + } + if(this._rendering) { - this._displayQ.push(arguments); - return; + // Pass along the current defer + this._displayQ.enqueue("displayChapter", [chap, end, defer]); + return defer.promise; } if(_.isNumber(chap)){ @@ -2433,10 +2464,16 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ render.then(function(chapter){ // chapter.currentLocationCfi = chap; chapter.gotoCfi(cfi); + defer.resolve(book.renderer); }); } else if(end) { render.then(function(chapter){ chapter.lastPage(); + defer.resolve(book.renderer); + }); + } else { + render.then(function(){ + defer.resolve(book.renderer); }); } @@ -2451,21 +2488,17 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ //-- Clear render queue render.then(function(){ var inwait; - book._rendering = false; - if(book._displayQ.length) { - inwait = book._displayQ.shift(); - book.displayChapter.apply(book, inwait); - } - + book._displayQ.dequeue(); }); - return render; + + return defer.promise; }; EPUBJS.Book.prototype.nextPage = function(){ var next; - if(!this.isRendered) return this._enqueue("nextPage", arguments); + if(!this.isRendered) return this._q.enqueue("nextPage", arguments); next = this.renderer.nextPage(); @@ -2477,7 +2510,7 @@ EPUBJS.Book.prototype.nextPage = function(){ EPUBJS.Book.prototype.prevPage = function() { var prev; - if(!this.isRendered) return this._enqueue("prevPage", arguments); + if(!this.isRendered) return this._q.enqueue("prevPage", arguments); prev = this.renderer.prevPage(); @@ -2510,28 +2543,48 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() { return this.renderer.currentLocationCfi; }; -EPUBJS.Book.prototype.gotoCfi = function(cfiString){ +EPUBJS.Book.prototype.goto = function(target){ + + if(typeof target === "number"){ + return this.gotoPage(target); + } else if(target.indexOf("epubcfi(") === 0) { + return this.gotoCfi(target); + } else if(target.indexOf("%") === target.length-1) { + return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); + } else { + return this.gotoHref(target); + } + +}; + +EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){ var cfi, spinePos, spineItem, rendered, - deferred; + deferred = defer || new RSVP.defer(); if(!this.isRendered) { this.settings.previousLocationCfi = cfiString; return false; } + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]); + return false; + } cfi = new EPUBJS.EpubCFI(cfiString); spinePos = cfi.spinePos; spineItem = this.spine[spinePos]; - deferred = new RSVP.defer(); - + promise = deferred.promise; + this._moving = true; //-- If same chapter only stay on current chapter if(this.currentChapter && this.spinePos === spinePos){ this.renderer.gotoCfi(cfi); - deferred.resolve(this.currentChapter); - return deferred.promise; + this._moving = false; + deferred.resolve(this.renderer.currentLocationCfi); } else { if(!spineItem || spinePos == -1) { @@ -2546,24 +2599,35 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString){ render = this.renderer.displayChapter(this.currentChapter, this.globalLayoutProperties); render.then(function(rendered){ - rendered.gotoCfi(cfi); - }); + rendered.gotoCfi(cfi); + this._moving = false; + deferred.resolve(rendered.currentLocationCfi); + }.bind(this)); } - - return render; } + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return promise; }; -EPUBJS.Book.prototype.goto = function(url){ +EPUBJS.Book.prototype.gotoHref = function(url, defer){ var split, chapter, section, absoluteURL, spinePos; - var deferred = new RSVP.defer(); - //if(!this.isRendered) return this._enqueue("goto", arguments); + var deferred = defer || new RSVP.defer(); + if(!this.isRendered) { this.settings.goto = url; - return; + return false; } - + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoHref", [url, deferred]); + return false; + } + split = url.split("#"); chapter = split[0]; section = split[1] || false; @@ -2581,14 +2645,34 @@ EPUBJS.Book.prototype.goto = function(url){ if(!this.currentChapter || spinePos != this.currentChapter.spinePos){ //-- Load new chapter if different than current return this.displayChapter(spinePos).then(function(){ - if(section) this.render.section(section); - }.bind(this)); + if(section){ + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); + }.bind(this)); }else{ //-- Only goto section - if(section) this.render.section(section); - deferred.resolve(this.currentChapter); - return deferred.promise; + if(section) { + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); } + + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return deferred.promise; +}; + +EPUBJS.Book.prototype.gotoPage = function(pg){ + var cfi = this.pagination.cfiFromPage(pg); + return this.gotoCfi(cfi); +}; + +EPUBJS.Book.prototype.gotoPercentage = function(percent){ + var pg = this.pagination.pageFromPercentage(percent); + return this.gotoCfi(pg); }; EPUBJS.Book.prototype.preloadNextChapter = function() { @@ -2648,7 +2732,7 @@ EPUBJS.Book.prototype.fromStorage = function(stored) { */ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { - if(!this.isRendered) return this._enqueue("setStyle", arguments); + if(!this.isRendered) return this._q.enqueue("setStyle", arguments); this.settings.styles[style] = val; @@ -2657,14 +2741,14 @@ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { }; EPUBJS.Book.prototype.removeStyle = function(style) { - if(!this.isRendered) return this._enqueue("removeStyle", arguments); + if(!this.isRendered) return this._q.enqueue("removeStyle", arguments); this.renderer.removeStyle(style); this.renderer.reformat(); delete this.settings.styles[style]; }; EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) { - if(!this.isRendered) return this._enqueue("addHeadTag", arguments); + if(!this.isRendered) return this._q.enqueue("addHeadTag", arguments); this.settings.headTags[tag] = attrs; }; @@ -2707,15 +2791,6 @@ EPUBJS.Book.prototype.destroy = function() { }; -EPUBJS.Book.prototype._enqueue = function(command, args) { - - this._q.push({ - 'command': command, - 'args': args - }); - -}; - EPUBJS.Book.prototype._ready = function() { this.trigger("book:ready"); @@ -2728,21 +2803,18 @@ EPUBJS.Book.prototype._rendered = function(err) { this.isRendered = true; this.trigger("book:rendered"); - this._q.forEach(function(item){ - book[item.command].apply(book, item.args); - }); - + this._q.flush(); }; EPUBJS.Book.prototype.applyStyles = function(callback){ - if(!this.isRendered) return this._enqueue("applyStyles", arguments); + if(!this.isRendered) return this._q.enqueue("applyStyles", arguments); this.renderer.applyStyles(this.settings.styles); callback(); }; EPUBJS.Book.prototype.applyHeadTags = function(callback){ - if(!this.isRendered) return this._enqueue("applyHeadTags", arguments); + if(!this.isRendered) return this._q.enqueue("applyHeadTags", arguments); this.renderer.applyHeadTags(this.settings.headTags); callback(); }; @@ -2750,7 +2822,7 @@ EPUBJS.Book.prototype.applyHeadTags = function(callback){ EPUBJS.Book.prototype._registerReplacements = function(renderer){ renderer.registerHook("beforeChapterDisplay", this.applyStyles.bind(this), true); renderer.registerHook("beforeChapterDisplay", this.applyHeadTags.bind(this), true); - renderer.registerHook("beforeChapterDisplay", EPUBJS.replace.hrefs, true); + renderer.registerHook("beforeChapterDisplay", EPUBJS.replace.hrefs.bind(this), true); if(this._needsAssetReplacement()) { @@ -3221,6 +3293,47 @@ EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); } }; + +EPUBJS.core.queue = function(_scope){ + var _q = []; + var scope = _scope; + // Add an item to the queue + var enqueue = function(funcName, args, context) { + _q.push({ + "funcName" : funcName, + "args" : args, + "context" : context + }); + return _q; + }; + // Run one item + var dequeue = function(){ + var inwait; + if(_q.length) { + inwait = _q.shift(); + // Defer to any current tasks + setTimeout(function(){ + scope[inwait.funcName].apply(inwait.context || scope, inwait.args); + }, 0); + } + }; + // Run All + var flush = function(){ + while(_q.length) { + dequeue(); + } + }; + // Clear all items in wait + var clear = function(){ + _q = []; + }; + return { + "enqueue" : enqueue, + "dequeue" : dequeue, + "flush" : flush, + "clear" : clear + }; +}; EPUBJS.EpubCFI = function(cfiStr){ if(cfiStr) return this.parse(cfiStr); }; @@ -3246,10 +3359,7 @@ EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) { var segment = ''; segment += (part.index + 1) * 2; - if(part.id && part.id.slice(0, 6) === "EPUBJS") { - //-- ignore internal @EPUBJS ids for - return; - } else if(part.id) { + if(part.id) { segment += "[" + part.id + "]"; } @@ -3262,8 +3372,13 @@ EPUBJS.EpubCFI.prototype.generatePathComponent = function(steps) { EPUBJS.EpubCFI.prototype.generateCfiFromElement = function(element, chapter) { var steps = this.pathTo(element); var path = this.generatePathComponent(steps); - - return "epubcfi(" + chapter + "!" + path + "/1:0)"; + if(!path.length) { + // Start of Chapter + return "epubcfi(" + chapter + ")"; + } else { + // First Text Node + return "epubcfi(" + chapter + "!" + path + "/1:0)"; + } }; EPUBJS.EpubCFI.prototype.pathTo = function(node) { @@ -3319,18 +3434,18 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { end, text; + cfi.str = cfiStr; + if(cfiStr.indexOf("epubcfi(") === 0) { // Remove intial epubcfi( and ending ) cfiStr = cfiStr.slice(8, cfiStr.length-1); } - - chapterComponent = this.getChapterComponent(cfiStr); - pathComponent = this.getPathComponent(cfiStr); + pathComponent = this.getPathComponent(cfiStr) || ''; charecterOffsetComponent = this.getCharecterOffsetComponent(cfiStr); // Make sure this is a valid cfi or return - if(!chapterComponent.length || !pathComponent.length) { + if(!chapterComponent) { return {spinePos: -1}; } @@ -3392,8 +3507,83 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) { return cfi; }; +EPUBJS.EpubCFI.prototype.addMarker = function(cfi, _doc, _marker) { + var doc = _doc || document; + var marker = _marker || this.createMarker(doc); + var parent; + var lastStep; + var text; + var split; + + if(typeof cfi === 'string') { + cfi = this.parse(cfi); + } + // Get the terminal step + lastStep = cfi.steps[cfi.steps.length-1]; -EPUBJS.EpubCFI.prototype.getElement = function(cfi, _doc) { + // check spinePos + if(cfi.spinePos === -1) { + // Not a valid CFI + return false; + } + + // Find the CFI elements parent + parent = this.findParent(cfi, doc); + + if(!parent) { + // CFI didn't return an element + // Maybe it isnt in the current chapter? + return false; + } + + if(lastStep && lastStep.type === "text") { + text = parent.childNodes[lastStep.index]; + if(cfi.characterOffset){ + split = text.splitText(); + marker.classList.add("EPUBJS-CFI-SPLIT"); + parent.insertBefore(marker, split); + } else { + parent.insertBefore(marker, text); + } + } else { + parent.insertBefore(marker, parent.firstChild); + } + + return marker; +}; + +EPUBJS.EpubCFI.prototype.createMarker = function(_doc) { + var doc = _doc || document; + var element = doc.createElement('span'); + element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid(); + element.classList.add("EPUBJS-CFI-MARKER"); + + return element; +}; + +EPUBJS.EpubCFI.prototype.removeMarker = function(marker, _doc) { + var doc = _doc || document; + // var id = marker.id; + + // Remove only elements added as markers + if(marker.classList.contains("EPUBJS-CFI-MARKER")){ + marker.parentElement.removeChild(marker); + } + + // Cleanup textnodes + if(marker.classList.contains("EPUBJS-CFI-SPLIT")){ + nextSib = marker.nextSibling; + prevSib = marker.previousSibling; + if(nextSib.nodeType === 3 && prevSib.nodeType === 3){ + prevSib.innerText += nextSib.innerText; + marker.parentElement.removeChild(nextSib); + } + marker.parentElement.removeChild(marker); + } + +}; + +EPUBJS.EpubCFI.prototype.findParent = function(cfi, _doc) { var doc = _doc || document, element = doc.getElementsByTagName('html')[0], children = Array.prototype.slice.call(element.children), @@ -3404,38 +3594,30 @@ EPUBJS.EpubCFI.prototype.getElement = function(cfi, _doc) { cfi = this.parse(cfi); } - sections = cfi.steps; - + sections = cfi.steps.slice(0); // Clone steps array + if(!sections.length) { + return doc.getElementsByTagName('body')[0]; + } + while(sections && sections.length > 0) { part = sections.shift(); - - // Wrap text elements in a span and return that new element + // Find textNodes Parent if(part.type === "text") { text = element.childNodes[part.index]; - element = doc.createElement('span'); - element.id = "EPUBJS-CFI-MARKER:"+ EPUBJS.core.uuid(); - - if(cfi.characterOffset) { - textBegin = doc.createTextNode(text.textContent.slice(0, cfi.characterOffset)); - textEnd = doc.createTextNode(text.textContent.slice(cfi.characterOffset)); - text.parentNode.insertBefore(textEnd, text); - text.parentNode.insertBefore(element, textEnd); - text.parentNode.insertBefore(textBegin, element); - text.parentNode.removeChild(text); - } else { - text.parentNode.insertBefore(element, text); - } - // sort cut to find element by id + element = text.parentNode || element; + // Find element by id if present } else if(part.id){ element = doc.getElementById(part.id); - // find element in parent + // Find element in parent }else{ - if(!children) console.error("No Kids", element); element = children[part.index]; } - - - if(!element) console.error("No Element For", part, cfi); + // Element can't be found + if(typeof element === "undefined") { + console.error("No Element For", part, cfi.str); + return false; + } + // Get current element children and continue through steps children = Array.prototype.slice.call(element.children); } @@ -3681,7 +3863,7 @@ EPUBJS.Layout.Reflowable.prototype.calculatePages = function() { this.documentElement.style.width = "auto"; //-- reset width for calculations totalWidth = this.documentElement.scrollWidth; displayedPages = Math.round(totalWidth / this.spreadWidth); -// console.log(totalWidth, this.spreadWidth) + return { displayedPages : displayedPages, pageCount : displayedPages @@ -3798,11 +3980,12 @@ EPUBJS.Layout.Fixed.prototype.calculatePages = function(){ }; }; EPUBJS.Pagination = function(pageList) { - this.pageList = pageList; this.pages = []; this.locations = []; - this.epubcfi = new EPUBJS.EpubCFI(); + if(pageList && pageList.length) { + this.process(pageList); + } }; EPUBJS.Pagination.prototype.process = function(pageList){ @@ -3810,14 +3993,15 @@ EPUBJS.Pagination.prototype.process = function(pageList){ this.pages.push(item.page); this.locations.push(item.cfi); }, this); - + + this.pageList = pageList; this.firstPage = parseInt(this.pages[0]); this.lastPage = parseInt(this.pages[this.pages.length-1]); this.totalPages = this.lastPage - this.firstPage; }; EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){ - var pg; + var pg = -1; // check if the cfi is in the location list var index = this.locations.indexOf(cfi); if(index != -1 && index < (this.pages.length-1) ) { @@ -3831,12 +4015,11 @@ EPUBJS.Pagination.prototype.pageFromCfi = function(cfi){ // Add the new page in so that the locations and page array match up this.pages.splice(index, 0, pg); } - return pg; }; EPUBJS.Pagination.prototype.cfiFromPage = function(pg){ - var cfi; + var cfi = -1; // check that pg is an int if(typeof pg != "number"){ pg = parseInt(pg); @@ -3868,18 +4051,6 @@ EPUBJS.Pagination.prototype.percentageFromCfi = function(cfi){ var percentage = this.percentageFromPage(pg); return percentage; }; - -// TODO: move these -EPUBJS.Book.prototype.gotoPage = function(pg){ - var cfi = this.pagination.cfiFromPage(pg); - this.gotoCfi(cfi); -}; - -EPUBJS.Book.prototype.gotoPercentage = function(percent){ - var pg = this.pagination.pageFromPercentage(percent); - this.gotoCfi(pg); -}; - EPUBJS.Parser = function(baseUrl){ this.baseUrl = baseUrl || ''; }; @@ -4343,7 +4514,11 @@ EPUBJS.Render.Iframe.prototype.create = function(){ this.iframe = document.createElement('iframe'); this.iframe.id = "epubjs-iframe:" + EPUBJS.core.uuid(); this.iframe.scrolling = "no"; + this.iframe.seamless = "seamless"; + // Back up if seamless isn't supported + this.iframe.style.border = "none"; + this.iframe.addEventListener("load", this.loaded.bind(this), false); return this.iframe; }; @@ -4356,9 +4531,11 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ var render = this, deferred = new RSVP.defer(); - this.leftPos = 0; this.iframe.src = url; - + + // Reset the scroll position + render.leftPos = 0; + if(this.window) { this.unload(); } @@ -4372,12 +4549,12 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ render.window = render.iframe.contentWindow; render.window.addEventListener("resize", render.resized.bind(render), false); - + //-- Clear Margins if(render.bodyEl) { render.bodyEl.style.margin = "0"; } - + deferred.resolve(render.docEl); }; @@ -4391,6 +4568,12 @@ EPUBJS.Render.Iframe.prototype.load = function(url){ return deferred.promise; }; + +EPUBJS.Render.Iframe.prototype.loaded = function(v){ + var url = this.iframe.contentWindow.location.href; + this.trigger("render:loaded", url); +}; + // Resize the iframe to the given width and height EPUBJS.Render.Iframe.prototype.resize = function(width, height){ var iframeBox; @@ -4488,13 +4671,15 @@ EPUBJS.Render.Iframe.prototype.getBaseElement = function(){ // Checks if an element is on the screen EPUBJS.Render.Iframe.prototype.isElementVisible = function(el){ var rect; + var left; if(el && typeof el.getBoundingClientRect === 'function'){ rect = el.getBoundingClientRect(); + left = rect.left; //+ rect.width; if( rect.width !== 0 && rect.height !== 0 && // Element not visible - rect.left >= 0 && - rect.left < this.pageWidth ) { + left >= 0 && + left < this.pageWidth ) { return true; } } @@ -4515,6 +4700,9 @@ EPUBJS.Render.Iframe.prototype.scroll = function(bool){ EPUBJS.Render.Iframe.prototype.unload = function(){ this.window.removeEventListener("resize", this.resized); }; + +//-- Enable binding events to Render +RSVP.EventTarget.mixin(EPUBJS.Render.Iframe.prototype); EPUBJS.Renderer = function(renderMethod) { // Dom events to listen for this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click"]; @@ -4529,6 +4717,9 @@ EPUBJS.Renderer = function(renderMethod) { console.error("Not a Valid Rendering Method"); } + // Listen for load events + this.render.on("render:loaded", this.loaded.bind(this)); + // Cached for replacement urls from storage this.caches = {}; @@ -4637,9 +4828,9 @@ EPUBJS.Renderer.prototype.load = function(url){ this.visible(false); - loaded = this.render.load(url); + render = this.render.load(url); - loaded.then(function(contents) { + render.then(function(contents) { var formated; this.contents = contents; @@ -4653,6 +4844,7 @@ EPUBJS.Renderer.prototype.load = function(url){ this.render.window.addEventListener("resize", this.resized, false); } + this.addEventListeners(); this.addSelectionListeners(); @@ -4678,6 +4870,13 @@ EPUBJS.Renderer.prototype.load = function(url){ return deferred.promise; }; +EPUBJS.Renderer.prototype.loaded = function(url){ + this.trigger("render:loaded", url); + // var uri = EPUBJS.core.uri(url); + // var relative = uri.path.replace(book.bookUrl, ''); + // console.log(url, uri, relative); +}; + /** * Reconciles the current chapters layout properies with * the global layout properities. @@ -4706,8 +4905,7 @@ EPUBJS.Renderer.prototype.reconcileLayoutSettings = function(global, chapter){ settings[property] = value; } }); - - return settings; + return settings; }; /** @@ -4768,7 +4966,7 @@ EPUBJS.Renderer.prototype.reformat = function(){ pages = renderer.layout.calculatePages(); renderer.updatePages(pages); - + // Give the css styles time to update clearTimeout(this.timeoutTillCfi); this.timeoutTillCfi = setTimeout(function(){ @@ -4839,7 +5037,6 @@ EPUBJS.Renderer.prototype.page = function(pg){ this.currentLocationCfi = this.getPageCfi(); this.trigger("renderer:locationChanged", this.currentLocationCfi); - return true; } //-- Return false if page is greater than the total @@ -4892,7 +5089,20 @@ EPUBJS.Renderer.prototype.section = function(fragment){ }; -// Walk the node tree from an element to the root +EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) { + var children = node.childNodes; + var leng = children.length; + + if(leng && + children[0] && // First Child + children[0].nodeType === 3 && // This is a textNodes + children[0].textContent.trim().length) { // With non whitespace or return charecters + return true; + } + return false; +}; + +// Walk the node tree from a start element to next visible element EPUBJS.Renderer.prototype.walk = function(node) { var r, children, leng, startNode = node, @@ -4904,7 +5114,7 @@ EPUBJS.Renderer.prototype.walk = function(node) { while(!r && stack.length) { node = stack.shift(); - if( this.render.isElementVisible(node) ) { + if( this.render.isElementVisible(node) && this.firstElementisTextNode(node)) { r = node; } @@ -4915,8 +5125,8 @@ EPUBJS.Renderer.prototype.walk = function(node) { } else { return r; } - for (var i = 0; i < leng; i++) { - if(children[i] != prevNode) stack.push(children[i]); + for (var i = leng-1; i >= 0; i--) { + if(children[i] != prevNode) stack.unshift(children[i]); } } @@ -4948,13 +5158,19 @@ EPUBJS.Renderer.prototype.getPageCfi = function(prevEl){ // Goto a cfi position in the current chapter EPUBJS.Renderer.prototype.gotoCfi = function(cfi){ var element; + var pg; if(_.isString(cfi)){ cfi = this.epubcfi.parse(cfi); } - element = this.epubcfi.getElement(cfi, this.doc); - this.pageByElement(element); + marker = this.epubcfi.addMarker(cfi, this.doc); + if(marker) { + pg = this.render.getPageNumberByElement(marker); + // Must Clean up Marker before going to page + this.epubcfi.removeMarker(marker, this.doc); + this.page(pg); + } }; // Walk nodes until a visible element is found @@ -5187,12 +5403,12 @@ EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callba //-- Enable binding events to Renderer RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype); - var EPUBJS = EPUBJS || {}; EPUBJS.replace = {}; //-- Replaces the relative links within the book to use our internal page changer EPUBJS.replace.hrefs = function(callback, renderer){ + var book = this; var replacments = function(link, done){ var href = link.getAttribute("href"), relative = href.search("://"), @@ -5205,7 +5421,7 @@ EPUBJS.replace.hrefs = function(callback, renderer){ }else{ link.onclick = function(){ - renderer.book.goto(href); + book.goto(href); return false; }; diff --git a/build/reader.js b/build/reader.js index 33896be..6d07ab9 100644 --- a/build/reader.js +++ b/build/reader.js @@ -695,6 +695,8 @@ EPUBJS.reader.TocController = function(toc) { $list.find(".toc_link").on("click", function(event){ var url = this.getAttribute('href'); + event.preventDefault(); + //-- Provide the Book with the url to show // The Url must be found in the books manifest book.goto(url); @@ -705,19 +707,18 @@ EPUBJS.reader.TocController = function(toc) { $(this).parent('li').addClass("currentChapter"); - event.preventDefault(); }); $list.find(".toc_toggle").on("click", function(event){ var $el = $(this).parent('li'), open = $el.hasClass("openChapter"); + event.preventDefault(); if(open){ $el.removeClass("openChapter"); } else { $el.addClass("openChapter"); } - event.preventDefault(); }); return { diff --git a/demo/js/epub.min.js b/demo/js/epub.min.js index b8029f0..3bf10db 100644 --- a/demo/js/epub.min.js +++ b/demo/js/epub.min.js @@ -1,3 +1,3 @@ -(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;g=h?e.resolve():(g=c,b=new EPUBJS.Chapter(this.spine[g],this.store),d.displayChapter(b,this.globalLayoutProperties).then(function(){for(var a=d.nextPage();a;)a=d.nextPage();j(e)})),e.promise}.bind(this);j().then(function(){d.remove(),this.element.removeChild(e),f.resolve(c)}.bind(this))}return d.on("renderer:locationChanged",function(a){i+=1,c.push({cfi:a,page:i})}),f.promise},EPUBJS.Book.prototype.generatePagination=function(a,b){var c,d=this;return this.ready.spine.promise.then(function(){c=d.generatePageList(a,b).then(function(a){d.pageList=d.contents.pageList=a,d.pagination.process(a),d.ready.pageList.resolve(d.pageList)})}),c},EPUBJS.Book.prototype.loadPagination=function(a){var b=JSON.parse(a);return b&&b.length&&(this.pageList=b,this.pagination.process(this.pageList),this.ready.all.then(function(){this.ready.pageList.resolve(this.pageList)}.bind(this))),this.pageList},EPUBJS.Book.prototype.getPageList=function(){return this.ready.pageList.promise},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.listenToRenderer=function(a){var b=this;a.Events.forEach(function(c){a.on(c,function(a){b.trigger(c,a)})}),a.on("renderer:locationChanged",function(a){var b,c;this.pageList.length>0&&(b=this.pagination.pageFromCfi(a),c=this.pagination.percentageFromPage(b),this.trigger("book:pageChanged",{page:b,percentage:c}))}.bind(this))},EPUBJS.Book.prototype.unlistenToRenderer=function(a){a.Events.forEach(function(b){a.off(b)})},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a,this.settings.encoding):this.settings.contained?this.zip.getXml(a,this.settings.encoding):EPUBJS.core.request(a,"xml",this.settings.withCredentials)},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=EPUBJS.core.uri(a),d=c.protocol,e="/"==c.path[0],f=window.location,g=f.origin||f.protocol+"//"+f.host,h=document.getElementsByTagName("base");return h.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void 0:EPUBJS.core.resolveUrl(b||f.pathname,c.path)},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=localStorage.getItem(a); -return localStorage&&null!==b?!0:!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){localStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){localStorage.removeItem(this.settings.bookKey)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){var i=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,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),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b){var c,d,e,f=this;return this.isRendered?this._rendering?(this._displayQ.push(arguments),void 0):(_.isNumber(a)?e=a:(d=new EPUBJS.EpubCFI(a),e=d.spinePos),(0>e||e>=this.spine.length)&&(console.warn("Not A Valid Location"),e=0,b=!1,d=!1),this.spinePos=e,this.currentChapter=new EPUBJS.Chapter(this.spine[e],this.store),this._rendering=!0,c=f.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),d?c.then(function(a){a.gotoCfi(d)}):b&&c.then(function(a){a.lastPage()}),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.shift(),f.displayChapter.apply(f,a))}),c):this._enqueue("displayChapter",arguments)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.renderer.nextPage(),a?void 0:this.nextChapter()):this._enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.renderer.prevPage(),a?void 0:this.prevChapter()):this._enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos0?(this.spinePos-=1,this.displayChapter(this.spinePos,!0)):(this.trigger("book:atStart"),void 0)},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){return this.isRendered?this.renderer.currentLocationCfi:!1},EPUBJS.Book.prototype.gotoCfi=function(a){var b,c,d,e;return this.isRendered?(b=new EPUBJS.EpubCFI(a),c=b.spinePos,d=this.spine[c],e=new RSVP.defer,this.currentChapter&&this.spinePos===c?(this.renderer.gotoCfi(b),e.resolve(this.currentChapter),e.promise):(d&&-1!=c||(c=0,d=this.spine[c]),this.currentChapter=new EPUBJS.Chapter(d,this.store),this.currentChapter&&(this.spinePos=c,render=this.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),render.then(function(a){a.gotoCfi(b)})),render)):(this.settings.previousLocationCfi=a,!1)},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.currentChapter?this.currentChapter.spinePos:0),"number"!=typeof e?!1:this.currentChapter&&e==this.currentChapter.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.settings.goto=a,void 0)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a,b=this.spinePos+1;return b>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[b]),a&&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){return this.isRendered?(this.settings.styles[a]=b,this.renderer.setStyle(a,b,c),this.renderer.reformat(),void 0):this._enqueue("setStyle",arguments)},EPUBJS.Book.prototype.removeStyle=function(a){return this.isRendered?(this.renderer.removeStyle(a),this.renderer.reformat(),delete this.settings.styles[a],void 0):this._enqueue("removeStyle",arguments)},EPUBJS.Book.prototype.addHeadTag=function(a,b){return this.isRendered?(this.settings.headTags[a]=b,void 0):this._enqueue("addHeadTag",arguments)},EPUBJS.Book.prototype.useSpreads=function(a){console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"),a===!1?this.forceSingle(!0):this.forceSingle(!1)},EPUBJS.Book.prototype.forceSingle=function(a){this.renderer.forceSingle(a),this.isRendered&&this.renderer.reformat()},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&this.saveContents(),this.unlistenToRenderer(this.renderer),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.applyStyles=function(a){return this.isRendered?(this.renderer.applyStyles(this.settings.styles),a(),void 0):this._enqueue("applyStyles",arguments)},EPUBJS.Book.prototype.applyHeadTags=function(a){return this.isRendered?(this.renderer.applyHeadTags(this.settings.headTags),a(),void 0):this._enqueue("applyHeadTags",arguments)},EPUBJS.Book.prototype._registerReplacements=function(a){a.registerHook("beforeChapterDisplay",this.applyStyles.bind(this),!0),a.registerHook("beforeChapterDisplay",this.applyHeadTags.bind(this),!0),a.registerHook("beforeChapterDisplay",EPUBJS.replace.hrefs,!0),this._needsAssetReplacement()&&a.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Book.prototype._needsAssetReplacement=function(){return this.settings.fromStorage?"filesystem"==this.storage.getStorageType()?!1:!0:this.settings.contained?!0:!1},EPUBJS.Book.prototype.parseLayoutProperties=function(a){var b=this.layoutOveride&&this.layoutOveride.layout||a.layout||"reflowable",c=this.layoutOveride&&this.layoutOveride.spread||a.spread||"auto",d=this.layoutOveride&&this.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},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,b){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b},EPUBJS.Chapter.prototype.contents=function(a){var b=a||this.store;return b?b.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer,c=a||this.store;return c?(this.tempUrl||(this.tempUrl=c.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,c){function d(){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?e?this.response:new Blob([this.response]):this.response,g.resolve(a)}else g.reject({message:this.response,stack:(new Error).stack})}var e=window.URL,f=e?"blob":"arraybuffer",g=new RSVP.defer,h=new XMLHttpRequest,i=XMLHttpRequest.prototype;return"overrideMimeType"in i||Object.defineProperty(i,"overrideMimeType",{value:function(){}}),c&&(h.withCredentials=!0),h.open("GET",a,!0),h.onreadystatechange=d,"blob"==b&&(h.responseType=f),"json"==b&&h.setRequestHeader("Accept","application/json"),"xml"==b&&h.overrideMimeType("text/xml"),h.send(),g.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.uri=function(a){var b,c,d,e={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:a},f=a.indexOf("://"),g=a.indexOf("?"),h=a.indexOf("#");return-1!=h&&(e.fragment=a.slice(h+1),a=a.slice(0,h)),-1!=g&&(e.search=a.slice(g+1),a=a.slice(0,g)),-1!=f?(e.protocol=a.slice(0,f),b=a.slice(f+3),d=b.indexOf("/"),-1===d?(e.host=e.path,e.path=""):(e.host=b.slice(0,d),e.path=b.slice(d)),e.origin=e.protocol+"://"+e.host,e.directory=EPUBJS.core.folder(e.path),e.base=e.origin+e.directory):(e.path=a,e.directory=EPUBJS.core.folder(a),e.base=e.directory),e.filename=a.replace(e.base,""),c=e.filename.lastIndexOf("."),-1!=c&&(e.extension=e.filename.slice(c+1)),e},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/");if(-1==b)var c="";return c=a.slice(0,b+1)},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=EPUBJS.core.uri(b),g=a.split("/");return f.host?b:(g.pop(),d=b.split("/"),d.forEach(function(a){".."===a?g.pop():e.push(a)}),c=g.concat(e),c.join("/"))},EPUBJS.core.uuid=function(){var a=(new Date).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});return b},EPUBJS.core.insert=function(a,b,c){var d=EPUBJS.core.locationOf(a,b,c);return b.splice(d+1,0,a),d+1},EPUBJS.core.locationOf=function(a,b,c,d,e){var f=d||0,g=e||b.length,h=parseInt(f+(g-f)/2);return c||(c=function(a,b){return a>b?1:b>a?-1:(a=b)?0:void 0}),1>=g-f||0===c(b[h],a)?h:-1===c(b[h],a)?EPUBJS.core.locationOf(a,b,c,h,g):EPUBJS.core.locationOf(a,b,c,f,h)},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=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.generatePathComponent=function(a){var b=[];return a.forEach(function(a){var c="";c+=2*(a.index+1),a.id&&"EPUBJS"===a.id.slice(0,6)||(a.id&&(c+="["+a.id+"]"),b.push(c))}),b.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(a,b){var c=this.pathTo(a),d=this.generatePathComponent(c);return"epubcfi("+b+"!"+d+"/1:0)"},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.getChapterComponent=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(a){var b=a.split("!"),c=b[1]?b[1].split(":"):"";return c[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(a){var b=a.split(":");return b[1]||""},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f,g,h,i,j={};return 0===a.indexOf("epubcfi(")&&(a=a.slice(8,a.length-1)),c=this.getChapterComponent(a),d=this.getPathComponent(a),e=this.getCharecterOffsetComponent(a),c.length&&d.length?(b=c.split("/")[2]||"")?(j.spinePos=parseInt(b)/2-1||0,g=b.match(/\[(.*)\]/),j.spineId=g?g[1]:!1,-1!=d.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=d.split("/"),i=h[h.length-1],j.steps=[],h.forEach(function(a){var b,c,d,g;a&&(parseInt(a)%2?(b="text",c=parseInt(a)-1):(b="element",c=parseInt(a)/2-1,d=a.match(/\[(.*)\]/),d&&d[1]&&(g=d[1])),j.steps.push({type:b,index:c,id:g||!1}),f=e.match(/\[(.*)\]/),f&&f[1]?(j.characterOffset=parseInt(e.split("[")[0]),j.textLocationAssertion=f[1]):j.characterOffset=parseInt(e))}),j):{spinePos:-1}:{spinePos:-1}},EPUBJS.EpubCFI.prototype.getElement=function(a,b){var c,d,e,f,g,h=b||document,i=h.getElementsByTagName("html")[0],j=Array.prototype.slice.call(i.children);for("string"==typeof a&&(a=this.parse(a)),d=a.steps;d&&d.length>0;)c=d.shift(),"text"===c.type?(e=i.childNodes[c.index],i=h.createElement("span"),i.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),a.characterOffset?(f=h.createTextNode(e.textContent.slice(0,a.characterOffset)),g=h.createTextNode(e.textContent.slice(a.characterOffset)),e.parentNode.insertBefore(g,e),e.parentNode.insertBefore(i,g),e.parentNode.insertBefore(f,i),e.parentNode.removeChild(e)):e.parentNode.insertBefore(i,e)):c.id?i=h.getElementById(c.id):(j||console.error("No Kids",i),i=j[c.index]),i||console.error("No Element For",c,a),j=Array.prototype.slice.call(i.children);return i},EPUBJS.EpubCFI.prototype.compare=function(a,b){if("string"==typeof a&&(a=new EPUBJS.EpubCFI(a)),"string"==typeof b&&(b=new EPUBJS.EpubCFI(b)),a.spinePos>b.spinePos)return 1;if(a.spinePosb.steps[c].index)return 1;if(a.steps[c].indexb.characterOffset?1:a.characterOffset=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,0===f&&b&&b(),e.forEach(function(a){a(d,c)}),void 0)},{register:function(a){if(void 0===EPUBJS.hooks[a]&&(EPUBJS.hooks[a]={}),"object"!=typeof EPUBJS.hooks[a])throw"Already registered: "+a;return EPUBJS.hooks[a]},mixin:function(b){for(var c in a.prototype)b[c]=a.prototype[c]}}}(),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=b%2===0?b:Math.floor(b)-1,h=Math.ceil(g/8),i=h%2===0?h:h-1;return this.documentElement=a,this.spreadWidth=g+i,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=i+"px",a.style[f]=g+"px",a.style.width=g+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var a,b;return this.documentElement.style.width="auto",a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth),{displayedPages:b,pageCount:b}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=2,h=b%2===0?b:Math.floor(b)-1,i=Math.ceil(h/8),j=i%2===0?i:i-1,k=Math.floor((h-j)/g);return this.documentElement=a,this.spreadWidth=(k+j)*g,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=j+"px",a.style[f]=k+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth);return this.documentElement.style.width=a+this.spreadWidth+"px",{displayedPages:b,pageCount:2*b}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(a){var b,c,d,e,f=EPUBJS.core.prefixed("columnWidth"),g=a.querySelector("[name=viewport");return this.documentElement=a,g&&g.hasAttribute("content")&&(b=g.getAttribute("content"),c=b.split(","),c[0]&&(d=c[0].replace("width=","")),c[1]&&(e=c[1].replace("height=",""))),a.style.width=d+"px"||"auto",a.style.height=e+"px"||"auto",a.style[f]="auto",a.style.overflow="auto",{pageWidth:d,pageHeight:e}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Pagination=function(a){this.pageList=a,this.pages=[],this.locations=[],this.epubcfi=new EPUBJS.EpubCFI},EPUBJS.Pagination.prototype.process=function(a){a.forEach(function(a){this.pages.push(a.page),this.locations.push(a.cfi)},this),this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage},EPUBJS.Pagination.prototype.pageFromCfi=function(a){var b,c=this.locations.indexOf(a);return-1!=c&&c1?g[1]:!1;i&&d.push({cfi:i,packageUrl:h,page:f})}),d)}var e=a.querySelector('nav[*|type="page-list"]');return e?d(e):[]},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a){var b=this,c=new RSVP.defer;return this.leftPos=0,this.iframe.src=a,this.window&&this.unload(),this.iframe.onload=function(){b.document=b.iframe.contentDocument,b.docEl=b.document.documentElement,b.headEl=b.document.head,b.bodyEl=b.document.body,b.window=b.iframe.contentWindow,b.window.addEventListener("resize",b.resized.bind(b),!1),b.bodyEl&&(b.bodyEl.style.margin="0"),c.resolve(b.docEl)},this.iframe.onerror=function(a){c.reject({message:"Error Loading Contents: "+a,stack:(new Error).stack})},c.promise},EPUBJS.Render.Iframe.prototype.resize=function(a,b){this.iframe&&(this.iframe.height=b,isNaN(a)||a%2===0||(a+=1),this.iframe.width=a,this.width=this.iframe.getBoundingClientRect().width||a,this.height=this.iframe.getBoundingClientRect().height||b)},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){return this.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){return this.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b){var c=document.createElement(a);for(var d in b)c[d]=b[d];this.headEl&&this.headEl.appendChild(c)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){var b,c;if(a)return b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){return this.bodyEl},EPUBJS.Render.Iframe.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&&a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.nextPage=function(){var a=this.chapterPos+1;return a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(this.visibileEl),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.page(this.chapterPos-1)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b;a&&(b=this.render.getPageNumberByElement(a),this.page(b))},EPUBJS.Renderer.prototype.lastPage=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},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.render.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(a){return this.visibileEl=this.findFirstVisible(a),this.epubcfi.generateCfiFromElement(this.visibileEl,this.currentChapter.cfiBase)},EPUBJS.Renderer.prototype.gotoCfi=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.render.getBaseElement();return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.onResized=function(){var a;this.width=this.container.clientWidth,this.height=this.container.clientHeight,a=this.determineSpreads(this.minSpreadWidth),a!=this.spreads&&(this.spreads=a,this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=new EPUBJS.Layout[this.layoutMethod]),this.contents&&this.reformat(),this.trigger("renderer:resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.addEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.addEventListener(a,this.triggerEvent.bind(this),!1)},this)},EPUBJS.Renderer.prototype.removeEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.removeEventListener(a,this.triggerEvent,!1)},this)},EPUBJS.Renderer.prototype.triggerEvent=function(a){this.trigger("renderer:"+a.type,a)},EPUBJS.Renderer.prototype.addSelectionListeners=function(){this.render.document.addEventListener("selectionchange",this.onSelectionChange.bind(this),!1),this.render.window.addEventListener("mouseup",this.onMouseUp.bind(this),!1)},EPUBJS.Renderer.prototype.removeSelectionListeners=function(){this.doc.removeEventListener("selectionchange",this.onSelectionChange,!1),this.render.window.removeEventListener("mouseup",this.onMouseUp,!1)},EPUBJS.Renderer.prototype.onSelectionChange=function(){this.highlighted=!0},EPUBJS.Renderer.prototype.onMouseUp=function(){var a;this.highlighted&&(a=this.render.window.getSelection(),this.trigger("renderer:selected",a),this.highlighted=!1)},EPUBJS.Renderer.prototype.setMinSpreadWidth=function(a){this.minSpreadWidth=a,this.spreads=this.determineSpreads(a)},EPUBJS.Renderer.prototype.determineSpreads=function(a){return this.isForcedSingle||!a||this.width=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.currentChapter.store,h=this.caches[a],i=EPUBJS.core.uri(this.currentChapter.absolute),j=i.base,k=b,l=2e3,m=function(a,b){f[b]=a},n=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(b,d){var h=b.getAttribute(k),i=EPUBJS.core.resolveUrl(j,h),m=function(c){var e;b.onload=function(){clearTimeout(e),d(c,i)},b.onerror=function(a){clearTimeout(e),d(c,i),console.error(a)},"image"==a&&b.setAttribute("externalResourcesRequired","true"),"link[href]"==a&&d(c,i),b.setAttribute(k,c),e=setTimeout(function(){d(c,i)},l)};i in e?(m(e[i]),f[i]=e[i],delete e[i]):c(g,i,m,b)},n,m))},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);var EPUBJS=EPUBJS||{};EPUBJS.replace={},EPUBJS.replace.hrefs=function(a,b){var c=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()};b.replace("a[href]",c,a)},EPUBJS.replace.head=function(a,b){b.replaceWithStored("link[href]","href",EPUBJS.replace.links,a)},EPUBJS.replace.resources=function(a,b){b.replaceWithStored("[src]","src",EPUBJS.replace.srcs,a)},EPUBJS.replace.svg=function(a,b){b.replaceWithStored("image","xlink:href",function(a,b,c){a.getUrl(b).then(c)},a)},EPUBJS.replace.srcs=function(a,b,c){a.getUrl(b).then(c)},EPUBJS.replace.links=function(a,b,c,d){"stylesheet"===d.getAttribute("rel")?EPUBJS.replace.stylesheets(a,b).then(function(a,b){setTimeout(function(){c(a,b)},5)}):a.getUrl(b).then(c)},EPUBJS.replace.stylesheets=function(a,b){var c=new RSVP.defer;if(a)return a.getText(b).then(function(d){EPUBJS.replace.cssUrls(a,b,d).then(function(a){var b=window.URL||window.webkitURL||window.mozURL,d=new Blob([a],{type:"text/css"}),e=b.createObjectURL(d);c.resolve(e)},function(a){console.error(a)})}),c.promise},EPUBJS.replace.cssUrls=function(a,b,c){var d=new RSVP.defer,e=[],f=c.match(/url\(\'?\"?([^\'|^\"|^\)]*)\'?\"?\)/g);if(a)return f?(f.forEach(function(d){var f=EPUBJS.core.resolveUrl(b,d.replace(/url\(|[|\)|\'|\"]/g,"")),g=a.getUrl(f).then(function(a){c=c.replace(d,'url("'+a+'")')});e.push(g)}),RSVP.all(e).then(function(){d.resolve(c)}),d.promise):(d.resolve(c),d.promise)},EPUBJS.Unarchiver=function(a){return this.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=new zip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeof zip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){var b=new RSVP.defer,c=this.zipFs;return c.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b.promise},EPUBJS.Unarchiver.prototype.getXml=function(a,b){return this.getText(a,b).then(function(a){var b=new DOMParser;return b.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){var c=this,d=new RSVP.defer,e=window.decodeURIComponent(a),f=this.zipFs.find(e),g=window.URL||window.webkitURL||window.mozURL;return f?a in this.urlCache?(d.resolve(this.urlCache[a]),d.promise):(f.getBlob(b||zip.getMimeType(f.name),function(b){var e=g.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d.promise):(d.reject({message:"File not found in the epub: "+a,stack:(new Error).stack}),d.promise)},EPUBJS.Unarchiver.prototype.getText=function(a,b){{var c=new RSVP.defer,d=window.decodeURIComponent(a),e=this.zipFs.find(d);window.URL||window.webkitURL||window.mozURL}return e||console.error("No entry found",a),e.getText(function(a){c.resolve(a)},null,null,b||"UTF-8"),c.promise},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){var b=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];c&&b.revokeObjectURL(c)},EPUBJS.Unarchiver.prototype.failed=function(a){console.error(a)},EPUBJS.Unarchiver.prototype.afterSaved=function(){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(a){function b(){f--,0===f&&e.afterSaved()}var c=0,d=20,e=this,f=a.length;a.forEach(function(a){setTimeout(function(a){e.saveEntryFileToStorage(a,b)},c,a),c+=d}),console.log("time",c)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(a,b){a.getData(new zip.BlobWriter,function(c){EPUBJS.storage.save(a.filename,c,b)})}; \ No newline at end of file +(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;g=h?e.resolve():(g=c,b=new EPUBJS.Chapter(this.spine[g],this.store),d.displayChapter(b,this.globalLayoutProperties).then(function(){for(var a=!0;a;)a=d.nextPage();j(e)})),e.promise}.bind(this);j().then(function(){d.remove(),this.element.removeChild(e),f.resolve(c)}.bind(this))}return d.on("renderer:locationChanged",function(a){i+=1,c.push({cfi:a,page:i})}),f.promise},EPUBJS.Book.prototype.generatePagination=function(a,b){var c,d=this;return this.ready.spine.promise.then(function(){c=d.generatePageList(a,b).then(function(a){d.pageList=d.contents.pageList=a,d.pagination.process(a),d.ready.pageList.resolve(d.pageList)})}),c},EPUBJS.Book.prototype.loadPagination=function(a){var b=JSON.parse(a);return b&&b.length&&(this.pageList=b,this.pagination.process(this.pageList),this.ready.pageList.resolve(this.pageList)),this.pageList},EPUBJS.Book.prototype.getPageList=function(){return this.ready.pageList.promise},EPUBJS.Book.prototype.getMetadata=function(){return this.ready.metadata.promise},EPUBJS.Book.prototype.getToc=function(){return this.ready.toc.promise},EPUBJS.Book.prototype.networkListeners=function(){var a=this;window.addEventListener("offline",function(){a.online=!1,a.trigger("book:offline")},!1),window.addEventListener("online",function(){a.online=!0,a.trigger("book:online")},!1)},EPUBJS.Book.prototype.listenToRenderer=function(a){var b=this;a.Events.forEach(function(c){a.on(c,function(a){b.trigger(c,a)})}),a.on("renderer:locationChanged",function(a){var b,c;this.pageList.length>0&&(b=this.pagination.pageFromCfi(a),c=this.pagination.percentageFromPage(b),this.trigger("book:pageChanged",{page:b,percentage:c}))}.bind(this)),a.on("render:loaded",this.loadChange.bind(this))},EPUBJS.Book.prototype.loadChange=function(a){var b=EPUBJS.core.uri(a);this.currentChapter&&b.path!=this.currentChapter.absolute&&(console.warn("Miss Match",b.path,this.currentChapter.absolute),this.goto(b.filename))},EPUBJS.Book.prototype.unlistenToRenderer=function(a){a.Events.forEach(function(b){a.off(b)})},EPUBJS.Book.prototype.loadXml=function(a){return this.settings.fromStorage?this.storage.getXml(a,this.settings.encoding):this.settings.contained?this.zip.getXml(a,this.settings.encoding):EPUBJS.core.request(a,"xml",this.settings.withCredentials)},EPUBJS.Book.prototype.urlFrom=function(a){var b,c=EPUBJS.core.uri(a),d=c.protocol,e="/"==c.path[0],f=window.location,g=f.origin||f.protocol+"//"+f.host,h=document.getElementsByTagName("base");return h.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void 0:EPUBJS.core.resolveUrl(b||f.pathname,c.path) +},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b=localStorage.getItem(a);return localStorage&&null!==b?!0:!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){localStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents))},EPUBJS.Book.prototype.removeSavedContents=function(){localStorage.removeItem(this.settings.bookKey)},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return console.error("Not an Element"),void 0;this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){var i=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,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),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b,c){var d,e,f,g=this,h=c||new RSVP.defer;return this.isRendered?this._rendering?(this._displayQ.enqueue("displayChapter",[a,b,h]),h.promise):(_.isNumber(a)?f=a:(e=new EPUBJS.EpubCFI(a),f=e.spinePos),(0>f||f>=this.spine.length)&&(console.warn("Not A Valid Location"),f=0,b=!1,e=!1),this.spinePos=f,this.currentChapter=new EPUBJS.Chapter(this.spine[f],this.store),this._rendering=!0,d=g.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),e?d.then(function(a){a.gotoCfi(e),h.resolve(g.renderer)}):b?d.then(function(a){a.lastPage(),h.resolve(g.renderer)}):d.then(function(){h.resolve(g.renderer)}),this.settings.fromStorage||this.settings.contained||d.then(function(){g.preloadNextChapter()}),d.then(function(){g._rendering=!1,g._displayQ.dequeue()}),h.promise):(this._q.enqueue("displayChapter",arguments),h.reject({message:"Rendering",stack:(new Error).stack}),h.promise)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.renderer.nextPage(),a?void 0:this.nextChapter()):this._q.enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.renderer.prevPage(),a?void 0:this.prevChapter()):this._q.enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){return this.spinePos0?(this.spinePos-=1,this.displayChapter(this.spinePos,!0)):(this.trigger("book:atStart"),void 0)},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){return this.isRendered?this.renderer.currentLocationCfi:!1},EPUBJS.Book.prototype.goto=function(a){return"number"==typeof a?this.gotoPage(a):0===a.indexOf("epubcfi(")?this.gotoCfi(a):a.indexOf("%")===a.length-1?this.gotoPercentage(parseInt(a.substring(0,a.length-1))):this.gotoHref(a)},EPUBJS.Book.prototype.gotoCfi=function(a,b){var c,d,e,f=b||new RSVP.defer;return this.isRendered?this._moving?(this._gotoQ.enqueue("gotoCfi",[a,f]),!1):(c=new EPUBJS.EpubCFI(a),d=c.spinePos,e=this.spine[d],promise=f.promise,this._moving=!0,this.currentChapter&&this.spinePos===d?(this.renderer.gotoCfi(c),this._moving=!1,f.resolve(this.renderer.currentLocationCfi)):(e&&-1!=d||(d=0,e=this.spine[d]),this.currentChapter=new EPUBJS.Chapter(e,this.store),this.currentChapter&&(this.spinePos=d,render=this.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),render.then(function(a){a.gotoCfi(c),this._moving=!1,f.resolve(a.currentLocationCfi)}.bind(this)))),promise.then(function(){this._gotoQ.dequeue()}.bind(this)),promise):(this.settings.previousLocationCfi=a,!1)},EPUBJS.Book.prototype.gotoHref=function(a,b){var c,d,e,f,g=b||new RSVP.defer;return this.isRendered?this._moving?(this._gotoQ.enqueue("gotoHref",[a,g]),!1):(c=a.split("#"),d=c[0],e=c[1]||!1,f=this.spineIndexByURL[d],d||(f=this.currentChapter?this.currentChapter.spinePos:0),"number"!=typeof f?!1:this.currentChapter&&f==this.currentChapter.spinePos?(e&&this.render.section(e),g.resolve(this.renderer.currentLocationCfi),promise.then(function(){this._gotoQ.dequeue()}.bind(this)),g.promise):this.displayChapter(f).then(function(){e&&this.render.section(e),g.resolve(this.renderer.currentLocationCfi)}.bind(this))):(this.settings.goto=a,!1)},EPUBJS.Book.prototype.gotoPage=function(a){var b=this.pagination.cfiFromPage(a);return this.gotoCfi(b)},EPUBJS.Book.prototype.gotoPercentage=function(a){var b=this.pagination.pageFromPercentage(a);return this.gotoCfi(b)},EPUBJS.Book.prototype.preloadNextChapter=function(){var a,b=this.spinePos+1;return b>=this.spine.length?!1:(a=new EPUBJS.Chapter(this.spine[b]),a&&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){return this.isRendered?(this.settings.styles[a]=b,this.renderer.setStyle(a,b,c),this.renderer.reformat(),void 0):this._q.enqueue("setStyle",arguments)},EPUBJS.Book.prototype.removeStyle=function(a){return this.isRendered?(this.renderer.removeStyle(a),this.renderer.reformat(),delete this.settings.styles[a],void 0):this._q.enqueue("removeStyle",arguments)},EPUBJS.Book.prototype.addHeadTag=function(a,b){return this.isRendered?(this.settings.headTags[a]=b,void 0):this._q.enqueue("addHeadTag",arguments)},EPUBJS.Book.prototype.useSpreads=function(a){console.warn("useSpreads is deprecated, use forceSingle or set a layoutOveride instead"),a===!1?this.forceSingle(!0):this.forceSingle(!1)},EPUBJS.Book.prototype.forceSingle=function(a){this.renderer.forceSingle(a),this.isRendered&&this.renderer.reformat()},EPUBJS.Book.prototype.unload=function(){this.settings.restore&&this.saveContents(),this.unlistenToRenderer(this.renderer),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._ready=function(){this.trigger("book:ready")},EPUBJS.Book.prototype._rendered=function(){this.isRendered=!0,this.trigger("book:rendered"),this._q.flush()},EPUBJS.Book.prototype.applyStyles=function(a){return this.isRendered?(this.renderer.applyStyles(this.settings.styles),a(),void 0):this._q.enqueue("applyStyles",arguments)},EPUBJS.Book.prototype.applyHeadTags=function(a){return this.isRendered?(this.renderer.applyHeadTags(this.settings.headTags),a(),void 0):this._q.enqueue("applyHeadTags",arguments)},EPUBJS.Book.prototype._registerReplacements=function(a){a.registerHook("beforeChapterDisplay",this.applyStyles.bind(this),!0),a.registerHook("beforeChapterDisplay",this.applyHeadTags.bind(this),!0),a.registerHook("beforeChapterDisplay",EPUBJS.replace.hrefs.bind(this),!0),this._needsAssetReplacement()&&a.registerHook("beforeChapterDisplay",[EPUBJS.replace.head,EPUBJS.replace.resources,EPUBJS.replace.svg],!0)},EPUBJS.Book.prototype._needsAssetReplacement=function(){return this.settings.fromStorage?"filesystem"==this.storage.getStorageType()?!1:!0:this.settings.contained?!0:!1},EPUBJS.Book.prototype.parseLayoutProperties=function(a){var b=this.layoutOveride&&this.layoutOveride.layout||a.layout||"reflowable",c=this.layoutOveride&&this.layoutOveride.spread||a.spread||"auto",d=this.layoutOveride&&this.layoutOveride.orientation||a.orientation||"auto";return{layout:b,spread:c,orientation:d}},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,b){this.href=a.href,this.absolute=a.url,this.id=a.id,this.spinePos=a.index,this.cfiBase=a.cfiBase,this.properties=a.properties,this.manifestProperties=a.manifestProperties,this.linear=a.linear,this.pages=1,this.store=b},EPUBJS.Chapter.prototype.contents=function(a){var b=a||this.store;return b?b.get(href):EPUBJS.core.request(href,"xml")},EPUBJS.Chapter.prototype.url=function(a){var b=new RSVP.defer,c=a||this.store;return c?(this.tempUrl||(this.tempUrl=c.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,c){function d(){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?e?this.response:new Blob([this.response]):this.response,g.resolve(a)}else g.reject({message:this.response,stack:(new Error).stack})}var e=window.URL,f=e?"blob":"arraybuffer",g=new RSVP.defer,h=new XMLHttpRequest,i=XMLHttpRequest.prototype;return"overrideMimeType"in i||Object.defineProperty(i,"overrideMimeType",{value:function(){}}),c&&(h.withCredentials=!0),h.open("GET",a,!0),h.onreadystatechange=d,"blob"==b&&(h.responseType=f),"json"==b&&h.setRequestHeader("Accept","application/json"),"xml"==b&&h.overrideMimeType("text/xml"),h.send(),g.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.uri=function(a){var b,c,d,e={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:a},f=a.indexOf("://"),g=a.indexOf("?"),h=a.indexOf("#");return-1!=h&&(e.fragment=a.slice(h+1),a=a.slice(0,h)),-1!=g&&(e.search=a.slice(g+1),a=a.slice(0,g)),-1!=f?(e.protocol=a.slice(0,f),b=a.slice(f+3),d=b.indexOf("/"),-1===d?(e.host=e.path,e.path=""):(e.host=b.slice(0,d),e.path=b.slice(d)),e.origin=e.protocol+"://"+e.host,e.directory=EPUBJS.core.folder(e.path),e.base=e.origin+e.directory):(e.path=a,e.directory=EPUBJS.core.folder(a),e.base=e.directory),e.filename=a.replace(e.base,""),c=e.filename.lastIndexOf("."),-1!=c&&(e.extension=e.filename.slice(c+1)),e},EPUBJS.core.folder=function(a){var b=a.lastIndexOf("/");if(-1==b)var c="";return c=a.slice(0,b+1)},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=EPUBJS.core.uri(b),g=a.split("/");return f.host?b:(g.pop(),d=b.split("/"),d.forEach(function(a){".."===a?g.pop():e.push(a)}),c=g.concat(e),c.join("/"))},EPUBJS.core.uuid=function(){var a=(new Date).getTime(),b="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==b?c:7&c|8).toString(16)});return b},EPUBJS.core.insert=function(a,b,c){var d=EPUBJS.core.locationOf(a,b,c);return b.splice(d+1,0,a),d+1},EPUBJS.core.locationOf=function(a,b,c,d,e){var f=d||0,g=e||b.length,h=parseInt(f+(g-f)/2);return c||(c=function(a,b){return a>b?1:b>a?-1:(a=b)?0:void 0}),1>=g-f||0===c(b[h],a)?h:-1===c(b[h],a)?EPUBJS.core.locationOf(a,b,c,h,g):EPUBJS.core.locationOf(a,b,c,f,h)},EPUBJS.core.queue=function(a){var b=[],c=a,d=function(a,c,d){return b.push({funcName:a,args:c,context:d}),b},e=function(){var a;b.length&&(a=b.shift(),setTimeout(function(){c[a.funcName].apply(a.context||c,a.args)},0))},f=function(){for(;b.length;)e()},g=function(){b=[]};return{enqueue:d,dequeue:e,flush:f,clear:g}},EPUBJS.EpubCFI=function(a){return a?this.parse(a):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=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.generatePathComponent=function(a){var b=[];return a.forEach(function(a){var c="";c+=2*(a.index+1),a.id&&(c+="["+a.id+"]"),b.push(c)}),b.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(a,b){var c=this.pathTo(a),d=this.generatePathComponent(c);return d.length?"epubcfi("+b+"!"+d+"/1:0)":"epubcfi("+b+")"},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.getChapterComponent=function(a){var b=a.split("!");return b[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(a){var b=a.split("!"),c=b[1]?b[1].split(":"):"";return c[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(a){var b=a.split(":");return b[1]||""},EPUBJS.EpubCFI.prototype.parse=function(a){var b,c,d,e,f,g,h,i,j={};return j.str=a,0===a.indexOf("epubcfi(")&&(a=a.slice(8,a.length-1)),c=this.getChapterComponent(a),d=this.getPathComponent(a)||"",e=this.getCharecterOffsetComponent(a),c?(b=c.split("/")[2]||"")?(j.spinePos=parseInt(b)/2-1||0,g=b.match(/\[(.*)\]/),j.spineId=g?g[1]:!1,-1!=d.indexOf(",")&&console.warn("CFI Ranges are not supported"),h=d.split("/"),i=h[h.length-1],j.steps=[],h.forEach(function(a){var b,c,d,g;a&&(parseInt(a)%2?(b="text",c=parseInt(a)-1):(b="element",c=parseInt(a)/2-1,d=a.match(/\[(.*)\]/),d&&d[1]&&(g=d[1])),j.steps.push({type:b,index:c,id:g||!1}),f=e.match(/\[(.*)\]/),f&&f[1]?(j.characterOffset=parseInt(e.split("[")[0]),j.textLocationAssertion=f[1]):j.characterOffset=parseInt(e))}),j):{spinePos:-1}:{spinePos:-1}},EPUBJS.EpubCFI.prototype.addMarker=function(a,b,c){var d,e,f,g,h=b||document,i=c||this.createMarker(h);return"string"==typeof a&&(a=this.parse(a)),e=a.steps[a.steps.length-1],-1===a.spinePos?!1:(d=this.findParent(a,h))?(e&&"text"===e.type?(f=d.childNodes[e.index],a.characterOffset?(g=f.splitText(),i.classList.add("EPUBJS-CFI-SPLIT"),d.insertBefore(i,g)):d.insertBefore(i,f)):d.insertBefore(i,d.firstChild),i):!1},EPUBJS.EpubCFI.prototype.createMarker=function(a){var b=a||document,c=b.createElement("span");return c.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),c.classList.add("EPUBJS-CFI-MARKER"),c},EPUBJS.EpubCFI.prototype.removeMarker=function(a,b){a.classList.contains("EPUBJS-CFI-MARKER")&&a.parentElement.removeChild(a),a.classList.contains("EPUBJS-CFI-SPLIT")&&(nextSib=a.nextSibling,prevSib=a.previousSibling,3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.innerText+=nextSib.innerText,a.parentElement.removeChild(nextSib)),a.parentElement.removeChild(a))},EPUBJS.EpubCFI.prototype.findParent=function(a,b){var c,d,e,f=b||document,g=f.getElementsByTagName("html")[0],h=Array.prototype.slice.call(g.children);if("string"==typeof a&&(a=this.parse(a)),d=a.steps.slice(0),!d.length)return f.getElementsByTagName("body")[0];for(;d&&d.length>0;){if(c=d.shift(),"text"===c.type?(e=g.childNodes[c.index],g=e.parentNode||g):g=c.id?f.getElementById(c.id):h[c.index],"undefined"==typeof g)return console.error("No Element For",c,a.str),!1;h=Array.prototype.slice.call(g.children)}return g},EPUBJS.EpubCFI.prototype.compare=function(a,b){if("string"==typeof a&&(a=new EPUBJS.EpubCFI(a)),"string"==typeof b&&(b=new EPUBJS.EpubCFI(b)),a.spinePos>b.spinePos)return 1;if(a.spinePosb.steps[c].index)return 1;if(a.steps[c].indexb.characterOffset?1:a.characterOffset=f&&b&&b()}var e,f;return"undefined"==typeof this.hooks[a]?!1:(e=this.hooks[a],f=e.length,0===f&&b&&b(),e.forEach(function(a){a(d,c)}),void 0)},{register:function(a){if(void 0===EPUBJS.hooks[a]&&(EPUBJS.hooks[a]={}),"object"!=typeof EPUBJS.hooks[a])throw"Already registered: "+a;return EPUBJS.hooks[a]},mixin:function(b){for(var c in a.prototype)b[c]=a.prototype[c]}}}(),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=b%2===0?b:Math.floor(b)-1,h=Math.ceil(g/8),i=h%2===0?h:h-1;return this.documentElement=a,this.spreadWidth=g+i,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=i+"px",a.style[f]=g+"px",a.style.width=g+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var a,b;return this.documentElement.style.width="auto",a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth),{displayedPages:b,pageCount:b}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(a,b,c){var d=EPUBJS.core.prefixed("columnAxis"),e=EPUBJS.core.prefixed("columnGap"),f=EPUBJS.core.prefixed("columnWidth"),g=2,h=b%2===0?b:Math.floor(b)-1,i=Math.ceil(h/8),j=i%2===0?i:i-1,k=Math.floor((h-j)/g);return this.documentElement=a,this.spreadWidth=(k+j)*g,a.style.width="auto",a.style.overflow="hidden",a.style.height=c+"px",a.style[d]="horizontal",a.style[e]=j+"px",a.style[f]=k+"px",{pageWidth:this.spreadWidth,pageHeight:c}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var a=this.documentElement.scrollWidth,b=Math.round(a/this.spreadWidth);return this.documentElement.style.width=a+this.spreadWidth+"px",{displayedPages:b,pageCount:2*b}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(a){var b,c,d,e,f=EPUBJS.core.prefixed("columnWidth"),g=a.querySelector("[name=viewport");return this.documentElement=a,g&&g.hasAttribute("content")&&(b=g.getAttribute("content"),c=b.split(","),c[0]&&(d=c[0].replace("width=","")),c[1]&&(e=c[1].replace("height=",""))),a.style.width=d+"px"||"auto",a.style.height=e+"px"||"auto",a.style[f]="auto",a.style.overflow="auto",{pageWidth:d,pageHeight:e}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Pagination=function(a){this.pages=[],this.locations=[],this.epubcfi=new EPUBJS.EpubCFI,a&&a.length&&this.process(a)},EPUBJS.Pagination.prototype.process=function(a){a.forEach(function(a){this.pages.push(a.page),this.locations.push(a.cfi)},this),this.pageList=a,this.firstPage=parseInt(this.pages[0]),this.lastPage=parseInt(this.pages[this.pages.length-1]),this.totalPages=this.lastPage-this.firstPage},EPUBJS.Pagination.prototype.pageFromCfi=function(a){var b=-1,c=this.locations.indexOf(a);return-1!=c&&c1?g[1]:!1;i&&d.push({cfi:i,packageUrl:h,page:f})}),d)}var e=a.querySelector('nav[*|type="page-list"]');return e?d(e):[]},EPUBJS.Render.Iframe=function(){this.iframe=null,this.document=null,this.window=null,this.docEl=null,this.bodyEl=null,this.leftPos=0,this.pageWidth=0},EPUBJS.Render.Iframe.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id="epubjs-iframe:"+EPUBJS.core.uuid(),this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.iframe.addEventListener("load",this.loaded.bind(this),!1),this.iframe},EPUBJS.Render.Iframe.prototype.load=function(a){var b=this,c=new RSVP.defer;return this.iframe.src=a,b.leftPos=0,this.window&&this.unload(),this.iframe.onload=function(){b.document=b.iframe.contentDocument,b.docEl=b.document.documentElement,b.headEl=b.document.head,b.bodyEl=b.document.body,b.window=b.iframe.contentWindow,b.window.addEventListener("resize",b.resized.bind(b),!1),b.bodyEl&&(b.bodyEl.style.margin="0"),c.resolve(b.docEl)},this.iframe.onerror=function(a){c.reject({message:"Error Loading Contents: "+a,stack:(new Error).stack})},c.promise},EPUBJS.Render.Iframe.prototype.loaded=function(){var a=this.iframe.contentWindow.location.href;this.trigger("render:loaded",a)},EPUBJS.Render.Iframe.prototype.resize=function(a,b){this.iframe&&(this.iframe.height=b,isNaN(a)||a%2===0||(a+=1),this.iframe.width=a,this.width=this.iframe.getBoundingClientRect().width||a,this.height=this.iframe.getBoundingClientRect().height||b)},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){return this.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){return this.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b){var c=document.createElement(a);for(var d in b)c[d]=b[d];this.headEl&&this.headEl.appendChild(c)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){var b,c;if(a)return b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){return this.bodyEl},EPUBJS.Render.Iframe.prototype.isElementVisible=function(a){var b,c;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect(),c=b.left,0!==b.width&&0!==b.height&&c>=0&&c=1&&a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.nextPage=function(){var a=this.chapterPos+1;return a<=this.displayedPages?(this.chapterPos=a,this.render.page(a),this.currentLocationCfi=this.getPageCfi(this.visibileEl),this.trigger("renderer:locationChanged",this.currentLocationCfi),!0):!1},EPUBJS.Renderer.prototype.prevPage=function(){return this.page(this.chapterPos-1)},EPUBJS.Renderer.prototype.pageByElement=function(a){var b;a&&(b=this.render.getPageNumberByElement(a),this.page(b))},EPUBJS.Renderer.prototype.lastPage=function(){this.page(this.displayedPages)},EPUBJS.Renderer.prototype.section=function(a){var b=this.doc.getElementById(a);b&&this.pageByElement(b)},EPUBJS.Renderer.prototype.firstElementisTextNode=function(a){var b=a.childNodes,c=b.length;return c&&b[0]&&3===b[0].nodeType&&b[0].textContent.trim().length?!0:!1},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.render.isElementVisible(a)&&this.firstElementisTextNode(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=d-1;j>=0;j--)c[j]!=e&&g.unshift(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(a){return this.visibileEl=this.findFirstVisible(a),this.epubcfi.generateCfiFromElement(this.visibileEl,this.currentChapter.cfiBase)},EPUBJS.Renderer.prototype.gotoCfi=function(a){var b;_.isString(a)&&(a=this.epubcfi.parse(a)),marker=this.epubcfi.addMarker(a,this.doc),marker&&(b=this.render.getPageNumberByElement(marker),this.epubcfi.removeMarker(marker,this.doc),this.page(b))},EPUBJS.Renderer.prototype.findFirstVisible=function(a){var b,c=a||this.render.getBaseElement();return b=this.walk(c),b?b:a},EPUBJS.Renderer.prototype.onResized=function(){var a;this.width=this.container.clientWidth,this.height=this.container.clientHeight,a=this.determineSpreads(this.minSpreadWidth),a!=this.spreads&&(this.spreads=a,this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=new EPUBJS.Layout[this.layoutMethod]),this.contents&&this.reformat(),this.trigger("renderer:resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.addEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.addEventListener(a,this.triggerEvent.bind(this),!1)},this)},EPUBJS.Renderer.prototype.removeEventListeners=function(){this.listenedEvents.forEach(function(a){this.render.document.removeEventListener(a,this.triggerEvent,!1)},this)},EPUBJS.Renderer.prototype.triggerEvent=function(a){this.trigger("renderer:"+a.type,a)},EPUBJS.Renderer.prototype.addSelectionListeners=function(){this.render.document.addEventListener("selectionchange",this.onSelectionChange.bind(this),!1),this.render.window.addEventListener("mouseup",this.onMouseUp.bind(this),!1)},EPUBJS.Renderer.prototype.removeSelectionListeners=function(){this.doc.removeEventListener("selectionchange",this.onSelectionChange,!1),this.render.window.removeEventListener("mouseup",this.onMouseUp,!1)},EPUBJS.Renderer.prototype.onSelectionChange=function(){this.highlighted=!0},EPUBJS.Renderer.prototype.onMouseUp=function(){var a;this.highlighted&&(a=this.render.window.getSelection(),this.trigger("renderer:selected",a),this.highlighted=!1)},EPUBJS.Renderer.prototype.setMinSpreadWidth=function(a){this.minSpreadWidth=a,this.spreads=this.determineSpreads(a)},EPUBJS.Renderer.prototype.determineSpreads=function(a){return this.isForcedSingle||!a||this.width=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.currentChapter.store,h=this.caches[a],i=EPUBJS.core.uri(this.currentChapter.absolute),j=i.base,k=b,l=2e3,m=function(a,b){f[b]=a},n=function(){d&&d(),_.each(e,function(a){g.revokeUrl(a)}),h=f};g&&(h||(h={}),e=_.clone(h),this.replace(a,function(b,d){var h=b.getAttribute(k),i=EPUBJS.core.resolveUrl(j,h),m=function(c){var e;b.onload=function(){clearTimeout(e),d(c,i)},b.onerror=function(a){clearTimeout(e),d(c,i),console.error(a)},"image"==a&&b.setAttribute("externalResourcesRequired","true"),"link[href]"==a&&d(c,i),b.setAttribute(k,c),e=setTimeout(function(){d(c,i)},l)};i in e?(m(e[i]),f[i]=e[i],delete e[i]):c(g,i,m,b)},n,m))},RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);var EPUBJS=EPUBJS||{};EPUBJS.replace={},EPUBJS.replace.hrefs=function(a,b){var c=this,d=function(a,b){{var d=a.getAttribute("href"),e=d.search("://");"#"==d[0]}-1!=e?a.setAttribute("target","_blank"):a.onclick=function(){return c.goto(d),!1},b()};b.replace("a[href]",d,a)},EPUBJS.replace.head=function(a,b){b.replaceWithStored("link[href]","href",EPUBJS.replace.links,a)},EPUBJS.replace.resources=function(a,b){b.replaceWithStored("[src]","src",EPUBJS.replace.srcs,a)},EPUBJS.replace.svg=function(a,b){b.replaceWithStored("image","xlink:href",function(a,b,c){a.getUrl(b).then(c)},a)},EPUBJS.replace.srcs=function(a,b,c){a.getUrl(b).then(c)},EPUBJS.replace.links=function(a,b,c,d){"stylesheet"===d.getAttribute("rel")?EPUBJS.replace.stylesheets(a,b).then(function(a,b){setTimeout(function(){c(a,b)},5)}):a.getUrl(b).then(c)},EPUBJS.replace.stylesheets=function(a,b){var c=new RSVP.defer;if(a)return a.getText(b).then(function(d){EPUBJS.replace.cssUrls(a,b,d).then(function(a){var b=window.URL||window.webkitURL||window.mozURL,d=new Blob([a],{type:"text/css"}),e=b.createObjectURL(d);c.resolve(e)},function(a){console.error(a)})}),c.promise},EPUBJS.replace.cssUrls=function(a,b,c){var d=new RSVP.defer,e=[],f=c.match(/url\(\'?\"?([^\'|^\"|^\)]*)\'?\"?\)/g);if(a)return f?(f.forEach(function(d){var f=EPUBJS.core.resolveUrl(b,d.replace(/url\(|[|\)|\'|\"]/g,"")),g=a.getUrl(f).then(function(a){c=c.replace(d,'url("'+a+'")')});e.push(g)}),RSVP.all(e).then(function(){d.resolve(c)}),d.promise):(d.resolve(c),d.promise)},EPUBJS.Unarchiver=function(a){return this.libPath=EPUBJS.filePath,this.zipUrl=a,this.loadLib(),this.urlCache={},this.zipFs=new zip.fs.FS,this.promise},EPUBJS.Unarchiver.prototype.loadLib=function(){"undefined"==typeof zip&&console.error("Zip lib not loaded"),zip.workerScriptsPath=this.libPath},EPUBJS.Unarchiver.prototype.openZip=function(a){var b=new RSVP.defer,c=this.zipFs;return c.importHttpContent(a,!1,function(){b.resolve(c)},this.failed),b.promise},EPUBJS.Unarchiver.prototype.getXml=function(a,b){return this.getText(a,b).then(function(a){var b=new DOMParser;return b.parseFromString(a,"application/xml")})},EPUBJS.Unarchiver.prototype.getUrl=function(a,b){var c=this,d=new RSVP.defer,e=window.decodeURIComponent(a),f=this.zipFs.find(e),g=window.URL||window.webkitURL||window.mozURL;return f?a in this.urlCache?(d.resolve(this.urlCache[a]),d.promise):(f.getBlob(b||zip.getMimeType(f.name),function(b){var e=g.createObjectURL(b);d.resolve(e),c.urlCache[a]=e}),d.promise):(d.reject({message:"File not found in the epub: "+a,stack:(new Error).stack}),d.promise)},EPUBJS.Unarchiver.prototype.getText=function(a,b){{var c=new RSVP.defer,d=window.decodeURIComponent(a),e=this.zipFs.find(d);window.URL||window.webkitURL||window.mozURL}return e||console.error("No entry found",a),e.getText(function(a){c.resolve(a)},null,null,b||"UTF-8"),c.promise},EPUBJS.Unarchiver.prototype.revokeUrl=function(a){var b=window.URL||window.webkitURL||window.mozURL,c=unarchiver.urlCache[a];c&&b.revokeObjectURL(c)},EPUBJS.Unarchiver.prototype.failed=function(a){console.error(a)},EPUBJS.Unarchiver.prototype.afterSaved=function(){this.callback()},EPUBJS.Unarchiver.prototype.toStorage=function(a){function b(){f--,0===f&&e.afterSaved()}var c=0,d=20,e=this,f=a.length;a.forEach(function(a){setTimeout(function(a){e.saveEntryFileToStorage(a,b)},c,a),c+=d}),console.log("time",c)},EPUBJS.Unarchiver.prototype.saveEntryFileToStorage=function(a,b){a.getData(new zip.BlobWriter,function(c){EPUBJS.storage.save(a.filename,c,b)})}; \ No newline at end of file diff --git a/demo/js/reader.min.js b/demo/js/reader.min.js index 2e1996a..ef7f2ea 100644 --- a/demo/js/reader.min.js +++ b/demo/js/reader.min.js @@ -1 +1 @@ -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,jQuery),EPUBJS.Reader=function(a,b){var c,d,e=this;this.settings=_.defaults(b||{},{restore:!0,reload:!1,bookmarks:null,contained:null,bookKey:null,styles:null,sidebarReflow:!1,generatePagination:!1}),this.setBookKey(a),this.settings.restore&&this.isSaved()&&this.applySavedSettings(),this.settings.styles=this.settings.styles||{fontSize:"100%"},this.book=c=new EPUBJS.Book({bookPath:a,restore:this.settings.restore,reload:this.settings.reload,contained:this.settings.contained,bookKey:this.settings.bookKey,styles:this.settings.styles}),this.settings.previousLocationCfi&&c.gotoCfi(this.settings.previousLocationCfi),this.offline=!1,this.sidebarOpen=!1,this.settings.bookmarks||(this.settings.bookmarks=[]),this.settings.generatePagination&&c.generatePagination(1076,588),c.renderTo("viewer"),e.ReaderController=EPUBJS.reader.ReaderController.call(e,c),e.SettingsController=EPUBJS.reader.SettingsController.call(e,c),e.ControlsController=EPUBJS.reader.ControlsController.call(e,c),e.SidebarController=EPUBJS.reader.SidebarController.call(e,c),e.BookmarksController=EPUBJS.reader.BookmarksController.call(e,c);for(d in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(d)&&(e[d]=EPUBJS.reader.plugins[d].call(e,c));return c.ready.all.then(function(){e.ReaderController.hideLoader()}),c.getMetadata().then(function(a){e.MetaController=EPUBJS.reader.MetaController.call(e,a)}),c.getToc().then(function(a){e.TocController=EPUBJS.reader.TocController.call(e,a)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),document.addEventListener("keydown",this.adjustFontSize.bind(this),!1),c.on("renderer:keydown",this.adjustFontSize.bind(this)),c.on("renderer:keydown",e.ReaderController.arrowKeys.bind(this)),this},EPUBJS.Reader.prototype.adjustFontSize=function(a){var b,c=2,d=187,e=189,f=48,g=a.ctrlKey||a.metaKey;this.settings.styles&&(this.settings.styles.fontSize||(this.settings.styles.fontSize="100%"),b=parseInt(this.settings.styles.fontSize.slice(0,-1)),g&&a.keyCode==d&&(a.preventDefault(),this.book.setStyle("fontSize",b+c+"%")),g&&a.keyCode==e&&(a.preventDefault(),this.book.setStyle("fontSize",b-c+"%")),g&&a.keyCode==f&&(a.preventDefault(),this.book.setStyle("fontSize","100%")))},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],this.trigger("reader:unbookmarked",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=0,h=function(b){var c=document.createElement("li"),d=document.createElement("a");return c.id="bookmark-"+g,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),g++,c};return this.settings.bookmarks.forEach(function(a){var b=h(a);d.appendChild(b)}),c.append(d),this.on("reader:bookmarked",function(a){var b=h(a);c.append(b)}),this.on("reader:unbookmarked",function(a){var b=$("#bookmark-"+a);b.remove()}),{show:e,hide:f}},EPUBJS.reader.ControlsController=function(a){var b=this,c=($("#store"),$("#fullscreen")),d=($("#fullscreenicon"),$("#cancelfullscreenicon"),$("#slider")),e=($("#main"),$("#sidebar"),$("#setting")),f=$("#bookmark"),g=function(){b.offline=!1},h=function(){b.offline=!0},i=!1;return a.on("book:online",g),a.on("book:offline",h),d.on("click",function(){b.sidebarOpen?(b.SidebarController.hide(),d.addClass("icon-menu"),d.removeClass("icon-right")):(b.SidebarController.show(),d.addClass("icon-right"),d.removeClass("icon-menu"))}),c.on("click",function(){screenfull.toggle($("#container")[0])}),screenfull&&document.addEventListener(screenfull.raw.fullscreenchange,function(){i=screenfull.isFullscreen,i?c.addClass("icon-resize-small").removeClass("icon-resize-full"):c.addClass("icon-resize-full").removeClass("icon-resize-small")}),e.on("click",function(){b.SettingsController.show()}),f.on("click",function(){var a=b.book.getCurrentLocationCfi(),c=b.isBookmarked(a);-1===c?(b.addBookmark(a),f.addClass("icon-bookmark").removeClass("icon-bookmark-empty")):(b.removeBookmark(a),f.removeClass("icon-bookmark").addClass("icon-bookmark-empty"))}),a.on("renderer:locationChanged",function(a){var c=b.isBookmarked(a);-1===c?f.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):f.addClass("icon-bookmark").removeClass("icon-bookmark-empty")}),a.on("book:pageChanged",function(a){console.log("page",a.page,a.percentage)}),{}},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=this,h=function(){g.settings.sidebarReflow?b.removeClass("single"):b.removeClass("closed")},i=function(){g.settings.sidebarReflow?b.addClass("single"):b.addClass("closed")},j=function(){d.show(),m()},k=function(){d.hide()},l=function(){c.addClass("show")},m=function(){c.removeClass("show")},n=!1,o=function(b){37==b.keyCode&&(a.prevPage(),f.addClass("active"),n=!0,setTimeout(function(){n=!1,f.removeClass("active")},100),b.preventDefault()),39==b.keyCode&&(a.nextPage(),e.addClass("active"),n=!0,setTimeout(function(){n=!1,e.removeClass("active")},100),b.preventDefault())};return document.addEventListener("keydown",o,!1),e.on("click",function(b){a.nextPage(),b.preventDefault()}),f.on("click",function(b){a.prevPage(),b.preventDefault()}),a.on("renderer:spreads",function(a){a?l():m()}),{slideOut:i,slideIn:h,showLoader:j,hideLoader:k,showDivider:l,hideDivider:m,arrowKeys:o}},EPUBJS.reader.SettingsController=function(){var a=(this.book,this),b=$("#settings-modal"),c=$(".overlay"),d=function(){b.addClass("md-show")},e=function(){b.removeClass("md-show")},f=$("#sidebarReflow");return f.on("click",function(){a.settings.sidebarReflow=!a.settings.sidebarReflow}),b.find(".closer").on("click",function(){e()}),c.on("click",function(){e()}),{show:d,hide:e}},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.length>0&&(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 +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,jQuery),EPUBJS.Reader=function(a,b){var c,d,e=this;this.settings=_.defaults(b||{},{restore:!0,reload:!1,bookmarks:null,contained:null,bookKey:null,styles:null,sidebarReflow:!1,generatePagination:!1}),this.setBookKey(a),this.settings.restore&&this.isSaved()&&this.applySavedSettings(),this.settings.styles=this.settings.styles||{fontSize:"100%"},this.book=c=new EPUBJS.Book({bookPath:a,restore:this.settings.restore,reload:this.settings.reload,contained:this.settings.contained,bookKey:this.settings.bookKey,styles:this.settings.styles}),this.settings.previousLocationCfi&&c.gotoCfi(this.settings.previousLocationCfi),this.offline=!1,this.sidebarOpen=!1,this.settings.bookmarks||(this.settings.bookmarks=[]),this.settings.generatePagination&&c.generatePagination(1076,588),c.renderTo("viewer"),e.ReaderController=EPUBJS.reader.ReaderController.call(e,c),e.SettingsController=EPUBJS.reader.SettingsController.call(e,c),e.ControlsController=EPUBJS.reader.ControlsController.call(e,c),e.SidebarController=EPUBJS.reader.SidebarController.call(e,c),e.BookmarksController=EPUBJS.reader.BookmarksController.call(e,c);for(d in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(d)&&(e[d]=EPUBJS.reader.plugins[d].call(e,c));return c.ready.all.then(function(){e.ReaderController.hideLoader()}),c.getMetadata().then(function(a){e.MetaController=EPUBJS.reader.MetaController.call(e,a)}),c.getToc().then(function(a){e.TocController=EPUBJS.reader.TocController.call(e,a)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),document.addEventListener("keydown",this.adjustFontSize.bind(this),!1),c.on("renderer:keydown",this.adjustFontSize.bind(this)),c.on("renderer:keydown",e.ReaderController.arrowKeys.bind(this)),this},EPUBJS.Reader.prototype.adjustFontSize=function(a){var b,c=2,d=187,e=189,f=48,g=a.ctrlKey||a.metaKey;this.settings.styles&&(this.settings.styles.fontSize||(this.settings.styles.fontSize="100%"),b=parseInt(this.settings.styles.fontSize.slice(0,-1)),g&&a.keyCode==d&&(a.preventDefault(),this.book.setStyle("fontSize",b+c+"%")),g&&a.keyCode==e&&(a.preventDefault(),this.book.setStyle("fontSize",b-c+"%")),g&&a.keyCode==f&&(a.preventDefault(),this.book.setStyle("fontSize","100%")))},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],this.trigger("reader:unbookmarked",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=0,h=function(b){var c=document.createElement("li"),d=document.createElement("a");return c.id="bookmark-"+g,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),g++,c};return this.settings.bookmarks.forEach(function(a){var b=h(a);d.appendChild(b)}),c.append(d),this.on("reader:bookmarked",function(a){var b=h(a);c.append(b)}),this.on("reader:unbookmarked",function(a){var b=$("#bookmark-"+a);b.remove()}),{show:e,hide:f}},EPUBJS.reader.ControlsController=function(a){var b=this,c=($("#store"),$("#fullscreen")),d=($("#fullscreenicon"),$("#cancelfullscreenicon"),$("#slider")),e=($("#main"),$("#sidebar"),$("#setting")),f=$("#bookmark"),g=function(){b.offline=!1},h=function(){b.offline=!0},i=!1;return a.on("book:online",g),a.on("book:offline",h),d.on("click",function(){b.sidebarOpen?(b.SidebarController.hide(),d.addClass("icon-menu"),d.removeClass("icon-right")):(b.SidebarController.show(),d.addClass("icon-right"),d.removeClass("icon-menu"))}),c.on("click",function(){screenfull.toggle($("#container")[0])}),screenfull&&document.addEventListener(screenfull.raw.fullscreenchange,function(){i=screenfull.isFullscreen,i?c.addClass("icon-resize-small").removeClass("icon-resize-full"):c.addClass("icon-resize-full").removeClass("icon-resize-small")}),e.on("click",function(){b.SettingsController.show()}),f.on("click",function(){var a=b.book.getCurrentLocationCfi(),c=b.isBookmarked(a);-1===c?(b.addBookmark(a),f.addClass("icon-bookmark").removeClass("icon-bookmark-empty")):(b.removeBookmark(a),f.removeClass("icon-bookmark").addClass("icon-bookmark-empty"))}),a.on("renderer:locationChanged",function(a){var c=b.isBookmarked(a);-1===c?f.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):f.addClass("icon-bookmark").removeClass("icon-bookmark-empty")}),a.on("book:pageChanged",function(a){console.log("page",a.page,a.percentage)}),{}},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=this,h=function(){g.settings.sidebarReflow?b.removeClass("single"):b.removeClass("closed")},i=function(){g.settings.sidebarReflow?b.addClass("single"):b.addClass("closed")},j=function(){d.show(),m()},k=function(){d.hide()},l=function(){c.addClass("show")},m=function(){c.removeClass("show")},n=!1,o=function(b){37==b.keyCode&&(a.prevPage(),f.addClass("active"),n=!0,setTimeout(function(){n=!1,f.removeClass("active")},100),b.preventDefault()),39==b.keyCode&&(a.nextPage(),e.addClass("active"),n=!0,setTimeout(function(){n=!1,e.removeClass("active")},100),b.preventDefault())};return document.addEventListener("keydown",o,!1),e.on("click",function(b){a.nextPage(),b.preventDefault()}),f.on("click",function(b){a.prevPage(),b.preventDefault()}),a.on("renderer:spreads",function(a){a?l():m()}),{slideOut:i,slideIn:h,showLoader:j,hideLoader:k,showDivider:l,hideDivider:m,arrowKeys:o}},EPUBJS.reader.SettingsController=function(){var a=(this.book,this),b=$("#settings-modal"),c=$(".overlay"),d=function(){b.addClass("md-show")},e=function(){b.removeClass("md-show")},f=$("#sidebarReflow");return f.on("click",function(){a.settings.sidebarReflow=!a.settings.sidebarReflow}),b.find(".closer").on("click",function(){e()}),c.on("click",function(){e()}),{show:d,hide:e}},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.length>0&&(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");a.preventDefault(),b.goto(d),c.find(".currentChapter").addClass("openChapter").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter")}),c.find(".toc_toggle").on("click",function(a){var b=$(this).parent("li"),c=b.hasClass("openChapter");a.preventDefault(),c?b.removeClass("openChapter"):b.addClass("openChapter")}),{show:g,hide:h}}; \ No newline at end of file diff --git a/examples/page_list.json b/examples/page_list.json new file mode 100644 index 0000000..35d6a25 --- /dev/null +++ b/examples/page_list.json @@ -0,0 +1 @@ +[{"cfi":"epubcfi(/6/2[cover]!4/1:0)","page":1},{"cfi":"epubcfi(/6/4[titlepage]!4/1:0)","page":2},{"cfi":"epubcfi(/6/6[brief-toc]!4/1:0)","page":3},{"cfi":"epubcfi(/6/8[xpreface_001]!4/1:0)","page":4},{"cfi":"epubcfi(/6/10[xintroduction_001]!4/1:0)","page":5},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/2/1:0)","page":6},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/18/1:0)","page":7},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/34/1:0)","page":8},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/54/1:0)","page":9},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/70/1:0)","page":10},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/1:0)","page":11},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/102/1:0)","page":12},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/116/1:0)","page":13},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/130/1:0)","page":14},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/140/1:0)","page":15},{"cfi":"epubcfi(/6/12[xepigraph_001]!4/2/154/1:0)","page":16},{"cfi":"epubcfi(/6/14[xchapter_001]!4/2/2/1:0)","page":17},{"cfi":"epubcfi(/6/14[xchapter_001]!4/2/1:0)","page":18},{"cfi":"epubcfi(/6/14[xchapter_001]!4/2/18/1:0)","page":19},{"cfi":"epubcfi(/6/14[xchapter_001]!4/2/26/1:0)","page":20},{"cfi":"epubcfi(/6/16[xchapter_002]!4/2/2/1:0)","page":21},{"cfi":"epubcfi(/6/16[xchapter_002]!4/2/1:0)","page":22},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/2/1:0)","page":23},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/10/1:0)","page":24},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/24/1:0)","page":25},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/46/1:0)","page":26},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/1:0)","page":27},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/90/1:0)","page":28},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/104/1:0)","page":29},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/112/1:0)","page":30},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/118/1:0)","page":31},{"cfi":"epubcfi(/6/18[xchapter_003]!4/2/132/1:0)","page":32},{"cfi":"epubcfi(/6/20[xchapter_004]!4/2/2/1:0)","page":33},{"cfi":"epubcfi(/6/20[xchapter_004]!4/2/1:0)","page":34},{"cfi":"epubcfi(/6/20[xchapter_004]!4/2/12/1:0)","page":35},{"cfi":"epubcfi(/6/22[xchapter_005]!4/1:0)","page":36},{"cfi":"epubcfi(/6/24[xchapter_006]!4/1:0)","page":37},{"cfi":"epubcfi(/6/24[xchapter_006]!4/2/14/1:0)","page":38},{"cfi":"epubcfi(/6/26[xchapter_007]!4/1:0)","page":39},{"cfi":"epubcfi(/6/26[xchapter_007]!4/2/16/1:0)","page":40},{"cfi":"epubcfi(/6/28[xchapter_008]!4/1:0)","page":41},{"cfi":"epubcfi(/6/28[xchapter_008]!4/2/10/1:0)","page":42},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/2/1:0)","page":43},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/18/1:0)","page":44},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/1:0)","page":45},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/26/1:0)","page":46},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/34/1:0)","page":47},{"cfi":"epubcfi(/6/30[xchapter_009]!4/2/44/1:0)","page":48},{"cfi":"epubcfi(/6/32[xchapter_010]!4/2/2/1:0)","page":49},{"cfi":"epubcfi(/6/32[xchapter_010]!4/2/1:0)","page":50},{"cfi":"epubcfi(/6/32[xchapter_010]!4/2/18/1:0)","page":51},{"cfi":"epubcfi(/6/34[xchapter_011]!4/1:0)","page":52},{"cfi":"epubcfi(/6/36[xchapter_012]!4/1:0)","page":53},{"cfi":"epubcfi(/6/36[xchapter_012]!4/2/12/1:0)","page":54},{"cfi":"epubcfi(/6/38[xchapter_013]!4/2/2/1:0)","page":55},{"cfi":"epubcfi(/6/38[xchapter_013]!4/2/1:0)","page":56},{"cfi":"epubcfi(/6/38[xchapter_013]!4/2/18/1:0)","page":57},{"cfi":"epubcfi(/6/40[xchapter_014]!4/1:0)","page":58},{"cfi":"epubcfi(/6/42[xchapter_015]!4/2/2/1:0)","page":59},{"cfi":"epubcfi(/6/42[xchapter_015]!4/2/1:0)","page":60},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/2/1:0)","page":61},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/10/1:0)","page":62},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/16/1:0)","page":63},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/54/1:0)","page":64},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/1:0)","page":65},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/92/1:0)","page":66},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/112/1:0)","page":67},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/128/1:0)","page":68},{"cfi":"epubcfi(/6/44[xchapter_016]!4/2/154/1:0)","page":69},{"cfi":"epubcfi(/6/46[xchapter_017]!4/2/2/1:0)","page":70},{"cfi":"epubcfi(/6/46[xchapter_017]!4/2/1:0)","page":71},{"cfi":"epubcfi(/6/46[xchapter_017]!4/2/36/1:0)","page":72},{"cfi":"epubcfi(/6/46[xchapter_017]!4/2/54/1:0)","page":73},{"cfi":"epubcfi(/6/48[xchapter_018]!4/2/2/1:0)","page":74},{"cfi":"epubcfi(/6/48[xchapter_018]!4/2/1:0)","page":75},{"cfi":"epubcfi(/6/50[xchapter_019]!4/2/2/1:0)","page":76},{"cfi":"epubcfi(/6/50[xchapter_019]!4/2/1:0)","page":77},{"cfi":"epubcfi(/6/52[xchapter_020]!4/1:0)","page":78},{"cfi":"epubcfi(/6/52[xchapter_020]!4/2/14/1:0)","page":79},{"cfi":"epubcfi(/6/54[xchapter_021]!4/2/2/1:0)","page":80},{"cfi":"epubcfi(/6/54[xchapter_021]!4/2/1:0)","page":81},{"cfi":"epubcfi(/6/56[xchapter_022]!4/2/2/1:0)","page":82},{"cfi":"epubcfi(/6/56[xchapter_022]!4/2/1:0)","page":83},{"cfi":"epubcfi(/6/56[xchapter_022]!4/2/36/1:0)","page":84},{"cfi":"epubcfi(/6/58[xchapter_023]!4/1:0)","page":85},{"cfi":"epubcfi(/6/60[xchapter_024]!4/2/2/1:0)","page":86},{"cfi":"epubcfi(/6/60[xchapter_024]!4/2/1:0)","page":87},{"cfi":"epubcfi(/6/60[xchapter_024]!4/2/24/1:0)","page":88},{"cfi":"epubcfi(/6/62[xchapter_025]!4/1:0)","page":89},{"cfi":"epubcfi(/6/64[xchapter_026]!4/2/2/1:0)","page":90},{"cfi":"epubcfi(/6/64[xchapter_026]!4/2/1:0)","page":91},{"cfi":"epubcfi(/6/66[xchapter_027]!4/2/2/1:0)","page":92},{"cfi":"epubcfi(/6/66[xchapter_027]!4/2/1:0)","page":93},{"cfi":"epubcfi(/6/66[xchapter_027]!4/2/20/1:0)","page":94},{"cfi":"epubcfi(/6/68[xchapter_028]!4/2/2/1:0)","page":95},{"cfi":"epubcfi(/6/68[xchapter_028]!4/2/1:0)","page":96},{"cfi":"epubcfi(/6/70[xchapter_029]!4/2/2/1:0)","page":97},{"cfi":"epubcfi(/6/70[xchapter_029]!4/2/1:0)","page":98},{"cfi":"epubcfi(/6/72[xchapter_030]!4/1:0)","page":99},{"cfi":"epubcfi(/6/74[xchapter_031]!4/1:0)","page":100},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/2/1:0)","page":101},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/18/1:0)","page":102},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/28/1:0)","page":103},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/44/1:0)","page":104},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/1:0)","page":105},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/56/1:0)","page":106},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/70/1:0)","page":107},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/74/1:0)","page":108},{"cfi":"epubcfi(/6/76[xchapter_032]!4/2/88/1:0)","page":109},{"cfi":"epubcfi(/6/78[xchapter_033]!4/1:0)","page":110},{"cfi":"epubcfi(/6/78[xchapter_033]!4/2/12/1:0)","page":111},{"cfi":"epubcfi(/6/80[xchapter_034]!4/2/2/1:0)","page":112},{"cfi":"epubcfi(/6/80[xchapter_034]!4/2/1:0)","page":113},{"cfi":"epubcfi(/6/80[xchapter_034]!4/2/16/1:0)","page":114},{"cfi":"epubcfi(/6/80[xchapter_034]!4/2/20/1:0)","page":115},{"cfi":"epubcfi(/6/82[xchapter_035]!4/2/2/1:0)","page":116},{"cfi":"epubcfi(/6/82[xchapter_035]!4/2/10/1:0)","page":117},{"cfi":"epubcfi(/6/82[xchapter_035]!4/2/1:0)","page":118},{"cfi":"epubcfi(/6/82[xchapter_035]!4/2/16/1:0)","page":119},{"cfi":"epubcfi(/6/84[xchapter_036]!4/2/2/1:0)","page":120},{"cfi":"epubcfi(/6/84[xchapter_036]!4/2/26/1:0)","page":121},{"cfi":"epubcfi(/6/84[xchapter_036]!4/2/1:0)","page":122},{"cfi":"epubcfi(/6/84[xchapter_036]!4/2/82/1:0)","page":123},{"cfi":"epubcfi(/6/84[xchapter_036]!4/2/92/1:0)","page":124},{"cfi":"epubcfi(/6/86[xchapter_037]!4/1:0)","page":125},{"cfi":"epubcfi(/6/88[xchapter_038]!4/1:0)","page":126},{"cfi":"epubcfi(/6/90[xchapter_039]!4/1:0)","page":127},{"cfi":"epubcfi(/6/92[xchapter_040]!4/2/2/1:0)","page":128},{"cfi":"epubcfi(/6/92[xchapter_040]!4/2/1:0)","page":129},{"cfi":"epubcfi(/6/92[xchapter_040]!4/2/58/1:0)","page":130},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/2/1:0)","page":131},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/10/1:0)","page":132},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/16/1:0)","page":133},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/1:0)","page":134},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/40/1:0)","page":135},{"cfi":"epubcfi(/6/94[xchapter_041]!4/2/44/1:0)","page":136},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/2/1:0)","page":137},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/10/1:0)","page":138},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/20/1:0)","page":139},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/1:0)","page":140},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/42/1:0)","page":141},{"cfi":"epubcfi(/6/96[xchapter_042]!4/2/50/1:0)","page":142},{"cfi":"epubcfi(/6/98[xchapter_043]!4/1:0)","page":143},{"cfi":"epubcfi(/6/100[xchapter_044]!4/2/2/1:0)","page":144},{"cfi":"epubcfi(/6/100[xchapter_044]!4/2/1:0)","page":145},{"cfi":"epubcfi(/6/100[xchapter_044]!4/2/22/1:0)","page":146},{"cfi":"epubcfi(/6/100[xchapter_044]!4/2/26/1:0)","page":147},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/2/1:0)","page":148},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/10/1:0)","page":149},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/1:0)","page":150},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/28/1:0)","page":151},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/38/1:0)","page":152},{"cfi":"epubcfi(/6/102[xchapter_045]!4/2/46/1:0)","page":153},{"cfi":"epubcfi(/6/104[xchapter_046]!4/1:0)","page":154},{"cfi":"epubcfi(/6/104[xchapter_046]!4/2/8/1:0)","page":155},{"cfi":"epubcfi(/6/106[xchapter_047]!4/1:0)","page":156},{"cfi":"epubcfi(/6/106[xchapter_047]!4/2/10/1:0)","page":157},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/2/1:0)","page":158},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/26/1:0)","page":159},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/40/1:0)","page":160},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/1:0)","page":161},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/66/1:0)","page":162},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/80/1:0)","page":163},{"cfi":"epubcfi(/6/108[xchapter_048]!4/2/98/1:0)","page":164},{"cfi":"epubcfi(/6/110[xchapter_049]!4/1:0)","page":165},{"cfi":"epubcfi(/6/112[xchapter_050]!4/1:0)","page":166},{"cfi":"epubcfi(/6/112[xchapter_050]!4/2/16/1:0)","page":167},{"cfi":"epubcfi(/6/114[xchapter_051]!4/2/2/1:0)","page":168},{"cfi":"epubcfi(/6/114[xchapter_051]!4/2/1:0)","page":169},{"cfi":"epubcfi(/6/114[xchapter_051]!4/2/22/1:0)","page":170},{"cfi":"epubcfi(/6/116[xchapter_052]!4/1:0)","page":171},{"cfi":"epubcfi(/6/118[xchapter_053]!4/2/2/1:0)","page":172},{"cfi":"epubcfi(/6/118[xchapter_053]!4/2/1:0)","page":173},{"cfi":"epubcfi(/6/118[xchapter_053]!4/2/18/1:0)","page":174},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/2/1:0)","page":175},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/14/1:0)","page":176},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/22/1:0)","page":177},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/26/1:0)","page":178},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/40/1:0)","page":179},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/50/1:0)","page":180},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/1:0)","page":181},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/84/1:0)","page":182},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/106/1:0)","page":183},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/120/1:0)","page":184},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/142/1:0)","page":185},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/168/1:0)","page":186},{"cfi":"epubcfi(/6/120[xchapter_054]!4/2/182/1:0)","page":187},{"cfi":"epubcfi(/6/122[xchapter_055]!4/2/2/1:0)","page":188},{"cfi":"epubcfi(/6/122[xchapter_055]!4/2/1:0)","page":189},{"cfi":"epubcfi(/6/122[xchapter_055]!4/2/20/1:0)","page":190},{"cfi":"epubcfi(/6/124[xchapter_056]!4/2/2/1:0)","page":191},{"cfi":"epubcfi(/6/124[xchapter_056]!4/2/1:0)","page":192},{"cfi":"epubcfi(/6/126[xchapter_057]!4/1:0)","page":193},{"cfi":"epubcfi(/6/126[xchapter_057]!4/2/16/1:0)","page":194},{"cfi":"epubcfi(/6/128[xchapter_058]!4/1:0)","page":195},{"cfi":"epubcfi(/6/128[xchapter_058]!4/2/16/1:0)","page":196},{"cfi":"epubcfi(/6/130[xchapter_059]!4/1:0)","page":197},{"cfi":"epubcfi(/6/130[xchapter_059]!4/2/16/1:0)","page":198},{"cfi":"epubcfi(/6/132[xchapter_060]!4/2/2/1:0)","page":199},{"cfi":"epubcfi(/6/132[xchapter_060]!4/2/1:0)","page":200},{"cfi":"epubcfi(/6/134[xchapter_061]!4/2/2/1:0)","page":201},{"cfi":"epubcfi(/6/134[xchapter_061]!4/2/1:0)","page":202},{"cfi":"epubcfi(/6/134[xchapter_061]!4/2/32/1:0)","page":203},{"cfi":"epubcfi(/6/136[xchapter_062]!4/1:0)","page":204},{"cfi":"epubcfi(/6/138[xchapter_063]!4/1:0)","page":205},{"cfi":"epubcfi(/6/140[xchapter_064]!4/2/2/1:0)","page":206},{"cfi":"epubcfi(/6/140[xchapter_064]!4/2/12/1:0)","page":207},{"cfi":"epubcfi(/6/140[xchapter_064]!4/2/1:0)","page":208},{"cfi":"epubcfi(/6/140[xchapter_064]!4/2/44/1:0)","page":209},{"cfi":"epubcfi(/6/140[xchapter_064]!4/2/84/1:0)","page":210},{"cfi":"epubcfi(/6/142[xchapter_065]!4/1:0)","page":211},{"cfi":"epubcfi(/6/142[xchapter_065]!4/2/12/1:0)","page":212},{"cfi":"epubcfi(/6/144[xchapter_066]!4/1:0)","page":213},{"cfi":"epubcfi(/6/146[xchapter_067]!4/1:0)","page":214},{"cfi":"epubcfi(/6/148[xchapter_068]!4/2/2/1:0)","page":215},{"cfi":"epubcfi(/6/148[xchapter_068]!4/2/1:0)","page":216},{"cfi":"epubcfi(/6/150[xchapter_069]!4/1:0)","page":217},{"cfi":"epubcfi(/6/152[xchapter_070]!4/1:0)","page":218},{"cfi":"epubcfi(/6/152[xchapter_070]!4/2/16/1:0)","page":219},{"cfi":"epubcfi(/6/154[xchapter_071]!4/2/2/1:0)","page":220},{"cfi":"epubcfi(/6/154[xchapter_071]!4/2/16/1:0)","page":221},{"cfi":"epubcfi(/6/154[xchapter_071]!4/2/1:0)","page":222},{"cfi":"epubcfi(/6/154[xchapter_071]!4/2/40/1:0)","page":223},{"cfi":"epubcfi(/6/156[xchapter_072]!4/2/2/1:0)","page":224},{"cfi":"epubcfi(/6/156[xchapter_072]!4/2/1:0)","page":225},{"cfi":"epubcfi(/6/156[xchapter_072]!4/2/20/1:0)","page":226},{"cfi":"epubcfi(/6/158[xchapter_073]!4/2/2/1:0)","page":227},{"cfi":"epubcfi(/6/158[xchapter_073]!4/2/1:0)","page":228},{"cfi":"epubcfi(/6/158[xchapter_073]!4/2/42/1:0)","page":229},{"cfi":"epubcfi(/6/158[xchapter_073]!4/2/72/1:0)","page":230},{"cfi":"epubcfi(/6/160[xchapter_074]!4/2/2/1:0)","page":231},{"cfi":"epubcfi(/6/160[xchapter_074]!4/2/1:0)","page":232},{"cfi":"epubcfi(/6/160[xchapter_074]!4/2/22/1:0)","page":233},{"cfi":"epubcfi(/6/162[xchapter_075]!4/2/2/1:0)","page":234},{"cfi":"epubcfi(/6/162[xchapter_075]!4/2/1:0)","page":235},{"cfi":"epubcfi(/6/164[xchapter_076]!4/1:0)","page":236},{"cfi":"epubcfi(/6/164[xchapter_076]!4/2/8/1:0)","page":237},{"cfi":"epubcfi(/6/166[xchapter_077]!4/1:0)","page":238},{"cfi":"epubcfi(/6/168[xchapter_078]!4/2/2/1:0)","page":239},{"cfi":"epubcfi(/6/168[xchapter_078]!4/2/1:0)","page":240},{"cfi":"epubcfi(/6/168[xchapter_078]!4/2/24/1:0)","page":241},{"cfi":"epubcfi(/6/170[xchapter_079]!4/1:0)","page":242},{"cfi":"epubcfi(/6/170[xchapter_079]!4/2/10/1:0)","page":243},{"cfi":"epubcfi(/6/172[xchapter_080]!4/1:0)","page":244},{"cfi":"epubcfi(/6/172[xchapter_080]!4/2/12/1:0)","page":245},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/2/1:0)","page":246},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/24/1:0)","page":247},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/40/1:0)","page":248},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/1:0)","page":249},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/62/1:0)","page":250},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/74/1:0)","page":251},{"cfi":"epubcfi(/6/174[xchapter_081]!4/2/86/1:0)","page":252},{"cfi":"epubcfi(/6/176[xchapter_082]!4/2/2/1:0)","page":253},{"cfi":"epubcfi(/6/176[xchapter_082]!4/2/1:0)","page":254},{"cfi":"epubcfi(/6/178[xchapter_083]!4/1:0)","page":255},{"cfi":"epubcfi(/6/180[xchapter_084]!4/1:0)","page":256},{"cfi":"epubcfi(/6/182[xchapter_085]!4/2/2/1:0)","page":257},{"cfi":"epubcfi(/6/182[xchapter_085]!4/2/1:0)","page":258},{"cfi":"epubcfi(/6/182[xchapter_085]!4/2/16/1:0)","page":259},{"cfi":"epubcfi(/6/184[xchapter_086]!4/2/2/1:0)","page":260},{"cfi":"epubcfi(/6/184[xchapter_086]!4/2/1:0)","page":261},{"cfi":"epubcfi(/6/184[xchapter_086]!4/2/26/1:0)","page":262},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/2/1:0)","page":263},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/12/1:0)","page":264},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/20/1:0)","page":265},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/30/1:0)","page":266},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/1:0)","page":267},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/42/1:0)","page":268},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/48/1:0)","page":269},{"cfi":"epubcfi(/6/186[xchapter_087]!4/2/62/1:0)","page":270},{"cfi":"epubcfi(/6/188[xchapter_088]!4/2/2/1:0)","page":271},{"cfi":"epubcfi(/6/188[xchapter_088]!4/2/1:0)","page":272},{"cfi":"epubcfi(/6/190[xchapter_089]!4/2/2/1:0)","page":273},{"cfi":"epubcfi(/6/190[xchapter_089]!4/2/1:0)","page":274},{"cfi":"epubcfi(/6/190[xchapter_089]!4/2/30/1:0)","page":275},{"cfi":"epubcfi(/6/192[xchapter_090]!4/1:0)","page":276},{"cfi":"epubcfi(/6/192[xchapter_090]!4/2/20/1:0)","page":277},{"cfi":"epubcfi(/6/194[xchapter_091]!4/2/2/1:0)","page":278},{"cfi":"epubcfi(/6/194[xchapter_091]!4/2/16/1:0)","page":279},{"cfi":"epubcfi(/6/194[xchapter_091]!4/2/1:0)","page":280},{"cfi":"epubcfi(/6/194[xchapter_091]!4/2/64/1:0)","page":281},{"cfi":"epubcfi(/6/196[xchapter_092]!4/1:0)","page":282},{"cfi":"epubcfi(/6/196[xchapter_092]!4/2/14/1:0)","page":283},{"cfi":"epubcfi(/6/198[xchapter_093]!4/2/2/1:0)","page":284},{"cfi":"epubcfi(/6/198[xchapter_093]!4/2/1:0)","page":285},{"cfi":"epubcfi(/6/198[xchapter_093]!4/2/24/1:0)","page":286},{"cfi":"epubcfi(/6/200[xchapter_094]!4/2/2/1:0)","page":287},{"cfi":"epubcfi(/6/200[xchapter_094]!4/2/1:0)","page":288},{"cfi":"epubcfi(/6/202[xchapter_095]!4/1:0)","page":289},{"cfi":"epubcfi(/6/204[xchapter_096]!4/2/2/1:0)","page":290},{"cfi":"epubcfi(/6/204[xchapter_096]!4/2/1:0)","page":291},{"cfi":"epubcfi(/6/204[xchapter_096]!4/2/20/1:0)","page":292},{"cfi":"epubcfi(/6/206[xchapter_097]!4/1:0)","page":293},{"cfi":"epubcfi(/6/208[xchapter_098]!4/1:0)","page":294},{"cfi":"epubcfi(/6/208[xchapter_098]!4/2/12/1:0)","page":295},{"cfi":"epubcfi(/6/210[xchapter_099]!4/2/2/1:0)","page":296},{"cfi":"epubcfi(/6/210[xchapter_099]!4/2/1:0)","page":297},{"cfi":"epubcfi(/6/210[xchapter_099]!4/2/20/1:0)","page":298},{"cfi":"epubcfi(/6/210[xchapter_099]!4/2/26/1:0)","page":299},{"cfi":"epubcfi(/6/212[xchapter_100]!4/2/2/1:0)","page":300},{"cfi":"epubcfi(/6/212[xchapter_100]!4/2/20/1:0)","page":301},{"cfi":"epubcfi(/6/212[xchapter_100]!4/2/1:0)","page":302},{"cfi":"epubcfi(/6/212[xchapter_100]!4/2/54/1:0)","page":303},{"cfi":"epubcfi(/6/212[xchapter_100]!4/2/76/1:0)","page":304},{"cfi":"epubcfi(/6/214[xchapter_101]!4/2/2/1:0)","page":305},{"cfi":"epubcfi(/6/214[xchapter_101]!4/2/1:0)","page":306},{"cfi":"epubcfi(/6/214[xchapter_101]!4/2/18/1:0)","page":307},{"cfi":"epubcfi(/6/216[xchapter_102]!4/2/2/1:0)","page":308},{"cfi":"epubcfi(/6/216[xchapter_102]!4/2/1:0)","page":309},{"cfi":"epubcfi(/6/216[xchapter_102]!4/2/24/1:0)","page":310},{"cfi":"epubcfi(/6/218[xchapter_103]!4/1:0)","page":311},{"cfi":"epubcfi(/6/218[xchapter_103]!4/2/18/1:0)","page":312},{"cfi":"epubcfi(/6/220[xchapter_104]!4/2/2/1:0)","page":313},{"cfi":"epubcfi(/6/220[xchapter_104]!4/2/1:0)","page":314},{"cfi":"epubcfi(/6/220[xchapter_104]!4/2/18/1:0)","page":315},{"cfi":"epubcfi(/6/222[xchapter_105]!4/2/2/1:0)","page":316},{"cfi":"epubcfi(/6/222[xchapter_105]!4/2/1:0)","page":317},{"cfi":"epubcfi(/6/222[xchapter_105]!4/2/24/1:0)","page":318},{"cfi":"epubcfi(/6/224[xchapter_106]!4/1:0)","page":319},{"cfi":"epubcfi(/6/224[xchapter_106]!4/2/10/1:0)","page":320},{"cfi":"epubcfi(/6/226[xchapter_107]!4/1:0)","page":321},{"cfi":"epubcfi(/6/226[xchapter_107]!4/2/12/1:0)","page":322},{"cfi":"epubcfi(/6/228[xchapter_108]!4/2/2/1:0)","page":323},{"cfi":"epubcfi(/6/228[xchapter_108]!4/2/1:0)","page":324},{"cfi":"epubcfi(/6/228[xchapter_108]!4/2/66/1:0)","page":325},{"cfi":"epubcfi(/6/230[xchapter_109]!4/1:0)","page":326},{"cfi":"epubcfi(/6/230[xchapter_109]!4/2/28/1:0)","page":327},{"cfi":"epubcfi(/6/232[xchapter_110]!4/2/2/1:0)","page":328},{"cfi":"epubcfi(/6/232[xchapter_110]!4/2/1:0)","page":329},{"cfi":"epubcfi(/6/232[xchapter_110]!4/2/22/1:0)","page":330},{"cfi":"epubcfi(/6/232[xchapter_110]!4/2/34/1:0)","page":331},{"cfi":"epubcfi(/6/234[xchapter_111]!4/1:0)","page":332},{"cfi":"epubcfi(/6/236[xchapter_112]!4/1:0)","page":333},{"cfi":"epubcfi(/6/236[xchapter_112]!4/2/12/1:0)","page":334},{"cfi":"epubcfi(/6/238[xchapter_113]!4/2/2/1:0)","page":335},{"cfi":"epubcfi(/6/238[xchapter_113]!4/2/1:0)","page":336},{"cfi":"epubcfi(/6/240[xchapter_114]!4/1:0)","page":337},{"cfi":"epubcfi(/6/242[xchapter_115]!4/1:0)","page":338},{"cfi":"epubcfi(/6/242[xchapter_115]!4/2/14/1:0)","page":339},{"cfi":"epubcfi(/6/244[xchapter_116]!4/1:0)","page":340},{"cfi":"epubcfi(/6/246[xchapter_117]!4/1:0)","page":341},{"cfi":"epubcfi(/6/248[xchapter_118]!4/1:0)","page":342},{"cfi":"epubcfi(/6/248[xchapter_118]!4/2/10/1:0)","page":343},{"cfi":"epubcfi(/6/250[xchapter_119]!4/2/2/1:0)","page":344},{"cfi":"epubcfi(/6/250[xchapter_119]!4/2/18/1:0)","page":345},{"cfi":"epubcfi(/6/250[xchapter_119]!4/2/1:0)","page":346},{"cfi":"epubcfi(/6/250[xchapter_119]!4/2/64/1:0)","page":347},{"cfi":"epubcfi(/6/252[xchapter_120]!4/1:0)","page":348},{"cfi":"epubcfi(/6/254[xchapter_121]!4/1:0)","page":349},{"cfi":"epubcfi(/6/256[xchapter_122]!4/1:0)","page":350},{"cfi":"epubcfi(/6/258[xchapter_123]!4/2/2/1:0)","page":351},{"cfi":"epubcfi(/6/258[xchapter_123]!4/2/1:0)","page":352},{"cfi":"epubcfi(/6/260[xchapter_124]!4/2/2/1:0)","page":353},{"cfi":"epubcfi(/6/260[xchapter_124]!4/2/1:0)","page":354},{"cfi":"epubcfi(/6/262[xchapter_125]!4/2/2/1:0)","page":355},{"cfi":"epubcfi(/6/262[xchapter_125]!4/2/1:0)","page":356},{"cfi":"epubcfi(/6/264[xchapter_126]!4/2/2/1:0)","page":357},{"cfi":"epubcfi(/6/264[xchapter_126]!4/2/1:0)","page":358},{"cfi":"epubcfi(/6/266[xchapter_127]!4/1:0)","page":359},{"cfi":"epubcfi(/6/268[xchapter_128]!4/2/2/1:0)","page":360},{"cfi":"epubcfi(/6/268[xchapter_128]!4/2/1:0)","page":361},{"cfi":"epubcfi(/6/270[xchapter_129]!4/1:0)","page":362},{"cfi":"epubcfi(/6/272[xchapter_130]!4/2/2/1:0)","page":363},{"cfi":"epubcfi(/6/272[xchapter_130]!4/2/1:0)","page":364},{"cfi":"epubcfi(/6/272[xchapter_130]!4/2/22/1:0)","page":365},{"cfi":"epubcfi(/6/274[xchapter_131]!4/1:0)","page":366},{"cfi":"epubcfi(/6/276[xchapter_132]!4/2/2/1:0)","page":367},{"cfi":"epubcfi(/6/276[xchapter_132]!4/2/1:0)","page":368},{"cfi":"epubcfi(/6/276[xchapter_132]!4/2/30/1:0)","page":369},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/2/1:0)","page":370},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/26/1:0)","page":371},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/40/1:0)","page":372},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/1:0)","page":373},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/64/1:0)","page":374},{"cfi":"epubcfi(/6/278[xchapter_133]!4/2/82/1:0)","page":375},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/2/1:0)","page":376},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/14/1:0)","page":377},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/1:0)","page":378},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/44/1:0)","page":379},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/54/1:0)","page":380},{"cfi":"epubcfi(/6/280[xchapter_134]!4/2/90/1:0)","page":381},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/2/1:0)","page":382},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/10/1:0)","page":383},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/28/1:0)","page":384},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/1:0)","page":385},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/76/1:0)","page":386},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/90/1:0)","page":387},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/110/1:0)","page":388},{"cfi":"epubcfi(/6/282[xchapter_135]!4/2/124/1:0)","page":389},{"cfi":"epubcfi(/6/284[xchapter_136]!4/1:0)","page":390},{"cfi":"epubcfi(/6/286[copyright]!4/1:0)","page":391},{"cfi":"epubcfi(/6/288[toc]!4/2/2/1:0)","page":392},{"cfi":"epubcfi(/6/288[toc]!4/2/1:0)","page":393},{"cfi":"epubcfi(/6/288[toc]!4/2/4[toc]/2/204[toc-chapter_098]/1:0)","page":394}] \ No newline at end of file diff --git a/examples/pagination.html b/examples/pagination.html index f9af76d..1bb8a5b 100644 --- a/examples/pagination.html +++ b/examples/pagination.html @@ -139,6 +139,11 @@ var totalPages = document.getElementById("totalpg"); var slider = document.createElement("input"); var pageList; + var slide = function(){ + book.gotoPage(slider.value); + }; + var throttledSlide = _.throttle(slide, 200); + var mouseDown = false; var rendered = book.renderTo("area"); @@ -165,9 +170,12 @@ slider.setAttribute("step", 1); slider.setAttribute("value", 0); - slider.addEventListener("change", function(value){ - console.log(slider.value) - book.gotoPage(slider.value); + slider.addEventListener("change", throttledSlide, false); + slider.addEventListener("mousedown", function(){ + mouseDown = true; + }, false); + slider.addEventListener("mouseup", function(){ + mouseDown = false; }, false); // Wait for book to be rendered to get current page @@ -181,14 +189,15 @@ controls.appendChild(slider); totalPages.innerText = book.pagination.totalPages; - currentPage.addEventListener("change", function(value){ - console.log(currentPage.value) + currentPage.addEventListener("change", function(){ book.gotoPage(currentPage.value); }, false); }); book.on('book:pageChanged', function(location){ - slider.value = location.page; + if(!mouseDown) { + slider.value = location.page; + } currentPage.value = location.page; }); diff --git a/reader/controllers/toc_controller.js b/reader/controllers/toc_controller.js index 90919a5..0976eaf 100644 --- a/reader/controllers/toc_controller.js +++ b/reader/controllers/toc_controller.js @@ -82,6 +82,8 @@ EPUBJS.reader.TocController = function(toc) { $list.find(".toc_link").on("click", function(event){ var url = this.getAttribute('href'); + event.preventDefault(); + //-- Provide the Book with the url to show // The Url must be found in the books manifest book.goto(url); @@ -92,19 +94,18 @@ EPUBJS.reader.TocController = function(toc) { $(this).parent('li').addClass("currentChapter"); - event.preventDefault(); }); $list.find(".toc_toggle").on("click", function(event){ var $el = $(this).parent('li'), open = $el.hasClass("openChapter"); + event.preventDefault(); if(open){ $el.removeClass("openChapter"); } else { $el.addClass("openChapter"); } - event.preventDefault(); }); return { diff --git a/src/book.js b/src/book.js index 0df6027..a233cbd 100644 --- a/src/book.js +++ b/src/book.js @@ -83,10 +83,15 @@ EPUBJS.Book = function(options){ this.ready.all.then(this._ready.bind(this)); - this._q = []; + // Queue for methods used before rendering this.isRendered = false; + this._q = EPUBJS.core.queue(this); + // Queue for rendering this._rendering = false; - this._displayQ = []; + this._displayQ = EPUBJS.core.queue(this); + // Queue for going to another location + this._moving = false; + this._gotoQ = EPUBJS.core.queue(this); /** * Creates a new renderer. @@ -440,6 +445,7 @@ EPUBJS.Book.prototype.listenToRenderer = function(renderer){ EPUBJS.Book.prototype.loadChange = function(url){ var uri = EPUBJS.core.uri(url); if(this.currentChapter && uri.path != this.currentChapter.absolute){ + console.warn("Miss Match", uri.path, this.currentChapter.absolute); this.goto(uri.filename); } }; @@ -631,18 +637,28 @@ EPUBJS.Book.prototype.restore = function(identifier){ }; -EPUBJS.Book.prototype.displayChapter = function(chap, end){ +EPUBJS.Book.prototype.displayChapter = function(chap, end, deferred){ var book = this, render, cfi, pos, - store; - - if(!this.isRendered) return this._enqueue("displayChapter", arguments); + store, + defer = deferred || new RSVP.defer(); + if(!this.isRendered) { + this._q.enqueue("displayChapter", arguments); + // Reject for now. TODO: pass promise to queue + defer.reject({ + message : "Rendering", + stack : new Error().stack + }); + return defer.promise; + } + if(this._rendering) { - this._displayQ.push(arguments); - return; + // Pass along the current defer + this._displayQ.enqueue("displayChapter", [chap, end, defer]); + return defer.promise; } if(_.isNumber(chap)){ @@ -673,10 +689,16 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ render.then(function(chapter){ // chapter.currentLocationCfi = chap; chapter.gotoCfi(cfi); + defer.resolve(book.renderer); }); } else if(end) { render.then(function(chapter){ chapter.lastPage(); + defer.resolve(book.renderer); + }); + } else { + render.then(function(){ + defer.resolve(book.renderer); }); } @@ -691,21 +713,17 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){ //-- Clear render queue render.then(function(){ var inwait; - book._rendering = false; - if(book._displayQ.length) { - inwait = book._displayQ.shift(); - book.displayChapter.apply(book, inwait); - } - + book._displayQ.dequeue(); }); - return render; + + return defer.promise; }; EPUBJS.Book.prototype.nextPage = function(){ var next; - if(!this.isRendered) return this._enqueue("nextPage", arguments); + if(!this.isRendered) return this._q.enqueue("nextPage", arguments); next = this.renderer.nextPage(); @@ -717,7 +735,7 @@ EPUBJS.Book.prototype.nextPage = function(){ EPUBJS.Book.prototype.prevPage = function() { var prev; - if(!this.isRendered) return this._enqueue("prevPage", arguments); + if(!this.isRendered) return this._q.enqueue("prevPage", arguments); prev = this.renderer.prevPage(); @@ -750,28 +768,48 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() { return this.renderer.currentLocationCfi; }; -EPUBJS.Book.prototype.gotoCfi = function(cfiString){ +EPUBJS.Book.prototype.goto = function(target){ + + if(typeof target === "number"){ + return this.gotoPage(target); + } else if(target.indexOf("epubcfi(") === 0) { + return this.gotoCfi(target); + } else if(target.indexOf("%") === target.length-1) { + return this.gotoPercentage(parseInt(target.substring(0, target.length-1))); + } else { + return this.gotoHref(target); + } + +}; + +EPUBJS.Book.prototype.gotoCfi = function(cfiString, defer){ var cfi, spinePos, spineItem, rendered, - deferred; + deferred = defer || new RSVP.defer(); if(!this.isRendered) { this.settings.previousLocationCfi = cfiString; return false; } + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoCfi", [cfiString, deferred]); + return false; + } cfi = new EPUBJS.EpubCFI(cfiString); spinePos = cfi.spinePos; spineItem = this.spine[spinePos]; - deferred = new RSVP.defer(); - + promise = deferred.promise; + this._moving = true; //-- If same chapter only stay on current chapter if(this.currentChapter && this.spinePos === spinePos){ this.renderer.gotoCfi(cfi); - deferred.resolve(this.currentChapter); - return deferred.promise; + this._moving = false; + deferred.resolve(this.renderer.currentLocationCfi); } else { if(!spineItem || spinePos == -1) { @@ -786,24 +824,35 @@ EPUBJS.Book.prototype.gotoCfi = function(cfiString){ render = this.renderer.displayChapter(this.currentChapter, this.globalLayoutProperties); render.then(function(rendered){ - rendered.gotoCfi(cfi); - }); + rendered.gotoCfi(cfi); + this._moving = false; + deferred.resolve(rendered.currentLocationCfi); + }.bind(this)); } - - return render; } + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return promise; }; -EPUBJS.Book.prototype.goto = function(url){ +EPUBJS.Book.prototype.gotoHref = function(url, defer){ var split, chapter, section, absoluteURL, spinePos; - var deferred = new RSVP.defer(); - //if(!this.isRendered) return this._enqueue("goto", arguments); + var deferred = defer || new RSVP.defer(); + if(!this.isRendered) { this.settings.goto = url; - return; + return false; } - + + // Currently going to a chapter + if(this._moving) { + this._gotoQ.enqueue("gotoHref", [url, deferred]); + return false; + } + split = url.split("#"); chapter = split[0]; section = split[1] || false; @@ -821,14 +870,34 @@ EPUBJS.Book.prototype.goto = function(url){ if(!this.currentChapter || spinePos != this.currentChapter.spinePos){ //-- Load new chapter if different than current return this.displayChapter(spinePos).then(function(){ - if(section) this.render.section(section); - }.bind(this)); + if(section){ + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); + }.bind(this)); }else{ //-- Only goto section - if(section) this.render.section(section); - deferred.resolve(this.currentChapter); - return deferred.promise; + if(section) { + this.render.section(section); + } + deferred.resolve(this.renderer.currentLocationCfi); } + + promise.then(function(){ + this._gotoQ.dequeue(); + }.bind(this)); + + return deferred.promise; +}; + +EPUBJS.Book.prototype.gotoPage = function(pg){ + var cfi = this.pagination.cfiFromPage(pg); + return this.gotoCfi(cfi); +}; + +EPUBJS.Book.prototype.gotoPercentage = function(percent){ + var pg = this.pagination.pageFromPercentage(percent); + return this.gotoCfi(pg); }; EPUBJS.Book.prototype.preloadNextChapter = function() { @@ -888,7 +957,7 @@ EPUBJS.Book.prototype.fromStorage = function(stored) { */ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { - if(!this.isRendered) return this._enqueue("setStyle", arguments); + if(!this.isRendered) return this._q.enqueue("setStyle", arguments); this.settings.styles[style] = val; @@ -897,14 +966,14 @@ EPUBJS.Book.prototype.setStyle = function(style, val, prefixed) { }; EPUBJS.Book.prototype.removeStyle = function(style) { - if(!this.isRendered) return this._enqueue("removeStyle", arguments); + if(!this.isRendered) return this._q.enqueue("removeStyle", arguments); this.renderer.removeStyle(style); this.renderer.reformat(); delete this.settings.styles[style]; }; EPUBJS.Book.prototype.addHeadTag = function(tag, attrs) { - if(!this.isRendered) return this._enqueue("addHeadTag", arguments); + if(!this.isRendered) return this._q.enqueue("addHeadTag", arguments); this.settings.headTags[tag] = attrs; }; @@ -947,15 +1016,6 @@ EPUBJS.Book.prototype.destroy = function() { }; -EPUBJS.Book.prototype._enqueue = function(command, args) { - - this._q.push({ - 'command': command, - 'args': args - }); - -}; - EPUBJS.Book.prototype._ready = function() { this.trigger("book:ready"); @@ -968,21 +1028,18 @@ EPUBJS.Book.prototype._rendered = function(err) { this.isRendered = true; this.trigger("book:rendered"); - this._q.forEach(function(item){ - book[item.command].apply(book, item.args); - }); - + this._q.flush(); }; EPUBJS.Book.prototype.applyStyles = function(callback){ - if(!this.isRendered) return this._enqueue("applyStyles", arguments); + if(!this.isRendered) return this._q.enqueue("applyStyles", arguments); this.renderer.applyStyles(this.settings.styles); callback(); }; EPUBJS.Book.prototype.applyHeadTags = function(callback){ - if(!this.isRendered) return this._enqueue("applyHeadTags", arguments); + if(!this.isRendered) return this._q.enqueue("applyHeadTags", arguments); this.renderer.applyHeadTags(this.settings.headTags); callback(); }; diff --git a/src/core.js b/src/core.js index 5f9bc31..dcdea9b 100644 --- a/src/core.js +++ b/src/core.js @@ -343,4 +343,45 @@ EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { } else{ return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); } +}; + +EPUBJS.core.queue = function(_scope){ + var _q = []; + var scope = _scope; + // Add an item to the queue + var enqueue = function(funcName, args, context) { + _q.push({ + "funcName" : funcName, + "args" : args, + "context" : context + }); + return _q; + }; + // Run one item + var dequeue = function(){ + var inwait; + if(_q.length) { + inwait = _q.shift(); + // Defer to any current tasks + setTimeout(function(){ + scope[inwait.funcName].apply(inwait.context || scope, inwait.args); + }, 0); + } + }; + // Run All + var flush = function(){ + while(_q.length) { + dequeue(); + } + }; + // Clear all items in wait + var clear = function(){ + _q = []; + }; + return { + "enqueue" : enqueue, + "dequeue" : dequeue, + "flush" : flush, + "clear" : clear + }; }; \ No newline at end of file diff --git a/src/epubcfi.js b/src/epubcfi.js index 3dca891..2a7d8d1 100644 --- a/src/epubcfi.js +++ b/src/epubcfi.js @@ -276,8 +276,11 @@ EPUBJS.EpubCFI.prototype.findParent = function(cfi, _doc) { }else{ element = children[part.index]; } - - if(!element) return console.error("No Element For", part, cfi); + // Element can't be found + if(typeof element === "undefined") { + console.error("No Element For", part, cfi.str); + return false; + } // Get current element children and continue through steps children = Array.prototype.slice.call(element.children); } diff --git a/src/pagination.js b/src/pagination.js index c0f02e9..bb8d99b 100644 --- a/src/pagination.js +++ b/src/pagination.js @@ -69,15 +69,4 @@ EPUBJS.Pagination.prototype.percentageFromCfi = function(cfi){ var pg = this.pageFromCfi(cfi); var percentage = this.percentageFromPage(pg); return percentage; -}; - -// TODO: move these -EPUBJS.Book.prototype.gotoPage = function(pg){ - var cfi = this.pagination.cfiFromPage(pg); - return this.gotoCfi(cfi); -}; - -EPUBJS.Book.prototype.gotoPercentage = function(percent){ - var pg = this.pagination.pageFromPercentage(percent); - return this.gotoCfi(pg); -}; +}; \ No newline at end of file diff --git a/src/renderer.js b/src/renderer.js index dfd9ad4..a0c96ba 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -388,7 +388,7 @@ EPUBJS.Renderer.prototype.firstElementisTextNode = function(node) { var children = node.childNodes; var leng = children.length; - if(leng && + if(leng && children[0] && // First Child children[0].nodeType === 3 && // This is a textNodes children[0].textContent.trim().length) { // With non whitespace or return charecters diff --git a/tests/render.js b/tests/render.js index 225534d..60f66f2 100644 --- a/tests/render.js +++ b/tests/render.js @@ -10,7 +10,7 @@ asyncTest("renderTo element on page", 1, function() { start(); }; - render.then(result, result); + render.then(result).catch(result); }); @@ -177,8 +177,6 @@ asyncTest("Add styles to book", 4, function() { var $iframe = $( "iframe", "#qunit-fixture" ), $body; - console.log(Book) - equal( Book.renderer.render.bodyEl.style.background, '', "background not set"); Book.setStyle("background", "purple");