在创建CKEditor插件时,如何在对话框中添加“colorpicker”?

时间:2012-01-11 03:44:04

标签: javascript jquery colors ckeditor

  1. 用户点击我的插件按钮。
  2. 弹出包含一些文本框等的对话框
  3. 在该对话框中,用户可以单击按钮,弹出颜色选择器,让用户选择他想要的颜色。

2 个答案:

答案 0 :(得分:2)

今天我遇到了同样的问题。这是我的解决方案,实际上是来自CKEditor 4.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)
                            }
                        }
                    ]
                },
                ...
            ]
        }
    ],

};
});

答案 1 :(得分:0)

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

http://jscolor.com/

此实现的不同之处在于用户无需click按钮来选择颜色。当用户focus进入相应的字段时,将触发颜色选择。