ckeditor - Ckeditor 3 - 选择工具栏按钮时单击插入元素
问题描述
我想在单击 Ckeditor textarea 窗口时插入某些文本或 html(默认和重复)。
我创建了一个自定义插件,它可以在单击工具栏按钮时添加一些文本,或者在通过下面的代码片段单击 textarea 窗口时添加文本。
CKEDITOR.plugins.add( 'duppointer',
{
init: function( editor )
{
editor.addCommand( 'insertDup',
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
editor.insertText( '#' );
}
});
editor.on( 'contentDom', function(){
this.document.on( 'click', function() {
editor.insertText( '#' );
});
});
editor.ui.addButton( 'duppointer',
{
label: 'Insert Duplicate Text',
command: 'insertDup',
} );
}
} );
但是,我只想在工具栏按钮处于活动状态时才在单击时插入文本,否则指针单击必须正常。
有可能实现这一目标吗?
解决方案
由于没有人回应,我开始深入挖掘API并了解按钮的状态。最后,我得到了我正在寻找的东西,如果它是正确的方法,但它对我有用,
CKEDITOR.plugins.add( 'duppointer',
{
init: function( editor )
{
var ccommand = editor.addCommand( 'duppointer',
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
ccommand.toggleState();
},
editorfocus: true,
});
editor.on( 'contentDom', function(){
this.document.on( 'click', function() {
if(ccommand.state == CKEDITOR.TRISTATE_ON){
editor.insertText( '#' );
}
});
});
editor.ui.addButton( 'duppointer',
{
label: 'Insert Duplicate',
command: 'duppointer',
icon: this.path + 'images/dup.jpg'
} );
}
} );
推荐阅读
- redis - 授权是Redis:ACL
- html - 悬停触发重叠 CSS
- asp.net - 如何根据条件要求填充实体属性 - ASP NET Core MVC 和实体框架
- javascript - 页面刷新后保持下拉菜单打开
- amazon-web-services - Sagemaker Pytorch 模型 - 调用 InvokeEndpoint 操作时发生错误(InternalFailure)(达到最大重试次数:4):
- javascript - NodeJS 动态环境变量设置
- database - MongoDB 查询一个是简单的查找,另一个是使用正则表达式搜索相同的字符串,但结果都不同
- javascript - 使用 GULP 将来自 IP/$url 的请求重定向到 IP:port
- html - 动画剪辑路径时如何防止SVG路径上的轮廓?
- php - 我不能在 NB(8.2) 中使用宇宙飞船