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;bm/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("
  • Searching...

  • "),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;h0&&(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}};