对于 CKEditor 4,每个编辑器的可用命令会有所不同,具体取决于:
- 您加载了哪些插件。
- 您为编辑器提供了哪些配置选项。
以下是列出可用命令的两个函数。
注意:在编辑器实例准备好之前,这两个函数将返回一个不完整的列表。
//get all commands from specific editor
function getEditorInstanceCommands(instanceId) {
var results = [], command, instance;
instance = CKEDITOR.instances[instanceId];
if (instance) {
for (command in instance.commands) {
if (results.indexOf(command) == -1) results.push(command);
}
}
return results;
}
//get all commands from all editors
function getAllCommands() {
var results = [], key, instance, command;
for (key in CKEDITOR.instances) {
instance = CKEDITOR.instances[key];
for (command in instance.commands) {
if (results.indexOf(command) == -1) results.push(command);
}
}
return results;
}
要在编辑器准备就绪时获取每个编辑器的所有命令列表,您可以执行以下操作:
//get all commands from specific editor
function getEditorInstanceCommands(instanceId) {
var results = [], command, instance;
instance = CKEDITOR.instances[instanceId];
if (instance) {
for (command in instance.commands) {
if (results.indexOf(command) == -1) results.push(command);
}
}
return results;
}
CKEDITOR.on('instanceReady', function(e) {
console.info(getEditorInstanceCommands(e.editor.name));
});
要创建包含所有可能命令的编辑器,然后获取这些命令,您可以执行以下操作:
<div id='MyEditor'></div>
<script>
CKEDITOR.inline('MyEditor', { customConfig: '' });
var commands = getEditorInstanceCommands('MyEditor');
</script>