CKEditor Sensitive Word marker display processing method

Source: Internet
Author: User

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{' < ': ' &lt; ', ' > ': ' &gt; ', ' & ': ' &amp; ', ' ' ': ' &quot; '}[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{' < ': ' &lt; ', ' > ': ' &gt; ', ' & ': ' &amp; ', ' ' ': ' &quot; '}[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.