KindEditor 自定义插件

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 = '<div style="padding:20px;">' +
					//url
					'<div class="ke-dialog-row">' +
					'<label for="keUrl" style="width:60px;">链接</label>' +
					'<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
					//type
					'<div class="ke-dialog-row"">' +
					'<label for="keTitle" style="width:60px;">标题</label>' +
					'<input class="ke-input-text" type="text" id="keTitle" name="title" value="" style="width:260px;" /></div>' +
					'</div>' +
					'</div>',
				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="<a data-type=\"0\" biz-itemid=\"null\" data-tmpl=\"350x100\" data-tmplid=\"6\" data-rd=\"2\" data-style=\"2\" data-border=\"1\" href=\""+url+"\">"+title+"</a>";
							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属性。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值