@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.64 kB
JavaScript
import{a as V,f as _}from"./chunk-PYNED64U.js";import{a as F,c as D}from"./chunk-J6QTJS4P.js";import{a as h}from"./chunk-M4MN2QTO.js";import{d as y,g as L,h as I,i as E,o as $}from"./chunk-IRIM6TPQ.js";import{d as v}from"./chunk-L67DAW3A.js";var p=v(F());var o=window.$,g=class extends V{constructor(e){super(e,!0,!0);this.isCreated=!1;this.isOpen=!1}create(){super.create(),this.extensionHost.subscribe(h.CANVAS_INDEX_CHANGE,t=>{this.selectIndex(parseInt(t))}),this.extensionHost.subscribe(h.LOGIN,()=>{this.loadThumbs()}),this.extensionHost.subscribe(h.CLICKTHROUGH,()=>{this.loadThumbs()}),this.$thumbs=o('<div class="thumbs"></div>'),this.$element.append(this.$thumbs);let e=this.extension.helper.getViewingDirection()||p.ViewingDirection.LEFT_TO_RIGHT;this.$thumbs.addClass(e);let s=this;o.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}}" style="white-space: normal;">{{>label}} </span> <span class="searchResults" title="{{:~searchResultsTitle()}}">{{>data.searchResults}}</span> </div> </a> {{if ~separator()}} <div class="separator"></div> {{/if}}'});let r=this.options.thumbsExtraHeight;o.views.helpers({separator:function(){return!1},extraHeight:function(){return r},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===p.ViewingDirection.LEFT_TO_RIGHT||i===p.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?$.format(s.content.searchResults,t.toString()):$.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 r=E.median(s);for(let t=0;t<this.thumbs.length;t++){let i=this.thumbs[t];i.height=r}this.$thumbs.link(o.templates.thumbsTemplate,this.thumbs),this.$thumbs.undelegate(".thumb","click"),this.$thumbs.delegate(".thumb","click",function(t){t.preventDefault();let i=o.view(this).data;return e.lastThumbClickedIndex=i.index,e.extensionHost.publish(h.THUMB_SELECTED,i),!1}),this.$thumbs.delegate(".thumb","keydown",function(t){let i=t.originalEvent,l=I.getCharCode(i);if(l===32||l===13){t.preventDefault();let m=o.view(this).data;e.lastThumbClickedIndex=m.index,e.extensionHost.publish(h.THUMB_SELECTED,m)}}),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,l=this.options.thumbsLoadRange,m={start:i>l?i-l:0,end:i<this.thumbs.length-1-l?i+l:this.thumbs.length-1},S=this.options.thumbsImageFadeInDuration,T=this;for(let c=m.start;c<=m.end;c++){let u=this.getThumbByIndex(c),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");T.config.options.thumbsCacheInvalidation&&T.config.options.thumbsCacheInvalidation.enabled&&(C+=`${T.config.options.thumbsCacheInvalidation.paramType}t=${y.getTimeStamp()}`);let b=o('<img src="'+C+'" alt=""/>');b.hide(),b.on("load",function(){o(this).fadeIn(S,function(){o(this).parent().switchClass("loading","loaded")})}),b.on("error",function(){o(this).parent().switchClass("loading","loadingFailed")}),a.append(b)}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(){o(this.$thumbs).find("span.index").hide(),o(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(),setTimeout(()=>{this.$element.width("100%")},1)}};var f=class extends g{create(){this.setConfig("resourcesLeftPanel"),super.create()}};var w=v(F());var H=v(D()),d=window.$,R=class extends _{constructor(n){super(n)}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 f(this.$thumbsView),this.dataBind()}dataBind(){this.dataBindThumbsView();let n=this.extension.helper.getCurrentCanvas().getResources();n.length===0&&this.$resourcesView.hide();for(let e=0;e<n.length;e++){let r=n[e].getResource();if(r){let t=H.LanguageMap.getValue(r.getLabel());if(t){let i=L.simplifyMimeType(r.getFormat().toString()),l=d('<li><a href="'+r.id+'" target="_blank">'+t+" ("+i+")</li>");this.$resources.append(l)}}}}dataBindThumbsView(){if(!this.thumbsView)return;let n,e,s=this.extension.helper.getViewingDirection();s&&(s===w.ViewingDirection.LEFT_TO_RIGHT||s===w.ViewingDirection.RIGHT_TO_LEFT)?(n=this.config.options.twoColThumbWidth,e=this.config.options.twoColThumbHeight):(n=this.config.options.oneColThumbWidth,e=this.config.options.oneColThumbHeight),typeof n>"u"&&(n=100),typeof e>"u"&&(e=100),this.thumbsView.thumbs=this.extension.helper.getThumbs(n,e),this.thumbsView.thumbs.length<2&&this.$thumbsView.hide(),this.thumbsView.databind()}expandFullStart(){super.expandFullStart(),this.extensionHost.publish(h.LEFTPANEL_EXPAND_FULL_START)}expandFullFinish(){super.expandFullFinish(),this.extensionHost.publish(h.LEFTPANEL_EXPAND_FULL_FINISH)}collapseFullStart(){super.collapseFullStart(),this.extensionHost.publish(h.LEFTPANEL_COLLAPSE_FULL_START)}collapseFullFinish(){super.collapseFullFinish(),this.extensionHost.publish(h.LEFTPANEL_COLLAPSE_FULL_FINISH)}resize(){super.resize(),this.$views.height(this.$main.height()),this.$resources.height(this.$main.height())}};export{R as a};