自定义插件CKEditor 4不插入内容onOK



我为CKEditor 4编写了一个'简单'插件,用于插入具有数据属性和类的div(数据属性是通过简单的对话窗口设置的)。除了单击ok之外,一切都可以工作,没有任何东西插入到实际的编辑器窗口中。有人可以看看我的代码下面,也许指出我在哪里走错了。谢谢。

编辑配置

CKEDITOR.editorConfig = function (config) {
config.BaseHref = 'http://cdn.aoec.com/';
config.extraPlugins = 'contactforms,autogrow,justify,filebrowser,showblocks,tabletools,tweetabletext,widget,widgetbootstrap,widgettemplatemenu,wsc,moxiemanager,video,bootstrapCollapse,image2';
config.autoGrow_minHeight = 400;
config.contentsCss = '/content/styles/site.css';
config.skin = 'flat';
config.allowedContent = true;
config.bootstrapCollapse_managePopupContent = true;
config.toolbar = [
    ['Source', '-', 'Templates', 'ShowBlocks'],
    ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
    ['Link', 'Unlink', 'Anchor'], ['Table', 'TableTools', 'HorizontalRule', 'SpecialChar'],
    ['CreatePlaceholder', 'Image', 'Video'],
    ['Bold', 'Italic', 'Strike', 'Subscript', 'SuperScript', '-', 'RemoveFormat', 'Styles', 'Format'],
    ['NumberedList', 'BulletedList', '-', 'BlockQuote'],
    ['createDiv', 'JustifyLeft', 'JustfiyCenter', 'JustifyRight', 'JustifyBlock'],
    ['TweetableText'], ['WidgetTemplateMenu'],
    ['BootstrapCollapse'], ['ContactForms']
];
};

Plugin.js

CKEDITOR.plugins.add('contactforms', {
icons: 'contactforms',
init: function (editor) {
    editor.addCommand('contactforms', new CKEDITOR.dialogCommand('contactformsdialog', {
        allowedContent: 'div[class,data-form-id]'
    }));
    editor.ui.addButton('ContactForms', {
        label: 'Insert a Contact Form',
        command: 'contactforms',
        toolbar: 'insert'
    });
    CKEDITOR.dialog.add('contactformsdialog', this.path + 'dialogs/contactforms.js');
}
});

contactforms.js

CKEDITOR.dialog.add('contactformsdialog', function(editor) {
return {
    title: 'Insert a Contact Form',
    minWidth: 320,
    minHeight: 200,
    contents: [
        {
            id: 'tab-basic',
            label: 'Basic Settings',
            elements: [
                {
                    type: 'text',
                    id: 'formid',
                    label: 'Form ID',
                    validate: CKEDITOR.dialog.validate.notEmpty("Form ID field cannot be empty.")
                }
            ]
        }
    ],
    onOK: function() {
        var dialog = this;
        var theForm = editor.document.createElement('div');
        theForm.setAttribute('class', 'contactform');
        var theFormId = dialog.getValueOf('tab-basic', 'formid');
        theForm.setAttribute('data-form-id', theFormId);
        editor.insertElement(theForm);

    }
};
});

我发现了错误。onOK应该是onOK。

最新更新