(function(){tinymce.create("tinymce.plugins.FEImageUploadPlugin",{init:function(e,t){e.addCommand("feOpenModal",function(){jQuery("#uploadImgModal").modal("show");var e=jQuery("#images_upload_container");var t=new ImagesUpload({el:e,uploaderID:"images_upload",multi_selection:false,unique_names:false,upload_later:true,filters:[{title:"Image Files",extensions:"gif,jpg,png"}],multipart_params:{_ajax_nonce:e.find(".et_ajaxnonce").attr("id"),action:"et_upload_images"},cbAdded:function(e,t){var n;if(e.files.length>1){while(e.files.length>1){e.removeFile(e.files[0])}}for(n=0;n<e.files.length;n++){jQuery("span.filename").text(e.files[n].name)}},cbUploaded:function(e,t,n){if(n.success){tinyMCE.activeEditor.execCommand("mceInsertContent",false,"[img]"+n.data+"[/img]");jQuery("#uploadImgModal").modal("hide");jQuery("span.filename").text("No file chosen");e.splice();e.refresh();e.destroy()}else{console.log(n);jQuery("#uploadImgModal").modal("hide");jQuery("span.filename").text("No file chosen");e.splice();e.refresh();e.destroy();jQuery("button#insert").prop("disabled",false);pubsub.trigger("fe:showNotice",n.msg,"error")}},onError:function(e,t){},beforeSend:function(){jQuery("button#insert").prop("disabled",true)},success:function(){jQuery("button#insert").prop("disabled",false)}});jQuery("button.close , span.btn-cancel").click(function(){t.controller.splice();t.controller.refresh();t.controller.destroy();jQuery("input#external_link").val("");jQuery("span.filename").text("No file chosen")});jQuery("button#insert").click(function(e){e.preventDefault();var n=jQuery("input#external_link");if(ForumEngine.app.currentUser.get("id")===0&&n.val()=="")return false;if(t.controller.files.length>0){hasUploadError=false;t.controller.start()}if(n.val()!=""){tinyMCE.activeEditor.execCommand("mceInsertContent",false,"[img]"+n.val()+"[/img]");jQuery("#uploadImgModal").modal("hide");t.controller.splice();t.controller.refresh();t.controller.destroy();jQuery("input#external_link").val("");jQuery("span.filename").text(fe_front.texts.no_file_choose)}})});e.addButton("feimage",{title:fe_front.texts.upload_images,image:t+"/img/upload-image.gif",cmd:"feOpenModal"})},getInfo:function(){return{longname:"FE Image Upload",author:"thaint",version:"0.0.1"}}});tinymce.PluginManager.add("feimage",tinymce.plugins.FEImageUploadPlugin)})()