/*! * @overview RSVP - a tiny implementation of Promises/A+. * @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors * @license Licensed under MIT license * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE * @version 3.6.2 */(function(n,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):r(n.RSVP=n.RSVP||{})})(this,function(n){"use strict";function r(e,t){for(var o=0,s=e.length;o2&&arguments[2]!==void 0)||arguments[2],f=arguments[3];return tt(this,e.call(this,o,s,u,f))}return nt(t,e),t.prototype._init=function(o,s){this._result={},this._enumerate(s),this._remaining===0&&_(this.promise,this._result)},t.prototype._enumerate=function(o){var s=this.promise,u=[];for(var f in o)ht.call(o,f)&&u.push({position:f,entry:o[f]});var y=u.length;this._remaining=y;for(var P=void 0,A=0;s._state===K&&Av?1:p0?m:m+1:l===0?m:l===-1?EPUBJS.core.locationOf(n,r,i,m,d):EPUBJS.core.locationOf(n,r,i,h,m))},EPUBJS.core.indexOfSorted=function(n,r,i,c,a){var l,h=c||0,d=a||r.length,m=parseInt(h+(d-h)/2);return i||(i=function(p,v){return p>v?1:p-1||(this.settings.bookmarks.push(n),this.trigger("reader:bookmarked",n))},EPUBJS.Reader.prototype.removeBookmark=function(n){var r=this.isBookmarked(n);r!==-1&&(this.settings.bookmarks.splice(r,1),this.trigger("reader:unbookmarked",r))},EPUBJS.Reader.prototype.isBookmarked=function(n){return this.settings.bookmarks.indexOf(n)},EPUBJS.Reader.prototype.clearBookmarks=function(){this.settings.bookmarks=[]},EPUBJS.Reader.prototype.addNote=function(n){this.settings.annotations.push(n)},EPUBJS.Reader.prototype.removeNote=function(n){var r=this.settings.annotations.indexOf(n);r!==-1&&delete this.settings.annotations[r]},EPUBJS.Reader.prototype.clearNotes=function(){this.settings.annotations=[]},EPUBJS.Reader.prototype.setBookKey=function(n){return this.settings.bookKey||(this.settings.bookKey="epubjsreader:"+EPUBJS.VERSION+":"+window.location.host+":"+n),this.settings.bookKey},EPUBJS.Reader.prototype.isSaved=function(n){return!!localStorage&&localStorage.getItem(this.settings.bookKey)!==null},EPUBJS.Reader.prototype.removeSavedSettings=function(){if(!localStorage)return!1;localStorage.removeItem(this.settings.bookKey)},EPUBJS.Reader.prototype.applySavedSettings=function(){var n;if(!localStorage)return!1;try{n=JSON.parse(localStorage.getItem(this.settings.bookKey))}catch(r){return!1}return!!n&&(n.styles&&(this.settings.styles=EPUBJS.core.defaults(this.settings.styles||{},n.styles)),this.settings=EPUBJS.core.defaults(this.settings,n),!0)},EPUBJS.Reader.prototype.saveSettings=function(){if(this.book&&(this.settings.previousLocationCfi=this.rendition.currentLocation().start.cfi),!localStorage)return!1;localStorage.setItem(this.settings.bookKey,JSON.stringify(this.settings))},EPUBJS.Reader.prototype.unload=function(){this.settings.restore&&localStorage&&this.saveSettings()},EPUBJS.Reader.prototype.hashChanged=function(){var n=window.location.hash.slice(1);this.rendition.display(n)},EPUBJS.Reader.prototype.selectedRange=function(n){var r="#"+n;this.settings.history&&window.location.hash!=r&&(history.pushState({},"",r),this.currentLocationCfi=n)},RSVP.EventTarget.mixin(EPUBJS.Reader.prototype),EPUBJS.reader.BookmarksController=function(){var n=this.book,r=this.rendition,i=$("#bookmarksView"),c=i.find("#bookmarks"),a=document.createDocumentFragment(),l=function(){i.show()},h=function(){i.hide()},d=0,m=function(p){var v=document.createElement("li"),k=document.createElement("a");v.id="bookmark-"+d,v.classList.add("list_item");var C,R=n.spine.get(p);return R.index in n.navigation.toc?(C=n.navigation.toc[R.index],k.textContent=C.label):k.textContent=p,k.href=p,k.classList.add("bookmark_link"),k.addEventListener("click",function(j){var N=this.getAttribute("href");r.display(N),j.preventDefault()},!1),v.appendChild(k),d++,v};return this.settings.bookmarks.forEach(function(p){var v=m(p);a.appendChild(v)}),c.append(a),this.on("reader:bookmarked",function(p){var v=m(p);c.append(v)}),this.on("reader:unbookmarked",function(p){$("#bookmark-"+p).remove()}),{show:l,hide:h}},EPUBJS.reader.ControlsController=function(n){var r=this,i=this.rendition,c=($("#store"),$("#fullscreen")),a=($("#fullscreenicon"),$("#cancelfullscreenicon"),$("#slider")),l=($("#main"),$("#sidebar"),$("#setting")),h=$("#bookmark");return a.on("click",function(){r.sidebarOpen?(r.SidebarController.hide(),a.addClass("icon-menu"),a.removeClass("icon-right")):(r.SidebarController.show(),a.addClass("icon-right"),a.removeClass("icon-menu"))}),typeof screenfull!="undefined"&&(c.on("click",function(){screenfull.toggle($("#container")[0])}),screenfull.raw&&document.addEventListener(screenfull.raw.fullscreenchange,function(){fullscreen=screenfull.isFullscreen,fullscreen?c.addClass("icon-resize-small").removeClass("icon-resize-full"):c.addClass("icon-resize-full").removeClass("icon-resize-small")})),l.on("click",function(){r.SettingsController.show()}),h.on("click",function(){var d=r.rendition.currentLocation().start.cfi;r.isBookmarked(d)===-1?(r.addBookmark(d),h.addClass("icon-bookmark").removeClass("icon-bookmark-empty")):(r.removeBookmark(d),h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"))}),i.on("relocated",function(d){var m=d.start.cfi,p="#"+m;r.isBookmarked(m)===-1?h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):h.addClass("icon-bookmark").removeClass("icon-bookmark-empty"),r.currentLocationCfi=m,r.settings.history&&window.location.hash!=p&&history.pushState({},"",p)}),{}},EPUBJS.reader.MetaController=function(n){var r=n.title,i=n.creator,c=$("#book-title"),a=$("#chapter-title"),l=$("#title-seperator");document.title=r+" \u2013 "+i,c.html(r),a.html(i),l.show()},EPUBJS.reader.NotesController=function(){var n=this.book,r=this.rendition,i=this,c=$("#notesView"),a=$("#notes"),l=$("#note-text"),h=$("#note-anchor"),d=i.settings.annotations,m=n.renderer,p=[],v=new ePub.CFI,k=function(){c.show()},C=function(){c.hide()},R=function(x){var b,g,_,O,L,D=n.renderer.doc;if(D.caretPositionFromPoint?(b=D.caretPositionFromPoint(x.clientX,x.clientY),g=b.offsetNode,_=b.offset):D.caretRangeFromPoint&&(b=D.caretRangeFromPoint(x.clientX,x.clientY),g=b.startContainer,_=b.startOffset),g.nodeType!==3){for(var F=0;FX/2.5&&(G=X/2.5,pop_content.style.maxHeight=G+"px"),popRect.height+I>=X-25?(T.style.top=I-popRect.height+"px",T.classList.add("above")):T.classList.remove("above"),z-popRect.width<=0?(T.style.left=z+"px",T.classList.add("left")):T.classList.remove("left"),z+popRect.width/2>=ne?(T.style.left=z-300+"px",popRect=T.getBoundingClientRect(),T.style.left=z-popRect.width+"px",popRect.height+I>=X-25?(T.style.top=I-popRect.height+"px",T.classList.add("above")):T.classList.remove("above"),T.classList.add("right")):T.classList.remove("right")},O=function(){p[g].classList.add("on")},L=function(){p[g].classList.remove("on")},D=function(){setTimeout(function(){p[g].classList.remove("show")},100)},F=function(){i.ReaderController.slideOut(),k()};x.addEventListener("mouseover",_,!1),x.addEventListener("mouseout",D,!1),x.addEventListener("click",F,!1)};return h.on("click",function(x){h.text("Cancel"),l.prop("disabled","true"),r.on("click",R)}),d.forEach(function(x){j(x)}),{show:k,hide:C}},EPUBJS.reader.ReaderController=function(n){var r=$("#main"),i=$("#divider"),c=$("#loader"),a=$("#next"),l=$("#prev"),h=this,n=this.book,d=this.rendition,m=function(){d.currentLocation().start.cfi,h.settings.sidebarReflow?(r.removeClass("single"),r.one("transitionend",function(){d.resize()})):r.removeClass("closed")},p=function(){var S=d.currentLocation();S&&(S.start.cfi,h.settings.sidebarReflow?(r.addClass("single"),r.one("transitionend",function(){d.resize()})):r.addClass("closed"))},v=function(){c.show(),R()},k=function(){c.hide()},C=function(){i.addClass("show")},R=function(){i.removeClass("show")},j=!1,N=function(S){S.keyCode==37&&(n.package.metadata.direction==="rtl"?d.next():d.prev(),l.addClass("active"),j=!0,setTimeout(function(){j=!1,l.removeClass("active")},100),S.preventDefault()),S.keyCode==39&&(n.package.metadata.direction==="rtl"?d.prev():d.next(),a.addClass("active"),j=!0,setTimeout(function(){j=!1,a.removeClass("active")},100),S.preventDefault())};return document.addEventListener("keydown",N,!1),a.on("click",function(S){n.package.metadata.direction==="rtl"?d.prev():d.next(),S.preventDefault()}),l.on("click",function(S){n.package.metadata.direction==="rtl"?d.next():d.prev(),S.preventDefault()}),d.on("layout",function(S){S.spread===!0?C():R()}),d.on("relocated",function(S){S.atStart&&l.addClass("disabled"),S.atEnd&&a.addClass("disabled")}),{slideOut:p,slideIn:m,showLoader:v,hideLoader:k,showDivider:C,hideDivider:R,arrowKeys:N}},EPUBJS.reader.SettingsController=function(){var n=(this.book,this),r=$("#settings-modal"),i=$(".overlay"),c=function(){r.addClass("md-show")},a=function(){r.removeClass("md-show")};return $("#sidebarReflow").on("click",function(){n.settings.sidebarReflow=!n.settings.sidebarReflow}),r.find(".closer").on("click",function(){a()}),i.on("click",function(){a()}),{show:c,hide:a}},EPUBJS.reader.SidebarController=function(n){var r=this,i=$("#sidebar"),c=$("#panels"),a="Toc",l=function(p){var v=p+"Controller";a!=p&&r[v]!==void 0&&(r[a+"Controller"].hide(),r[v].show(),a=p,c.find(".active").removeClass("active"),c.find("#show-"+p).addClass("active"))},h=function(){return a},d=function(){r.sidebarOpen=!0,r.ReaderController.slideOut(),i.addClass("open")},m=function(){r.sidebarOpen=!1,r.ReaderController.slideIn(),i.removeClass("open")};return c.find(".show_view").on("click",function(p){var v=$(this).data("view");l(v),p.preventDefault()}),{show:d,hide:m,getActivePanel:h,changePanelTo:l}},EPUBJS.reader.TocController=function(n){var r=(this.book,this.rendition),i=$("#tocView"),c=document.createDocumentFragment(),a=!1,l=function(v,k){var C=document.createElement("ul");return k||(k=1),v.forEach(function(R){var j=document.createElement("li"),N=document.createElement("a");toggle=document.createElement("a");var S;j.id="toc-"+R.id,j.classList.add("list_item"),N.textContent=R.label,N.href=R.href,N.classList.add("toc_link"),j.appendChild(N),R.subitems&&R.subitems.length>0&&(k++,S=l(R.subitems,k),toggle.classList.add("toc_toggle"),j.insertBefore(toggle,N),j.appendChild(S)),C.appendChild(j)}),C},h=function(){i.show()},d=function(){i.hide()},m=function(v){var k=v.id,C=i.find("#toc-"+k),R=i.find(".currentChapter");i.find(".openChapter"),C.length&&(C!=R&&C.has(a).length>0&&R.removeClass("currentChapter"),C.addClass("currentChapter"),C.parents("li").addClass("openChapter"))};r.on("renderered",m);var p=l(n);return c.appendChild(p),i.append(c),i.find(".toc_link").on("click",function(v){var k=this.getAttribute("href");v.preventDefault(),r.display(k),i.find(".currentChapter").addClass("openChapter").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter")}),i.find(".toc_toggle").on("click",function(v){var k=$(this).parent("li"),C=k.hasClass("openChapter");v.preventDefault(),C?k.removeClass("openChapter"):k.addClass("openChapter")}),{show:h,hide:d}};