PageSourceSearch

https://cjss.ac.cn/style/web/js/public/newsEdit.js?t=1790683611884

js cjss.ac.cn collected 2026-10-02 07:22:35 UTC 45,340 bytes, 1,385 lines download raw bytes

1//编辑器
2var ue;
3//编辑容器可编辑框
4var editTextarea;
5//编辑容器视图
6var editDiv;
7
8//当期操作的dom
9var thisObj;
10//选中的文本内容
11var txt;
12//新闻ID
13var newsId;
14//编辑区域的内容
15var editHtml;
16//编辑区域标题
17var editTitle;
18//存储删除段落信息提示框
19var alertRemovePMsg;
20
21//选中内容
22var selTxt;
23//选择对象
24var sel;
25//操作对象
26var range;
27
28$(function () {
29	var url = window.location.href;
30	if(url.indexOf("_preview.htm")>0){
31		
32		var checkCode = window.location.hash;
33		if(checkCode != ''){
34			newsId = checkCode.replace("#", "");
35			var result = $.ajax({
36	    		type:'post',
37	    		async:false,
38	    		url:local_host +"manager/cms/news/news/checkEditNewsSession",
39	    		success:function(obj){
40	    			if(obj == "success"){
41	    				initContenteditable();
42	    			}
43	    		}
44			})
45		}
46		//测试开放
47		//initContenteditable();
48		//inputFocus();
49		
50	}
51	
52	
53});
54
55//重置alert样式
56//(function(){
57//	window.alert = function(name){
58//		var iframe = document.createElement("IFRAME");
59//		iframe.style.display="none";
60//		iframe.setAttribute("src", 'data:text/plain');
61//		document.documentElement.appendChild(iframe);
62//		window.frames[0].window.alert(name);
63//		iframe.parentNode.removeChild(iframe);
64//	}
65//})();
66
67_flagindex = 0;
68//禁用浏览器Ctrl+s事件 并且使用快捷键直接保存
69$(document).bind("keydown", function(e) {
70    //console.log(e.which);
71    if (e.ctrlKey && (e.which == 83)) {
72        e.preventDefault();
73        setTimeout(function() {
74        	saveEditNews("");
75        }, 100);
76        return false;
77    }
78});
79
80/**
81 * 保存编辑的新闻
82 */
83function saveEditNews(html){
84	var isSave = false;
85	var saveContentHtml = $(".box-article-content").html();
86	var saveTitleHtml = $(".article-title-center").html();
87	if(saveContentHtml != editHtml){
88		isSave = true;
89	}
90	if(saveTitleHtml != editTitle){
91		isSave = true;
92	}
93	
94	if(isSave){
95		
96		var pContentList = new Array();
97		
98		$(".box-article-content").children().each(function(ind,val){
99			
100			//上一篇下一篇 跳过
101			var elCss = val.className;
102			if(elCss == "neighborCatalog"){
103				return true;
104			}
105			
106			//工具内容跳过
107			if(elCss != undefined && elCss.indexOf("jiajian")!=-1){
108				return true;
109			}
110			//跳过编辑器
111			var id = val.id;
112			if(id == 'editorDivTool'){
113				return true;
114			}
115			
116			//跳过文本域
117			var tagName = val.tagName;
118			if(tagName == 'textarea'){
119				return true;
120			}
121			
122			//去除空style
123			var style = $(val).attr("style");
124			if(style == undefined){
125				style = "";
126			}else{
127				style = style.replace("display: none;","");
128			}
129			
130			var content = val.innerHTML;
131			var cp = {
132					"id":null,
133					"newsId":newsId,
134					"articleId":null,
135					"paraContent":content,
136					"sortNum":ind+1,
137					"paraType":"para",
138					"styleContent":style
139					};
140			
141			pContentList[ind] = cp;
142		})
143		
144		var data = {
145			"newsId":newsId,
146			"newsTitle":saveTitleHtml,
147			"newsContent":JSON.stringify(pContentList)
148		}
149		$.ajax({
150			type:'post',
151			data:data,
152			url:local_host +"manager/cms/news/news/editSaveNew",
153			success:function(obj){
154				if(obj == "success"){
155					editTitle = $(".article-title-center").html();
156					editHtml = $(".box-article-content").html();
157				}else if(obj.indexOf("登录过期")>0){
158					alert("登录过期,重新登录后编辑!")
159				}
160			}
161		})
162	}
163}
164
165//初始化编辑器Only并且激活可编辑元素
166function initContenteditable(){
167	//取消加减工具显示
168//	$(".box-article-content").hover(function(){
169//		
170//	},function(){
171//		try {
172//			//销毁加减段落工具栏
173//			$(".jiajian").remove();
174//		} catch (e) {
175//			// TODO: handle exception
176//		}
177//	});
178	
179	//激活标题
180	$(".article-title-center")
181		.attr("contenteditable","true")
182		.attr("onfocus","inputFocus(this);")
183		.attr("onblur","inputBlur(this);")
184		.attr("onkeydown", "return onContenteditableEnter(event, false);");
185	
186	//激活段落
187	//children()
188	$(".box-article-content").children().each(function(ind,val){
189		//上一篇下一篇 跳过
190		var elCss = $(val).attr("class");
191		if(elCss == "neighborCatalog"){
192			return false;
193		}
194		$(val).attr("contenteditable","true");
195			//.attr("onblur", "inputBlur(this);");
196			//.attr("onfocus", "inputFocus(this);");
197		
198		$(val).bind("focus", function(){
199			inputFocus(this);
200		});	
201		
202		$(val).bind("blur", function(){
203			inputBlur(this);
204		});	
205		
206		$(val).bind("keydown", function(){
207			onContenteditableEnter(event, true);
208		});
209		
210		$(val).bind("mouseup", function(){
211			onContenteditableMouseUp(event, true, this);
212		});
213	})
214	
215	//绑定P的mouseup事件
216//	$('p').mouseup(function(){
217//		//获取选中内容
218//		var tempTxt = window.getSelection?window.getSelection().toString():document.selection.createRange().text;
219//		if(tempTxt != undefined && tempTxt != ""){
220//			txt = tempTxt;
221//			//console.log(txt);
222//			//console.log($(".box-article-content s1").text());
223//		}
224//	})
225	
226	//初始化编辑器
227	//initUeditor();
228	
229	//初始化 消息提示框
230//	alertRemovePMsg = $(
231//	"<div id='myAlert' class='alert alert-success'>" + 
232//	"    <a href='#' class='close' data-dismiss='alert'>&times;</a>" + 
233//	"    <strong>成功!</strong>结果是成功的。" + 
234//	"</div>");
235//	$("body").prepend(alertRemovePMsg);
236}
237
238//初始化编辑器
239function initUeditor(){
240	//创建编辑器容器 并且追加到顶部
241	editDiv = $("<div id='editorDivTool' calss='editorDivTool' style='display:none;'><textarea id='editContent'></textarea></div>");
242	$(".news-details-body").prepend(editDiv);
243	
244	ue = UE.getEditor('editContent',{
245		toolbars: [[
246		       //撤销、重做
247	           'undo', 'redo', '|',
248	          'bold', 'italic', 'underline', 'fontborder', /*'strikethrough',*/ 'superscript', 'subscript',  
249	          //'autotypeset', 'blockquote', 'pasteplain', '|', 
250	          //'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
251	          //'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
252	          //'customstyle', 'paragraph', 'fontfamily', 
253	          'fontsize', '|',
254	          //'directionalityltr', 'directionalityrtl', 'indent', '|',
255	          //'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify'
256	          //, '|', 'touppercase', 'tolowercase', '|'
257	          ,'link', 'unlink'//, 'anchor'
258	          //, '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
259	          //'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background'
260	          , '|','horizontal', 'date', 'time', 'spechars'
261	          //, '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols'
262	      ]]
263	});
264	
265	//编辑器加载完成后执行
266	ue.addListener('ready', function(){
267		//隐藏编辑器计量DIV
268		$(".edui-editor-bottomContainer").hide();
269		//隐藏编辑器内容DIV
270		$("#edui1_iframeholder").hide();
271		
272		//绑定加粗工具栏
273		//customBold();
274		
275		//工具栏居中
276		$("#edui2").css("text-align","center");
277		//显示工具栏
278		$("#editorDivTool").show();
279		
280		editTitle = $(".article-title-center").html();
281		editHtml = $(".box-article-content").html();
282	})
283	
284	ue.addListener('contentchange', function(){
285		$(thisObj).html(ue.getContent().replace("<p>","").replace("</p>", ""));
286		//内容变化后就保存
287		saveEditNews("");
288	})
289	
290	ue.addListener('superscript', function(){
291		alert("superscript");
292	})
293}
294
295//光标离开后保存
296function inputBlur(obj){
297	try {
298		saveEditNews("");
299	} catch (e) {
300		// TODO: handle exception
301	}
302}
303
304//光标触发段落事件
305function inputFocus(obj){
306	
307	try {
308		
309		$(thisObj).show();
310		
311		//销毁编辑器
312		ue.destroy();
313		editDiv.remove();
314		
315	} catch (e) {
316		//console.log(e);
317	}
318	
319	try {
320		
321		thisObj = obj;
322		//var html = $(obj).html();
323		//UE.getEditor('editContent').setContent(html);
324		//initEditorNew(obj);
325		//$(obj).attr("onblur","inputBlur(this);")
326		
327		//销毁加减段落工具栏
328		$(".jiajian").remove();
329		var classStr = $(obj).attr("class");
330		if(classStr != undefined){
331			//跳过标题 加减工具
332			if(classStr.indexOf("article-title-center") != -1){
333				return true;
334			}
335		}
336		
337		//上下左右空
338		var marginTopVal = obj.style.marginTop.replace("px","");
339		var marginRightVal = obj.style.marginRight.replace("px","");
340		var marginBottomVal = obj.style.marginBottom.replace("px","");
341		var marginLeftVal = obj.style.marginLeft.replace("px","");
342		//缩进
343		var textIndentVal = obj.style.textIndent.replace("em","");
344		//行高
345		var textLineHeight = obj.style.lineHeight.replace("px","");
346		//对齐方式
347		var textAlign = obj.style.textAlign;
348		
349		//重新渲染加减工具栏
350		var ejj = "";
351		//ejj += "<div class='jiajian' style='position:relative;bottom:0px; float:right;font-size:12px;font-weight:bold;'>";
352		ejj += "<div class='jiajian light'>";
353		//保存按钮
354		//ejj += "<div class='btnwrap savewrap'><a class=' icon-save save' title='保存文档'>" +
355		//		/*"<img src='../../style/web/images/public/Save.png' style='width:20px'/>" +*/
356		//		"</a>&emsp;</div>";
357		//标题
358		ejj +="<div class='tooltit'>工具栏</div>"
359		
360		//加粗
361		ejj += "<div class='btnwrap jiacu-wrap'>" +
362				"<a class=' icon-jiacu jiacu' title='加粗'><i class='icon'></i>" +
363				"&emsp;<span class='icontext'>加粗</span></a></div>";
364		//斜体
365		ejj += "<div class='btnwrap xieti-wrap'>" +
366				"<a class=' icon-xieti xieti' title='斜体'><i class='icon'></i>" +
367				"&emsp;<span class='icontext'>斜体</span></a></div>";
368		//段落链接
369		ejj += "<div class='btnwrap duanluolianjie-wrap'>" +
370				"<a class=' icon-duanluolianjie duanluolianjie' title='段落链接'>" +
371				"<i class='icon'></i>" +
372				"&emsp;<span class='icontext'>段落链接</span></a></div>";
373		//插入图片
374		ejj += "<div class='btnwrap insertenclosure-wrap'><a class='insertpic' title='插入图片'>" +
375		"<i class='icon'></i>" +
376		"</a>&emsp;"+
377		"<div class='inputwrap' ><span>插入图片</span>"+
378		"<input  class='charu-input ' type='file' accept='image/gif,image/jpeg,image/jpg,image/png,image/svg'  value=' '/></div>"+
379		"<button class='jianju-btn '></button> </div>";
380		//插入附件
381		ejj += "<div class='btnwrap enclosure-wrap'><a class='enclosure' title='插入附件'>" +
382		"<i class='icon'></i>" +
383		"</a>&emsp;"+
384		"<div class='inputwrap' ><span>插入附件</span>"+
385		"<input  class='charu-input ' type='file'  value=' '/></div>"+
386		"<button class='jianju-btn '></button> </div>";
387		//对齐方式
388		ejj += "<div class='btnwrap duiqifangshi-wrap'>" +
389				"<a class=' icon-duiqifangshi duiqifangshi-left title='居左对齐'><i class='icon-left'></i></a>" +
390				"<a class=' icon-duiqifangshi duiqifangshi-center' title='居中对齐'><i class='icon-center'></i></a>" +
391				"<a class=' icon-duiqifangshi duiqifangshi-right' title='居右对齐'><i class='icon-right'></i></a>" +
392				"<a class=' icon-duiqifangshi duiqifangshi-double' title='两端方式'><i class='icon-double'></i></a>" +
393				"</div>";
394		//字体
395		ejj += "<div class='btnwrap ziti-wrap'>" +
396				"<a class=' icon-ziti ziti' title='字体'><i class='icon'></i>" +
397				"&emsp;<span class='icontext'>字体</span>"+
398				"&emsp;<select class='icontext fontFamily'>" +
399				"<option style='font-family:宋体,SimSun'>宋体</option>"+
400				"<option style='font-family:微软雅黑,Microsoft YaHei'>微软雅黑</option>"+
401				"<option style='font-family:楷体,楷体_GB2312, SimKai'>楷体</option>"+
402				"<option style='font-family:黑体, SimHei'>黑体</option>"+
403				"<option style='font-family:隶书, SimLi'>隶书</option>"+
404				"<option style='font-family:andale mono'>andale mono</option>"+
405				"<option style='font-family:arial, helvetica,sans-serif'>arial</option>"+
406				"<option style='font-family:arial black,avant garde'>arial black</option>"+
407				"<option style='font-family:comic sans ms'>comic sans ms</option>"+
408				"<option style='font-family:impact,chicago'>impact</option>"+
409				"<option style='font-family:times new roman'>times new roman</option>"+
410				"</select></a></div>";
411		//字号
412		ejj += "<div class='btnwrap zihao-wrap'>" +
413				"<a class=' icon-zihao zihao' title='字号'><i class='icon'></i>" +
414				"&emsp;<span class='icontext'>字号</span>"+
415				"&emsp;<select class='icontext fontSize'>" +
416				"<option value=''>默认大小</option>"+
417				"<option style='font-size:12px' value='12px'>12px</option>"+
418				"<option style='font-size:13px' value='13px'>13px</option>"+
419				"<option style='font-size:14px' value='14px'>14px</option>"+
420				"<option style='font-size:15px' value='15px'>15px</option>"+
421				"<option style='font-size:16px' value='16px'>16px</option>"+
422				"<option style='font-size:17px' value='17px'>17px</option>"+
423				"<option style='font-size:18px' value='18px'>18px</option>"+
424				"<option style='font-size:19px' value='19px'>19px</option>"+
425				"<option style='font-size:20px' value='20px'>20px</option>"+
426				"<option style='font-size:22px' value='22px'>22px</option>"+
427				"<option style='font-size:24px' value='24px'>24px</option>"+
428				"<option style='font-size:26px' value='26px'>26px</option>"+
429				"<option style='font-size:28px' value='28px'>28px</option>"+
430				"<option style='font-size:30px' value='30px'>30px</option>"+
431				"<option style='font-size:32px' value='32px'>32px</option>"+
432				"<option style='font-size:34px' value='24px'>34px</option>"+
433				"<option style='font-size:36px' value='36px'>36px</option>"+
434				"</select></a></div>";
435		//字体颜色
436		ejj += "<div class='btnwrap ziti-wrap'>" +
437				"<a class=' icon-zitiyanse zitiyanse' title='字体颜色'>" +
438				"<i class='icon'></i>" +
439				"</a>&emsp;"+
440				"<div class='inputwrap' ><span>字体颜色</span>"+
441				"<input  class='color-input-font' type='color' default-value='#ffffff' /></div>"+
442				"</div>";
443		ejj += "<div class='line-coler'></div>";
444		//无序列表
445		ejj += "<div class='btnwrap unorderwrap'><a class='unorder' title='无序列表'>"+
446		"<i class='icon'></i>" +
447		"&emsp;<span class='icontext'>
447无序列表</span>"+
448		"&emsp;<select class='icontext noListStyle' >" +
449		"<option value='undefined' selected >无</option>"+
450		"<option value='&bull;'>&bull;&ensp;小黑点</option>"+
451		"<option value='&omicron;'>&omicron;&ensp;大圆圈</option>"+
452		"<option value='■'>■&ensp;小方块</option>"+
453		"<option value='○'>○&ensp;小圆圈</option>"+
454		"<option value=''>清除</option>"+
455		"</select></a></div>";
456		
457		//背景颜色
458		ejj += "<div class='btnwrap beijingyanse-wrap'>" +
459				"<a class=' icon-beijingyanse beijingyanse' title='背景颜色'>" +
460				"<i class='icon'></i>" +
461				/*"&emsp;<span class='icontext'>背景颜色</span></a></div>";*/
462				"</a>&emsp;"+
463				"<div class='inputwrap' ><span>背景颜色</span>"+
464				"<input  class='color-input' type='color' default-value='#ffffff' /></div>"+
465				"</div>";
466		//行高
467		ejj += "<div class='btnwrap hanggao-wrap'>" +
468				"<a class=' icon-hanggao hanggao' title='行高'><i class='icon'></i></a>&emsp;"+
469				"<div class='inputwrap' ><span>行间距</span>"+
470				"<input  class='jianju-input hanggao-val' type='number' value='"+ textLineHeight +"'/> px</div>"+
471				"<button class='jianju-btn hanggao-btn'></button> </div>";
472		//增加上间距
473		ejj += "<div class='btnwrap top-wrap'><a class=' jianju jianju-top' title='增加上间距'>" +
474				"<i class='icon'></i>" +
475				"</a>&emsp;"+
476				"<div class='inputwrap' ><span>增加上间距</span>"+
477				"<input  class='jianju-input' type='number'  value='"+ marginTopVal +"'/> px</div>"+
478				"<button class='jianju-btn'></button> </div>";
479		//增加下间距
480		ejj += "<div class='btnwrap bottom-wrap'><a class=' jianju jianju-bottom' title='增加下间距'>" +
481				"<i class='icon'></i>" +
482				"</a>&emsp;"+
483				"<div class='inputwrap' ><span>增加下间距</span>"+
484				"<input  class='jianju-input' type='number' value='"+marginBottomVal+"' /> px</div>"+
485				"<button class='jianju-btn'></button> </div>";
486		//增加左侧间距
487		ejj += "<div class='btnwrap left-wrap'><a class=' jianju jianju-left' title='增加左侧间距'>" +
488				"<i class='icon'></i>" +
489				"</a>&emsp;"+
490				"<div class='inputwrap' ><span>增加左间距</span>"+
491				"<input  class='jianju-input' type='number' value='"+marginLeftVal+"' /> px</div>"+
492				"<button class='jianju-btn'></button> </div>";
493		//增加右侧间距
494		ejj += "<div class='btnwrap right-wrap'><a class=' jianju jianju-right' title='增加右侧间距'>" +
495				"<i class='icon'></i>" +
496				"</a>&emsp;"+
497				"<div class='inputwrap' ><span>增加右间距</span>"+
498				"<input  class='jianju-input' type='number' value='"+marginRightVal+"' /> px</div>"+
499				"<button class='jianju-btn'></button> </div>";
500		
501		//首行缩进
502		ejj += "<div class='btnwrap indentwrap'><a class=' suojin' title='设置缩进'>" +
503				"<i class='icon'></i>" +
504				"</a>&emsp;"+
505				"<div class='inputwrap' ><span>设置缩进</span>"+
506				"<input  class='jianju-input indentwrap-val' type='number'  value='"+ textIndentVal +"'/> em</div>"+
507				"<button class='jianju-btn indentwrap-btn'></button> </div>";
508				/*"<img src='../../style/web/images/public/ico-textindent.png' style='width:20px'/>" +*/
509		//取消缩进
510		/*ejj += "<div class='btnwrap indentwrap-hide'><a class=' suojin-hide' title='取消缩进'>" +
511				"<i class='icon'></i>" +
512				"</a>&emsp;"+
513				"<div class='inputwrap' ><span>取消缩进</span>"+
514				"<input  class='jianju-input' type='number'  value='"+ 1 +"'/></div>"+
515				"<button class='jianju-btn'></button> </div>";
516		*/
517		ejj += "<div class='line-coler'></div>";
518		//富文本编辑
519		ejj += "<div class='btnwrap editwrap' style='display:none;'><a class=' shezhi' title='富文本编辑'>" +
520		"<i class='icon'></i>" +
521		"&emsp;<span class='icontext'>富文本编辑</span></a></div>";
522		ejj += "<div class='btnwrap editwrap-hide' style='display:none;'><a class=' shezhiHide' title='富文本编辑'>" +
523		"<i class='icon'></i>" +
524			"&emsp;<span class='icontext'>退出富文本编辑</span></a></div>";
525		//input
526		/*ejj += "<div class='inputwrap' style='position:absolute;
526left: 0;top: 33px;'><input  class='jianju-input' type='text'  /> px</div>";*/
527		
528		//增加上段落
529		ejj += "<div class='btnwrap addwrap'><a class='jia jia-top' title='增加上段落'>"+
530		"<i class='icon'></i>" +
531		"&emsp;<span class='icontext'>增加上段落</span></a></div>";
532		//增加下段落
533		ejj += "<div class='btnwrap addwrap'><a class='jia jia-bottom' title='增加下段落'>"+
534		"<i class='icon'></i>" +
535		"&emsp;<span class='icontext'>增加下段落</span></a></div>";
536		//删除段落
537		ejj += "<div class='btnwrap removewrap'><a class='jian' title='删除段落'>"+
538		"<i class='icon'></i>" +
539		"&emsp;<span class='icontext'>删除段落</span></a></div>";
540		//清除段落内格式
541		ejj += "<div class='btnwrap cleanwrap'><a class='clean' title='清除段落内格式'>"+
542		"<i class='icon'></i>" +
543		"&emsp;<span class='icontext'>清除段落内格式</span></a></div>";
544		
545		ejj += "</div>"
546		var jiajian = $(ejj);
547		if(obj == undefined){
548			$(".box-article-content").append(jiajian);
549		}else{
550			$(obj).after(jiajian);
551		}
552		tankuang();
553		//$(".jiajian .save").attr("onmousedown","saveEditNews('');");
554		//清除段落内格式
555		$(".jiajian .cleanwrap").attr("onclick", "cleanStyle();");
556		//点击高亮
557		$(".jiajian .btnwrap a i").attr("onclick","lightbtn(this)");
558		//富文本
559		$(".jiajian .shezhi").attr("onmousedown","initEditorNew(this);");
560		//$(".jiajian .shezhi").attr("onmousedown","initUMEditorNew(this);");
561		$(".jiajian .shezhiHide").attr("onclick", "removeEditorNew();");
562		//增减段落
563		$(".jiajian .jia-top").attr("onmousedown","addp(this,'top');");
564		$(".jiajian .jia-bottom").attr("onmousedown","addp(this,'bottom');");
565		$(".jiajian .jian").attr("onmousedown","removep(this);");
566		//上下左右空
567		$(".jiajian .jianju-btn").attr("onclick","jianju(this);");
568		//缩进
569		$(".jiajian .indentwrap-btn").attr("onclick","indent(this,'add');");
570		//$(".jiajian .indentwrap-hide").attr("onclick","indent(this, 'rem');");
571		//加粗
572		$(".jiajian .jiacu-wrap").attr("onclick", "styleAdd('b');");
573		//斜体
574		$(".jiajian .xieti-wrap").attr("onclick", "styleAdd('i');");
575		//$(".jiajian .jiacu-wrap").attr("onclick", "styleAdd('i');");
576		//对齐
577		$(".jiajian .duiqifangshi-left").attr("onclick","styleAdd('text-align','left');");
578		$(".jiajian .duiqifangshi-center").attr("onclick","styleAdd('text-align','center');");
579		$(".jiajian .duiqifangshi-right").attr("onclick","styleAdd('text-align','right');");
580		$(".jiajian .duiqifangshi-double").attr("onclick","styleAdd('text-align','justify');");
581		
582		//无序列表
583		$(".jiajian .noListStyle").attr("onchange", "styleAddList();")
584		//行高
585		$(".jiajian .hanggao-btn").attr("onclick", "hanggaoAdd();");
586		
587		//字体 字号
588		$(".jiajian .fontFamily").attr("onchange", "styleAddFont('family');");
589		$(".jiajian .fontSize").attr("onchange", "styleAddFont('size');");
590		
591		//背景颜色
592		$(".jiajian .color-input").attr("onchange", "styleAddFont('color');");
593		//字体颜色
594		$(".jiajian .color-input-font").attr("onchange", "styleAddFont('fontcolor');");
595		// 点击段落链接弹框
596		$(".jiajian .duanluolianjie").attr("onclick","tankuang();");
597		
598		//控制缩进是否显示
599//		if(textIndentVal != undefined && textIndentVal != '' && textIndentVal != '0em' ){
600//			$(".indentwrap").hide();
601//		}else{
602//			$(".indentwrap-hide").hide();
603//		}
604		//控制缩进是否显示
605//		if(textIndentVal != undefined && textIndentVal != '' && textIndentVal != '0em' ){
606//			$(".indentwrap").hide();
607//		}else{
608//			$(".indentwrap-hide").hide();
609//		}
610		//控制图标高亮问题
611		/*if(_flagindex != 0){
612			$(".jiajian").addClass("light");
613		}
614		_flagindex = _flagindex + 1*/
615		
616		//缓存可保存区域
617		editHtml = $(".box-article-content").html();
618		editTitle = $(".article-title-center").html();
619	} catch (e) {
620		console.log(e);
621	}
622}
623
624/*
625 * 图标高亮
626 */
627function lightbtn(e){
628	if($(e).parents(".btnwrap").hasClass("duiqifangshi-wrap")){
629		$(".btnwrap").removeClass("lightbg");
630		$(e).addClass("lightbg").parent().siblings().find("i").removeClass("lightbg");
631	}else{
632		$(".duiqifangshi-wrap i").removeClass("lightbg");
633		$(e).parents(".btnwrap").addClass("lightbg").siblings().removeClass("lightbg");
634	}
635}
636/*
637 * 点击段落链接弹框
638 */
639function tankuang(){
640	if($("body").find(".framewrap").length > 0){
641		$(".framewrap").show()
642	}else{
643		var frames = ''
644			frames += "<div class='framewrap' onclick='hidetankuang()' >" +
645			"<div class='framecon' >" +
646			"<h3 class='frametit'>超链接</h3>" +
647			"<a class='closeframe' >X</a>" +
648			"<table class=''>" +
649			"<tr> <td><label for='text'> 文本内容:</label></td>" +
650			" <td><input class='txt' id='text' type='text'></td></tr>" +
651			"<tr> <td><label for='href'> 链接地址:</label></td>" +
652			" <td><input class='txt' id='hrefs' type='text' onblur='CheckUrl(this)'></td></tr>" +
653			"<tr> <td><label for='title'> 标题:</label></td>" +
654			" <td><input class='txt' id='title' type='text'></td></tr>" +
655			"<tr> <td colspan='2'><label for='target'>是否在新窗口打开:</label><input id='target' type='checkbox' /></td></tr>" +
656			"<tr> <td colspan='2' id='msg'><span>您输入的超链接中不包含http等协议名称,默认将为您添加http://前缀</span></tr>" +
657			"</table>" +
658			"<div class='comfirmwrap'>" +
659			"<a class='comfirmbtn combutton' onclick='hidetankuang()'>确认</a> <a class='cancelbtn combutton' onclick='hidetankuang()'>取消</a></div>" +
660			"</div><div>"
661			$("body").append(frames);
662	}
663	
664}
665// 点击关闭弹框
666function hidetankuang(){
667	$(".framewrap").hide(300)
668}
669
670
671
672
673
674/*
675 * 查看输入是否为正确网址
676 * 
677 */
678function CheckUrl(){
679	 var url=document.getElementById("hrefs").value;
680	 //var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;
681	 
682	 if(!hrefStartWith(url,["http","/","ftp://",'#'])){
683		 $("#msg").show();
684	 }
685	 else{
686		 $("#msg").hide();
687	 }
688}
689function hrefStartWith(href,arr){
690    href = href.replace(/^\s+|\s+$/g, '');
691    for(var i=0,ai;ai=arr[i++];){
692        if(href.indexOf(ai)==0){
693            return true;
694        }
695    }
696    return false;
697}
698/*
699 * 清除段内格式
700 * */
701function cleanStyle(obj){
702	try {
703		if(thisObj != undefined){
704			var msg = "删除段落格式后无法恢复,您确定要删除么?";
705			if (confirm(msg)==true){
706				$(thisObj).find(".span-list").remove();
707				$(thisObj).focus().html($(thisObj).text());
708				saveEditNews("");
709				return true;
710			}else{
711				return false;
712			}
713		}else{
714			alert("请选择要删除的内容!");
715		}
716	} catch (e) {
717		console.log(e);
718	}
719}
720
721/*
722 * 回车事件,处理激活段落输入回车多div问题
723 * @isEnable true 可以回车, false 不可以回车
724 * */
725function onContenteditableEnter(e, isEnable){
726	var ev = (typeof event!= 'undefined') ? window.event : e;
727	if(ev.keyCode == 13){
728		if(isEnable){
729			setTimeout(function(){
730				addp(thisObj, 'bottom');
731			}, 5);
732		}
733		return false;
734	}
735}
736
737/**
738 * 添加下拉样式
739 */
740function styleAddList(){
741	try {
742		$(thisObj).children(".span-list").remove();
743		$(thisObj).css("padding-left",0);
744	} catch (e) {
745		// TODO: handle exception
746	}
747	var val=$(".noListStyle").val();
748	if(val == ""){
749		/*$(thisObj).children(".span-list").remove();
750		$(thisObj).css("padding-left",0);*/
751		$(thisObj).focus();
752	}else{
753		var html = "<span class='span-list'>
753"+val+"</span>" + $(thisObj).html();
754		$(thisObj).css("padding-left","25px");
755		$(thisObj).focus().html(html);
756		//var _tempVal = $(".noListStyle option").attr("value");
757	}
758	setTimeout(function(){
759		saveEditNews("");
760	}, 100);
761}
762
763/**
764 * 随机数
765 * @returns
766 */
767function sj() {
768    //x上限,y下限     
769    var x = 10000;
770    var y = 0;
771    var rand = parseInt(Math.random() * (x - y + 1) + y);
772    if(rand == tempRangeId){
773    	sj();
774    }
775    return rand;
776}
777
778/**
779 * 字体字号
780 */
781function styleAddFont(styleType){
782	try {
783		var styleVal;
784		
785		if(styleType == 'size'){
786			styleVal = "font-size:" + $(".fontSize").val() + ";";
787		}else if(styleType == 'family'){
788			styleVal = "font-family:" + $(".fontFamily").val() + ";";
789		}else if(styleType == 'color'){
790			styleVal = "background-color:" + $(".color-input").val() + ";";
791		}else if(styleType == 'fontcolor'){
792			styleVal = "color:" + $(".color-input-font").val() + ";";
793		}
794		
795		var selObj;
796	    if (window.getSelection) { 
797	    	selObj = window.getSelection();
798	    } 
799	    var _range = selObj.getRangeAt(0);
800	    
801	    var spanDom;
802	    if(!_range.collapsed){
803	    	var tempRangeId = sj();
804	    	spanDom = document.createElement("span");
805	    	spanDom.setAttribute("id", tempRangeId);
806	    	spanDom.setAttribute("style", styleVal);
807	    	spanDom.innerHTML = _range.toString();
808	    	_range.deleteContents();
809			_range.insertNode(spanDom);
810			
811			selObj.removeAllRanges();
812			var _newrange = document.createRange();
813			_newrange.selectNode(spanDom);
814			selObj.addRange(_range);
815	    }
816	    setTimeout(function(){
817			saveEditNews("");
818		}, 100);
819	} catch (e) {
820		// TODO: handle exception
821	}
822}
823
824/**
825 * 添加基本样式
826 * @param tagType
827 * @param val
828 */
829function styleAdd(tagType, val){
830	if(tagType=='b' || tagType=='strong' || tagType == 'i' || tagType == 'em'){
831		try {
832			var selObj;
833		    if (window.getSelection) { //现代浏览器
834		    	selObj = window.getSelection();
835		    } 
836		    var _range = selObj.getRangeAt(0);
837			
838			var strongDom;
839			if(!_range.collapsed){
840				tempRangeId = sj();
841				strongDom = document.createElement(tagType);
842				strongDom.setAttribute("id", tempRangeId);
843				// 设置 strong 内容
844				strongDom.innerHTML = _range.toString();
845				_range.deleteContents();
846				_range.insertNode(strongDom);
847				
848				selObj.removeAllRanges();
849				var _newrange = document.createRange();
850				_newrange.selectNode(strongDom);
851				selObj.addRange(_range);
852			}else{
853				var tmpText =  document.createTextNode(newRange.toString());
854				
855				newRange.insertNode( tmpText );//.removeInlineStyle( tagNames );
856				newRange.setStartBefore(tmpText);
857			}
858			
859			setTimeout(function(){
860				saveEditNews("");
861			}, 100);
862		} catch (e) {
863			console.log(e);
864		}
865	} else if(tagType == 'text-align'){
866		if(val === 'undefined'){
867			val = 'left';
868		}
869		$(thisObj).css("text-align", val);
870	}
871	
872}
873
874var selectionStart, selectionEnd;
875var newRange;
876var tempRangeId;
877/**
878 * 获取鼠标选中内容
879 */
880function onContenteditableMouseUp(event, isEnable, obj){
881	
882	event = event || window.event;
883    var keyCode = event.keyCode || event.which;
884     
885   
886	
887}�/*
888function _getSelection(){
889	try {
890		var userSelection;
891	    if (window.getSelection) { //现代浏览器
892	    	sel = userSelection = window.getSelection();
893	    } else if (document.selection) { //IE浏览器 考虑到Opera,应该放在后面
894	    	sel = userSelection = document.selection.createRange();
895	    }
896	
897	    var getRangeIndex = function(selectionObject) {
898	        if (window.getSelection){
899	            range = selectionObject.getRangeAt(0);
900	            newRange = range.cloneRange();
901	            //getCursortPosition(thisObj);
902	        	return [range.startOffset, range.endOffset];
903	        }else { // 较老版本Safari!
904	            var range               = document.selection.createRange();             //对选择的文字create Range
905	            // var selectText          = range.text;                                //选中的文字
906	            var selectTextLength    = range.text.length;                            //选中文字长度
907	            thisObj.select();                                                      //textarea全选
908	            //StartToStart、StartToEnd、EndToStart、EndToEnd
909	            range.setEndPoint("StartToStart", document.selection.createRange());    //指针移动到选中文字开始
910	            var selectTextPosition  = range.text.length;                            //选中文字的结束位置
911	            range.collapse(false);                                                  //将插入点移动到当前范围的开始
912	            range.moveEnd("character", -selectTextLength);   //更改范围的结束位置,减去长度,字符开始位置,character不能改
913	            range.moveEnd("character", selectTextLength);   //再更改范围的结束位置,到字符结束位置
914	            range.select();                                                         //然后选中字符
915	             
916	            //返回字符的开始和结束位置
917	            return [selectTextPosition - selectTextLength, selectTextPosition];
918	        }
919	    }
920	     
921	    var rangeIndex = getRangeIndex(userSelection);
922	    selectionStart = rangeIndex[0];
923	    selectionEnd   = rangeIndex[1];
924	} catch (e) {
925		console.log(e);
926	}
927	
928//		if (window.getSelection) {
929//			sel = document.getSelection();
930//			// 选择范围
931//			range = sel.getRangeAt(0);
932//			// 获取选择的文字
933//			//selTxt = sel.getRangeAt(0).extractContents().textContent;
934//			// 删除被选择的内容
935//	        //range.deleteContents();
936//			//range.collapse(true);
937//	        // 创建新的元素 strong
938//	        //strong = $("<strong></strong>")[0];
939//	        // 设置 strong 内容
940//	        //strong.innerHTML = txt;
941//	        // 在被选择的位置添加加粗的元素
942//	        //range.insertNode(strong);
943//			
944////			$(".jiacu-wrap").bind("click", function(){
945////				alert(range.toString());
946////			});
947//			
948//		}else{
949//			var range = document.selection.createRange();
950//		}
951}
952*/
953//获取光标位置函数 
954var CaretPos = 0;
955//获取光标位置
956function getCursortPosition (ctrl) 
957{
958    //获取光标位置函数 
959    //var CaretPos = 0; 
960    // IE Support
961    if (document.selection) 
962    { 
963        ctrl.focus (); // 获取焦点
964        var Sel = document.selection.createRange (); // 创建选定区域
965        Sel.moveStart('character', -ctrl.value.length); // 移动开始点到最左边位置
966        CaretPos = Sel.text.length;                      // 获取当前选定区的文本内容长度
967    } 
968    // Firefox support 
969    else if (ctrl.selectionStart || ctrl.selectionStart == '0')
970    {
971        CaretPos =ctrl.selectionStart; // 获取选定区的开始点 
972    }
973    return CaretPos; 
974}
975
976
977function keepLastIndex(obj) {
978    if (window.getSelection) {//ie11 10 9 ff safari
979        obj.focus(); //解决ff不获取焦点无法定位问题
980        var range = window.getSelection();//创建range
981        range.selectAllChildren(obj);//range 选择obj下所有子内容
982        range.collapseToEnd();//光标移至最后
983    }
984    else if (document.selection) {//ie10 9 8 7 6 5
985        var range = document.selection.createRange();//创建选择对象
986        //var range = document.body.createTextRange();
987        range.moveToElementText(obj);//range定位到obj
988        range.collapse(false);//光标移至最后
989        range.select();
990    }
991}
992
993//设置行高
994function hanggaoAdd(obj){
995	var val = $(".hanggao-val").val();
996	if(val == '' || val === 'undefined'){
997		$(thisObj).css("line-height", "unset");
998		$(thisObj).find(".span-list").css("line-height", "unset");
999	}else{
1000		$(thisObj).css("line-height", val + "px");
1001		$(thisObj).find(".span-list").css("line-height", val-3 + "px");
1002	}
1003	
1004	setTimeout(function(){
1005		$(thisObj).focus();
1006		
1007		saveEditNews("");
1008	}, 100);
1009}
1010
1011//首行缩进
1012function indent(obj, type){
1013	try{
1014		if(type == 'add'){
1015			var val = $(".indentwrap-val").val();
1016			if(val === 'undefined'){
1017				val = "0";
1018			}
1019			$(thisObj).css("text-indent", val + "em");
1020			//$(".indentwrap").hide();
1021			//$(".indentwrap-hide").show();
1022		}/*else{
1023			$(thisObj).css("text-indent","0em");
1024			$(".indentwrap").show();
1025			$(".indentwrap-hide").hide();
1026		}*/
1027		setTimeout(function(){
1028			
1029			saveEditNews("");
1030			
1031			
1032		}, 100);
1033		
1034	} catch (e) {
1035		
1036	}
1037}
1038//增加上下左右间距
1039function jianju(obj){
1040	try {
1041		var _val = $(obj).siblings(".inputwrap").find(".jianju-input").val();
1042		if(_val === 'undefined'){
1043			_val = 0;
1044		}
1045		var _parent = $(obj).parents("div[class $= -wrap]").attr("class");
1046		var _index = _parent.lastIndexOf(' ');
1047		_parent = _parent.substring(_index,_parent.length-5).trim();
1048		$(obj).parents(".jiajian").prev().css("margin-"+_parent,_val +"px");
1049		$(obj).siblings(".inputwrap").val(_val);
1050		saveEditNews("");
1051	} catch (e) {
1052		
1053	}
1054}
1055
1056//增加段落事件
1057function addp(obj, topBottom){
1058	try {
1059		var pObj = $("<p contenteditable='true'></p>");
1060			//.attr("contenteditable","true")
1061			//.attr("onfocus","inputFocus(this);")
1062			//.attr("onblur","inputBlur(this);")
1063			//.attr("onkeydown", "return onContenteditableEnter(event, true);");
1064		if(topBottom == 'top'){
1065			$(thisObj).before(pObj);
1066		}else{
1067			$(thisObj).after(pObj);
1068		}
1069		
1070		//激活光标
1071		setTimeout(function(){
1072			pObj.focus();
1073			
1074			$(pObj).bind("focus", function(){
1075				inputFocus(this);
1076			});	
1077			
1078//			$(pObj).bind("blur", function(){
1079//				inputBlur(this);
1080//			});	
1081			
1082			$(pObj).bind("keydown", function(){
1083				onContenteditableEnter(event, true);
1084			});
1085			
1086//			$(pObj).bind("mouseup", function(){
1087//				onContenteditableMouseUp(event, true, this);
1088//			});
1089			
1090			thisObj = pObj;
1091			
1092			saveEditNews("");
1093		}, 100);
1094		
1095	} catch (e) {
1096		console.log(e);
1097	}
1098	
1099}
1100
1101//删除段落事件
1102function removep(obj){
1103	try {
1104		if(thisObj != undefined){
1105			var msg = "删除段落后无法恢复,您确定要删除么?";
1106			if (confirm(msg)==true){
1107				$(thisObj).remove();
1108				thisObj = undefined;
1109				saveEditNews("");
1110				return true;
1111			}else{
1112				return false;
1113			}
1114		}else{
1115			alert("请选择要删除的段落!");
1116		}
1117	} catch (e) {
1118		console.log(e);
1119	}
1120	
1121}
1122
1123//销毁编辑器
1124function removeEditorNew(){
1125	try {
1126		saveEditNews("");
1127		
1128		$(".editwrap").show();
1129		$(".editwrap-hide").hide();
1130		$(thisObj).show();
1131		
1132		ue.destroy();
1133		editDiv.remove();
1134	} catch (e) {
1135		// TODO: handle exception
1136	}
1137}
1138/**
1139 * EMEditor编辑器
1140 */
1141function initUMEditorNew(){
1142	//实例化编辑器
1143    var um = UM.getEditor($(thisObj).attr("id"));
1144    
1145}
1146//针对段落初始化编辑器
1147function initEditorNew(editButObj){
1148	var elemObj;
1149	//初始化之前先销毁
1150	try {
1151		$(".editwrap").hide();
1152		$(".editwrap-hide").show();
1153		
1154		elemObj = $(editButObj).parents(".jiajian").prev();
1155		
1156		//$(editButObj).hide();
1157		
1158		//UE.delEditor("editContent");
1159		ue.destroy();
1160		//editTextarea.remove();
1161		editDiv.remove();
1162
1163		
1164	} catch (e) {
1165		// TODO: handle exception
1166	}
1167	
1168	
1169	//var html = $(elemObj).html();
1170	//获取包含标签本身的所有内容
1171	var html = $(elemObj).prop('outerHTML');
1172	//$(elemObj).after(editTextarea);
1173	
1174	editDiv = $("<div id='editorDivTool' calss='editorDivTool' style='margin-bottom:8px; display:none;'><textarea id='editContent'></textarea></div>");
1175	$(elemObj).before(editDiv);
1176	ue = UE.getEditor(
1177		'editContent',{
1178		toolbars: [[
1179		       //撤销、重做
1180	           'undo', 'redo', '|',
1181	          'bold', 'italic', 'underline', /*'fontborder', 'strikethrough',*/ 'superscript', 'subscript',  
1182	          //'autotypeset', 'blockquote', 'pasteplain', '|', 
1183	          'forecolor', /*'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',*/
1184	          //'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
1185	          //'customstyle', 'paragraph', 'fontfamily', 
1186	          'fontfamily','fontsize', '|',
1187	          //'directionalityltr', 'directionalityrtl', 'indent', '|',
1188	          'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify'
1189	          //, '|', 'touppercase', 'tolowercase', '|'
1190	          ,'link', 'unlink', 'anchor',
1191	          //, '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
1192	          /*'simpleupload',*/ 'insertimage', //'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background'
1193	          , '|'/*,'horizontal', 'date', 'time'*/, 'spechars'
1194	          //, '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols'
1195	      ]] 
1196	      ,enableContextMenu: false
1197	      ,elementPathEnabled: false
1198	      //,wordCount:false
1199	      ,wordCountMsg:'<b><span style="color:red;">富文本编辑只针对段内样式,无法添加新段落!,需要增减段落请使用右侧工具栏功能!</span></b>'
1200	});
1201	
1202	//编辑器加载完成后执行
1203	ue.addListener('ready', function(){
1204		//隐藏编辑器计量DIV
1205		//$(".edui-editor-bottomContainer").hide();
1206		//隐藏编辑器内容DIV
1207		//$("#edui1_iframeholder").hide();
1208		
1209		//绑定加粗工具栏
1210		//customBold();
1211		
1212		//工具栏居中
1213		//$(".edui-toolbar").css("text-align","center");
1214		
1215		ue.setContent(html);
1216		
1217		$(elemObj).hide();
1218		
1219		
1220		//显示工具栏
1221		$("#editorDivTool").show();
1222		
1223		//设置光标
1224		ue.focus(true);
1225		
1226		//统计元素路径td 隐藏
1227		$("#edui1_elementpath").hide();
1228		
1229		//ue.execCommand('inserthtml','是否需');
1230		//editTitle = $(".article-title-center").html();
1231		//editHtml = $(".box-article-content").html();
1232		
1233		UE.dom.domUtils.on(ue.body,"keydown",function(oEvent){
1234		   var oEvent = oEvent || window.oEvent; 
1235		   //获取键盘的keyCode值
1236		   var nKeyCode = oEvent.keyCode || oEvent.which || oEvent.charCode;
1237		   //获取ctrl 键对应的事件属性
1238		   var bCtrlKeyCode = oEvent.ctrlKey || oEvent.metaKey;
1239		   if( nKeyCode == 83 && bCtrlKeyCode  ) {
1240			   //
1241			   saveEditNews("");
1242			   //阻止触发默认的ctrl+s事件
1243			   oEvent.returnValue = false;
1244		   }
1245		   //禁用回车
1246		   else if(nKeyCode == 13){
1247			   oEvent.returnValue = false;
1248		   } 
1249	    });
1250		
1251		//saveEditNews("");
1252		
1253		//缓存可保存区域
1254		editHtml = $(".box-article-content").html();
1255		editTitle = $(".article-title-center").html();
1256	})
1257	
1258//	ue.addListener('keydown', function(){
1259//		var oEvent = $(this); 
1260//		//获取键盘的keyCode值
1261//		var nKeyCode = oEvent.keyCode || oEvent.which || oEvent.charCode;
1262//		//alert(nKeyCode);
1263//	})
1264	
1265	//编辑的同时通报到原始标签上
1266	ue.addListener('contentchange', function(){
1267		//$(thisObj).html(ue.getContent().replace("<p>","").replace("</p>", ""));
1268		$.each($(ue.getContent()),function(ind,pval){
1269			if(ind == 0){
1270				var editroP_Style = $(pval).attr("style");
1271				if(editroP_Style != null && editroP_Style != undefined){
1272					//剔除 隐藏的段落显示属性
1273					editroP_Style = editroP_Style.replace("display: block;","");
1274				}
1275				$(thisObj).attr("style", editroP_Style);
1276				$(thisObj).html(pval.innerHTML);
1277				$(thisObj).hide();
1278			}/*
1279				如果富文本编辑器开启回车 这个是有用的
1280			else{
1281				var newP = $(pval).attr("contenteditable","true")
1282				.attr("onfocus","inputFocus(this);")
1283				.attr("onblur","inputBlur(this);");
1284				$(thisObj).after(newP);
1285			}*/
1286		})
1287		
1288		//统计元素路径td 隐藏
1289		$("#edui1_elementpath").hide();
1290		
1291		//内容变化了就保存
1292		saveEditNews("");
1293		
1294		
1295	})
1296	
1297	//编辑器离开body事件 任何离开都触发
1298	ue.addListener('blur', function(){
1299		try {
1300			//销毁
1301			//ue.destroy();
1302			//editDiv.remove();
1303			
1304			//saveEditNews("");
1305		} catch (e) {
1306			console.log(e);
1307		}
1308	});
1309}
1310
1311
1312var cursorPosition = {
1313    get: function (textarea) {
1314        var rangeData = {text: "", start: 0, end: 0 };
1315      
1316        if (textarea.setSelectionRange) { // W3C   
1317            textarea.focus();
1318            rangeData.start= textarea.selectionStart;
1319            rangeData.end = textarea.selectionEnd;
1320            rangeData.text = (rangeData.start != rangeData.end) ? textarea.value.substring(rangeData.start, rangeData.end): "";
1321        } else if (document.selection) { // IE
1322            textarea.focus();
1323            var i,
1324                oS = document.selection.createRange(),
1325                oR = document.body.createTextRange();
1326            oR.moveToElementText(textarea);
1327              
1328            rangeData.text = oS.text;
1329            rangeData.bookmark = oS.getBookmark();
1330              
1331            for (i = 0; oR.compareEndPoints('StartToStart', oS) < 0 && oS.moveStart("character", -1) !== 0; i ++) {
1332  
1333                if (textarea.value.charAt(i) == '\r' ) {
1334                    i ++;
1335                }
1336            }
1337            rangeData.start = i;
1338            rangeData.end = rangeData.text.length + rangeData.start;
1339        }
1340          
1341        return rangeData;
1342    },
1343      
1344    set: function (textarea, rangeData) {
1345        var oR, start, end;
1346        if(!rangeData) {
1347            alert("You must get cursor position first.")
1348        }
1349        textarea.focus();
1350        if (textarea.setSelectionRange) { // W3C
1351            textarea.setSelectionRange(rangeData.start, rangeData.end);
1352        } else if (textarea.createTextRange) { // IE
1353            oR = textarea.createTextRange();
1354            if(textarea.value.length === rangeData.start) {
1355                oR.collapse(false);
1356                oR.select();
1357            } else {
1358                oR.moveToBookmark(rangeData.bookmark);
1359                oR.select();
1360            }
1361        }
1362    },
1363  
1364    add: function (textarea, rangeData, text) {
1365        var oValue, nValue, oR, sR, nStart, nEnd, st;
1366        this.set(textarea, rangeData);
1367          
1368        if (textarea.setSelectionRange) { // W3C
1369            oValue = textarea.value;
1370            nValue = oValue.substring(0, rangeData.start) + text + oValue.substring(rangeData.end);
1371            nStart = nEnd = rangeData.start + text.length;
1372            st = textarea.scrollTop;
1373            textarea.value = nValue;
1374            if(textarea.scrollTop != st) {
1375                textarea.scrollTop = st;
1376            }
1377            textarea.setSelectionRange(nStart, nEnd);
1378        } else if (textarea.createTextRange) { // IE
1379            sR = document.selection.createRange();
1380            sR.text = text;
1381            sR.setEndPoint('StartToEnd', sR);
1382            sR.select();
1383        }
1384    }
1385}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.