1、环境依赖
本文环境依赖于tp3.2.3+kindeditor4.1.10
2、代码简述
插件存放位置
Public\plugins\kindeditor\plugins\attach
插件初始化
<script charset="utf-8" src="/Public/plugins/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/Public/plugins/kindeditor/lang/zh-CN.js"></script>
<script>
var editor;
KindEditor.ready(function(K) {
editor = K.create('textarea[name="content"]', {
resizeType : 1,
allowPreviewEmoticons : false,
allowImageUpload : false,
items : [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link','attach']
});
});
</script>
注意items 最后的 'attach' 即插件名称插件核心js文件attach.js
// Google Maps: http://code.google.com/apis/maps/index.html
KindEditor.plugin('attach', function(K) {
var self = this, name = 'attach', lang = self.lang(name + '.');
// TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'attach/attach.html" style="width:410px;height:210px;"></iframe>');
var win, doc,dialog;
function init(){
var dialog = self.createDialog({
name : name,
width :400,
height:60,
title : self.lang(name),
body : iframe,
yesBtn : {
name : self.lang('yes'),
click : function(e) {
var ret = iframe[0].contentWindow.retvalue;
if(ret==null){
self.hideDialog()
alert("请先上传资料");
return ;
}
if(typeof ret=="string"){
ret = JSON.parse(ret);
}
if(ret.code!=0){
self.hideDialog()
alert(ret.errmsg);
return ;
}
var str = "<img src=\""+self.pluginsPath+"/attach/images/attach.jpg\" class=\"ke-attach\"/>";
self.insertHtml("<p style=\"text-align:center\"><a href=\""+ret.data+"\">"+str+"</a></p>");
self.hideDialog()
}
},
beforeRemove : function() {
}
});
return dialog;
}
function ready() {
win = iframe[0].contentWindow;
doc = K.iframeDoc(iframe);
}
iframe.bind('load', function() {
iframe.unbind('load');
if (K.IE) {
ready();
} else {
setTimeout(ready, 0);
}
});
self.clickToolbar(name, function() {
init()
});
});
插件上传不了需要插件的联系我
http://www.imwinlion.com/archives/38