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 中两分钟集成敏感词组件
现如今大部分服务都会有用户输入,为了服务的正常运行,很多时候不得不针对输入进行敏感词的检测.替换.如果人工做这样的工作,不仅效率低,成本也高.所以,先让代码去处理输入,成为了经济方便的途径.水弟在这里 ...
随机推荐
- [转载]为什么使用%lf读取double型的值,而用%f进行显示?
博客地址:http://blog.csdn.net/shenzhou111/article/details/7826444 今天看到一篇好文章,mark一下. 出去旅游了一下,所以有些天没敲代码,于是 ...
- 2016 Multi-University Training Contest 2 第一题Acperience
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Probl ...
- 横向浅谈移动技术------( 原生,混合,web --- 谁能问鼎移动开发的明天)
目前移动互联网基本采用了NativeApp.WebApp.HybridApp三种开发模式,很难说这三种模式那种更优越,目前的情况可以说是三分天下吧,不同的开发者可以根据自己的实际情况选择不同的开发模式 ...
- 全连接的BP神经网络
<全连接的BP神经网络> 本文主要描述全连接的BP神经网络的前向传播和误差反向传播,所有的符号都用Ng的Machine learning的习惯.下图给出了某个全连接的神经网络图. 1前向传 ...
- vc2010配置opencv2.4.4库(图文 转)
VC 2010下安装OpenCV2.4.4 说明: 安装平台:32位XP,VS2010: OpenCV 2.4.4不支持VC 6.0: 网上有很多用CMake编译OpenCV的安装教程,这 ...
- 纯css切换左侧菜单
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Linux学习笔记24——进程管道
一 管道的作用 通常把一个进程的输出通过管道连接到另一个进程的输入. 二 popen和pclose函数 #include <stdio.h> FILE *popen(const char ...
- apache php gzip压缩输出的实现方法
一.gzip介绍 gzip是GNU zip的缩写,它是一个GNU自由软件的文件压缩程序,也经常用来表示gzip这种文件格式.软件的作者是Jean-loup Gailly和Mark Adler.1992 ...
- CSU 1511 残缺的棋盘 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...
- UVA 11796 Dog Distance(向量)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...