openmedialibrary/static/epub.js/epub.min.js

4 lines
78 KiB
JavaScript
Raw Normal View History

2014-05-17 15:45:43 +00:00
(function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.push,h=d.slice,i=d.concat,j=e.toString,k=e.hasOwnProperty,l=d.forEach,m=d.map,n=d.reduce,o=d.reduceRight,p=d.filter,q=d.every,r=d.some,s=d.indexOf,t=d.lastIndexOf,u=Array.isArray,v=Object.keys,w=f.bind,x=function(a){return a instanceof x?a:this instanceof x?void(this._wrapped=a):new x(a)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=x),exports._=x):a._=x,x.VERSION="1.4.4";var y=x.each=x.forEach=function(a,b,d){if(null!=a)if(l&&a.forEach===l)a.forEach(b,d);else if(a.length===+a.length){for(var e=0,f=a.length;f>e;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(x.has(a,g)&&b.call(d,a[g],g,a)===c)return};x.map=x.collect=function(a,b,c){var d=[];return null==a?d:m&&a.map===m?a.map(b,c):(y(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)};var z="Reduce of empty array with no initial value";x.reduce=x.foldl=x.inject=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),n&&a.reduce===n)return d&&(b=x.bind(b,d)),e?a.reduce(b,c):a.reduce(b);if(y(a,function(a,f,g){e?c=b.call(d,c,a,f,g):(c=a,e=!0)}),!e)throw new TypeError(z);return c},x.reduceRight=x.foldr=function(a,b,c,d){var e=arguments.length>2;if(null==a&&(a=[]),o&&a.reduceRight===o)return d&&(b=x.bind(b,d)),e?a.reduceRight(b,c):a.reduceRight(b);var f=a.length;if(f!==+f){var g=x.keys(a);f=g.length}if(y(a,function(h,i,j){i=g?g[--f]:--f,e?c=b.call(d,c,a[i],i,j):(c=a[i],e=!0)}),!e)throw new TypeError(z);return c},x.find=x.detect=function(a,b,c){var d;return A(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,!0):void 0}),d},x.filter=x.select=function(a,b,c){var d=[];return null==a?d:p&&a.filter===p?a.filter(b,c):(y(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},x.reject=function(a,b,c){return x.filter(a,function(a,d,e){return!b.call(c,a,d,e)},c)},x.every=x.all=function(a,b,d){b||(b=x.identity);var e=!0;return null==a?e:q&&a.every===q?a.every(b,d):(y(a,function(a,f,g){return(e=e&&b.call(d,a,f,g))?void 0:c}),!!e)};var A=x.some=x.any=function(a,b,d){b||(b=x.identity);var e=!1;return null==a?e:r&&a.some===r?a.some(b,d):(y(a,function(a,f,g){return e||(e=b.call(d,a,f,g))?c:void 0}),!!e)};x.contains=x.include=function(a,b){return null==a?!1:s&&a.indexOf===s?-1!=a.indexOf(b):A(a,function(a){return a===b})},x.invoke=function(a,b){var c=h.call(arguments,2),d=x.isFunction(b);return x.map(a,function(a){return(d?b:a[b]).apply(a,c)})},x.pluck=function(a,b){return x.map(a,function(a){return a[b]})},x.where=function(a,b,c){return x.isEmpty(b)?c?null:[]:x[c?"find":"filter"](a,function(a){for(var c in b)if(b[c]!==a[c])return!1;return!0})},x.findWhere=function(a,b){return x.where(a,b,!0)},x.max=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.max.apply(Math,a);if(!b&&x.isEmpty(a))return-1/0;var d={computed:-1/0,value:-1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},x.min=function(a,b,c){if(!b&&x.isArray(a)&&a[0]===+a[0]&&65535>a.length)return Math.min.apply(Math,a);if(!b&&x.isEmpty(a))return 1/0;var d={computed:1/0,value:1/0};return y(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;d.computed>g&&(d={value:a,computed:g})}),d.value},x.shuffle=function(a){var b,c=0,d=[];return y(a,function(a){b=x.random(c++),d[c-1]=d[b],d[b]=a}),d};var B=function(a){return x.isFunction(a)?a:function(b){return b[a]}};x.sortBy=function(a,b,c){var d=B(b);return x.pluck(x.map(a,function(a,b,e){return{value:a,index:b,criteria:d.call(c,a,b,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index<b.index?-1:1}),"value")};var C=function(a,b,c,d){var e={},f=B(b||x.identity);return y(a,function(b,g){var h=f.call(c,b,g,a);d(e,h,b)}),e};x.groupBy=function(a,b,c){return C(a,b,c,function(a,b,c){(x.has(a,b)?a[b]:a[b]=[]).push(c)})},x.countBy=function(a,b,c){return C(a,b,c,function(a,b){x.has(a,b)||(a[b]=0),a[b]++})},x.sortedIndex=function(a,b,c,d){c=null==c?x.identity:B(c);for(var e=c.call(d,b),f=0
return h.length&&(b=h[0].href),c.protocol?c.origin+c.path:!d&&e?(b||g)+c.path:d||e?void 0:EPUBJS.core.resolveUrl(b||f.pathname,c.path)},EPUBJS.Book.prototype.unarchive=function(a){return this.zip=new EPUBJS.Unarchiver,this.store=this.zip,this.zip.openZip(a)},EPUBJS.Book.prototype.isContained=function(a){var b=EPUBJS.core.uri(a);return!b.extension||"epub"!=b.extension&&"zip"!=b.extension?!1:!0},EPUBJS.Book.prototype.isSaved=function(a){var b;return localStorage?(b=localStorage.getItem(a),localStorage&&null!==b?!0:!1):!1},EPUBJS.Book.prototype.generateBookKey=function(a){return"epubjs:"+EPUBJS.VERSION+":"+window.location.host+":"+a},EPUBJS.Book.prototype.saveContents=function(){return localStorage?void localStorage.setItem(this.settings.bookKey,JSON.stringify(this.contents)):!1},EPUBJS.Book.prototype.removeSavedContents=function(){return localStorage?void localStorage.removeItem(this.settings.bookKey):!1},EPUBJS.Book.prototype.renderTo=function(a){var b,c=this;if(_.isElement(a))this.element=a;else{if("string"!=typeof a)return void console.error("Not an Element");this.element=EPUBJS.core.getEl(a)}return b=this.opened.then(function(){return c.renderer.initialize(c.element,c.settings.width,c.settings.height),c._rendered(),c.startDisplay()})},EPUBJS.Book.prototype.startDisplay=function(){var a;return a=this.settings.goto?this.goto(this.settings.goto):this.settings.previousLocationCfi?this.gotoCfi(this.settings.previousLocationCfi):this.displayChapter(this.spinePos)},EPUBJS.Book.prototype.restore=function(a){var b,c=this,d=["manifest","spine","metadata","cover","toc","spineNodeIndex","spineIndexByURL","globalLayoutProperties"],e=!1,f=this.generateBookKey(a),g=localStorage.getItem(f),h=d.length;if(this.settings.clearSaved&&(e=!0),!e&&"undefined"!=g&&null!==g)for(c.contents=JSON.parse(g),b=0;h>b;b++){var i=d[b];if(!c.contents[i]){e=!0;break}c[i]=c.contents[i]}return!e&&g&&this.contents&&this.settings.contentsPath?(this.settings.bookKey=f,this.ready.manifest.resolve(this.manifest),this.ready.spine.resolve(this.spine),this.ready.metadata.resolve(this.metadata),this.ready.cover.resolve(this.cover),this.ready.toc.resolve(this.toc),!0):!1},EPUBJS.Book.prototype.displayChapter=function(a,b,c){var d,e,f,g=this,h=c||new RSVP.defer;return this.isRendered?this._rendering?(this._displayQ.enqueue("displayChapter",[a,b,h]),h.promise):(_.isNumber(a)?f=a:(e=new EPUBJS.EpubCFI(a),f=e.spinePos),(0>f||f>=this.spine.length)&&(console.warn("Not A Valid Location"),f=0,b=!1,e=!1),this.spinePos=f,this.currentChapter=new EPUBJS.Chapter(this.spine[f],this.store),this._rendering=!0,d=g.renderer.displayChapter(this.currentChapter,this.globalLayoutProperties),d.then(e?function(a){a.gotoCfi(e),h.resolve(g.renderer)}:b?function(a){a.lastPage(),h.resolve(g.renderer)}:function(){h.resolve(g.renderer)}),this.settings.fromStorage||this.settings.contained||d.then(function(){g.preloadNextChapter()}),d.then(function(){g._rendering=!1,g._displayQ.dequeue()}),h.promise):(this._q.enqueue("displayChapter",arguments),h.reject({message:"Rendering",stack:(new Error).stack}),h.promise)},EPUBJS.Book.prototype.nextPage=function(){var a;return this.isRendered?(a=this.renderer.nextPage(),a?void 0:this.nextChapter()):this._q.enqueue("nextPage",arguments)},EPUBJS.Book.prototype.prevPage=function(){var a;return this.isRendered?(a=this.renderer.prevPage(),a?void 0:this.prevChapter()):this._q.enqueue("prevPage",arguments)},EPUBJS.Book.prototype.nextChapter=function(){if(this.spinePos<this.spine.length-1){for(var a=this.spinePos+1;this.spine[a]&&this.spine[a].linear&&"no"==this.spine[a].linear;)a++;if(a<this.spine.length-1)return this.spinePos=a,this.displayChapter(this.spinePos);this.trigger("book:atEnd")}else this.trigger("book:atEnd")},EPUBJS.Book.prototype.prevChapter=function(){if(this.spinePos>0){for(var a=this.spinePos-1;this.spine[a]&&this.spine[a].linear&&"no"==this.spine[a].linear;)a--;if(a>=0)return this.spinePos=a,this.displayChapter(this.spinePos,!0);this.trigger("book:atStart")}else this.trigger("book:atStart")},EPUBJS.Book.prototype.getCurrentLocationCfi=function(){re
},EPUBJS.Render.Iframe.prototype.resized=function(){this.width=this.iframe.getBoundingClientRect().width,this.height=this.iframe.getBoundingClientRect().height},EPUBJS.Render.Iframe.prototype.totalWidth=function(){return this.docEl.scrollWidth},EPUBJS.Render.Iframe.prototype.totalHeight=function(){return this.docEl.scrollHeight},EPUBJS.Render.Iframe.prototype.setPageDimensions=function(a,b){this.pageWidth=a,this.pageHeight=b},EPUBJS.Render.Iframe.prototype.setLeft=function(a){this.document.defaultView.scrollTo(a,0)},EPUBJS.Render.Iframe.prototype.setStyle=function(a,b,c){c&&(a=EPUBJS.core.prefixed(a)),this.bodyEl&&(this.bodyEl.style[a]=b)},EPUBJS.Render.Iframe.prototype.removeStyle=function(a){this.bodyEl&&(this.bodyEl.style[a]="")},EPUBJS.Render.Iframe.prototype.addHeadTag=function(a,b){var c=document.createElement(a);for(var d in b)c[d]=b[d];this.headEl&&this.headEl.appendChild(c)},EPUBJS.Render.Iframe.prototype.page=function(a){this.leftPos=this.pageWidth*(a-1),this.setLeft(this.leftPos)},EPUBJS.Render.Iframe.prototype.getPageNumberByElement=function(a){var b,c;if(a)return b=this.leftPos+a.getBoundingClientRect().left,c=Math.floor(b/this.pageWidth)+1},EPUBJS.Render.Iframe.prototype.getBaseElement=function(){return this.bodyEl},EPUBJS.Render.Iframe.prototype.isElementVisible=function(a){var b,c;return a&&"function"==typeof a.getBoundingClientRect&&(b=a.getBoundingClientRect(),c=b.left,0!==b.width&&0!==b.height&&c>=0&&c<this.pageWidth)?!0:!1},EPUBJS.Render.Iframe.prototype.scroll=function(a){this.iframe.scrolling=a?"yes":"no"},EPUBJS.Render.Iframe.prototype.unload=function(){this.window.removeEventListener("resize",this.resized)},RSVP.EventTarget.mixin(EPUBJS.Render.Iframe.prototype),EPUBJS.Renderer=function(a){this.listenedEvents=["keydown","keyup","keypressed","mouseup","mousedown","click"],a&&"undefined"!=typeof EPUBJS.Render[a]?this.render=new EPUBJS.Render[a]:console.error("Not a Valid Rendering Method"),this.render.on("render:loaded",this.loaded.bind(this)),this.caches={},this.epubcfi=new EPUBJS.EpubCFI,this.spreads=!0,this.isForcedSingle=!1,this.resized=_.throttle(this.onResized.bind(this),10),this.layoutSettings={},EPUBJS.Hooks.mixin(this),this.getHooks("beforeChapterDisplay")},EPUBJS.Renderer.prototype.Events=["renderer:keydown","renderer:keyup","renderer:keypressed","renderer:mouseup","renderer:mousedown","renderer:click","renderer:selected","renderer:chapterUnloaded","renderer:chapterDisplayed","renderer:locationChanged","renderer:resized","renderer:spreads"],EPUBJS.Renderer.prototype.initialize=function(a,b,c){this.container=a,this.element=this.render.create(),this.initWidth=b,this.initHeight=c,this.width=b||this.container.clientWidth,this.height=c||this.container.clientHeight,this.container.appendChild(this.element),b&&c?this.render.resize(this.width,this.height):this.render.resize("100%","100%")},EPUBJS.Renderer.prototype.displayChapter=function(a,b){var c=this;return this.currentChapter&&(this.currentChapter.unload(),this.render.window.removeEventListener("resize",this.resized),this.removeEventListeners(),this.removeSelectionListeners(),this.trigger("renderer:chapterUnloaded")),this.currentChapter=a,this.chapterPos=1,this.currentChapterCfiBase=a.cfiBase,this.layoutSettings=this.reconcileLayoutSettings(b,a.properties),a.url().then(function(a){return c.load(a)})},EPUBJS.Renderer.prototype.load=function(a){var b=new RSVP.defer;return this.layoutMethod=this.determineLayout(this.layoutSettings),this.layout=new EPUBJS.Layout[this.layoutMethod],this.visible(!1),render=this.render.load(a),render.then(function(a){var c;this.contents=a,this.doc=this.render.document,c=this.layout.format(a,this.render.width,this.render.height),this.render.setPageDimensions(c.pageWidth,c.pageHeight),this.initWidth||this.initHeight||this.render.window.addEventListener("resize",this.resized,!1),this.addEventListeners(),this.addSelectionListeners(),this.beforeDisplay(function(){var a=this.layout.calculatePages(),c=this.currentChapter;this.updatePages(a),c.cfi=this.currentLocationCfi=this.getPageCfi(),this.trigger("renderer:chapterDispla
//# sourceMappingURL=epub.min.map