【问题标题】:ckeditor - javascriptspellcheck pluginckeditor - javascriptspellcheck 插件
【发布时间】:2012-12-21 13:34:42
【问题描述】:

我正在尝试使用ckEditorjavascriptspellchecker 集成到网页中(注意我使用的是ckeditor 3.6 版)。我想用使用 javascriptspellcheck 的新自定义插件替换默认的拼写检查和 SCAYT(键入时进行拼写检查)插件。

我按照 javascriptspellchecker 网站上的示例创建了一个插件,但它不能正常工作。 javascriptspellchecker 获取 textarea 的 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 检查原始 textarea 时,值似乎没有改变。

新的拼写检查插件

(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 plugin 来捕获更改事件,并尝试在每次更改时再次调用 updateElement() 函数。但是这不起作用,有人可以帮忙吗?

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

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

【问题讨论】:

    标签: javascript jquery ckeditor


    【解决方案1】:

    在联系 JavaScriptSpellcheck 支持人员后,他们回复说“SCAYT 无法与任何编辑器一起使用,因为它可能会将垃圾 HT​​ML 注入您的表单中”。所以 CK Editor 的 SCAYT 插件是不可能的。在我的问题更新中,CK Editor (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
                });
            }
        });
    })();
    

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多