寻找详尽的命令列表和设置样式的方法

发布于 2024-08-26 06:21:28 字数 357 浏览 5 评论 0原文

我目前正在使用 CKEditor (http://ckeditor.com/)。我正在寻找:

1)默认情况下通过“execCommand”可用的命令的详尽列表。

2) 设置样式的机制(与 FONT 和 SIZE 组合框的方式相同)。我在文档中看到了名为“setStyle”的函数,但它似乎需要一个 exact 元素。我无法根据选择弄清楚如何执行此操作 - 无法使用 ID 或 CLASS,因为所选部分没有。

我已经在论坛上发帖了,但就回复而言,他们似乎不太活跃。任何帮助将不胜感激。

最好的。

I'm currently working with CKEditor (http://ckeditor.com/). I'm looking for:

1) an exhaustive list of commands available by default via 'execCommand'.

2) a mechanism by which to set styles (as in the same way the FONT and SIZE combo boxes do it). I saw the function called 'setStyle' in the documentation, however it seems to require an exact element. I can't for the life of me figure out how to do so based on the selection -- there is no way to use ID or CLASS, as the selected portions have none.

I've posted to the forums but they don't seem to be terribly active as far as replies are concerned. Any assistance would be most appreciated.

Best.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

悟红尘 2024-09-02 06:21:28

您可以在 _source 文件夹中搜索“.addCommand”,这将为您提供可以在编辑器上执行的所有命令的完整列表。我猜您只对该列表的一部分感兴趣,因为其中一些是供内部使用的。

You can do a little search in the _source folder for ".addCommand" and that will give you a full list of all commands that can be executed on an editor. I guess that you are interested only in a part of that list, as some are meant for internal use.

殤城〤 2024-09-02 06:21:28

对于 CKEditor 4,每个编辑器的可用命令会有所不同,具体取决于:

  1. 您加载了哪些插件。
  2. 您为编辑器提供了哪些配置选项。

下面是两个列出可用命令的函数。

注意:在编辑器实例准备就绪之前,这两个函数将返回不完整的列表。

//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>

For CKEditor 4 the available commands vary for each editor based on:

  1. Which plugins you have loaded.
  2. What configuration options you've given an editor.

Below are two functions that will list available commands.

Note: Until an editor instance is ready, these two functions will return an incomplete list.

//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;
}

To get a list of all commands per editor as the editor becomes ready you would do something like:

//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));
});

To create an editor with all possible commands and then to get those commands you can do the following:

<div id='MyEditor'></div>
<script>
    CKEDITOR.inline('MyEditor', { customConfig: '' });
    var commands = getEditorInstanceCommands('MyEditor');
</script>
千と千尋 2024-09-02 06:21:28

我可以推荐的最好的事情是查看 javscript api

可以进行一些研究和尝试错误 我能够更改字体颜色,

 $('#test').click(function (){
 //   fck is the instace name of the editor
    editor = CKEDITOR.instances.fck;
    var selected_text = editor.getSelection().getNative();
 // editor.insertHtml('[foo]' + selected_text + '[bar]');
    var element = editor.getSelection().getStartElement();
    element.setStyle( 'color', '#ff0000' );
 })

只需付出一点努力即可得到你想要的东西,我的朋友。

best thing I can recommend is to to look at the javscript api

ok with a little research some trial and error I was able to change the font color

 $('#test').click(function (){
 //   fck is the instace name of the editor
    editor = CKEDITOR.instances.fck;
    var selected_text = editor.getSelection().getNative();
 // editor.insertHtml('[foo]' + selected_text + '[bar]');
    var element = editor.getSelection().getStartElement();
    element.setStyle( 'color', '#ff0000' );
 })

just got to put in a little elbow grease to get what you want my friend.

烛影斜 2024-09-02 06:21:28

我没有使用 execCommand,但根据我的理解,您可以执行工具栏中的任何内容。

