我正在开发一个项目,其要求是:如果用户按下快捷键,则符号将插入文本编辑器中。喜欢:
if press Shift+1 then insert ✓
if press Shift+2 then insert ✗
我在textarea做过这个,但是我在这个项目中使用CKEDITOR而且我已经尝试过按键'像这样,但没有工作:
CKEDITOR.config.keystrokes = [
[ CKEDITOR.SHIFT + 76, function(){
console.log('sdsd');
} ]
];
有人可以帮帮我吗?谢谢高级。
答案 0 :(得分:1)
您可以使用命令执行如下的功能。
CKEDITOR.plugins.add('foo',
{
init: function( editor ) {
editor.addCommand( 'sample', {
exec: function( editor ) {
alert( 'Executing a command for the editor name "' + editor.name + '"!' );
}
} );
editor.setKeystroke( CKEDITOR.CTRL + 81, 'sample' ); // CTRL+Q
}
});
或以你的方式但是在定义命令之后。
CKEDITOR.config.keystrokes = [
[ CKEDITOR.SHIFT + 76, 'sample' ]
];
CKEDITOR.config.keystrokes
的第二个值要求命令名称不是函数。
NB:由于实现是使用插件。您还必须配置编辑器以使用extraPlugins
配置
CKEDITOR.replace('editor', {
extraPlugins : 'foo'
});
根据您的需要,只需将按键映射到符号即可。您可以使用this插件。
免责声明:我是that插件的作者
答案 1 :(得分:0)
您需要使用这样的setkystroke方法:
对于4.x,请使用editor.setKeystroke:
CKEDITOR.plugins.add( 'test', {
init: function( editor ) {
editor.setKeystroke( CKEDITOR.CTRL + 81, 'bold' ); // CTRL+Q
}
} );
对于3.x:
CKEDITOR.plugins.add( 'test', {
init: function( editor ) {
editor.on( 'instanceReady', function( evt ) {
evt.removeListener();
this.keystrokeHandler.keystrokes[ CKEDITOR.CTRL + 81 ] = 'bold'; // CTRL+Q
} );
}
} );