1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00
epub.js/demo/js/reader.min.js

1 line
No EOL
7.7 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){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),EPUBJS.Reader=function(a,b){var c,d=this;this.settings=_.defaults(b||{},{restore:!0,bookmarks:null}),this.setBookKey(a),this.settings.restore&&this.isSaved()&&this.applySavedSettings(),this.book=c=new EPUBJS.Book({bookPath:a,restore:this.settings.restore,previousLocationCfi:this.settings.previousLocationCfi}),this.offline=!1,this.sidebarOpen=!1,this.settings.bookmarks||(this.settings.bookmarks=[]),c.renderTo("viewer"),d.ReaderController=EPUBJS.reader.ReaderController.call(d,c),d.SettingsController=EPUBJS.reader.SettingsController.call(d,c),d.ControlsController=EPUBJS.reader.ControlsController.call(d,c),d.SidebarController=EPUBJS.reader.SidebarController.call(d,c),d.BookmarksController=EPUBJS.reader.BookmarksController.call(d,c);for(var e in EPUBJS.reader.plugins)EPUBJS.reader.plugins.hasOwnProperty(e)&&(d[e]=EPUBJS.reader.plugins[e].call(d,c));return c.ready.all.then(function(){d.ReaderController.hideLoader()}),c.getMetadata().then(function(a){d.MetaController=EPUBJS.reader.MetaController.call(d,a)}),c.getToc().then(function(a){d.TocController=EPUBJS.reader.TocController.call(d,a)}),window.addEventListener("beforeunload",this.unload.bind(this),!1),this},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]},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=function(b){var c=document.createElement("li"),d=document.createElement("a");return 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),c};return this.settings.bookmarks.forEach(function(a){var b=g(a);d.appendChild(b)}),c.append(d),this.on("reader:bookmarked",function(a){var b=g(a);c.append(b)}),{show:e,hide:f}},EPUBJS.reader.ControlsController=function(a){var b=this,c=($("#store"),$("#fullscreen")),d=$("#fullscreenicon"),e=$("#cancelfullscreenicon"),f=$("#slider"),g=($("#main"),$("#sidebar"),$("#setting")),h=$("#bookmark"),i=function(){b.offline=!1},j=function(){b.offline=!0};return a.on("book:online",i),a.on("book:offline",j),f.on("click",function(){b.sidebarOpen?(b.SidebarController.hide(),f.addClass("icon-menu"),f.removeClass("icon-right")):(b.SidebarController.show(),f.addClass("icon-right"),f.removeClass("icon-menu"))}),c.on("click",function(){screenfull.toggle($("#container")[0]),d.toggle(),e.toggle()}),g.on("click",function(){b.SettingsController.show()}),h.on("click",function(){h.addClass("icon-bookmark"),h.removeClass("icon-bookmark-empty"),b.addBookmark(b.book.getCurrentLocationCfi())}),a.on("renderer:pageChanged",function(a){var c=b.isBookmarked(a);-1===c?h.removeClass("icon-bookmark").addClass("icon-bookmark-empty"):h.addClass("icon-bookmark").removeClass("icon-bookmark-empty")}),{}},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=function(){b.removeClass("closed")},h=function(){b.addClass("closed")},i=function(){d.show(),l()},j=function(){d.hide(),a.single||k()},k=function(){c.addClass("show")},l=function(){c.removeClass("show")},m=!1,n=function(b){37==b.keyCode&&(a.prevPage(),f.addClass("active"),m=!0,setTimeout(function(){m=!1,f.removeClass("active")},100),b.preventDefault()),39==b.keyCode&&(a.nextPage(),e.addClass("active"),m=!0,setTimeout(function(){m=!1,e.removeClass("active")},100),b.preventDefault())};return document.addEventListener("keydown",n,!1),e.on("click",function(b){a.nextPage(),b.preventDefault()}),f.on("click",function(b){a.prevPage(),b.preventDefault()}),{slideOut:h,slideIn:g,showLoader:i,hideLoader:j,showDivider:k,hideDivider:l}},EPUBJS.reader.SettingsController=function(){this.book;var a=$("#settings-modal"),b=$(".overlay"),c=function(){a.addClass("md-show")},d=function(){a.removeClass("md-show")};return a.find(".closer").on("click",function(){d()}),b.on("click",function(){d()}),{show:c,hide:d}},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&&(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}};