editor.execCommand( "div" );
editor.execCommand( "bold" );

要设置样式,请将其添加到您的 config.js 文件中。

CKEDITOR.editorConfig = function(config) {
    CKEDITOR.addStylesSet('customStyles',
    [
        { name: 'Header 1', element: 'h1' },
        { name: 'Header 2', element: 'h2' },
        { name: 'Header 3', element: 'h3' },
        { name: 'Text', element: 'p' },
        { name: 'Left Align', element: 'img', attributes: { 'class': 'ImageLeft'} },
        { name: 'Right Align', element: 'img', attributes: { 'class': 'ImageRight'} }
    ]);
};

I have not used the execCommand, but from my understanding you can execute anything that is in the toolbar.

editor.execCommand( "div" );
editor.execCommand( "bold" );

To set style add this to you config.js file.

CKEDITOR.editorConfig = function(config) {
    CKEDITOR.addStylesSet('customStyles',
    [
        { name: 'Header 1', element: 'h1' },
        { name: 'Header 2', element: 'h2' },
        { name: 'Header 3', element: 'h3' },
        { name: 'Text', element: 'p' },
        { name: 'Left Align', element: 'img', attributes: { 'class': 'ImageLeft'} },
        { name: 'Right Align', element: 'img', attributes: { 'class': 'ImageRight'} }
    ]);
};
反目相谮 2024-09-02 06:21:28

尽管我知道这不是一个详尽的列表,并且会根据配置而有所不同。如果您不想仅仅为了获得基本命令列表而输入所有这些内容,那么以下是我在 CKEDITOR 4 上执行内联编辑器时得到的结果:

["contextMenu"、"about"、"a11yHelp"、"粗体"、"斜体"、"下划线"、"删除线"、"下标"、"上标"、"块引用"、"剪切"、"复制"、"粘贴"、"输入"、"shiftEnter"、"水平规则"、"图像"、"缩进"、"减少缩进"、"链接"、"锚点"、"取消链接"、"removeAnchor"、"编号列表"、 “bulletedlist”、“pastetext”、“pastefromword”、“removeFormat”、“specialchar”、“scaytcheck”、“blur”、“blurBack”、“selectNextCell”、“selectPreviousCell”、“table”、“tableProperties”、“tableDelete” ”、“cellProperties”、“rowDelete”、“rowInsertBefore”、“rowInsertAfter”、“columnDelete”、“columnInsertBefore”、“columnInsertAfter”、“cellDelete”、“cellMerge”、“cellMergeRight”、“cellMergeDown”、“cellVerticalSplit”、 “cellHorizo​​ntalSplit”,“cellInsertBefore”,“cellInsertAfter”,“撤消”,“重做”,“checkspell”,“accessPreviousSpace”,“accessNextSpace”]

Though I know this is not an exhaustive list and will differ based on configuration. If you don't want to have to type in all of this just to get a basic list of commands, here is what I get when doing an inline editor on CKEDITOR 4:

["contextMenu", "about", "a11yHelp", "bold", "italic", "underline", "strike", "subscript", "superscript", "blockquote", "cut", "copy", "paste", "enter", "shiftEnter", "horizontalrule", "image", "indent", "outdent", "link", "anchor", "unlink", "removeAnchor", "numberedlist", "bulletedlist", "pastetext", "pastefromword", "removeFormat", "specialchar", "scaytcheck", "blur", "blurBack", "selectNextCell", "selectPreviousCell", "table", "tableProperties", "tableDelete", "cellProperties", "rowDelete", "rowInsertBefore", "rowInsertAfter", "columnDelete", "columnInsertBefore", "columnInsertAfter", "cellDelete", "cellMerge", "cellMergeRight", "cellMergeDown", "cellVerticalSplit", "cellHorizontalSplit", "cellInsertBefore", "cellInsertAfter", "undo", "redo", "checkspell", "accessPreviousSpace", "accessNextSpace"]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文