I have jsfiddle.
Here the filter word is communicated to the user when he types it on ckeditor. In my example, filtered words are ants and words. So if you enter these words, it will warn the user.
HTML
<input type="textarea" id="editor1"/>
<div id="dest"></div>
Js
var filter = ['ants', 'words'],
regAry = new Array(),
alertedWords = new Array(),
reg = new RegExp("(/s" + filter.join("|") + "/s)", "g");
for(var f in filter) {
regAry[f] = new RegExp(filter[f], "g");
alertedWords[f] = 0;
}
var editor = CKEDITOR.replace( 'editor1' );
editor.on('contentDom', function() {
editor.document.on('keyup', function(event) {
for(var index in regAry) {
var value = CKEDITOR.instances['editor1'].getData();
var test = value.match(regAry[index]);
if( test && test.length > alertedWords[index] )
{
alert("The following word/words "+ CKEDITOR.instances['editor1'].getData().match(regAry[index])+" is banned");
}
alertedWords[index] = (test ? test.length : 0);
}
});
});
Now my problem arises if I have 2 or more ckeditors such as this This
seems to not work. Although editors appear, warnings are not displayed.
HTML
<input type="textarea" id="editor1"/>
<input type="textarea" id="editor2"/>
<div id="dest"></div>
Js
var filter = ['ants', 'words'],
regAry = new Array(),
alertedWords = new Array(),
reg = new RegExp("(/s" + filter.join("|") + "/s)", "g");
for(var f in filter) {
regAry[f] = new RegExp(filter[f], "g");
alertedWords[f] = 0;
}
for(var i=1;i<3;i++){
var editor = CKEDITOR.replace( 'editor'+i );
editor.on('contentDom', function() {
editor.document.on('keyup', function(event) {
for(var index in regAry) {
var value = CKEDITOR.instances['editor'+i].getData();
var test = value.match(regAry[index]);
if( test && test.length > alertedWords[index] )
{
alert("The following word/words "+ CKEDITOR.instances['editor'+i].getData().match(regAry[index])+" is banned");
}
alertedWords[index] = (test ? test.length : 0);
}
});
});
}
Plz will suggest me what to do.
source
share