CKEditor:使用工具栏按钮控制Entermode
默认情况下,CKEditor的输入键行为是添加一个CKEditor:使用工具栏按钮控制Entermode,ckeditor,Ckeditor,默认情况下,CKEditor的输入键行为是添加一个标记并开始一个新段落。但是,可以在配置中使用.EnterMode参数修改该行为 我想知道是否有一种方法可以在运行时更改Enter键的行为,方法是在工具栏中插入一个按钮,在和(单行与双线)之间切换,就像Word中一样 有什么想法吗?将以下内容保存到编辑器\u dir/plugins/entermode/plugin.js: 'use strict'; (function() { CKEDITOR.plugins.add( 'entermo
标记并开始一个新段落。但是,可以在配置中使用.EnterMode
参数修改该行为
我想知道是否有一种方法可以在运行时更改Enter键的行为,方法是在工具栏中插入一个按钮,在
和
(单行与双线)之间切换,就像Word中一样
有什么想法吗?将以下内容保存到编辑器\u dir/plugins/entermode/plugin.js
:
'use strict';
(function() {
CKEDITOR.plugins.add( 'entermode', {
icons: 'entermode',
init: function( editor ) {
var enterP = new enterModeCommand( editor, CKEDITOR.ENTER_P );
var enterBR = new enterModeCommand( editor, CKEDITOR.ENTER_BR );
editor.addCommand( 'entermodep', enterP );
editor.addCommand( 'entermodebr', enterBR );
if ( editor.ui.addButton ) {
editor.ui.addButton( 'EnterP', {
label: 'Enter mode P',
command: 'entermodep',
toolbar: 'paragraph,10'
});
editor.ui.addButton( 'EnterBR', {
label: 'Enter mode BR',
command: 'entermodebr',
toolbar: 'paragraph,20'
});
}
editor.on( 'dataReady', function() {
refreshButtons( editor );
});
}
});
function refreshButtons( editor ) {
editor.getCommand( 'entermodep' ).setState(
editor.config.enterMode == CKEDITOR.ENTER_P ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
editor.getCommand( 'entermodebr' ).setState(
editor.config.enterMode == CKEDITOR.ENTER_BR ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
}
function enterModeCommand( editor, mode ) {
this.mode = mode;
}
enterModeCommand.prototype = {
exec: function( editor ) {
editor.config.enterMode = this.mode;
refreshButtons( editor );
},
refresh: function( editor, path ) {
refreshButtons( editor );
}
};
})();
现在将以下内容添加到皮肤文件中的toolbar.css
:
.cke_button__enterp_icon, .cke_button__enterbr_icon { display: none !important; }
.cke_button__enterp_label, .cke_button__enterbr_label { display: inline !important; }
…或者画一些图标,如果你愿意的话
运行编辑器时启用插件:
CKEDITOR.replace( 'id', { extraPlugins: 'entermode' } );
现在,您可以从工具栏控制config.enterMode
。很抱歉我的响应太晚。我现在正在尝试您的方法,但在我的项目中的任何地方都找不到toolbar.css文件,我是否应该在/skins/moono/文件夹中创建该文件?您可以将其添加到editor.css
,因为toolbar.css
在发布版本中是它的一部分。