1.在plugins下新建文件夹 taobao
2.在taobao文件夹下新建taobao.js
KindEditor.plugin('taobao', function(K) {
var self = this, name = 'taobao';
self.plugin.taobao = {
edit : function() {
var lang = self.lang(name + '.'),
html = '' +
'
',
dialog = self.createDialog({
name : name,
width : 450,
title : self.lang(name),
body : html,
yesBtn : {
name : self.lang('yes'),
click : function(e) {
var url = K.trim(urlBox.val());
var title=K.trim(titleBox.val());
if (url == 'http://' || K.invalidUrl(url)) {
alert(self.lang('invalidUrl'));
urlBox[0].focus();
return;
}
var itemStr="
"+title+"";
self.insertHtml(itemStr).hideDialog().focus();
}
}
}),
div = dialog.div,
urlBox = K('input[name="url"]', div),
titleBox=K('input[name="title"]', div);
urlBox.val('http://');
self.cmd.selection();
var a = self.plugin.getSelectedLink();
if (a) {
self.cmd.range.selectNode(a[0]);
self.cmd.select();
urlBox.val(a.attr('data-ke-src'));
titleBox.val(a.text());
}
urlBox[0].focus();
urlBox[0].select();
},
'delete' : function() {
self.exec('unlink', null);
}
};
self.clickToolbar(name, self.plugin.taobao.edit);
});
3.添加样式,themes/default/default.css
.ke-icon-taobao {
background-position: 0px -624px;
width: 16px;
height: 16px;
}
4.在lang/zh_CN.js里添加
taobao:'淘宝',
5.修改初始化配置文件
一.在items 中添加taobao该自定义插件
二.修改htmlTags中标签设置指定保留的属性,如A标签中
a : ['id', 'class', 'href', 'target', 'name','data-type','biz-itemid','data-tmpl','data-tmplid','data-rd','data-style','data-border'],
htmlTags 指定要保留的HTML标记和属性。哈希数组的key为HTML标签名,value为HTML属性数组,"."开始的属性表示style属性。