第一步: 在 KE.setting中的items中添加 'attach';
第二步: 添加以下插件代码,涉及到的相关附件类型的图片可以自己找,或者做
KE.plugin['attach'] = {
click:function (id) {
KE.util.selection(id);
var dialog = new KE.dialog( {
id : id,
cmd : 'attach',
file : 'attach.shtml?id=' + id + '&ver=' + KE.version,
width : 300,
height : 90,
title : KE.lang['attach'],
yesButton : KE.lang['yes'],
noButton : KE.lang['no']
});
dialog.show();
},
check:function (id) {
var dialogDoc = KE.util.getIframeDoc(KE.g[id].dialog);
var type = KE.$('type', dialogDoc).value;
var url = '';
if (type == 1) {
url = KE.$('attachFile', dialogDoc).value;
} else {
url = KE.$('attachUrl', dialogDoc).value;
}
if (url.match(/\.(doc|xls|txt|rar|zip|gif|jpg|ppt|pps|mp3|wav|mid|midi|png|bmp|pdf|chm|html|htm|shtml)(\?|$)/i) == null) {
alert(KE.lang['invalidAttach']);
window.focus();
KE.g[id].yesButton.focus();
return false;
}
return true;
},
exec:function (id) {
KE.util.select(id);
var dialogDoc = KE.util.getIframeDoc(KE.g[id].dialog);
var type = KE.$('type', dialogDoc).value;
if (!this.check(id)) {
return false;
}
if (type == 1) {
KE.$('editorId', dialogDoc).value = id;
dialogDoc.uploadForm.submit();
return false;
} else {
var url = KE.$('attachUrl', dialogDoc).value;
var attachName;
attachName = url.substr(url.lastIndexOf('/') + 1);
this.insert(id, url, attachName);
}
},
insert:function (id, url, attachName) {
var ext;
ext = url.substr(url.lastIndexOf('.') + 1);
ext = ext.toUpperCase();
var fileImageName;
switch (ext) {
case 'TXT':
fileImageName = 'txt.gif';
break;
case 'CHM':
case 'HLP':
fileImageName = 'hlp.gif';
break;
case 'DOC':
fileImageName = 'doc.gif';
break;
case 'PDF':
fileImageName = 'pdf.gif';
break;
case 'MDB':
fileImageName = 'mdb.gif';
break;
case 'GIF':
case 'JPG':
case 'PNG':
case 'BMP':
fileImageName = 'pic.gif';
break;
case 'ASP':
case 'JSP':
case 'JS':
case 'PHP':
case 'PHP3':
case 'ASPX':
fileImageName = 'code.gif';
break;
case 'HTM':
case 'HTML':
case 'SHTML':
fileImageName = 'htm.gif';
break;
case 'ZIP':
case 'RAR':
fileImageName = 'zip.gif';
break;
case 'EXE':
fileImageName = 'exe.gif';
break;
case 'AVI':
case 'MPG':
case 'MPEG':
case 'ASF':
fileImageName = 'mp.gif';
break;
case 'RA':
case 'RM':
fileImageName = 'rm.gif';
break;
case 'MID':
case 'WAV':
case 'MP3':
case 'MIDI':
fileImageName = 'audio.gif';
break;
case 'XLS':
fileImageName = 'xls.gif';
break;
case 'PPT':
case 'PPS':
fileImageName = 'ppt.gif';
break;
default:
fileImageName = 'unknow.gif';
break;
}
var html = '<img border=0 width="18" height="18" src="'+KE.scriptPath+'plugins/fileimage/' + fileImageName +
'"><a href="' + url + '" target=_blank>' + attachName + '</a><br>';
KE.util.insertHtml(id, html);
KE.layout.hide(id);
KE.util.focus(id);
}};
attach.shtml 代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Accessory</title>
<style type="text/css" rel="stylesheet">
body {
font-size:12px;
margin: 0px;
background-color:#F0F0EE;
overflow: hidden;
}
td.left1 {
font-size:12px;
width: 50px;
padding: 2px;
}
td.right1 {
font-size:12px;
padding: 2px;
}
td.left2 {
font-size:12px;
width: 35px;
padding: 2px;
}
td.right2 {
font-size:12px;
padding: 2px;
width: 50px;
}
</style>
<script type="text/javascript">
function changeType(obj) {
if (obj.value == 1) {
document.getElementById('attachUrl').style.display = 'none';
document.getElementById('attachFile').style.display = 'block';
} else {
document.getElementById('attachUrl').style.display = 'block';
document.getElementById('attachFile').style.display = 'none';
}
}
</script>
</head>
<body>
<form name="uploadForm" method="post" enctype="multipart/form-data" action="../jsp/uploadAttach.jsp">
<input type="hidden" id="editorId" name="id" value="" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="left1">
<select id="type" name="type" onchange="javascript:changeType(this);">
<option value="1" selected="selected">本地</option>
<option value="2">远程</option>
</select>
</td>
<td class="right1">
<input type="file" id="attachFile" name="attachFile" style="width:220px;" />
<input type="text" id="attachUrl" name="attachUrl" value="http://" maxlength="255" style="width:220px;display:none;" />
</td>
</tr>
</table>
</form>
</body>
</html>
第三步: 默认开启,可以通过设置items开启使用。