var XWiki=function(d){function m(){const a=this.property.up("form");require(["jquery"],function(b){const c=new FormData;var e=b("#attachfile")[0].files[0];const f=b("#uploadAttachment input[name\x3d'filename']");c.append("upload",e);const k=new d.widgets.Notification("\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f...","inprogress");e={form_token:b(a).find('[name\x3d"form_token"]').val(),sheet:"CKEditor.FileUploader",outputSyntax:"plain"};f.prop("checked")&&(e.filename=f.val());
b.ajax({url:d.currentDocument.getURL("get",(new URLSearchParams(e)).toString()),method:"POST",data:c,processData:!1,contentType:!1,headers:{"X-XWiki-Temporary-Attachment-Support":!0}}).done(function(h){k.replace(new d.widgets.Notification("\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e.","done"));b(a).append(b("\x3cinput/\x3e").prop("type","hidden").prop("name","uploadedFiles").prop("value",
h.fileName));b(a).find('input[type\x3d"hidden"].property-reference').prop("value",h.fileName);this.updateAttachment(h.fileName,h.url);this.dialog.closeDialog()}.bind(this)).fail(function(){k.replace(new d.widgets.Notification("\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u0443\u0434\u0430\u043b\u0430\u0441\u044c.","error"))})}.bind(this))}d.AttachmentPicker=Class.create({initialize:function(a,b){this.property=a;this.dialog=b;this.gallery=
b.dialogBox;this.property.down("input")||(this.directSave=!0);this.defaultValue="";if(a=this.gallery.down(".gallery_emptyChoice .gallery_attachmenttitle"))this.defaultValue=a.title;this.defaultImageSource="";if(a=this.gallery.down(".gallery_emptyChoice.gallery_image img"))this.defaultImageSource=a.src.replace(/\?.*$/,"");this.filterFormUpload();this.addDeleteListeners();this.addSelectListeners();this.updateCurrentSelection();this.addCloseListener();var c=this.property.down("img");c&&(c.observe("load",
function(){c.up("div").removeClassName("hidden")}),c.observe("error",function(){c.up("div").addClassName("hidden")}))},filterFormUpload:function(){this.gallery.select('.uploadAttachment input[type\x3d"file"]').each(function(a){a.__allowedExtensions=a.title.toLowerCase().replace(/\s*[,|; ]\s*/g," ").strip();a.__allowedExtensions=""!=a.__allowedExtensions?a.__allowedExtensions.split(" "):!1});this.gallery.select(".uploadAttachment").invoke("observe","submit",function(a){a.stop();a=a.element();var b=
!1;a.select('input[type\x3d"file"]').each(function(c){""==c.value?(new d.widgets.Notification("\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438","error"),b=!0):c.__allowedExtensions&&-1==c.__allowedExtensions.indexOf(this.getFileExtension(c.value))&&(new d.widgets.Notification("\u041d\u0435\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0444\u0430\u0439\u043b\u0430",
"error"),b=!0);Event.fire(document,"xwiki:actions:beforeUpload",{file:c.files[0]}).defaultPrevented&&(b=!0)}.bind(this));b||(this.directSave?a.submit():m.call(this))}.bindAsEventListener(this))},getFileExtension:function(a){a=a.replace("\\","/").split("/");if(0==a.length)return null;a=a[a.length-1].split(".");return a[a.length-1].toLowerCase()},addDeleteListeners:function(){this.gallery.select(".gallery_actions .tool.delete").invoke("observe","click",this.onDelete.bindAsEventListener(this))},addSelectListeners:function(){this.gallery.select(".gallery_actions .tool.select").invoke("observe",
"click",this.onSelect.bindAsEventListener(this))},onDelete:function(a){a.stop();deleteTool=a.element();deleteTool.disabled||new d.widgets.ConfirmedAjaxRequest(deleteTool.readAttribute("href"),{onCreate:function(){deleteTool.disabled=!0},onSuccess:function(){var b=deleteTool.up(".gallery_attachmentbox");if(b){if(b.hasClassName("current")){this.updateAttachment(this.defaultValue,this.defaultImageSource);this.gallery.down(".gallery_emptyChoice")&&this.gallery.down(".gallery_emptyChoice").addClassName("current");
var c=this.gallery.down('input[type\x3d"checkbox"][name\x3d"filename"]');c.disabled=!0;c.up("label").down("strong").update("");this.directSave||(this.property.down("input").value=this.defaultValue)}b.remove()}}.bind(this),onComplete:function(){deleteTool.disabled=!1}},{confirmationText:"\u0412\u044b \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b?",progressMessageText:"\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435...",
successMessageText:"\u0424\u0430\u0439\u043b \u0443\u0434\u0430\u043b\u0435\u043d",failureMessageText:"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430:"})},onSelect:function(a){a.stop();var b=a.element(),c=b.up(".gallery_attachmentbox").down(".gallery_attachmenttitle").title,e=b.up(".gallery_attachmentbox.gallery_image");e&&(e=e.down(".gallery_attachmentframe img"))&&(e=e.src.replace(/\?.*$/,""));e||="";this.directSave?
b.disabled||new Ajax.Request(a.element().href,{onCreate:function(){b.disabled=!0;b._x_notif=new d.widgets.Notification("\u0417\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440...","inprogress")},onSuccess:function(){b._x_notif.hide();this.updateAttachment(c,e);this.dialog.closeDialog()}.bindAsEventListener(this),onFailure:function(f){f=f.statusText||"Server not responding";b._x_notif?b._x_notif.replace(new d.widgets.Notification("\u041e\u0448\u0438\u0431\u043a\u0430:"+
f,"error")):new d.widgets.Notification(this.interactionParameters.failureMessageText+f,"error")},on0:function(f){f.request.options.onFailure(f)},onComplete:function(){b.disabled=!1}}):(this.updateAttachment(c,e),this.property.down("input").value=c,this.dialog.closeDialog())},updateAttachment:function(a,b){var c=this.property.down("img");if(c){if(c.src=c.src.replace(/^[^\?]+($|\?)/,b+"$1"),c=c.up("a"))c.href=c.href.replace(/^[^\?]+($|\?)/,b+"$1")}else if(b=this.property.down(".displayed"))if(b.update(a),
c=b.up("a"))c.href=c.href.replace(/^[^\?]+($|\?)/,a+"$1")},updateCurrentSelection:function(){if(this.directSave)this.gallery.down(".current .tool.select").addClassName("hidden");else{var a=this.property.down("input").value;a=(a=this.gallery.down('.gallery_attachmenttitle[title\x3d"'+a.replace('"',"\\22 ")+'"]'))?a.up(".gallery_attachmentbox"):this.gallery.down(".gallery_emptyChoice");a.hasClassName("current")||(this.gallery.select(".gallery_attachmentbox.current .tool.select").invoke("removeClassName",
"hidden"),this.gallery.select(".gallery_attachmentbox.current").invoke("removeClassName","current"),a.addClassName("current"));a.down(".tool.select").addClassName("hidden")}},addCloseListener:function(){var a=$("attachment-picker-close");a&&a.observe("click",function(b){b.stop();this.dialog.closeDialog()}.bindAsEventListener(this))}});var l=(new Element("div",{"class":"imgcenter"})).update('\x3cimg src\x3d"/xwiki/resources/icons/xwiki/ajax-loader-large.gif?cache-version\x3d1759477984000"/\x3e'),g;
document.observe("xwiki:dom:loaded",function(){$$(".attachment-picker-start").invoke("observe","click",function(a){a.stop();var b=a.element();a=b.href;0>a.indexOf("?")&&(a+="?");a+="\x26xpage\x3dplain";g=new d.widgets.ModalPopup(l,{},{verticalPosition:"top",removeOnClose:!0,title:"\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f"});g.shortcuts.close.keys=[];g.showDialog();g.dialog.down().setStyle({position:"fixed"});g.dialog.setStyle({top:document.viewport.getScrollOffsets().top+"px",position:"absolute"});
g.dialogBox.setStyle({overflow:"hidden",width:"80%",margin:"0 10%"});new Ajax.Updater(l.up(),a,{onComplete:function(){window.gallery_lb&&window.gallery_lb.updateImageList();if("function"==typeof d.fixLinksTargetAttribute){var c=d.contextaction;d.contextaction="view";d.fixLinksTargetAttribute(g.dialog);d.contextaction=c}new d.AttachmentPicker(b.up(".attachment-picker"),g)}})})});return d}(XWiki||{});
XWiki.widgets.ModalPopup.prototype.showDialog=function(d){d&&Event.stop(d);this.active||(this.active=!0,this.dialog||this.createDialog(),this.attachKeyListeners(),this.dialog.show())};XWiki.widgets.ModalPopup.prototype.closeDialog=function(d){d&&Event.stop(d);this.options.onClose.call(this);this.dialog.hide();this.options.removeOnClose&&this.dialog.remove();this.detachKeyListeners();this.active=!1};