To add a method directly to the prototype:
(function () { /** Cancel All highlights * Noset =true back to clean up after the content is not refreshed editor * Noset =false or does not pass back the cleanup content Refresh editor*/CKEDITOR.editor.prototype.CancleSensitiveWordsHighlight=function () { varREGSTREPSWH = ' <span class= ' ep_ckeditor_sensitivewords "style=" background-color:[^<>:]+[;] * "> ([^<>]+) <\\/span>"; varHTMLEPSWH = This. GetData (); HTMLEPSWH= Htmlepswh.replace (eval ("/" + REGSTREPSWH + "/ig"), "$"); if( This. Document! =NULL) This. Document.getbody (). sethtml (HTMLEPSWH); returnHTMLEPSWH; } /** epswhlwords Sensitive words * Epswhligchar special characters ignored in sensitive words * epswhlcolor Highlight background*/CKEDITOR.editor.prototype.SensitiveWordsHighlight=function(Epswhlwords, Epswhligchar, Epswhlcolor) {//an empty string if(typeofEpswhlwords = = "string" &&!epswhlwords)return; //Empty Array if(typeofEpswhlwords = = "Object" && epswhlwords[0] = =undefined)return; varHTMLEPSWH = This. GetData (); //Highlight Template varHighlighcode = ' <span class= ' ep_ckeditor_sensitivewords "style=" background-color:{$color}; " >{$word}</span> '; if(!epswhlcolor) Epswhlcolor= "#ffff00"; Highlighcode= Highlighcode.replace ("{$color}", Epswhlcolor); //If there are highlights in the content, first clean up if(Htmlepswh.indexof (' ep_ckeditor_sensitivewords ') >-1) {HTMLEPSWH= This. Canclesensitivewordshighlight (); } //re-highlight varEpswhlkeywords = []; if(typeofEpswhlwords = = "string") Epswhlkeywords= Epswhlwords.split (', '); ElseEpswhlkeywords=epswhlwords; //delimiters that need to be ignored if(Epswhligchar && epswhligchar.length > 0) {Epswhligchar= Epswhligchar.replace (/[<>& "]/g,function(c) {return{' < ': ' < ', ' > ': ' > ', ' & ': ' & ', ' ' ': ' " '}[c]; }); Epswhligchar= "[" + Epswhligchar + "]*"; } Else{Epswhligchar= ' '; } for(vari = 0; i < epswhlkeywords.length; i++) { varAllkey = Epswhlkeywords[i].split ("); varRegstr =Allkey.join (Epswhligchar); Regstr= "(" + Regstr + ")"; varReg = eval ("/" + Regstr + "/ig"); varHcode = Highlighcode.replace ("{$word}", "$"); HTMLEPSWH=Htmlepswh.replace (Reg, Hcode); } //Document object is invalid in source mode, This.setdata is reload, not synchronous method, cannot use if( This. document!=NULL) This. Document.getbody (). sethtml (HTMLEPSWH); } })();
or add a plugin:
CKEDITOR.plugins.add (' Sensitivewordshighlight ', {init:function(editor) {/** Cancel all highlighted*/Editor. Canclesensitivewordshighlight=function () { varREGSTREPSWH = ' <span class= ' ep_ckeditor_sensitivewords "style=" background-color:[^<>:]+[;] * "> ([^<>]+) <\\/span>"; varHTMLEPSWH = This. GetData (); HTMLEPSWH= Htmlepswh.replace (eval ("/" + REGSTREPSWH + "/ig"), "$"); if( This. Document! =NULL) This. Document.getbody (). sethtml (HTMLEPSWH); returnHTMLEPSWH; } /** words Sensitive words * Igchar special characters ignored in sensitive words * color Highlight background*/Editor. Sensitivewordshighlight=function(Epswhlwords, Epswhligchar, Epswhlcolor) {//an empty string if(typeofEpswhlwords = = "string" &&!epswhlwords)return; //Empty Array if(typeofEpswhlwords = = "Object" && epswhlwords[0] = =undefined)return; varHTMLEPSWH = This. GetData (); //Highlight Template varHighlighcode = ' <span class= ' ep_ckeditor_sensitivewords "style=" background-color:{$color}; " >{$word}</span> '; if(!epswhlcolor) Epswhlcolor= "#ffff00"; Highlighcode= Highlighcode.replace ("{$color}", Epswhlcolor); //If there are highlights in the content, first clean up if(Htmlepswh.indexof (' ep_ckeditor_sensitivewords ') >-1) {HTMLEPSWH= This. Canclesensitivewordshighlight (); } //re-highlight varEpswhlkeywords = []; if(typeofEpswhlwords = = "string") Epswhlkeywords= Epswhlwords.split (', '); ElseEpswhlkeywords=epswhlwords; //delimiters that need to be ignored if(Epswhligchar && epswhligchar.length > 0) {Epswhligchar= Epswhligchar.replace (/[<>& "]/g,function(c) {return{' < ': ' < ', ' > ': ' > ', ' & ': ' & ', ' ' ': ' " '}[c]; }); Epswhligchar= "[" + Epswhligchar + "]*"; } Else{Epswhligchar= ' '; } for(vari = 0; i < epswhlkeywords.length; i++) { varAllkey = Epswhlkeywords[i].split ("); varRegstr =Allkey.join (Epswhligchar); Regstr= "(" + Regstr + ")"; varReg = eval ("/" + Regstr + "/ig"); varHcode = Highlighcode.replace ("{$word}", "$"); HTMLEPSWH=Htmlepswh.replace (Reg, Hcode); } //Document object is invalid in source mode, This.setdata is reload, not synchronous method, cannot use if( This. Document! =NULL) This. Document.getbody (). sethtml (HTMLEPSWH); } }});
Enable plugins:
Config.extraplugins = "Sensitivewordshighlight";
Call:
// Set CKEDITOR.instances.MYCKDEMO.SensitiveWordsHighlight (["One or two", "haha"], "' [email protected]#$^&* () =|{} ':; ', \\[\\]\\ . <>/?~! @#¥......&* ()-| {}【】‘;:”“‘。 ,、? " ," #FFFF00 "); // Cancel CKEDITOR.instances.MYCKDEMO.CancleSensitiveWordsHighlight ();
Note: The SetData () method in CKEditor refreshes the IFRAME non-synchronous method and uses multiple occurrences of the content to not display logically ~,~
CKEditor Sensitive Word marker display processing method