繁体   English   中英

ckeditor-javascriptspellcheck插件

[英]ckeditor - javascriptspellcheck plugin

我试图整合javascriptspellchecker与网页CKEDITOR (注意我用的CKEditor的3.6版)。 我想用使用javascriptspellcheck的新自定义插件替换默认的拼写检查和SCAYT(键入时进行拼写检查)插件。

我已根据javascriptspellchecker网站上的示例创建了一个插件,但无法正常工作。 javascriptspellchecker获取文本区域的ID并对其值进行拼写检查(或在选择SCAYT时在输入后将事件处理程序附加到拼写检查中)。 问题是,当我更改ckEditor实例中的文本时,隐藏的文本框似乎不会在后台更新。 这意味着我编写的插件仅检查textarea的原始值,而SCAYT不起作用。

到目前为止,我的插件:

(function () {
    //Section 1 : Code to execute when the toolbar button is pressed
    var a = {
        exec: function (editor) {
            $Spelling.SpellCheckInWindow($(editor.element).attr('id'))
        }
    },

    //Section 2 : Create the button and add the functionality to it
    b = 'javascriptspellcheck';
    CKEDITOR.plugins.add(b, {
        init: function (editor) {
            editor.addCommand(b, a);
            editor.ui.addButton("JavaScriptSpellCheck", {
                label: 'Check Spelling',
                icon: this.path + "images/spell.png",
                command: b
            });
        }
    });
})();

有谁知道是否可以制作一个有效的插件? 有没有一种方法可以强制编辑器更新隐藏的文本区域,或者可以将其他DOM元素传递给拼写检查器?

更新:

如果有用,我插件的SCAYT版本使用以下执行函数

exec: function (editor) {
    $Spelling.SpellCheckAsYouType($(editor.element).attr('id'))
}

更新2:

我找到了正常拼写检查的解决方案,可以在运行拼写检查之前调用editor.UpdateElement(),它可以工作! 我不确定为什么,但是当我用Firebug检查原始文本区域时,值似乎没有改变。

新的拼写检查插件

(function () {
    //Section 1 : Code to execute when the toolbar button is pressed
    var a = {
        exec: function (editor) {
            editor.updateElement();
            $Spelling.SpellCheckInWindow($(editor.element).attr('id'));
        }
    },

    //Section 2 : Create the button and add the functionality to it
    b = 'javascriptspellcheck';
    CKEDITOR.plugins.add(b, {
        init: function (editor) {
            editor.addCommand(b, a);
            editor.ui.addButton("JavaScriptSpellCheck", {
                label: 'Check Spelling',
                icon: this.path + "images/spell.png",
                command: b
            });
        }
    });
})();

我仍然无法让SCAYT工作。 我找到了一个ckeditor插件来捕获更改事件,并尝试在每次更改时再次调用updateElement()函数。 但这不起作用,任何人都可以帮忙吗?

我使用ckeditor onchange插件的SCAYT插件:

exec: function (editor) {
    editor.on('change', function (e) { this.updateElement(); });
    $Spelling.SpellCheckAsYouType($(editor.element).attr('id'));
}

联系JavaScriptSpellcheck支持人员后,他们回答说:“ SCAYT将无法与任何编辑器一起使用,因为它可能会向您的表单中注入垃圾HTML ”。 因此无法使用CK Editor的SCAYT插件。 在我的问题更新中,用于CK编辑器(v3.6)的窗口插件中有效的拼写检查代码如下:

(function () {
    //Section 1 : Code to execute when the toolbar button is pressed
    var a = {
        exec: function (editor) {
            editor.updateElement();
            $Spelling.SpellCheckInWindow($(editor.element).attr('id'));
        }
    },

    //Section 2 : Create the button and add the functionality to it
    b = 'javascriptspellcheck';
    CKEDITOR.plugins.add(b, {
        init: function (editor) {
            editor.addCommand(b, a);
            editor.ui.addButton("JavaScriptSpellCheck", {
                label: 'Check Spelling',
                icon: this.path + "images/spell.png",
                command: b
            });
        }
    });
})();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM