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