Ext.namespace("Zarafa.plugins.filepreviewer");Zarafa.plugins.filepreviewer.ABOUT='<p>Copyright (C) 2016 Zarafa B.V. <info@zarafa.com></p><p>Copyright (C) 2016 Kopano and its licensors</p><p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p><p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.</p><p>You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>.</p><hr /><p>The filepreviewer plugin contains the following third-party components:</p><h1>ViewerJS</h1><p>Copyright (C) 2015 viewerjs.org</p><h1>PDF.js</h1><p>Copyright (C) Mozilla and individual contributors </p>';
Ext.namespace("Zarafa.plugins.filepreviewer");
Zarafa.plugins.filepreviewer.FileviewerPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.filepreviewer.FileviewerPlugin.superclass.initPlugin.apply(this,arguments);Zarafa.core.data.SharedComponentType.addProperty("filepreviewer.viewpanel")},doOpen:function(a){Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"],a,{modal:!0,autoResize:!0})},isSupportedDocument:function(a){return a.match(/^.*\.(pdf|od[tps]|jpg|jpeg|png|bmp|gif|mp4|mp3|ogg|webm|wav)$/i)?!0:
!1},bidSharedComponent:function(a,b){var c=-1;switch(a){case Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"]:c=1;break;case Zarafa.core.data.SharedComponentType["common.view"]:if(b instanceof Zarafa.core.data.IPMAttachmentRecord){var d=b.get("name");this.isSupportedDocument(d)&&(c=2)}}return c},getSharedComponent:function(a,b){var c;switch(a){case Zarafa.core.data.SharedComponentType["common.view"]:c=this;break;case Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"]:c=
Zarafa.plugins.filepreviewer.ViewerPanel}return c}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"filepreviewer",displayName:_("File previewer plugin"),about:Zarafa.plugins.filepreviewer.ABOUT,pluginConstructor:Zarafa.plugins.filepreviewer.FileviewerPlugin}))});Ext.namespace("Zarafa.plugins.filepreviewer");
Zarafa.plugins.filepreviewer.ViewerPanel=Ext.extend(Ext.Panel,{viewerjsPath:"external/ViewerJS/index.html",pdfjsPath:"external/pdfjs/web/viewer.html",src:"",title:"",autoResize:!1,defaultScale:.8,constructor:function(a){a=a||{};if(Ext.isDefined(a.record)){this.title=a.record.get("name")||a.record.get("filename");var b=this.title.split(".").pop().toLowerCase();this.src=this.getIframeURL(a.record.getInlineImageUrl(),b)}else this.src=a.src,this.title=a.title;Ext.isDefined(a.autoResize)?this.autoResize=
a.autoResize:this.autoResize=!1;Ext.isDefined(a.defaultScale)?this.defaultScale=a.defaultScale:this.defaultScale=.8;(Ext.isFunction(Zarafa.isDeskApp)?Zarafa.isDeskApp():Ext.isDefined(window.nw))?(this.tag="webview",b=container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/path"),this.viewerSrc=this.src,this.src=location.href+b+"/html/blank.html"):this.tag="iframe";Ext.applyIf(a,{xtype:"filepreviewer.viewerpanel",layout:"anchor",anchor:"100%",items:[{xtype:"component",ref:"iframe",autoEl:{tag:this.tag,
src:this.src,style:{width:"100%",height:"100%"},frameborder:0,allowfullscreen:!0},listeners:{afterrender:this.onAfterRender,scope:this}}],title:Ext.util.Format.htmlEncode(this.title),header:!1,height:Ext.getBody().getViewSize().height*this.defaultScale,width:Ext.getBody().getViewSize().width*this.defaultScale});Zarafa.plugins.filepreviewer.ViewerPanel.superclass.constructor.call(this,a)},initEvents:function(){if(!0===this.autoResize)Ext.EventManager.onWindowResize(this.resizePanel,this);else!1!==
this.autoResize&&(this.autoResize.on("resize",this.resizePanel,this),Ext.isDefined(this.autoResize.autoScroll)&&(this.autoResize.initialAutoScrollValue=this.autoResize.autoScroll,this.autoResize.setAutoScroll(!1)))},onDestroy:function(){!0===this.autoResize?Ext.EventManager.removeResizeListener(this.resizePanel,this):!1!==this.autoResize&&(this.autoResize.un("resize",this.resizePanel,this),Ext.isDefined(this.autoResize.autoScroll)&&this.autoResize.setAutoScroll(this.autoResize.initialAutoScrollValue));
Zarafa.plugins.filepreviewer.ViewerPanel.superclass.onDestroy.call(this,arguments)},resizePanel:function(a,b){if(2<arguments.length){var c=arguments[0];a=c.getInnerWidth();b=c.getInnerHeight()}this.setWidth(a*this.defaultScale);this.setHeight(b*this.defaultScale);this.ownerCt instanceof Ext.Window&&this.ownerCt.center()},getIframeURL:function(a,b){var c=container.getBasePath()+"plugins/filepreviewer/",d="";if(Ext.isDefined(b)){if("pdf"===b)return d+="#zoom="+container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/config_pdf_default_zoom"),
a+="&filename="+this.title.replace("#","-"),c+this.pdfjsPath+"?file="+encodeURIComponent(a)+d;d=/(od[tps])$/i.test(b)?d+("?zoom="+container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/config_odf_default_zoom")):d+"?zoom=auto";d+="&type="+b}return c+this.viewerjsPath+d+"#"+a},onAfterRender:function(a){this.getEl().on("load",this.onLoadFrame,this.getEl(),{single:!0});this.getEl().on("contentload",this.onLoadWebview,this,{single:!0});"webview"===this.tag&&(a.el.dom.addEventListener("permissionrequest",
this.handlePermissionRequests),a.el.dom.addEventListener("dialog",this.handleDialogRequests,this))},onLoadFrame:function(){var a=this.dom.contentDocument,b=this;a.addEventListener("keydown",function(a){27===a.keyCode&&(a=new KeyboardEvent(a.type,a),b.dom.dispatchEvent(a))});a=a.getElementById("download");a=Ext.get(a);a.on("click",function(){Zarafa.core.Util.skipRequester=!0})},onLoadWebview:function(){var a=this.iframe.el.dom.getCookieStoreId(),b=0;chrome.cookies.getAll({url:location.href},function(c){c.forEach(function(d){chrome.cookies.set({url:location.href,
name:d.name,value:d.value,path:d.path,secure:d.secure,httpOnly:d.httpOnly,sameSite:d.sameSite,storeId:a},function(){++b===c.length&&(this.iframe.el.dom.src=this.viewerSrc)}.bind(this))}.bind(this))}.bind(this))},handleDialogRequests:function(a){if("alert"===a.messageType)window.alert(a.messageText);else if("confirm"===a.messageType)window.confirm(a.messageText)?a.dialog.ok():a.dialog.cancel();else if("prompt"===a.messageType){var b=window.prompt(a.messageText);null===b?a.dialog.cancel():a.dialog.ok(b)}},
handlePermissionRequests:function(a){a.preventDefault();switch(a.permission){case "download":case "media":case "loadplugin":case "fullscreen":a.request.allow();break;case "pointerLock":case "geolocation":a.request.deny();break;default:a.request.deny()}}});Ext.reg("filepreviewer.viewerpanel",Zarafa.plugins.filepreviewer.ViewerPanel);//# sourceMappingURL=filepreviewer.js.map
