Files
im/plugin/admin/public/libs/froala/js/plugins/file.min.js
T

7 lines
12 KiB
JavaScript
Raw Normal View History

2025-11-07 09:56:20 +08:00
/*!
* froala_editor v4.3.1 (https://www.froala.com/wysiwyg-editor)
* License https://froala.com/wysiwyg-editor/terms/
* Copyright 2014-2024 Froala Labs
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(e.FroalaEditor)}(this,function(m){"use strict";m=m&&m.hasOwnProperty("default")?m["default"]:m,Object.assign(m.POPUP_TEMPLATES,{"file.insert":"[_BUTTONS_][_UPLOAD_LAYER_][_PROGRESS_BAR_]"}),Object.assign(m.DEFAULTS,{fileUpload:!0,fileUploadURL:null,fileUploadParam:"file",fileUploadParams:{},fileUploadToS3:!1,fileUploadToAzure:!1,fileUploadMethod:"POST",fileMaxSize:10485760,fileAllowedTypes:["*"],fileInsertButtons:["fileBack","|"],fileUseSelectedText:!1}),m.PLUGINS.file=function(T){var i,u=T.$,A="https://i.froala.com/upload",c=2,v=3,g=4,S=5,P=6,o={};function w(){var e=T.popups.get("file.insert");e||(e=l()),e.find(".fr-layer.fr-active").removeClass("fr-active").addClass("fr-pactive"),e.find(".fr-file-progress-bar-layer").addClass("fr-active"),e.find(".fr-buttons").hide(),r(T.language.translate("Uploading"),0)}function a(e){var t=T.popups.get("file.insert");t&&(t.find(".fr-layer.fr-pactive").addClass("fr-active").removeClass("fr-pactive"),t.find(".fr-file-progress-bar-layer").removeClass("fr-active"),t.find(".fr-buttons").show(),e&&(T.events.focus(),T.popups.hide("file.insert")))}function r(e,t){var o=T.popups.get("file.insert");if(o){var i=o.find(".fr-file-progress-bar-layer");i.find("h3").text(e+(t?" ".concat(t,"%"):"")),i.removeClass("fr-error"),t?(i.find("div").removeClass("fr-indeterminate"),i.find("div > span").css("width","".concat(t,"%"))):i.find("div").addClass("fr-indeterminate")}}function h(e,t,o,i){var r;T.edit.on(),T.events.focus(!0),T.selection.restore(),T.opts.fileUseSelectedText&&T.selection.text().length&&(t=T.selection.text());var a='<a href="'.concat(e,'" id="fr-inserted-file" ');if(void 0!==i)for(r in i)i.hasOwnProperty(r)&&"link"!=r&&(a+="".concat(r,'="').concat(i[r],'" '));-1==a.indexOf(' class="')&&(a+='class="fr-file" '),a+=">".concat(t,"</a>"),T.html.insert(a);var n=T.$el.find("#fr-inserted-file");n.removeAttr("id"),T.popups.hide("file.insert"),T.undo.saveStep(),f(),T.events.trigger("file.inserted",[n,o])}function k(e,t,o){var i=this.status,r=this.response,a=this.responseXML,n=this.responseText;try{if(T.opts.fileUploadToS3||T.opts.fileUploadToAzure)if(201===i){var s;if(T.opts.fileUploadToAzure){if(!1===T.events.trigger("file.uploadedToAzure",[this.responseURL,o,r],!0))return T.edit.on(),!1;s=t}else s=function p(e){try{var t=u(e).find("Location").text(),o=u(e).find("Key").text();return!1===T.events.trigger("file.uploadedToS3",[t,o,e],!0)?(T.edit.on(),!1):t}catch(i){return x(g,e),!1}}(a);s&&h(s,e,r||a)}else x(g,r||a);else if(200<=i&&i<300){var l=function f(e){try{if(!1===T.events.trigger("file.uploaded",[e],!0))return T.edit.on(),!1;var t=JSON.parse(e);return t.link?t:(x(c,e),!1)}catch(o){return x(g,e),!1}}(n);l&&h(l.link,e,r||n,l)}else x(v,r||n)}catch(d){x(g,r||n)}}function R(){x(g,this.response||this.responseText||this.responseXML)}function C(e){if(e.lengthComputable){var t=e.loaded/e.total*100|0;r(T.language.translate("Uploading"),t)}}function x(e,t){T.edit.on(),function i(e){w();var t=T.popups.get("file.insert").find(".fr-file-progress-bar-layer");t.addClass("fr-error");var o=t.find("h3");o.text(e),T.events.disableBlur(),o.focus()}(T.language.translate("Something went wrong. Please try again.")),T.events.trigger("file.error",[{code:e,message:o[e]},t])}function z(){T.edit.on(),a(!0)}function n(e){if(void 0!==e&&0<e.length){var t=e[0].type;if(e[0].name&&e[0].name.endsWith(".msg")&&(t="application/vnd.ms-outlook"),!1===T.events.trigger("file.beforeUpload",[e]))return!1;var o,i=e[0];if(!(null!==T.opts.fileUploadURL&&T.opts.fileUploadURL!==A||T.opts.fileUploadToS3||T.opts.fileUploadToAzure))return function y(a){var n=new FileReader;n.onload=function(){for(var e=n.result,t=atob(n.result.split(",")[1]),o=[],i=0;i<t.length;i++)o.push(t.charCodeAt(i));var r=a.type;a.name&&a.name.endsWith(".msg")&&(r="application/vnd.ms-outlook"),e=window.URL.createObjectURL(new Blob([new Uint8Array(o)],{type:r})),T.file.insert(e,a.name,null)},w(),n.readAsDataUR