/*
 Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
 For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
(function(){CKEDITOR.plugins.add("uploadwidget",{lang:"az,bg,ca,cs,da,de,de-ch,el,en,en-au,eo,es,es-mx,et,eu,fa,fr,gl,hr,hu,id,it,ja,km,ko,ku,lv,nb,nl,no,oc,pl,pt,pt-br,ro,ru,sk,sq,sr,sr-latn,sv,tr,ug,uk,zh,zh-cn",requires:"widget,clipboard,filetools,notificationaggregator",init:function(a){a.filter.allow("*[!data-widget,!data-cke-upload-id]")},isSupportedEnvironment:function(){return CKEDITOR.plugins.clipboard.isFileApiSupported}});CKEDITOR.fileTools||(CKEDITOR.fileTools={});CKEDITOR.tools.extend(CKEDITOR.fileTools,
{addUploadWidget:function(a,c,e){var g=CKEDITOR.fileTools,b=a.uploadRepository,m=e.supportedTypes?10:20;CKEDITOR.plugins.clipboard.addFileMatcher(a,function(a){return e.supportedTypes?g.isTypeSupported(a,e.supportedTypes):!0});if(e.fileToElement)a.on("paste",function(d){d=d.data;var l=a.widgets.registered[c],k=d.dataTransfer,e=k.getFilesCount(),h=l.loadMethod||"loadAndUpload",f,n;if(!d.dataValue&&e)for(n=0;n<e;n++)if(f=k.getFile(n),!l.supportedTypes||g.isTypeSupported(f,l.supportedTypes)){var m=l.fileToElement(f);
f=b.create(f,void 0,l.loaderType);m&&(f[h](l.uploadUrl,l.additionalRequestParameters),CKEDITOR.fileTools.markElement(m,c,f.id),"loadAndUpload"!=h&&"upload"!=h||l.skipNotifications||CKEDITOR.fileTools.bindNotifications(a,f),d.dataValue+=m.getOuterHtml())}},null,null,m);CKEDITOR.tools.extend(e,{downcast:function(){return new CKEDITOR.htmlParser.text("")},init:function(){var d=this,c=this.wrapper.findOne("[data-cke-upload-id]").data("cke-upload-id"),k=b.loaders[c],e=CKEDITOR.tools.capitalize,h,f;k.on("update",
function(b){if("abort"===k.status&&"function"===typeof d.onAbort)d.onAbort(k);if(d.wrapper&&d.wrapper.getParent()){a.fire("lockSnapshot");b="on"+e(k.status);if("abort"===k.status||"function"!==typeof d[b]||!1!==d[b](k))f="cke_upload_"+k.status,d.wrapper&&f!=h&&(h&&d.wrapper.removeClass(h),d.wrapper.addClass(f),h=f),"error"!=k.status&&"abort"!=k.status||a.widgets.del(d);a.fire("unlockSnapshot")}else CKEDITOR.instances[a.name]&&a.editable().find('[data-cke-upload-id\x3d"'+c+'"]').count()||k.abort(),
b.removeListener()});k.update()},replaceWith:function(d,c){if(""===d.trim())a.widgets.del(this);else{var b=this==a.widgets.focused,e=a.editable(),h=a.createRange(),f,g;b||(g=a.getSelection().createBookmarks());h.setStartBefore(this.wrapper);h.setEndAfter(this.wrapper);b&&(f=h.createBookmark());e.insertHtmlIntoRange(d,h,c);a.widgets.checkWidgets({initOnlyNew:!0});a.widgets.destroy(this,!0);b?(h.moveToBookmark(f),h.select()):a.getSelection().selectBookmarks(g);a.fire("change")}},_getLoader:function(){var a=
this.wrapper.findOne("[data-cke-upload-id]");return a?this.editor.uploadRepository.loaders[a.data("cke-upload-id")]:null}});a.widgets.add(c,e)},markElement:function(a,c,e){a.setAttributes({"data-cke-upload-id":e,"data-widget":c})},bindNotifications:function(a,c){function e(){g=a._.uploadWidgetNotificaionAggregator;if(!g||g.isFinished())g=a._.uploadWidgetNotificaionAggregator=new CKEDITOR.plugins.notificationAggregator(a,a.lang.uploadwidget.uploadMany,a.lang.uploadwidget.uploadOne),g.once("finished",
function(){var b=g.getTaskCount();0===b?g.notification.hide():g.notification.update({message:1==b?a.lang.uploadwidget.doneOne:a.lang.uploadwidget.doneMany.replace("%1",b),type:"success",important:1})})}var g,b=null;c.on("update",function(){!b&&c.uploadTotal&&(e(),b=g.createTask({weight:c.uploadTotal}));b&&"uploading"==c.status&&b.update(c.uploaded)});c.on("uploaded",function(){b&&b.done()});c.on("error",function(){b&&b.cancel();a.showNotification(c.message,"warning")});c.on("abort",function(){b&&
b.cancel();CKEDITOR.instances[a.name]&&a.showNotification(a.lang.uploadwidget.abort,"info")})}})})();