@tindtechnologies/universalviewer
Version:
The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎
2 lines (1 loc) • 7.79 kB
JavaScript
import{a as F,e as T,g as R}from"./chunk-BIWUBEGG.js";import{a as V,c as P}from"./chunk-UYLDA6E6.js";import{c as y,e as L,f as I,g as E,n as g,p as o}from"./chunk-2YE6NNA6.js";import{c as f}from"./chunk-YAXTLTJC.js";var b=f(V());var n=window.$,v=class extends F{constructor(e){super(e,!0,!0);this.isCreated=!1;this.isOpen=!1}create(){super.create(),this.extensionHost.subscribe(o.CANVAS_INDEX_CHANGE,t=>{this.selectIndex(parseInt(t))}),this.extensionHost.subscribe(o.LOGIN,()=>{this.loadThumbs()}),this.extensionHost.subscribe(o.CLICKTHROUGH,()=>{this.loadThumbs()}),this.$thumbs=n('<div class="thumbs"></div>'),this.$element.append(this.$thumbs);let e=this.extension.helper.getViewingDirection()||b.ViewingDirection.LEFT_TO_RIGHT;this.$thumbs.addClass(e);let s=this;n.templates({thumbsTemplate:'<a id="thumb{{>index}}" class="{{:~className()}}" data-src="{{>uri}}" data-visible="{{>visible}}" data-index="{{>index}}" tabindex="0"> <div class="wrap" style="height:{{>height + ~extraHeight()}}px"></div> <div class="info"> <span class="index">{{:#index + 1}}</span> <span class="label" title="{{>label}}">{{>label}} </span> <span class="searchResults" title="{{:~searchResultsTitle()}}">{{>data.searchResults}}</span> </div> </a> {{if ~separator()}} <div class="separator"></div> {{/if}}'});let h=this.options.thumbsExtraHeight;n.views.helpers({separator:function(){return!1},extraHeight:function(){return h},className:function(){let t="thumb";this.data.index===0&&(t+=" first"),this.data.uri||(t+=" placeholder");let i=s.extension.helper.getViewingDirection();return i&&(i===b.ViewingDirection.LEFT_TO_RIGHT||i===b.ViewingDirection.RIGHT_TO_LEFT)||s.extension.helper.isPaged()?t+=" twoCol":t+=" oneCol",t},searchResultsTitle:function(){let t=Number(this.data.data.searchResults);return t?t>1?g.format(s.content.searchResults,t.toString()):g.format(s.content.searchResult,t.toString()):""}}),this.$element.on("scroll",()=>{this.scrollStop()},100),this.resize()}databind(){!this.thumbs||(this._$thumbsCache=null,this.createThumbs(),this.loadThumbs(0),this.selectIndex(this.extension.helper.canvasIndex))}createThumbs(){let e=this;if(!this.thumbs)return;let s=[];for(let t=0;t<this.thumbs.length;t++){let i=this.thumbs[t];s.push(i.height)}let h=E.median(s);for(let t=0;t<this.thumbs.length;t++){let i=this.thumbs[t];i.height=h}this.$thumbs.link(n.templates.thumbsTemplate,this.thumbs),this.$thumbs.undelegate(".thumb","click"),this.$thumbs.delegate(".thumb","click",function(t){t.preventDefault();let i=n.view(this).data;return e.lastThumbClickedIndex=i.index,e.extensionHost.publish(o.THUMB_SELECTED,i),!1}),this.$thumbs.delegate(".thumb","keydown",function(t){let i=t.originalEvent,r=I.getCharCode(i);if(r===T.Spacebar||r===T.Enter){t.preventDefault();let l=n.view(this).data;e.lastThumbClickedIndex=l.index,e.extensionHost.publish(o.THUMB_SELECTED,l)}}),this.setLabel(),this.isCreated=!0}scrollStop(){let e=1/((this.$thumbs.height()-this.$element.height())/this.$element.scrollTop());e>1&&(e=1);let s=Math.floor((this.thumbs.length-1)*e);this.loadThumbs(s)}loadThumbs(e=this.extension.helper.canvasIndex){if(!this.thumbs||!this.thumbs.length)return;let s,t=this.extension.helper.getCanvasByIndex(e).getContent();if(t.length){let u=t[0].getBody();if(u.length){let a=u[0].getType();a&&(s=a.toString().toLowerCase())}}let i=e,r=this.options.thumbsLoadRange,l={start:i>r?i-r:0,end:i<this.thumbs.length-1-r?i+r:this.thumbs.length-1},H=this.options.thumbsImageFadeInDuration,p=this;for(let m=l.start;m<=l.end;m++){let u=this.getThumbByIndex(m),a=u.find(".wrap");if(!a.hasClass("loading")&&!a.hasClass("loaded"))if(u.attr("data-visible")!=="false"){a.removeClass("loadingFailed"),a.addClass("loading"),s&&a.addClass(s);let C=u.attr("data-src");p.config.options.thumbsCacheInvalidation&&p.config.options.thumbsCacheInvalidation.enabled&&(C+=`${p.config.options.thumbsCacheInvalidation.paramType}t=${y.getTimeStamp()}`);let c=n('<img src="'+C+'" alt=""/>');c.hide(),c.on("load",function(){n(this).fadeIn(H,function(){n(this).parent().switchClass("loading","loaded")})}),c.on("error",function(){n(this).parent().switchClass("loading","loadingFailed")}),a.append(c)}else a.hide()}}show(){this.isOpen=!0,this.$element.show(),setTimeout(()=>{this.selectIndex(this.extension.helper.canvasIndex)},1)}hide(){this.isOpen=!1,this.$element.hide()}isPDF(){let s=this.extension.helper.getCurrentCanvas().getType();return s?s.toString().includes("pdf"):!1}setLabel(){n(this.$thumbs).find("span.index").hide(),n(this.$thumbs).find("span.label").show()}addSelectedClassToThumbs(e){this.getThumbByIndex(e).addClass("selected")}selectIndex(e){if(e===-1||!this.thumbs||!this.thumbs.length)return;this.getAllThumbs().removeClass("selected"),this.$selectedThumb=this.getThumbByIndex(e),this.addSelectedClassToThumbs(e),~this.extension.getPagedIndices(e).indexOf(this.lastThumbClickedIndex)||this.$element.scrollTop(this.$selectedThumb.position().top),this.loadThumbs(e)}getAllThumbs(){return this._$thumbsCache||(this._$thumbsCache=this.$thumbs.find(".thumb")),this._$thumbsCache}getThumbByIndex(e){return this.$thumbs.find('[data-index="'+e+'"]')}scrollToThumb(e){let s=this.getThumbByIndex(e);this.$element.scrollTop(s.position().top)}resize(){super.resize()}};var x=class extends v{create(){this.setConfig("resourcesLeftPanel"),super.create()}};var w=f(V());var _=f(P()),d=window.$,S=class extends R{constructor(e){super(e)}create(){this.setConfig("resourcesLeftPanel"),super.create(),this.setTitle(this.content.title),this.$tabsContent=d('<div class="tabsContent"></div>'),this.$main.append(this.$tabsContent),this.$views=d('<div class="views"></div>'),this.$tabsContent.append(this.$views),this.$thumbsView=d('<div class="thumbsView"></div>'),this.$views.append(this.$thumbsView),this.$resourcesView=d('<div class="resourcesView"></div>'),this.$resources=d("<ul></ul>"),this.$resourcesView.append(this.$resources),this.$views.append(this.$resourcesView),this.thumbsView=new x(this.$thumbsView),this.dataBind()}dataBind(){this.dataBindThumbsView();let e=this.extension.helper.getCurrentCanvas().getResources();e.length===0&&this.$resourcesView.hide();for(let s=0;s<e.length;s++){let t=e[s].getResource();if(t){let i=_.LanguageMap.getValue(t.getLabel());if(i){let r=L.simplifyMimeType(t.getFormat().toString()),l=d('<li><a href="'+t.id+'" target="_blank">'+i+" ("+r+")</li>");this.$resources.append(l)}}}}dataBindThumbsView(){if(!this.thumbsView)return;let e,s,h=this.extension.helper.getViewingDirection();h&&(h===w.ViewingDirection.LEFT_TO_RIGHT||h===w.ViewingDirection.RIGHT_TO_LEFT)?(e=this.config.options.twoColThumbWidth,s=this.config.options.twoColThumbHeight):(e=this.config.options.oneColThumbWidth,s=this.config.options.oneColThumbHeight),typeof e=="undefined"&&(e=100),typeof s=="undefined"&&(s=100),this.thumbsView.thumbs=this.extension.helper.getThumbs(e,s),this.thumbsView.thumbs.length<2&&this.$thumbsView.hide(),this.thumbsView.databind()}expandFullStart(){super.expandFullStart(),this.extensionHost.publish(o.LEFTPANEL_EXPAND_FULL_START)}expandFullFinish(){super.expandFullFinish(),this.extensionHost.publish(o.LEFTPANEL_EXPAND_FULL_FINISH)}collapseFullStart(){super.collapseFullStart(),this.extensionHost.publish(o.LEFTPANEL_COLLAPSE_FULL_START)}collapseFullFinish(){super.collapseFullFinish(),this.extensionHost.publish(o.LEFTPANEL_COLLAPSE_FULL_FINISH)}resize(){super.resize(),this.$views.height(this.$main.height()),this.$resources.height(this.$main.height())}};export{S as a};