2025-02-23 20:52:25 +01:00

1 line
4.0 KiB
JavaScript

"use strict";$(document).ready(function(){xcloud.init()});var xcloud=new function(){var _this=this;this.init=function(){rcmail.addEventListener("beforemenu-open",function(p){if(p.menu=="attachmentmenu"){$(".xcloud-attach-menu-container").remove();for(var plugin in rcmail.env.xcloud_plugins){_this.insertMenuAttachmentSaveCode(plugin,p["id"])}}});for(var plugin in rcmail.env.xcloud_plugins){if(rcmail.env.xcloud_plugins[plugin].enableAttachmentSave){_this.insertImageAttachmentSaveCode(plugin)}}var width=0;var elements=$("#compose-attachments input[type=button]");elements.each(function(){if($(this).outerWidth()>width){width=$(this).outerWidth()}});elements.width(width)};this.selectSuccess=function(data,linkType,plugin,parameters){if(linkType=="preview"){_this.selectPreviewSuccess(data,plugin,parameters)}else{_this.selectDirectSuccess(data,plugin,parameters)}};this.insertImageAttachmentSaveCode=function(plugin){if(!$("#aria-label-messageattachments").length||typeof window[plugin]["insertSaveButton"]!=="function"){return}$("p.image-attachment").each(function(){var container=$(this).find(".xcloud-save-button-container");if(!container.length){container=$("<div>").addClass("xcloud-save-button-container").appendTo($(this).find("span.attachment-links"))}var mimeId=$(this).find("a.image-link").first().attr("onclick").match(/\d+/)[0];var elementId=plugin+"-attachment-image-"+mimeId;$("<div>").addClass("xcloud-image-attachment-box").attr("id",elementId).appendTo(container);var name=$(this).find(".image-filename").text();var url=false;$(this).find("span.attachment-links > a").each(function(){var href=$(this).attr("href");if(href.indexOf("_download=1")!=-1){url=href}});if(!name||!url){return true}window[plugin]["insertSaveButton"](elementId,mimeId,name,url+"&download=1")})};this.insertMenuAttachmentSaveCode=function(plugin,mimeId){if(!$("#aria-label-messageattachments").length||typeof window[plugin]["insertSaveButton"]!=="function"){return}var elementId=plugin+"-attachment-menu-"+mimeId;if($("#"+elementId).length){return}$("<li>").addClass("xcloud-attach-menu-container").append($("<div>").attr("id",elementId).addClass("active")).appendTo($("#attachmentmenu ul"));var a=$("#attach"+mimeId+" a").first();if(!a.length){return}var url=a.attr("href");var name=undefined;var nameElement=a.find(".attachment-name");if(nameElement.length){name=nameElement.text()}else{var copy=a.clone();copy.find("span").remove();name=copy.text().trim()}if(!name||!url){return}window[plugin]["insertSaveButton"](elementId,mimeId,name,url+"&download=1")};this.selectPreviewSuccess=function(data,plugin,parameters){var html=$("input[name='_is_html']").val()=="1";var links=[];for(var key in data){if(data.hasOwnProperty(key)){if(html){links.push("<a class='xcloud-link "+plugin+"-link' href='"+data[key]["url"]+"'>"+data[key]["name"]+"</a>")}else{links.push(data[key]["url"])}}}if(html){tinyMCE.execCommand("mceInsertContent",false," "+links.join(", ")+" ")}else{var element=$("#composebody");var value=element.val();element.val(value.substring(0,element.prop("selectionStart"))+"\n\n"+links.join("\n")+"\n\n"+value.substring(element.prop("selectionEnd"),0))}};this.selectDirectSuccess=function(data,plugin,parameters){var uploadId=(new Date).getTime();rcmail.add2attachment_list(uploadId,{name:"",html:$("<span>").text(rcmail.gettext("attaching")).html(),classname:"uploading",complete:false});data={files:data,uploadId:uploadId,composeId:rcmail.env.compose_id};if(typeof parameters==="object"){for(var _name in parameters){data[_name]=parameters[_name]}}rcmail.http_post("plugin."+plugin+"_attach",data,rcmail.set_busy(true,"uploading"))};this.saveAttachmentDeployFile=function(mimeId){var data={code:xframework.getRandomCode(),name:$("#attachment-list #attach"+mimeId+" .attachment-name").text().trim()};xframework.ajax("SaveAttachmentDeployFile",{messageId:rcmail.env.uid,mbox:rcmail.env.mailbox,mimeId:mimeId,code:data.code});return data};this.removeAttachmentDeployFile=function(code){xframework.ajax("RemoveAttachmentDeployFile",{code:code})}};