经过一天的研究,我无法在不修改nicEdit.js的情况下完成它。但是,我只需进行很少的更改就能够完成。这里是我的更改(我正在使用版本0.9r24):
我添加了一个名为
customKeyDownFunction
的配置选项。默认情况下它什么也不做。
var nicEditorConfig = bkClass.extend({
buttons : {
'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
'italic' : {name : __('Click to Italic'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
'underline' : {name : __('Click to Underline'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
'left' : {name : __('Left Align'), command : 'justifyleft', noActive : true},
'center' : {name : __('Center Align'), command : 'justifycenter', noActive : true},
'right' : {name : __('Right Align'), command : 'justifyright', noActive : true},
'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true},
'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']},
'ul' : {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']},
'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']},
'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']},
'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
'removeformat' : {name : __('Remove Formatting'), command : 'removeformat', noActive : true},
'indent' : {name : __('Indent Text'), command : 'indent', noActive : true},
'outdent' : {name : __('Remove Indent'), command : 'outdent', noActive : true},
'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true}
},
iconsPath : '../nicEditorIcons.gif',
buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor'],
iconList : {"bgcolor":1,"forecolor":2,"bold":3,"center":4,"hr":5,"indent":6,"italic":7,"justify":8,"left":9,"ol":10,"outdent":11,"removeformat":12,"right":13,"save":24,"strikethrough":15,"subscript":16,"superscript":17,"ul":18,"underline":19,"image":20,"link":21,"unlink":22,"close":23,"arrow":25},
customKeyDownFunction : function() { }
});
我修改了keyDown函数。
keyDown : function(e,t) {
this.ne.options.customKeyDownFunction();
if(e.ctrlKey) {
this.ne.fireEvent('key',this,e);
}
}
当我创建我的nicEditor实例时,我定义了
customKeyDownFunction
。
var emailRtf = new nicEditor({
iconsPath : 'nicEdit/nicEditorIcons.gif',
buttonList : ['bold','italic','underline','fontSize','forecolor','ol','ul','link','unlink','removeformat'],
maxHeight: 600,
customKeyDownFunction: function() { alert('key down!'); }
}).panelInstance('REPLY_MESSAGE');
如果您不需要任何自定义功能,只需不定义
customKeyDownFunction
即可。
var emailRtf = new nicEditor({
iconsPath : 'nicEdit/nicEditorIcons.gif',
buttonList : ['bold','italic','underline','fontSize','forecolor','ol','ul','link','unlink','removeformat'],
maxHeight: 600
}).panelInstance('REPLY_MESSAGE');
这是我能做到的最好了。如果有更好的方法,请告诉我!
document.getElementById('REPLY_MESSAGE').parentElement.onkeypress = function(){alert('按键被按下!');};
- Simon Arsenault