Javascript 有没有一种方法可以在运行中添加按钮来链接CKEditor的插件?
有几种方法可以在运行时为CKEditor向工具栏添加功能。比如说, 还有一些方法可以为现有的CKEditor链接插件添加新的选择 有没有办法在运行时将按钮添加到现有的链接插件中?我有一个按钮要添加到链接插件中,该按钮取决于用户数据,因此必须在运行时添加该按钮。我使用并更改了源以支持动态更改显示的链接列表。在上面链接处的代码中,您可以看到它们定义了一个设置函数,该函数在每次打开对话框时都会被调用,并且选择按钮会显示:Javascript 有没有一种方法可以在运行中添加按钮来链接CKEditor的插件?,javascript,ckeditor,Javascript,Ckeditor,有几种方法可以在运行时为CKEditor向工具栏添加功能。比如说, 还有一些方法可以为现有的CKEditor链接插件添加新的选择 有没有办法在运行时将按钮添加到现有的链接插件中?我有一个按钮要添加到链接插件中,该按钮取决于用户数据,因此必须在运行时添加该按钮。我使用并更改了源以支持动态更改显示的链接列表。在上面链接处的代码中,您可以看到它们定义了一个设置函数,该函数在每次打开对话框时都会被调用,并且选择按钮会显示: setup : function (f) { this.allo
setup : function (f) {
this.allowOnChange = false;
this.setValue(f.url ? f.url.url : '');
this.allowOnChange = true;
}
您只需使用以下可用方法更改或刷新“选择”中的项目列表:
- this.clear()-删除选择列表中的所有项目
- this.remove(index)-删除选择列表中的项目
- add(文本,url)-在选择列表中添加一个项目
- this.getElement()-获取实际的select元素
我希望这是您想要的。我需要它根据上下文定制CKE。在绘制CDN版本时也很有用。下面是一个例子:
// Must be called before first editor instance creation (i.e. CKEDITOR.replace() action).
function registerPlugin()
{
// Exit if CKEDITOR not present
if (typeof CKEDITOR == undefined) return;
var pluginName = 'filegator'
// Exit if plugin already registered
if(CKEDITOR.config.extraPlugins.search(pluginName) >= 0) return;
// (1) Append plugin in config
CKEDITOR.config.extraPlugins += ',' + pluginName;
// FYI: To change entire CKE default config use:
// CKEDITOR.config = {your config here, like this found in config.js};
// (2) Register the plugin within the editor.
// (2a) File version
//CKEDITOR.plugins.addExternal( 'filegator', 'ckeditor/plugins/filegator/', 'plugin.js' );
// (2b) Inline version
CKEDITOR.plugins.add(pluginName, {
// Register the icons. They must match command names.
//icons: 'openFilegator',
// The plugin initialization logic goes inside this method.
init: function( editor ) {
// Define the editor command that inserts a timestamp.
editor.addCommand( 'openFilegator', {
// Define the function that will be fired when the command is executed.
exec: function( editor ) {
var now = new Date();
// Insert the timestamp into the document.
editor.insertHtml( 'The current date and time is: <em>' + now.toString() + '</em>' );
}
});
// Create the toolbar button that executes the above command.
editor.ui.addButton( 'Filegator', {
label: 'Open Filegator',
command: 'openFilegator',
toolbar: 'links',
className: 'cke-openFilegator',
icon: '/iframes/openFilegator.png',
});
}
});
}
//必须在创建第一个编辑器实例之前调用(即CKEDITOR.replace()操作)。
函数寄存器Plugin()
{
//如果编辑器不存在,则退出
if(typeof CKEDITOR==未定义)返回;
var pluginName='filegator'
//如果插件已经注册,则退出
if(CKEDITOR.config.extraPlugins.search(pluginName)>=0)返回;
//(1)在配置中附加插件
CKEDITOR.config.extraPlugins+=','+pluginName;
//仅供参考:要更改整个CKE默认配置,请使用:
//CKEDITOR.config={此处的配置,如config.js中的配置};
//(2)在编辑器中注册插件。
//(2a)文件版本
//addExternal('filegator','CKEDITOR/plugins/filegator/','plugin.js');
//(2b)内联版本
CKEDITOR.plugins.add(pluginName{
//注册图标。它们必须与命令名匹配。
//图标:“openFilegator”,
//插件初始化逻辑在这个方法中。
init:函数(编辑器){
//定义插入时间戳的编辑器命令。
editor.addCommand('openFilegator'{
//定义执行命令时将激发的函数。
执行:函数(编辑器){
var now=新日期();
//将时间戳插入文档中。
editor.insertHtml('当前日期和时间为:'+now.toString()+'');
}
});
//创建执行上述命令的工具栏按钮。
editor.ui.addButton('Filegator'{
标签:“Open Filegator”,
命令:“openFilegator”,
工具栏:“链接”,
类名:“cke openFilegator”,
图标:'/iframes/openFilegator.png',
});
}
});
}
然后在
之后的某个地方:
registerPlugin();
//将替换为CKEditor实例。
CKEDITOR.replace('editor1');
CKEDITOR.replace('editor2');
CKEDITOR.replace('editor3');
//等等。
registerPlugin();
// Replace the <textarea id="editor1"> with a CKEditor instance.
CKEDITOR.replace( 'editor1' );
CKEDITOR.replace( 'editor2' );
CKEDITOR.replace( 'editor3' );
// etc.