/*******************************************************************************
* KindEditor - WYSIWYG HTML Editor for Internet
* Copyright (C) 2006-2011 btoe.cn
*
* @author 微风 <350096958@qq.com>
* @site http://www.wjdhcms.com/

*******************************************************************************/



KindEditor.plugin("wjc", function(K) {
    var self = this,
        name = 'wjc',
        undefined;
    var editor = this;
    // 点击图标时执行
    editor.clickToolbar(name, function() {
    	var html = self.html();
		var text = self.text();
		if(text.length!=0){
			var ar = []; //存违禁词用的数组
			var br = []; //存标签属性值用的数组
			var biaoqian = /style=".*?"|title=".*?"|alt=".*?"/gi;  //匹配标签属性，防止标签属性中的违禁词被转换
			var ppbq = html.match(biaoqian);
			if(null != ppbq){
				for (var i = 0; i < ppbq.length; ++i) {
					var tmp1 = ppbq[i];
					ppbq[i] = ppbq[i].replace(ppbq[i], "[标签"+i+"]");  //将标签属性以“[标签9]”形式替换并讲原始属性的值存在数组中
					html = html.replace(tmp1, ppbq[i]);
					br[i] = tmp1;
				}
			};
			var regex = /首批|引领|免费.*?热线|精湛|尖端|前沿|24小时|No\.|认证|唯一|绝无仅有|最后一波|精致|完善|确保|保证|诚信单位|先进|特大|专家|优质|独创|[0-9]年|[0-9]多年|ISO900[0-9]|开创|终身|首屈一指|龙头|首创|顶尖|领航|完美|航母|星级|领军|知名|最|第一|一线|全网|独一无二|一流|一天|仅此一次|国家|全球|宇宙|世界|顶级|高级|极品|极佳|绝佳|绝对|绝无|绝不|仅有|终极|极致|首个|首选|独家|首发|冠军|免检|驰名|国际|大牌|金牌|名牌|王牌|领袖|领先|领导|缔造者|创领品牌|巨星|著名|掌门人|至尊|巅峰|奢侈|优秀|资深|领袖|之王|王者|冠军|史无前例|前无古人|永久|万能|祖传|特效|无敌|纯天然|100%|高档|正品|真皮|超赚|精准|老字号|特供|专供|专家推荐|免抽检|点击领奖|恭喜获奖|全民免单|点击有惊喜|点击获取|点击转身|点击试穿|点击翻转|领取奖品|秒杀|抢爆|再不抢就没了|不会更便宜了|没有他就|错过就没机会了|万人疯抢|全民疯抢|抢购|抢疯了|随时结束|随时涨价|马上降价|就选/gi;
			var result = html.match(regex);
			if (null == result || 0 == result.length) {
				parent.layer.msg('没有违禁词', { time: 1000 });
				return false;
			} else {
				for (var i = 0; i < result.length; ++i) {
					var tmp = result[i];
					result[i] = result[i].replace(result[i], "[违禁词"+i+"]");
					html = html.replace(tmp, result[i]);
					ar[i] = tmp;
				}
			};
			html = html.replace("wjc","");			
			var regex3 = /\[标签(-?[0-9]\d*)\]/gi;    //匹配之前替换的标签属性
			var result3 = html.match(regex3);
			if (null == result3 || 0 == result3.length) {
				
			} else {
				for (var i = 0; i < result3.length; ++i) {
					var ste1 = br[i];
					var tmp1 = result3[i];
					html = html.replace(result3[i], ste1); //将原始属性的值重新填入相应标签属性中去
				}
			};		
			var regex2 = /\[违禁词(-?[0-9]\d*)\]/gi;
			var result2 = html.match(regex2);
			if (null == result2 || 0 == result2.length) {
				
			} else {
				parent.layer.msg('共有' + result2.length + '个违禁词！', { time: 3000 });
				for (var i = 0; i < result2.length; ++i) {
					var ste = ar[i];
					//alert(ste)
					var tmp = result2[i];
					//alert(tmp)
					html = html.replace(result2[i], '<span class="wjc">'+ste+'</span>');
				}
			};
			editor.html(html);						
		}else {
			parent.layer.msg('没有内容！', { time: 1000 });
		}
	
    });
});
