var XWiki=(function(b){var a=b.viewers=b.viewers||{};a.Attachments=Class.create({counter:1,initialize:function(){if($("attachform")){this.prepareForm()}else{this.addTabLoadListener()}},prepareForm:function(){if(!$("attachform")){return}this.form=$("attachform").up("form");this.defaultFileDiv=this.form.down("input[type='file']").up("div");this.inputSize=this.form.down("input[type='file']").size;var c=this.attachHTML5Uploader(this.form.down("input[type='file']"));if(c){c.hideFormButtons()}else{this.addInitialRemoveButton();this.addAddButton();this.resetOnCancel()}this.blockEmptySubmit()},attachHTML5Uploader:function(c){if(typeof(b.FileUploader)!="undefined"){c.multiple=true;return new b.FileUploader(c,{responseContainer:$("_attachments"),responseURL:b.currentDocument.getURL("get","xpage=attachmentslist&forceTestRights=1"),maxFilesize:parseInt(c.readAttribute("data-max-file-size"))})}return false},addInitialRemoveButton:function(){this.defaultFileDiv.appendChild(this.createRemoveButton())},addAddButton:function(){var c=new Element("input",{type:"button",value:"Başka bir dosya ekle",className:"attachmentActionButton add-file-input"});this.addDiv=new Element("div");this.addDiv.appendChild(c);Event.observe(c,"click",this.addField.bindAsEventListener(this));this.defaultFileDiv.up().insertBefore(this.addDiv,this.defaultFileDiv.next())},blockEmptySubmit:function(){Event.observe(this.form,"submit",this.onSubmit.bindAsEventListener(this))},resetOnCancel:function(){Event.observe(this.form,"reset",this.onReset.bindAsEventListener(this));Event.observe(this.form.down(".cancel"),"click",this.onReset.bindAsEventListener(this))},addField:function(f){var e=new Element("input",{type:"file",name:"filepath_"+this.counter,size:this.inputSize,className:"uploadFileInput"});var c=new Element("input",{type:"hidden",name:"filename_"+this.counter});var d=this.createRemoveButton();var g=new Element("div",{"class":"fileupload-field"});g.insert(c).insert(e).insert(d);this.addDiv.parentNode.insertBefore(g,this.addDiv);f.element().blur();this.counter++},removeField:function(c){c.element().up("div").remove()},createRemoveButton:function(){var c=new Element("input",{type:"button",value:"Kaldır",title:"Bu dosyayı kaldır",className:"attachmentActionButton remove-file-input"});Event.observe(c,"click",this.removeField.bindAsEventListener(this));return c},onSubmit:function(d){var c=false;this.form.getInputs("file").each(function(e){if(e.value!=""){c=true}});if(!c){d.stop()}},onReset:function(c){if(c){c.stop()}this.form.getInputs("file").each(function(d){d.up().remove()});this.counter=1;this.addField(c)},addTabLoadListener:function(c){var d=function(e){if(e.memo.id=="Attachments"){this.prepareForm();document.stopObserving("xwiki:docextra:loaded",d);delete d}}.bindAsEventListener(this);document.observe("xwiki:docextra:loaded",d)}});(b.domIsLoaded&&new a.Attachments())||document.observe("xwiki:dom:loaded",function(){new a.Attachments()});return b}(XWiki||{}));require(["jquery","xwiki-events-bridge"],function(b){b(document).on("show.bs.modal","#deleteAttachment",function(c){b(this).data("relatedTarget",b(c.relatedTarget))});b(document).on("click","#deleteAttachment input.btn-danger",function(){var d=b("#deleteAttachment");var c=d.data("relatedTarget");var e;b.ajax({url:c.prop("href"),beforeSend:function(){c.prop("disabled",true);e=new XWiki.widgets.Notification("Siliniyor ...","inprogress")},success:function(){var f=c.closest(".attachment");f.remove();a();e.replace(new XWiki.widgets.Notification("Ek silindi","done"))},error:function(){c.prop("disabled",false);e.replace(new XWiki.widgets.Notification("eki silinemedi :","error"))}})});var a=function(){var f=b("#Attachmentstab").find(".itemCount");var c=b("#Attachmentspane .attachment").size();if(f){f.text("( __number__ )".replace("__number__",c))}if(b("#tmAttachments").length){b("#tmAttachments")[0].normalize();var e=" Eklentiler ";var d=e+"( __number__ )";d=d.replace("__number__",c);b("#tmAttachments").contents().last()[0].nodeValue=d}};b(document).on("xwiki:html5upload:done",function(){a()})});