ueditor 设置默认字体、大小和颜色;回车事件捕获

简单记录下,最近工作中要用到一个富文本框,采用之前同事用的ueditor,百度的开源软件。http://ueditor.baidu.com/doc/

他们的API不好看,好辛苦,百度搜了好久也没什么太多资料,最后还是去看源码,找到了比较好的修改方法:ueditor用iframe实现编辑框,设置body的样式即可,

//default font and color
UE.dom.domUtils.setStyles(self.ue.body, {
'color': '#868686','font-family' : "'Microsoft Yahei','Helvetica Neue', Helvetica, STHeiTi, Arial, sans-serif", 'font-size' : '14px'
});

看网上有人直接改ueditor.all.js文件我觉得太粗暴了(http://blog.csdn.net/yxstars/article/details/44655857),用我这种配置的方式会更好些,且在不同的实例中可以设置不同的样式,这样更好。

顺便说一句:修改配置文件ueditor.config.js只是修改可选项,不能修改默认值,所以实例的时候给options,或者editor.setOpt(Object)这些都没用。

################ 下面是我的代码片段,我还实现了回车即发送的功能,希望对其他朋友有所帮助

         #### code begin ############

//实例化编辑器
var self = this;
self.ue = UE.getEditor('editor',{toolbars: []});
self.ue.ready(function(){
self.isloadedUE = true;
//set Global.ueditor
Global.ueditor = self.ue;

self.ue.setDisabled();
//default font and color
UE.dom.domUtils.setStyles(self.ue.body, {
'color': '#868686','font-family' : "'Microsoft Yahei','Helvetica Neue', Helvetica, STHeiTi, Arial, sans-serif", 'font-size' : '14px'
});
//回车发送
UE.dom.domUtils.on(self.ue.body, 'keyup', function(event){
if(event.keyCode == 13){
console.log('enter ok');
event.preventDefault();
event.stopPropagation();
self.sendMsg();
}
});
});

################ code end ############

 

posted @ 2016-08-17 18:50  xxchao  阅读(9590)  评论(0编辑  收藏  举报