gpt4 book ai didi

javascript - ckeditor - javascript拼写检查插件

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:42 26 4
gpt4 key购买 nike

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

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

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

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

最佳答案

联系 JavaScriptSpellcheck 支持后,他们回复说“SCAYT 不能与任何编辑器一起使用,因为它有将垃圾 HT​​ML 注入(inject)您的表单的风险”。所以 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
});
}
});
})();

关于javascript - ckeditor - javascript拼写检查插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com