javascript - 从对话框 html 元素访问 ckeditor 函数而不使用 "onOk"

标签 javascript ckeditor

我正在尝试使用 html 元素创建自己的插件和对话框。单击 html 元素时,我希望将一些文本添加到编辑器中。我找不到绕过 onOk 函数的方法。

如果我在 onOk 函数内使用 editor.insertHtml(' some code ') ,则会添加文本,但如果我想在外部使用它,我会得到 未捕获的类型错误:无法读取未定义(…)的属性“编辑器”错误。

访问编辑器的正确方法是什么?

CKEDITOR.dialog.add( 'smiley2', function( editor ) {
    return {
        title: 'Abbreviation Properties',
        minWidth: 400,
        minHeight: 200,
        contents: [
            {
                id: 'tab-basic',
                label: 'Basic Settings',
                elements: [
                    {
                        type: 'html',
                        id: '2',
                        label: 'Explanation',
                        html: "<div onclick=\"editor.insertHtml(' some code ')\">add code</a></div></div>"
                    }
                ]
            }
        ],
         onShow : function()
            {          
            document.getElementById(this.getButton('ok').domId).style.display='none'; // disapper ok btn
            },
        onOk: function() {

            editor.insertHtml(' abbr ');
        }
    };
});

最佳答案

CKEDITOR.dialog.add( 'smiley2', function( editor ) {

    var onChoice = function(evt) {
            var target;
            target = new CKEDITOR.dom.element(evt); 
            editor.insertHtml("SMILEY YES!");
            CKEDITOR.dialog.getCurrent().hide();
    };
    var onClick = CKEDITOR.tools.addFunction(onChoice); 

    return {
        title: 'Abbreviation Properties',
        minWidth: 400,
        minHeight: 200,
        buttons: [CKEDITOR.dialog.cancelButton],
        contents: [
            {
                id: 'tab-basic',
                label: 'Basic Settings',
                elements: [
                    {
                        type: 'html',
                        id: '2',
                        label: 'Explana22tion',
                        html: "<div  onclick=\"CKEDITOR.tools.callFunction(" + onClick +", this); return false;\" >111111</a></div></div>"
                    }
                ]
            }
        ] 

    };
});

关于javascript - 从对话框 html 元素访问 ckeditor 函数而不使用 "onOk",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41120075/

相关文章:

javascript - Bootstrap 选项卡中的 CKeditor autogrow 插件

ckeditor - 使用什么 IDE 开始为 CKEditor 贡献代码?

javascript - Node.js/ express : download file via ajax

javascript - 具有复合索引的 IDBKeyRange 的奇怪行为

javascript - 将 PDF 文件加载到文本框中

javascript - 将 thisArg 传递给映射函数

symfony - EasyAdminBundle : Validation not working on CKEditorType

drupal - 如何在CKEditor中添加自定义段落格式

javascript - 替换ckeditor中的内容标签html

javascript - 为什么这个 jQuery 动画在 Firefox 4/5 上这么慢?