KindEditor.plugin('insertfile',function(K){var self=this,name='insertfile',lang=self.lang(name+'.'),allowFileUpload=K.undef(self.allowFileUpload,true),allowFileManager=K.undef(self.allowFileManager,false),formatUploadUrl=K.undef(self.formatUploadUrl,true),extraParams=K.undef(self.extraFileUploadParams,{}),uploadJson=K.undef(self.attachmentUploadJson,''),exteLimit=K.undef(self.attachmentExteLimit,''),sizeLimit=K.undef(self.attachmentSizeLimit,''),downloadUrl=K.undef(self.attachmentDownloadUrl,''),imgPath=self.pluginsPath+name+'/images/',filePostName=K.undef(self.filePostName,'imgFile'),uploadDesc=K.tmpl(self.lang('uploadDesc'),{exteLimit:K.formatExte(exteLimit,'、'),sizeLimit:sizeLimit});self.plugin.fileDialog=function(options){var fileUrl=K.undef(options.fileUrl,'http://'),fileTitle=K.undef(options.fileTitle,''),clickFn=options.clickFn;var html=['<div style="padding:20px;">','<div class="ke-dialog-row">','<label for="keUrl" style="width:60px;">'+lang.url+'</label>','<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;','<input type="button" class="ke-upload-button" value="'+lang.upload+'" /> &nbsp;','<span class="ke-button-common ke-button-outer">','<input type="button" class="ke-button-common ke-button" name="viewServer" value="'+lang.viewServer+'" />','</span>','</div>','<div class="ke-dialog-row">','<label for="keTitle" style="width:60px;">'+lang.title+'</label>','<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" />','<input type="hidden" name="exte" value="" /><input type="hidden" name="id" value="" />','</div>','<div class="ke-dialog-row ke-upload-attr">','<label style="width:60px;">'+self.lang('uploadAttribute')+'</label>'+uploadDesc+'','</div>','</div>','</form>','</div>'].join('');var dialog=self.createDialog({name:name,width:450,title:self.lang(name),body:html,yesBtn:{name:self.lang('yes'),click:function(e){if(dialog.isLoading){return;}var url=K.trim(urlBox.val()),title=titleBox.val(),exte=K.trim(exteBox.val()),id=K.trim(idBox.val());if(url=='http://'||K.invalidUrl(url)){alert(self.lang('invalidUrl'));urlBox[0].focus();return;}if(downloadUrl&&id){url=downloadUrl+'?id='+id;}if(K.trim(title)===''){title=url;}clickFn.call(self,url,title,exte);}}}),div=dialog.div;var urlBox=K('[name="url"]',div),viewServerBtn=K('[name="viewServer"]',div),titleBox=K('[name="title"]',div),exteBox=K('[name="exte"]',div),idBox=K('[name="id"]',div);if(allowFileUpload){var uploadbutton=K.uploadbutton({button:K('.ke-upload-button',div)[0],fieldName:filePostName,url:uploadJson,extraParams:extraParams,afterUpload:function(data){dialog.hideLoading();if(data.status&&data.store!=null){var store=data.store;if(store.length>0){var url=store[0].url;if(formatUploadUrl){url=K.formatUrl(url,'absolute');}urlBox.val(url);titleBox.val(store[0].name);exteBox.val(store[0].exte);idBox.val(store[0].id);if(self.afterUpload){self.afterUpload.call(self,url,data,name);}alert(self.lang('uploadSuccess'));}else{alert(data.message);}}else{alert(data.message);}},afterError:function(html){dialog.hideLoading();self.errorDialog(html);}});uploadbutton.fileBox.change(function(e){dialog.showLoading(self.lang('uploadLoading'));uploadbutton.submit();});}else{K('.ke-upload-button',div).hide();K('.ke-upload-attr',div).hide();}if(allowFileManager){viewServerBtn.click(function(e){self.loadPlugin('filemanager',function(){self.plugin.filemanagerDialog({viewType:'LIST',viewParam:'fileExte='+K.formatExte(exteLimit,',',''),clickFn:function(url,title,exte,id){if(self.dialogs.length>1){K('[name="url"]',div).val(url);K('[name="title"]',div).val(title);K('[name="exte"]',div).val(exte);K('[name="id"]',div).val(id);if(self.afterSelectFile){self.afterSelectFile.call(self,url);}self.hideDialog();}}});});});}else{viewServerBtn.hide();}urlBox.val(fileUrl);titleBox.val(fileTitle);urlBox[0].focus();urlBox[0].select();};self.clickToolbar(name,function(){self.plugin.fileDialog({clickFn:function(url,title,exte){var icon='';if(exte!=undefined&&exte){exte=K.undef(exteMaps.exte,'icon_default.gif');icon='<img class="ke-icon" src="'+imgPath+exte+'" width="16" height="16" align="absmiddle" />';}var html=icon+'<a class="ke-insertfile" href="'+url+'" data-ke-src="'+url+'" target="_blank">'+title+'</a>';self.insertHtml(html).hideDialog().focus();}});});var exteMaps={'rar':'icon_rar.gif','zip':'icon_rar.gif','doc':'icon_doc.gif','docx':'icon_doc.gif','pdf':'icon_pdf.gif','mp3':'icon_mp3.gif','mp4':'icon_mv.gif','xls':'icon_xls.gif','chm':'icon_chm.gif','ppt':'icon_ppt.gif','pptx':'icon_ppt.gif','avi':'icon_mv.gif','rmvb':'icon_mv.gif','wmv':'icon_mv.gif','flv':'icon_mv.gif','swf':'icon_mv.gif','rm':'icon_mv.gif','exe':'icon_exe.gif','psd':'icon_psd.gif','txt':'icon_txt.gif'};});