ckeditor 敏感词标记显示处理方法
直接在原型添加方法:
(function () {
/*
* 取消所有高亮
*/
CKEDITOR.editor.prototype.CancleSensitiveWordsHighlight = function () {
var regstrEpswh = '<span class="ep_ckeditor_sensitivewords" style="background-color:[^<>:]+[;]*">([^<>]+)<\\/span>';
var htmlEpswh = this.getData();
htmlEpswh = htmlEpswh.replace(eval("/" + regstrEpswh + "/ig"), "$1");
if (this.document != null)
this.document.getBody().setHtml(htmlEpswh);
return htmlEpswh;
}
/*
* epswhlwords 敏感词
* epswhligChar 敏感词中忽略的特殊字符
* epswhlcolor 高亮底色
*/
CKEDITOR.editor.prototype.SensitiveWordsHighlight = function (epswhlwords, epswhligChar, epswhlcolor) {
//空的字符串
if (typeof epswhlwords == "string" && !epswhlwords)
return;
//空数组
if (typeof epswhlwords == "object" && epswhlwords[0] == undefined)
return;
var htmlEpswh = this.getData();
//高亮模板
var highLighCOde = '<span class="ep_ckeditor_sensitivewords" style="background-color:{$color};">{$word}</span>';
if (!epswhlcolor)
epswhlcolor = "#ffff00";
highLighCOde = highLighCOde.replace("{$color}", epswhlcolor);
//如果内容中有高亮内容先进行清理
if (htmlEpswh.indexOf('ep_ckeditor_sensitivewords') > -1) {
htmlEpswh = this.CancleSensitiveWordsHighlight();
}
//重新高亮
var epswhlkeyWords = [];
if (typeof epswhlwords == "string")
epswhlkeyWords = epswhlwords.split(',');
else
epswhlkeyWords = epswhlwords;
//需要忽略的分隔符
if (epswhligChar && epswhligChar.length > 0) {
epswhligChar = epswhligChar.replace(/[<>&"]/g, function (c) { return { '<': '<', '>': '>', '&': '&', '"': '"' }[c]; });
epswhligChar = "[" + epswhligChar + "]*";
} else {
epswhligChar = '';
}
for (var i = 0; i < epswhlkeyWords.length; i++) {
var allkey = epswhlkeyWords[i].split('');
var regstr = allkey.join(epswhligChar);
regstr = "(" + regstr + ")";
var reg = eval("/" + regstr + "/ig");
var hcode = highLighCOde.replace("{$word}", "$1");
htmlEpswh = htmlEpswh.replace(reg, hcode);
}
//document 对象在源码模式无效,this.setData是重新加载,不是同步方法,不能使用
if (this.document!=null)
this.document.getBody().setHtml(htmlEpswh);
} })();
或者添加插件:
CKEDITOR.plugins.add('sensitivewordshighlight', {
init: function (editor) {
/*
* 取消所有高亮
*/
editor.CancleSensitiveWordsHighlight=function () {
var regstrEpswh = '<span class="ep_ckeditor_sensitivewords" style="background-color:[^<>:]+[;]*">([^<>]+)<\\/span>';
var htmlEpswh = this.getData();
htmlEpswh = htmlEpswh.replace(eval("/" + regstrEpswh + "/ig"), "$1");
if (this.document != null)
this.document.getBody().setHtml(htmlEpswh);
return htmlEpswh;
}
/*
* words 敏感词
* igChar 敏感词中忽略的特殊字符
* color 高亮底色
*/
editor.SensitiveWordsHighlight = function (epswhlwords, epswhligChar, epswhlcolor) {
//空的字符串
if (typeof epswhlwords == "string" && !epswhlwords)
return;
//空数组
if (typeof epswhlwords == "object" && epswhlwords[0] == undefined)
return;
var htmlEpswh = this.getData();
//高亮模板
var highLighCOde = '<span class="ep_ckeditor_sensitivewords" style="background-color:{$color};">{$word}</span>';
if (!epswhlcolor)
epswhlcolor = "#ffff00";
highLighCOde = highLighCOde.replace("{$color}", epswhlcolor);
//如果内容中有高亮内容先进行清理
if (htmlEpswh.indexOf('ep_ckeditor_sensitivewords') > -1) {
htmlEpswh = this.CancleSensitiveWordsHighlight();
}
//重新高亮
var epswhlkeyWords = [];
if (typeof epswhlwords == "string")
epswhlkeyWords = epswhlwords.split(',');
else
epswhlkeyWords = epswhlwords;
//需要忽略的分隔符
if (epswhligChar && epswhligChar.length > 0) {
epswhligChar = epswhligChar.replace(/[<>&"]/g, function (c) { return { '<': '<', '>': '>', '&': '&', '"': '"' }[c]; });
epswhligChar = "[" + epswhligChar + "]*";
} else {
epswhligChar = '';
}
for (var i = 0; i < epswhlkeyWords.length; i++) {
var allkey = epswhlkeyWords[i].split('');
var regstr = allkey.join(epswhligChar);
regstr = "(" + regstr + ")";
var reg = eval("/" + regstr + "/ig");
var hcode = highLighCOde.replace("{$word}", "$1");
htmlEpswh = htmlEpswh.replace(reg, hcode);
}
//document 对象在源码模式无效,this.setData是重新加载,不是同步方法,不能使用
if (this.document != null)
this.document.getBody().setHtml(htmlEpswh);
}
}
});
启用插件:
config.extraPlugins = "sensitivewordshighlight";
调用:
//设置
CKEDITOR.instances.MYCKDEMO.SensitiveWordsHighlight(["一二","哈哈"], "`~!@#$^&*()=|{}':;',\\[\\]\\.<>/?~!@#¥……&*()—|{}【】‘;:”“'。,、? ","#FFFF00");
//取消
CKEDITOR.instances.MYCKDEMO.CancleSensitiveWordsHighlight();
注意:ckeditor 中setData()方法要刷新iframe非同步方法,同时使用多次出现内容不按逻辑显示~,~
ckeditor 敏感词标记显示处理方法的更多相关文章
- PHP实现的敏感词过滤方法
PHP实现的敏感词过滤方法,以下是一份过滤敏感词的编码.有需要可以参考参考. /** * @todo 敏感词过滤,返回结果 * @param array $list 定义敏感词一维数组 * @para ...
- 基于DFA敏感词查询的算法简析
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 项目中需要对敏感词做一个过滤,首先有几个方案可以选择: a.直 ...
- js检测文章敏感词
在一些博客或者论坛中,文章中的敏感词需要显示出来和高亮显示起到提示用户的作用.这个功能实现的方法有很多,下面是js的实现方式. //将文章中匹配到的敏感词罗列出来 <span style=&qu ...
- JS采用ActiveXObject实现用户在提交表单时屏蔽敏感词的功能
本例中敏感词ciku.txt放在C盘根目录下,采用的ActiveXObject插件获取本地文件内容.使用此插件不需网上下插件,直接用如下js代码即可. 浏览器需修改interner安全选项的级别,启用 ...
- 敏感词过滤和XML的创建
今天我慢下来啦,因为这三天没有新的课程学习内容,自己仅仅看啦一些,这让我停下来栖息片刻:说说现在的生活,简单的进行着,每天要奔波着去上课,然后回来,每天都在想怎样学习这个小知识点,大脑也在想怎样解决程 ...
- [原创] Trie树 php 实现敏感词过滤
目录 背景 简介 存储结构 PHP 其他语言 字符串分割 示例代码 php 优化 缓存字典树 常驻服务 参考文章 背景 项目中需要过滤用户发送的聊天文本, 由于敏感词有将近2W条, 如果用 str_r ...
- 基于DFA算法、RegExp对象和vee-validate实现前端敏感词过滤
面临敏感词过滤的问题,最简单的方案就是对要检测的文本,遍历所有敏感词,逐个检测输入的文本是否包含指定的敏感词. 很明显上面这种实现方法的检测时间会随着敏感词库数量的增加而线性增加.系统会因此面临性能和 ...
- Java基础:String类详解,案例用户登录实现,案例手机号截取实现,案例敏感词替换实现;StringBuilder类详解,StringBuilder和String相互转换,附练习案例.
1.API 1.1 API概述-帮助文档的使用 什么是API API (Application Programming Interface) :应用程序编程接口 java中的API 指的就是 JDK ...
- .Net 中两分钟集成敏感词组件
现如今大部分服务都会有用户输入,为了服务的正常运行,很多时候不得不针对输入进行敏感词的检测.替换.如果人工做这样的工作,不仅效率低,成本也高.所以,先让代码去处理输入,成为了经济方便的途径.水弟在这里 ...
随机推荐
- ASP.NET MVC轻教程 Step By Step 11——数据注解
将验证规则写在Cotroller里不是一个好办法,这样会显得代码很啰嗦,更重要的是将业务逻辑写入Controller,使得Controller变得更“重”,不符合设计原则.更好的办法是使用验证注解属性 ...
- 查看SGA和PGA使用率
select name,total,round(total-free,2) used, round(free,2) free,round((total-free)/total*100,2) pctus ...
- Java 语言中 Enum 类型的使用介绍
Enum 类型的介绍 枚举类型(Enumerated Type) 很早就出现在编程语言中,它被用来将一组类似的值包含到一种类型当中.而这种枚举类型的名称则会被定义成独一无二的类型描述符,在这一点上和常 ...
- Linux驱动的两种加载方式过程分析
一.概念简述 在Linux下可以通过两种方式加载驱动程序:静态加载和动态加载. 静态加载就是把驱动程序直接编译进内核,系统启动后可以直接调用.静态加载的缺点是调试起来比较麻烦,每次修改一个地方都要重新 ...
- 高效的TCP消息发送组件
目前的.net 架构下缺乏高效的TCP消息发送组件,而这种组件是构建高性能分布式应用所必需的.为此我结合多年的底层开发经验开发了一个.net 下的高效TCP消息发送组件.这个组件在异步发送时可以达到每 ...
- HDU-2576 Tug of War
http://poj.org/problem?id=2576 二维数组01背包的变形. Tug of War Time Limit: 3000MS Memory Limit: 65536K Tot ...
- HDOJ1020 Encoding
Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following ...
- 国内maven镜像
<mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...
- java IO复习(三)
package com.zyw.io; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; ...
- HDU2037 今年暑假不AC 贪心算法
贪心算法 : 贪心算法就是只考虑眼前最优解而忽略整体的算法, 它所做出的仅是在某种意义上的局部最优解, 然后通过迭代的方法相继求出整体最优解. 但是不是所有问题都可以得到整体最优解, 所以选择贪心策略 ...