This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/vendor/epubjs/reader.min.js
2020-04-21 23:45:26 +02:00

1 line
29 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

EPUBJS.reader={},EPUBJS.reader.plugins={},function(a,b){var c=(a.ePubReader||{},a.ePubReader=function(a,b){return new EPUBJS.Reader(a,b)});"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,f,g=this,h=$("#viewer"),i=window.location.search;this.settings=EPUBJS.core.defaults(b||{},{bookPath:a,contained:void 0,sidebarReflow:!1,generatePagination:!1,history:!0,keyboard:{32:"next",34:"next",39:"next",33:"previous",37:"previous",36:"first",35:"last",65:"annotate",66:"bookmark",82:"reflow",83:"toggleSidebar",84:"toolbar",68:"toggleDay",78:"toggleNight",70:"toggleFullscreen",27:"closeSidebar"},nightMode:!1,dayMode:!1,maxWidth:72,pageArrows:!1,annotations:{},customStyles:{},activeStyles:{},session:{}}),this.Annotation=function(a,b,c,d){this.id=d||EPUBJS.core.uuid(),this.type=a,this.date=Date.now(),this.edited=this.date,this.anchor=b,this.body=c},this.Style=function(a,b,c,d){this.name=a,this.selector=b,this.rules=c,this.extra=d||null},i&&(f=i.slice(1).split("&"),f.forEach(function(a){var b=a.split("="),c=b[0],d=b[1]||"";g.settings[c]=decodeURIComponent(d)})),this.restoreDefaults(this.settings.session.defaults),this.restorePreferences(this.settings.session.preferences),this.restoreAnnotations(this.settings.session.annotations),this.book=c=new EPUBJS.Book(this.settings),this.offline=!1,this.sidebarOpen=!1,this.viewerResized=!1,this.settings.generatePagination&&c.generatePagination(h.width(),h.height()),c.renderTo("viewer").then(function(a){this.renderer=d=a,g.StyleController=EPUBJS.reader.StylesController.call(g,d)}),g.ReaderController=EPUBJS.reader.ReaderController.call(g,c),g.SettingsController=EPUBJS.reader.SettingsController.call(g,c),g.ControlsController=EPUBJS.reader.ControlsController.call(g,c),g.SidebarController=EPUBJS.reader.SidebarController.call(g,c),g.NotesController=EPUBJS.reader.NotesController.call(g,c),g.BookmarksController=EPUBJS.reader.BookmarksController.call(g,c),g.SearchController=EPUBJS.reader.SearchController.call(g,c);for(e in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(e)&&(g[e]=EPUBJS.reader.plugins[e].call(g,c));return c.ready.all.then(function(){g.ReaderController.hideLoader(),g.settings.session.cursor!=={}&&g.trigger("reader:gotobookmark",g.settings.session.cursor)}),c.getMetadata().then(function(a){g.MetaController=EPUBJS.reader.MetaController.call(g,a)}),c.getToc().then(function(a){g.TocController=EPUBJS.reader.TocController.call(g,a)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),window.addEventListener("hashchange",this.hashChanged.bind(this),!1),c.on("renderer:keydown",g.ReaderController.keyCommands.bind(this)),c.on("renderer:selected",this.selectedRange.bind(this)),this},EPUBJS.Reader.prototype.cfiToId=function(a){return a.replace(/\W/g,"")},EPUBJS.Reader.prototype.getBookmark=function(a){var b=this.cfiToId(a);return this.settings.annotations[b]},EPUBJS.Reader.prototype.addBookmark=function(a){var b,c,d,e,f=this.cfiToId(a),g=new EPUBJS.EpubCFI,h="";return d=g.generateRangeFromCfi(a,this.book.renderer.doc),b=d.startOffset,h=d.startContainer.wholeText,c=/\S/.test(h)?b>0&&" "!=h.charAt(b-1)?EPUBJS.core.ellipsize(h.substr(h.indexOf(" ",b))):EPUBJS.core.ellipsize(h.substr(b)):a,this.isBookmarked(f)?(e=this.getAnnotation(f),this.updateAnnotation(e)):(e=new this.Annotation("bookmark",a,c,this.cfiToId(a)),this.addAnnotation(e)),this.trigger("reader:bookmarkcreated",e),e},EPUBJS.Reader.prototype.updateBookmark=function(a){this.updateAnnotation(a)},EPUBJS.Reader.prototype.removeBookmark=function(a){var b=this.cfiToId(a);this.removeAnnotation(b)},EPUBJS.Reader.prototype.isBookmarked=function(a){var b=this.cfiToId(a);return void 0!==this.settings.annotations[b]},EPUBJS.Reader.prototype.clearBookmarks=function(){this.clearAnnotations("bookmark")},EPUBJS.Reader.prototype.getAnnotation=function(a){return this.settings.annotations[a]},EPUBJS.Reader.prototype.addAnnotation=function(a){this.settings.annotations[a.id]=a,this.settings.session.setBookmark(a.id,a.anchor,a.type,a)},EPUBJS.Reader.prototype.removeAnnotation=function(a){if(void 0!==this.settings.annotations[a]){var b=this.settings.annotations[a].type;this.trigger("reader:"+b+"removed",a),this.settings.session.deleteBookmark(a),delete this.settings.annotations[a]}},EPUBJS.Reader.prototype.updateAnnotation=function(a){a.edited=Date.now(),this.settings.annotations[a.id]=a,this.settings.session.setBookmark(a.id,a.anchor,a.type,a)},EPUBJS.Reader.prototype.clearAnnotations=function(a){if(a)for(var b in this.settings.annotations)this.settings.annotations.hasOwnProperty(b)&&this.settings.annotations[b].type===a&&(this.trigger("reader:"+a+"removed",b),this.settings.session.deleteBookmark(b),delete this.settings.annotations[b])},EPUBJS.Reader.prototype.addStyleSheet=function(a,b){var c=a,d=b||document.head,e=document.createElement("style");return e.appendChild(document.createTextNode("")),e.setAttribute("id",c),d.appendChild(e),e.sheet},EPUBJS.Reader.prototype.getStyleSheet=function(a,b){if(void 0!==a){var c=b||document.head,d=$(c).find("style#"+a);if(d.length)return d[0]}},EPUBJS.Reader.prototype.addCSSRule=function(a,b,c,d){void 0===d&&(d=0),"insertRule"in a?a.insertRule(b+"{"+c+"}",d):"addRule"in a&&a.addRule(b,c,d)},EPUBJS.Reader.prototype.addStyle=function(a,b,c,d){void 0===this.settings.customStyles[a]&&(this.settings.customStyles[a]=new this.Style(a,b,c,d),this.settings.session.setDefault("customStyles",this.settings.customStyles))},EPUBJS.Reader.prototype.enableStyle=function(a){var b=this.getStyleSheet(a.name,document.head),c=this.getStyleSheet(a.name,renderer.doc.head);c&&$(c).remove(),b&&$(b).remove();var d="",e=this.addStyleSheet(a.name,renderer.doc.head),f=this.addStyleSheet(a.name,document.head);for(var g in a.rules)d+=g+":"+a.rules[g]+"!important;";this.addCSSRule(e,a.selector,d,0),this.addCSSRule(f,"*"===a.selector?"#main":a.selector,d,0),this.settings.activeStyles[a.name]=!0,this.settings.session.setDefault("activeStyles",this.settings.activeStyles)},EPUBJS.Reader.prototype.disableStyle=function(a){var b=this.getStyleSheet(a.name,document.head),c=this.getStyleSheet(a.name,renderer.doc.head);c&&$(c).remove(),b&&$(b).remove(),this.settings.activeStyles[a.name]&&(delete this.settings.activeStyles[a.name],this.settings.session.setDefault("activeStyles",this.settings.activeStyles))},EPUBJS.Reader.prototype.updateStyle=function(a){var b=this.getStyleSheet(a.name,renderer.doc.head);this.settings.session.setDefault("customStyles",this.settings.customStyles),b&&this.enableStyle(a)},EPUBJS.Reader.prototype.deleteStyle=function(a){this.disableStyle(a),delete this.customStyles[a.name],this.settings.session.setDefault("customStyles",this.settings.customStyles)},EPUBJS.Reader.prototype.refreshStyles=function(a,b){var c=this.settings.activeStyles,d=this.settings.customStyles;for(var e in c)if(c.hasOwnProperty(e)){var f="",g=this.addStyleSheet(e,b.doc.head);for(var h in d[e].rules)d[e].rules.hasOwnProperty(h)&&(f+=h+":"+d[e].rules[h]+"!important;");this.addCSSRule(g,d[e].selector,f,0)}a&&a()},EPUBJS.Reader.prototype.restoreDefaults=function(a){for(var b=0;b<a.length;b++)this.settings[a[b].name]=a[b].value},EPUBJS.Reader.prototype.restorePreferences=function(a){for(var b=0;b<a.length;b++)this.settings[a[b].name]=a[b].value},EPUBJS.Reader.prototype.restoreAnnotations=function(a){if(a!=={})for(var b in this.settings.session.annotations)a.hasOwnProperty(b)&&null!==a[b].content&&(this.settings.annotations[a[b].name]=a[b].content)},EPUBJS.Reader.prototype.unload=function(){console.log("unload")},EPUBJS.Reader.prototype.hashChanged=function(){var a=window.location.hash.slice(1);this.book.goto(a)},EPUBJS.Reader.prototype.selectedRange=function(a){if(null!==a.anchorNode){var b=new EPUBJS.EpubCFI,c=b.generateCfiFromRangeAnchor(a,this.book.renderer.currentChapter.cfiBase),d="#"+c;this.settings.history&&window.location.hash!=d&&(history.pushState({},"",d),this.currentLocationCfi=c)}},RSVP.EventTarget.mixin(EPUBJS.Reader.prototype),EPUBJS.reader.BookmarksController=function(){var a=this,b=this.book,c=a.settings.annotations,d=$("#bookmarksView"),e=d.find("#bookmarks"),f=$("#bookmark"),g=function(){d.addClass("open")},h=function(){d.removeClass("open")},i=function(b){e.append(a.NotesController.createItem(b))};for(var j in c)c.hasOwnProperty(j)&&"bookmark"===c[j].type&&i(c[j]);return this.on("reader:bookmarkcreated",function(a){i(a)}),this.on("reader:bookmarkremoved",function(b){var c=$("#"+b),d=a.book.getCurrentLocationCfi(),e=a.cfiToId(d);c.remove(),e===b&&f.removeClass("icon-turned_in").addClass("icon-turned_in_not")}),this.on("reader:gotobookmark",function(a){a&&a.value&&b.gotoCfi(a.value)}),{show:g,hide:h}},EPUBJS.reader.ControlsController=function(a){var b=this,c=($("#store"),$("#fullscreen")),d=($("#fullscreenicon"),$("#cancelfullscreenicon"),$("#slider")),e=($("#main"),$("#sidebar"),$("#setting")),f=$("#bookmark"),g=$("#note"),h=function(){b.offline=!1},i=function(){b.offline=!0},j=!1;return a.on("book:online",h),a.on("book:offline",i),d.on("click",function(){b.sidebarOpen?b.SidebarController.hide():b.SidebarController.show()}),"undefined"!=typeof screenfull&&(c.on("click",function(){screenfull.toggle($("#container")[0])}),screenfull.raw&&document.addEventListener(screenfull.raw.fullscreenchange,function(){j=screenfull.isFullscreen,j?c.addClass("icon-fullscreen_exit").removeClass("icon-fullscreen"):c.addClass("icon-fullscreen").removeClass("icon-fullscreen_exit")})),e.on("click",function(){b.SettingsController.show()}),g.on("click",function(){b.SidebarController.changePanelTo("Notes")}),f.on("click",function(){var a=b.book.getCurrentLocationCfi();b.isBookmarked(a)?(b.removeBookmark(a),f.removeClass("icon-turned_in").addClass("icon-turned_in_not")):(b.addBookmark(a),f.addClass("icon-turned_in").removeClass("icon-turned_in_not"))}),a.on("renderer:locationChanged",function(a){var c="#"+a;b.settings.session.setCursor(a),b.isBookmarked(a)?f.addClass("icon-turned_in").removeClass("icon-turned_in_not"):f.removeClass("icon-turned_in").addClass("icon-turned_in_not"),b.currentLocationCfi=a,b.settings.history&&window.location.hash!=c&&history.pushState({},"",c)}),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.NotesController=function(){var a=this.book,b=this,c=$("#notesView"),d=$("#notes"),e=$("#note-text"),f=$("#note-anchor"),g=$("#next"),h=$("#prev"),i=($("#touch_nav"),b.settings.annotations),j=a.renderer,k=[],l=new EPUBJS.EpubCFI,m=function(){c.addClass("open"),e.focus()},n=function(){c.removeClass("open")};e.on("keydown",function(a){a.stopPropagation()});var o=function(c){var d,g,h,i,j,k=a.renderer.doc;if(k.caretPositionFromPoint?(d=k.caretPositionFromPoint(c.clientX,c.clientY),g=d.offsetNode,h=d.offset):k.caretRangeFromPoint&&(d=k.caretRangeFromPoint(c.clientX,c.clientY),g=d.startContainer,h=d.startOffset),3!==g.nodeType)for(var m=0;m<g.childNodes.length;m++)if(3==g.childNodes[m].nodeType){g=g.childNodes[m];break}h=g.textContent.indexOf(".",h),h===-1?h=g.length:h+=1,i=l.generateCfiFromTextNode(g,h,a.renderer.currentChapter.cfiBase),j=new b.Annotation("annotation",i,e.val()),b.addAnnotation(j),p(j),w(j),e.val(""),f.removeClass("icon-location_off"),f.addClass("icon-room"),e.prop("disabled",!1),a.off("renderer:click",o)},p=function(a){d.append(r(a))},q=function(b){var c=a.renderer.doc.getElementById("note-"+b),d=document.getElementById(b);d&&d.remove(),c&&(c.remove(),x())},r=function(c){var d=document.createElement("li"),e=document.createElement("div"),f=document.createElement("div"),g=document.createElement("span"),h=document.createElement("span"),j=document.createElement("a"),k=document.createElement("div"),l=document.createElement("span"),m=document.createElement("span");return e.textContent=c.body,f.textContent=new Date(c.edited).toUTCString(),d.classList.add("note"),h.classList.add("item-delete","item-control","icon-delete"),g.classList.add("item-edit","item-control","icon-rate_review"),j.classList.add("note-link","icon-link2"),f.classList.add("item-date"),h.setAttribute("title","delete"),g.setAttribute("title","edit"),j.setAttribute("title","context"),d.setAttribute("id",c.id),l.classList.add("item-save","edit-control","hide","icon-check"),m.classList.add("item-cancel","edit-control","hide","icon-close"),l.setAttribute("display","none"),m.setAttribute("display","none"),j.href="#"+c.anchor,j.onclick=function(){return a.gotoCfi(c.anchor),!1},h.onclick=function(){var a=this.parentNode.parentNode.getAttribute("id");b.removeAnnotation(a)},l.onclick=function(){var a=this.parentNode.parentNode.getAttribute("id"),c=i[a],d=this.parentNode.parentNode.firstChild;try{c.body=d.textContent,b.updateAnnotation(c)}catch(a){console.log("Updating annotation failed: "+a)}u(a)},m.onclick=function(){var a=this.parentNode.parentNode.getAttribute("id"),b=this.parentNode.parentNode.firstChild;b.textContent=i[a].body,u(a)},g.onclick=function(){t(this.parentNode.parentNode.getAttribute("id"))},k.appendChild(m),k.appendChild(l),k.appendChild(h),k.appendChild(g),k.appendChild(j),d.appendChild(e),d.appendChild(f),d.appendChild(k),d},s=function(a){var b=a.target,c=b.parentNode.getAttribute("id");27===a.keyCode&&(b.textContent=i[c].body,u(c)),a.stopPropagation()},t=function(a){var b=document.getElementById(a),c=b.firstChild;$(b).find(".item-control").toggleClass("hide"),$(b).find(".edit-control").toggleClass("hide"),c.setAttribute("contenteditable","true"),c.classList.add("editable"),c.addEventListener("keydown",s,!1)},u=function(a){var b=document.getElementById(a),c=b.firstChild;$(b).find(".item-control").toggleClass("hide"),$(b).find(".edit-control").toggleClass("hide"),c.classList.remove("editable"),c.removeAttribute("contenteditable"),c.removeEventListener("keydown",s,!1)},v=function(a){var b,c=d[0].getElementsByTagName("li");for(b=0;b<c.length&&c[b].getAttribute("id")!==a;b++);return b+1},w=function(b){var c=a.renderer.doc,d=document.createElement("span"),e=document.createElement("a");d.classList.add("note-marker","footnotesuperscript","reader_generated"),d.id="note-"+b.id,e.innerHTML=v(b.id)+"[Reader]",d.appendChild(e),l.addMarker(b.anchor,c,d),y(d,b.body),x()},x=function(){for(var b in i)if(i.hasOwnProperty(b)){var c=j.currentChapter,d=l.parse(i[b].anchor);if(d.spinePos===c.spinePos)try{var e=a.renderer.doc.getElementById("note-"+i[b].id);void 0!==e&&(e.innerHTML=v(i[b].id)+"[Reader]")}catch(a){console.log("renumbering of markers failed",i[b].anchor)}}},y=function(a,c){var d=a.id,e=function(){var b,e,i,l,m=j.height,n=j.width,o=225;k[d]||(k[d]=document.createElement("div"),k[d].setAttribute("class","popup"),pop_content=document.createElement("div"),k[d].appendChild(pop_content),pop_content.innerHTML=c,pop_content.setAttribute("class","pop_content"),j.render.document.body.appendChild(k[d]),k[d].addEventListener("mouseover",f,!1),k[d].addEventListener("mouseout",g,!1),j.on("renderer:locationChanged",h,this),j.on("renderer:locationChanged",g,this)),b=k[d],e=a.getBoundingClientRect(),i=e.left,l=e.top,b.classList.add("show"),popRect=b.getBoundingClientRect(),b.style.left=i-popRect.width/2+"px",b.style.top=l+"px",o>m/2.5&&(o=m/2.5,pop_content.style.maxHeight=o+"px"),popRect.height+l>=m-25?(b.style.top=l-popRect.height+"px",b.classList.add("above")):b.classList.remove("above"),i-popRect.width<=0?(b.style.left=i+"px",b.classList.add("left")):b.classList.remove("left"),i+popRect.width/2>=n?(b.style.left=i-300+"px",popRect=b.getBoundingClientRect(),b.style.left=i-popRect.width+"px",popRect.height+l>=m-25?(b.style.top=l-popRect.height+"px",b.classList.add("above")):b.classList.remove("above"),b.classList.add("right")):b.classList.remove("right")},f=function(){k[d].classList.add("on")},g=function(){k[d].classList.remove("on")},h=function(){setTimeout(function(){k[d].classList.remove("show")},100)},i=function(){b.SidebarController.changePanelTo("Notes"),b.SidebarController.show()};a.addEventListener("mouseover",e,!1),a.addEventListener("mouseout",h,!1),a.addEventListener("click",i,!1)};f.on("click",function(b){f[0].classList.contains("icon-room")?(f.removeClass("icon-room"),f.addClass("icon-location_off"),e.prop("disabled",!0),h.hasClass("touch_nav")&&(h.removeClass("touch_nav"),g.removeClass("touch_nav"),h.addClass("restore_touch_nav")),a.on("renderer:click",o)):(e.prop("disabled",!1),f.removeClass("icon-location_off"),f.addClass("icon-room"),h.hasClass("restore_touch_nav")&&(h.removeClass("restore_touch_nav"),h.addClass("touch_nav"),g.addClass("touch_nav")),a.off("renderer:click",o))});for(var z in i)i.hasOwnProperty(z)&&"annotation"===i[z].type&&p(i[z]);return this.on("reader:annotationcreated",function(a){p(a)}),this.on("reader:annotationremoved",function(a){q(a)}),j.registerHook("beforeChapterDisplay",function(a,b){var c=b.currentChapter;for(var d in i)if(i.hasOwnProperty(d)&&"annotation"===i[d].type){var e=l.parse(i[d].anchor);if(e.spinePos===c.spinePos)try{w(i[d])}catch(a){console.log("anchoring failed",i[d].anchor)}}a()},!0),{show:m,hide:n,createItem:r}},EPUBJS.reader.ReaderController=function(a){var b=$("#main"),c=$("#divider"),d=$("#loader"),e=$("#next"),f=$("#prev"),g=$("#sidebarReflow"),h=$("#metainfo"),i=$("#use_custom_colors"),j=($("#container"),$("#fullscreen")),k=$("#bookmark"),l=$("#note"),m=this,a=this.book,n=m.settings,o=function(){if(m.viewerResized){var c=a.getCurrentLocationCfi();m.viewerResized=!1,b.removeClass("single"),b.one("transitionend",function(){a.gotoCfi(c)})}},p=function(){var c=a.getCurrentLocationCfi();m.viewerResized=!0,b.addClass("single"),b.one("transitionend",function(){a.gotoCfi(c)})},q=function(){d.show(),t()},r=function(){d.hide()},s=function(){c.addClass("show")},t=function(){c.removeClass("show")},u=!1,v=function(a){u=!0,a.addClass("active"),setTimeout(function(){u=!1,a.removeClass("active")},100)},w=function(a){var b=!1;switch(n.keyboard[a.keyCode]){case"previous":f.click();break;case"next":e.click();break;case"first":b=1;break;case"last":break;case"annotate":l.click();break;case"bookmark":k.click();break;case"reflow":g.click();break;case"toggleSidebar":m.SidebarController.toggle();break;case"closeSidebar":m.SidebarController.hide();break;case"toggleFullscreen":j.click();break;case"toggleNight":h.click();break;case"toggleDay":i.click();break;default:console.log("unsupported keyCode: "+a.keyCode)}};return document.addEventListener("keydown",w,!1),e.on("click",function(b){"rtl"===a.metadata.direction?a.prevPage():a.nextPage(),v(e),b.preventDefault()}),f.on("click",function(b){"rtl"===a.metadata.direction?a.nextPage():a.prevPage(),v(f),b.preventDefault()}),a.on("renderer:spreads",function(a){a?s():t()}),{slideOut:p,slideIn:o,showLoader:q,hideLoader:r,showDivider:s,hideDivider:t,keyCommands:w}},EPUBJS.reader.SearchController=function(){var a=this,b=this.book,c="",d=$("#searchBox"),e=$("#searchBox").next(),f=$("#clear_search"),g=$("#searchResults"),h=$("#searchView"),i=$("#viewer iframe").contents().find("body"),j=($("#sidebar"),function(){h.addClass("open"),d.focus()}),k=function(){o(),h.removeClass("open")},l=function(b){return void 0===b&&(b=d.val()),""==b?void m():(a.SidebarController.changePanelTo("Search"),g.empty(),g.append("<li><p>Searching...</p></li>"),a.SearchController.query=b,void p(b,g[0]))};d.on("keydown",function(a){e.css("visibility",this.value.length?"visible":"hidden"),13===a.keyCode&&l(),a.stopPropagation()}),e.on("click",function(){$(this).css("visibility","hidden"),d.val("")}),f.on("click",function(){o(),g.empty()});var m=function(){o(),g.empty(),"Search"==a.SidebarController.getActivePanel()&&a.SidebarController.changePanelTo("Toc")},n=function(b){$("#viewer iframe").contents().find("body").highlight(a.SearchController.query,{element:"span"})},o=function(a){i=$("#viewer iframe").contents().find("body"),i.unhighlight(),b.off("renderer:chapterDisplayed",n)},p=function(a,c){return new Promise(function(d,e){for(var f=[],h=0;h<b.spine.length;h++){var i=b.spine[h];f.push(new Promise(function(c,d){new Promise(function(a,c){a(new EPUBJS.Chapter(i,b.store,b.credentials))}).then(function(a){return new Promise(function(b,c){a.load().then(function(){b(a)}).catch(c)})}).then(function(b){return Promise.resolve(b.find(a))}).then(function(a){c(a)})}))}Promise.all(f).then(function(d){return new Promise(function(e,f){e(d);var h=[].concat.apply([],d);c.innerHTML="";for(var i=0;i<h.length;i++)try{var j=document.createElement("li"),k=document.createElement("a");j.classList.add("list_item"),j.id="search-"+i,k.href=h[i].cfi,k.textContent=h[i].excerpt,k.classList.add("toc_link"),k.addEventListener("click",function(c){c.preventDefault(),b.gotoCfi(this.getAttribute("href")),g.find(".list_item").removeClass("currentChapter"),$(this).parent("li").addClass("currentChapter"),$(this).data("query",a),b.on("renderer:chapterDisplayed",n)}),j.appendChild(k),c.appendChild(j)}catch(a){console.warn(a)}})})})};return{show:j,hide:k,search:l,query:c,clear:m,unhighlight:o}},EPUBJS.reader.SettingsController=function(){var a=this,b=(this.book,a.settings),c=$("#settingsView"),d=($("#viewer"),$(".overlay")),e=$("#next"),f=$("#prev"),g=$("#close"),h=$("#sidebarReflow"),i=$("#touch_nav"),j=$("#page_turn_arrows"),k=$("#prev :first-child"),l=$("#next :first-child"),m=function(){c.addClass("open")},n=function(){c.removeClass("open")};return b.sidebarReflow?h.prop("checked",!0):h.prop("checked",!1),h.off("click").on("click",function(){b.sidebarReflow=!b.sidebarReflow,b.sidebarReflow&&a.sidebarOpen&&a.ReaderController.slideOut(),b.sidebarReflow||a.sidebarOpen||a.ReaderController.slideIn(),b.session.setDefault("sidebarReflow",b.sidebarReflow)}),c.find(".closer").on("click",function(){n()}),d.on("click",function(){n()}),parent!==window&&(g.show(),g.on("click",function(){a.book.destroy(),parent.OCA.Epubreader.Plugin.hide()})),i.prop("checked",!("ontouchstart"in document.documentElement)),i.prop("checked")||(e.addClass("touch_nav"),f.addClass("touch_nav")),i.off("change").on("change",function(){$(this).prop("checked")?(f.removeClass("touch_nav"),e.removeClass("touch_nav")):(f.addClass("touch_nav"),e.addClass("touch_nav"))}),b.pageArrows?(j.prop("checked",!0),k.removeClass("translucent"),l.removeClass("translucent")):(j.prop("checked",!1),k.addClass("translucent"),l.addClass("translucent")),j.off("change").on("change",function(){$(this).prop("checked")?(b.pageArrows=!0,k.removeClass("translucent"),l.removeClass("translucent")):(b.pageArrows=!1,k.addClass("translucent"),l.addClass("translucent")),b.session.setDefault("pageArrows",b.pageArrows)}),{show:m,hide:n}},EPUBJS.reader.SidebarController=function(a){var b=this,c=b.settings,d=$("#sidebar"),e=$("#panels"),f=$("#views"),g=$("#hide-Sidebar");$slider=$("#slider");var h="Toc",i=function(a){var c=a+"Controller";h!=a&&"undefined"!=typeof b[c]&&(b[h+"Controller"].hide(),b[c].show(),h=a,d.find(".open").removeClass("open"),e.find("#show-"+a).addClass("open"),f.find("#"+a.toLowerCase()+"View").addClass("open")),k()},j=function(){return h},k=function(){b.sidebarOpen=!0,c.sidebarReflow&&b.ReaderController.slideOut(),$slider.hide(),d.addClass("open")},l=function(){b.sidebarOpen=!1,$slider.show(),b.ReaderController.slideIn(),d.removeClass("open"),b.SearchController.unhighlight()},m=function(){b.sidebarOpen?l():k()};return g.on("click",function(){b.SidebarController.hide()}),e.find(".show_view").on("click",function(a){var b=$(this).data("view");i(b),a.preventDefault()}),{show:k,hide:l,toggle:m,getActivePanel:j,changePanelTo:i}},EPUBJS.reader.StylesController=function(a){var b=this,c=(this.book,b.settings),d=b.settings.customStyles,e=b.settings.activeStyles,f=$("#viewer"),g=$("#day_example"),h=$("#night_example"),i=$("#font_example"),j=$("#page_width"),k=$("#day_background"),l=$("#day_color"),m=$("#night_background"),n=$("#night_color"),o=$("#use_custom_colors"),p=$(".nightshift"),q=$("#custom_font_family"),r=$("#font_family"),s=$("#custom_font_size"),t=$("#font_size"),u=$("#custom_font_weight"),v=$("#font_weight"),w=$("#maximize_page");a.registerHook("beforeChapterDisplay",this.refreshStyles.bind(this),!0),this.addStyle("dayMode","*",{color:l.val(),background:k.val()}),this.addStyle("nightMode","*",{color:n.val(),background:m.val()}),this.addStyle("fontFamily","*",{"font-family":r.val()}),this.addStyle("fontSize","*",{"font-size":t.val()+"%"}),this.addStyle("fontWeight","*",{"font-weight":v.val()}),this.addStyle("pageWidth","#viewer",{"max-width":j.val()+"em"}),this.addStyle("maximizePage","#viewer",{margin:"auto",width:"100%",height:"95%",top:"5%"}),this.addStyle("appleBugs","document, html, body, p, span, div",{cursor:"pointer"}),g.css({background:d.dayMode.rules.background,color:d.dayMode.rules.color}),h.css({background:d.nightMode.rules.background,color:d.nightMode.rules.color}),i.css({"font-size":d.fontSize.rules["font-size"],"font-family":d.fontFamily.rules["font-family"],"font-weight":d.fontWeight.rules["font-weight"]}),r.val(d.fontFamily.rules["font-family"]),t.val(parseInt(d.fontSize.rules["font-size"])),v.val(d.fontWeight.rules["font-weight"]),j.val(parseInt(0+parseInt(d.pageWidth.rules["max-width"]))),navigator.userAgent.match(/(iPad|iPhone|iPod)/g)&&(e.appleBugs=!0);for(var x in e)if(e.hasOwnProperty(x)){switch(x){case"dayMode":o.prop("checked",!0);break;case"fontFamily":q.prop("checked",!0),r.prop("disabled",!1);break;case"fontSize":s.prop("checked",!0),t.prop("disabled",!1);break;case"fontWeight":u.prop("checked",!0),v.prop("disabled",!1);break;case"maximizePage":w.prop("checked",!0);break;case"appleBugs":console.log("Apple mobile bugs detected, applying workarounds...")}b.enableStyle(d[x])}return k.off("change").on("change",function(){d.dayMode.rules.background=k.val(),g.css("background",d.dayMode.rules.background),b.updateStyle(d.dayMode)}),l.off("change").on("change",function(){d.dayMode.rules.color=l.val(),g.css("color",d.dayMode.rules.color),b.updateStyle(d.dayMode)}),m.off("change").on("change",function(){d.nightMode.rules.background=m.val(),h.css("background",d.nightMode.rules.background),b.updateStyle(d.nightMode)}),n.off("change").on("change",function(){d.nightMode.rules.color=n.val(),h.css("color",d.nightMode.rules.color),b.updateStyle(d.nightMode)}),o.off("change").on("change",function(){$(this).prop("checked")?b.enableStyle(d.dayMode):b.disableStyle(d.dayMode)}),p.off("click").on("click",function(){c.nightMode?(b.disableStyle(d.nightMode),c.nightMode=!1):(b.enableStyle(d.nightMode),c.nightMode=!0)}),j.off("change").on("change",function(){d.pageWidth.rules["page-width"]=$(this).val()+"em",b.updateStyle(d.pageWidth),f.css("max-width",d.pageWidth.rules["page-width"])}),q.off("click").on("click",function(){$(this).prop("checked")?(r.prop("disabled",!1),b.enableStyle(d.fontFamily)):(r.prop("disabled",!0),b.disableStyle(d.fontFamily))}),s.off("click").on("click",function(){$(this).prop("checked")?(t.prop("disabled",!1),b.enableStyle(d.fontSize)):(t.prop("disabled",!0),b.disableStyle(d.fontSize))}),u.off("click").on("click",function(){$(this).prop("checked")?(v.prop("disabled",!1),b.enableStyle(d.fontWeight)):(v.prop("disabled",!0),b.disableStyle(d.fontWeight))}),w.off("click").on("click",function(){$(this).prop("checked")?b.enableStyle(d.maximizePage):b.disableStyle(d.maximizePage)}),t.off("change").on("change",function(){i.css("font-size",$(this).val()+"%"),d.fontSize.rules["font-size"]=$(this).val()+"%",b.updateStyle(d.fontSize)}),v.off("change").on("change",function(){d.fontWeight.rules["font-weight"]=$(this).val(),i.css("font-weight",$(this).val()),b.updateStyle(d.fontWeight)}),r.off("change").on("change",function(){d.fontFamily.rules["font-family"]=$(this).val(),i.css("font-family",$(this).val()),b.updateStyle(d.fontFamily)}),j.off("change").on("change",function(){d.pageWidth.rules["page-width"]=$(this).val()+"em",b.updateStyle(d.pageWidth),f.css("max-width",d.pageWidth.rules["page-width"])}),{}},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.addClass("open")},h=function(){c.removeClass("open")},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}};