CKEditor - JavaScriptSpellCheck插件

4
我正在尝试将javascriptspellchecker集成到一个网页中,该网页使用ckEditor(请注意,我正在使用ckeditor版本3.6)。我想用新的自定义插件替换默认的拼写检查和SCAYT(实时拼写检查)插件,这些插件使用javascriptspellcheck。
我已经按照javascriptspellchecker网站上的示例创建了一个插件,但它不能正常工作。javascriptspellchecker获取文本区域的id并对其值进行拼写检查(或在选择SCAYT时附加事件处理程序以进行输入后的拼写检查)。问题是,当我更改ckEditor实例中的文本时,隐藏的文本框似乎没有在后台更新。这意味着我编写的插件仅检查文本区域的原始值,而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()函数。但这并不起作用,有人能帮忙吗?
我的SCAYT插件使用ckeditor onchange插件:
exec: function (editor) {
    editor.on('change', function (e) { this.updateElement(); });
    $Spelling.SpellCheckAsYouType($(editor.element).attr('id'));
}
1个回答

3
在联系JavaScriptSpellcheck支持后,他们回复说:“SCAYT不会与任何编辑器一起使用,因为它可能会向您的表单中注入垃圾HTML”。因此,CK Editor的SCAYT插件是不可能的。如我在问题更新中所述,适用于CK Editor(v3.6)的Windows插件拼写检查的代码如下:
(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
            });
        }
    });
})();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接