当创建一个CKEditor插件时,我如何添加一个“;“颜色选择器”;到我的对话框

When creating a CKEditor plugin, how can I add a "colorpicker" to my dialog?

本文关键字:一个 选择器 颜色 颜色选择器 我的 对话框 添加 插件 CKEditor 创建 何添加      更新时间:2023-09-26
  1. 用户点击我的插件按钮
  2. 对话框弹出,其中包含一些文本框等
  3. 在该对话框中,用户可以单击一个按钮,就会弹出一个颜色选择器,让用户选择他想要的颜色

今天我遇到了同样的问题。这是我的解决方案,它实际上是从CKEditor4.2的TableCell插件中复制粘贴的。希望它能帮助

CKEDITOR.dialog.add( 'myDialog', function( editor ) {
return {
    title: 'Add Data',
    minWidth: 300,
    minHeight: 200,
    contents: [
        {
            id: 'dataTab',
            label: 'Line',
            title: 'Line',
            elements: [
                ...
                {   
                    type: "hbox",
                    padding: 0,
                    widths: ["80%", "20%"],
                    children: [
                        {
                            id: 'linecolor',
                            type: 'text',
                            label: 'Line color',
                            setup: function( element ) {
                                ...
                            },
                            commit: function( element ) {
                                ...
                            }
                        },
                        {
                            type: "button",
                            id: "lineColorChooser",
                            "class": "colorChooser",
                            label: "Choose",
                            style: "margin-left: 8px",
                            onLoad: function () {
                                this.getElement().getParent().setStyle("vertical-align", "bottom")
                            },
                            onClick: function () {
                                editor.getColorFromDialog(function (color) {
                                    color && this.getDialog().getContentElement("dataTab", "linecolor").setValue( color );
                                    this.focus()
                                }, this)
                            }
                        }
                    ]
                },
                ...
            ]
        }
    ],
};
});

使用以下颜色选择器插件;附加到CKEditor form:中的input[type="text"]字段

http://jscolor.com/

这种实现方式的不同之处在于,用户不需要click按钮来选择颜色。当用户focus进入适当的字段时,颜色选择被触发。