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/public/epubjs/reader.min.js

1 line
29 KiB
JavaScript
Raw Permalink Normal View History

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.se