RichTextUitl = {
	getRichText : function() {}, // 获取内容方法 content：正文内容，content_imgs：图片，attachment：附件，rtf_content：富文本内容
	showTips : function(){}, // 显示提示和错误信息的方法
	addLink : function(){}, // 链接标蓝（详情页调用）
	cropImage : function(){}, // 裁剪图片，将富文本中的图片换成Q50的缩略图（详情页调用）
	thumbnail2BigImgMap: new RMap(), // 替换富文本总的图片为缩略图时，生成的map，缩略图（Q50）-大图（Q80）
	afterPageRendered : function(){}, // 页面渲染完成后调用的方法（详情页调用）
	randomUUID : function() {}, // 获取 UUID
	loadImg : function() {}, // 加载图片方法
	beforeSetRtfContent : function(){}, // 在页面上设置富文本内容之前进行的操作（详情页调用）
	xssReg: new RegExp("(\\baler(?=t\\s*\\())|(\\bhref(?=\\s*=\\s*['\"]?\\s*javascript:))|(\\bsrc(?=\\s*=\\s*['\"]?\\s*javascript:))|((data|src)\\s*=['\"]?\\s*data(?=:)(?!:\\s*image))|(^[^<]*<(?=/textarea\\s*>))|(<(?=(script)|(/script)))|(<(?=(details)|(/details)))|(\\b(onstart|onafterprint|onbeforeprint|onbeforeunload|onerror|onhaschange|onload|onmessage|onoffline|ononline|onpagehide|onpageshow|onpopstate|onredo|onresize|onstorage|onundo|onunload|onblur|onchange|oncontextmenu|onfocus|onformchange|onforminput|oninput|oninvalid|onreset|onreset|onsubmit|onkey\\w*|onclick|ondblclick|ondrag\\w*|ondrop|onmouse\\w*|onscroll|ontouch\\w*)(?=(\\s*)=))",'gi'),
	Regex4LinkText: new RegExp('((((http[s]{0,1}|ftp)://)([a-zA-Z0-9\\-]+\\.)+[a-zA-Z0-9\\-]+(:\\d+)?)|(((http[s]{0,1}|ftp)://)?(((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))(:\\d+)?)|(([a-zA-Z0-9\\-]+\\.)+((ac)|(ad)|(ae)|(aero)|(af)|(ag)|(ai)|(al)|(am)|(an)|(ao)|(ar)|(arpa)|(as)|(asia)|(at)|(au)|(aw)|(ax)|(az)|(ba)|(bb)|(bd)|(be)|(bf)|(bg)|(bh)|(bi)|(biz)|(bj)|(bm)|(bn)|(bo)|(br)|(bs)|(bt)|(bv)|(bw)|(by)|(bz)|(ca)|(cat)|(cc)|(cd)|(cf)|(cg)|(ch)|(chintai)|(ci)|(ck)|(cl)|(cm)|(cn)|(co)|(com)|(coop)|(cr)|(cu)|(cv)|(cx)|(cy)|(cz)|(de)|(dj)|(dk)|(dm)|(do)|(dz)|(ec)|(edu)|(ee)|(eg)|(er)|(es)|(et)|(eu)|(fi)|(fj)|(fk)|(fm)|(fo)|(fr)|(ga)|(gb)|(gd)|(ge)|(gf)|(gg)|(gh)|(gi)|(gl)|(global)|(globo)|(gm)|(gmail)|(gn)|(gov)|(gp)|(gq)|(gr)|(gs)|(gt)|(gu)|(gw)|(gy)|(hk)|(hm)|(hn)|(hr)|(ht)|(hu)|(id)|(ie)|(il)|(im)|(in)|(info)|(int)|(iq)|(ir)|(is)|(it)|(je)|(jm)|(jo)|(jobs)|(jp)|(ke)|(kg)|(kh)|(ki)|(km)|(kn)|(kp)|(kr)|(kw)|(ky)|(kz)|(la)|(lb)|(lc)|(li)|(lk)|(lr)|(ls)|(lt)|(lu)|(lv)|(ly)|(ma)|(mc)|(md)|(me)|(mg)|(mh)|(mil)|(mk)|(ml)|(mm)|(mn)|(mo)|(mobi)|(mp)|(mq)|(mr)|(ms)|(mt)|(mu)|(museum)|(mv)|(mw)|(mx)|(my)|(mz)|(na)|(name)|(nc)|(ne)|(net)|(nf)|(ng)|(ni)|(nl)|(no)|(np)|(nr)|(nu)|(nz)|(om)|(org)|(pa)|(pe)|(pf)|(pg)|(ph)|(pk)|(pl)|(pm)|(pn)|(pr)|(pro)|(ps)|(pt)|(pw)|(py)|(qa)|(re)|(ro)|(rs)|(ru)|(rw)|(sa)|(sb)|(sc)|(sd)|(se)|(sg)|(sh)|(si)|(sj)|(sk)|(sl)|(sm)|(smile)|(so)|(sr)|(st)|(su)|(sy)|(sz)|(tc)|(td)|(tel)|(tf)|(tg)|(th)|(tj)|(tl)|(tm)|(tn)|(to)|(tp)|(tr)|(travel)|(tt)|(tv)|(tw)|(tz)|(ua)|(ug)|(uk)|(us)|(uy)|(uz)|(va)|(vc)|(ve)|(vg)|(vi)|(vn)|(vu)|(wf)|(ws)|(ye)|(yt)|(za)|(zm)|(zw))(?![a-zA-Z0-9]))(:\\d+)?)))(/[a-zA-Z0-9\\.\\-~!@#$%^&#$%^&amp;*+?:_/=&lt;&gt;()]*)?', 'gi'),//超链接文本
	loadEditorProfile : function(){}, // 编辑页加载相关配置
	loadDetailPageProfile: function(){}, // 详情页加载相关配置
	loadCssFile : function(){}, // 加载css文件
	loadJSFile : function(){}, // 加载js文件
	initUEditor : function(){}, // 初始化ueditor
	replaceIframeSrc: function(){},//编辑页调整附件地址
	imageViewer: '', // 查看图片插件
	imageViewerJSON: {},
	ueditor: '', // ueditor编辑器对象
	b64EncodeUnicode : function(){}, // base64编码
	showDeleteTips: true, // 删除图片时弹出 提示框
	limpidImg:function(){}, //图片变清晰方法
	t:'20221116',
	imgArray: new Array(), // 图片数组
	hasLoadAttachmentListener: false,
	isScreen: false,// 是否是投屏页
	// 上传文件需要的参数
	hasLoadViewer: false,
	hasLoadMedia: false,
	imageArray: new Array(),
	replaceDownloadFailedImg: true, // 下载第三方图片地址失败后替换成对应的失败图片
	downloadFailedImg: 'http://p.cldisk.com/star3/origin/e89a582776883b28de8a8894f0683a0a.png?rw=400&rh=225&_fileSize=7312&_orientation=1',
	existingImg: '', // 已有的图片，用于进入编辑页时存储已有的 图片
	setExistingImg : function(){}, // 设置已有的图片，编辑模式下调用
	customToolbars: {}, // 自定义按钮，key 页面名称，value页面地址
	insertAttachments : function(attachmentArray){}, // 插入附件
	updateAttachment : function(data){}, // 更新附件数据
	setBackground: false, // 设置附件背景
	dealWithTeachPlan : function(){}, // 处理教案相关逻辑
	userImgPlugin: true, // 是否使用图片插件
	createPPTcallback:function(){},
	isDetailPage: false, // 是否是详情页
	intranetMode: false, // 是否是内网模式，内网模式，静态资源走相对访问
	prefix: '',//线上编辑器的
	subAttchEditMode :function(){},// 详情页去掉附件的可编辑链接参数 enableEdit=1
	uploadedFolder: {}, // 记录上传的文件夹
	autoAddLink: true, // 是否自动添加链接
	template : [{'title':'新闻资讯', 'background':'https://noteyd.chaoxing.com/res/images/pc/note/ds.png', 'rtf_content':'<p class="p1" style="margin-bottom: 6px; text-align: center; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-family: &quot;Kaiti SC&quot;; color: rgb(0, 0, 0);" element-id="jzdl5ofc"><br/></p><h1 element-id="2ftvuhil" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;"><span style="font-family: 黑体, SimHei; font-size: 19px;"><b>&nbsp; &nbsp; &nbsp; &nbsp; 一、一级标题（<span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">黑体、四号字、加粗，序号为</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">一、</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">，居左，空</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">2</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">字）</span></b></span></h1><h1 element-id="abilxs4t" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;"><span style="font-family: 黑体, SimHei;"><br/></span></h1><h2 element-id="4wui7zvx" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;"><span style="font-family: 宋体, SimSun, STSong; font-size: 19px;">（一）二级标题（<span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">宋体、四号字，序号为</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“(</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">一</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">)）</span></span></h2><p class="p2" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;" element-id="pd04wt2b"><span style="font-size: 19px;">​</span><br/></p><h3 element-id="azki6p01" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;"><span style="font-family: 仿宋, FangSong; font-size: 19px;">（1）三级标题（<span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">仿宋体、四号字，序号为</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">（</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">1</span><span class="s1" style="color: rgb(0, 0, 0); font-kerning: none;">）</span><span class="s2" style="color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”）</span></span></h3><h3 element-id="0hiskcp4" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px;"><span class="s2" style="font-family: 仿宋, FangSong; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;"><br/></span></h3><p element-id="6ea27xws" style="text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; min-height: 17px; line-height: 1.8;"><span style="font-size: 19px;"><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">&nbsp; &nbsp; &nbsp;</span><span style="font-size: 19px; font-family: 仿宋, FangSong;"><span class="s2" style="font-size: 19px; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;"> &nbsp;9</span><span class="s1" style="font-size: 19px; color: rgb(0, 0, 0); font-kerning: none;">月</span><span class="s2" style="font-size: 19px; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">13</span><span class="s1" style="font-size: 19px; color: rgb(0, 0, 0); font-kerning: none;">日，由教育部高等教育司指导，中国高等教育学会主办，西安交通大学和超星尔雅集团承办的全国高校教师教学创新大赛总结会暨第二届启动会在西安交通大学举办。教育部高等教育司副司长武世兴指出，首届大赛为促进教学改革创新、引导教师潜心教书育人发挥了积极的作用，形成了比较完善的赛事组织体系。第二届大赛要继续以人才培养为中心，推进思政课程和课程思政建设，实现价值塑造、知识传授与能力培养相统一的教学效果；推进</span><span class="s2" style="font-size: 19px; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="font-size: 19px; color: rgb(0, 0, 0); font-kerning: none;">新工科，新医科，新农科，新文科</span><span class="s2" style="font-size: 19px; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”</span><span class="s1" style="font-size: 19px; color: rgb(0, 0, 0); font-kerning: none;">建设，深抓课程质量，打造人才培养新质量；全面提升教师教学能力，培养有大境界、大胸怀、大格局的优秀教师，提升教师应用现代信息技术的能力和水平，探索未来大学教育教学的新形态。</span></span></span></p><p element-id="7cvghjzt" style="text-align: justify; text-indent: 28.2px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-family: &quot;PingFang SC&quot;; color: rgb(0, 0, 0); line-height: 1.8;"><span style="font-family: 仿宋, FangSong; font-size: 19px;"><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">要坚持</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">‘</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">以本为本</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">’</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">，牢记办赛初心，以创新思维、创新实践、创新发展赋能大赛。</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">中国高等教育学会副会长张大良提出，大赛要为高校广大教师搭建互学互鉴的交流平台，深入挖掘各类课程和教学方式中蕴含的思想政治教育元素，彰显课程思政成效，在以赛促教、促学、促训、促研、促建、促创上下功夫，精心打造</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">竞赛</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">-</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">培训</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">-</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">研究</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">-</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">实践</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">于一体的多样化教师教学发展体系。他还指出，要加强大赛组织管理队伍建设，依托学会新型智库，提升赛事吸引力、公信力、影响力，促进大赛高标准、高水平、高质量、可持续创新发展。</span></span></p><p element-id="b2h51ysm" style="text-align: justify; text-indent: 28.2px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-family: &quot;PingFang SC&quot;; color: rgb(0, 0, 0); line-height: 1.8;"><span style="font-family: 仿宋, FangSong; font-size: 19px;"><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">据悉，全国高校教师教学创新大赛是助力推动高等教育</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">“</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">质量革命</span><span class="s2" style="font-size: 19px; font-family: 仿宋, FangSong; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-kerning: none;">”</span><span class="s1" style="font-size: 19px; font-family: 仿宋, FangSong; font-kerning: none;">的重要举措。本次会议聚焦教学创新，对持续推动大赛在比赛内容、模式等方面的完善创新和高质量发展提出了新的要求。</span></span></p><p element-id="rad74b0c" style="margin-bottom: 15px; text-align: justify; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-family: Helvetica; color: rgb(0, 0, 0); min-height: 12px; line-height: 1.8;"><span class="s1" style="font-kerning: none; font-family: 仿宋, FangSong; font-size: 19px;">&nbsp;</span></p><p element-id="jzq0mnif" style="margin-bottom: 15px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-family: Helvetica; color: rgb(0, 0, 0); min-height: 12px; line-height: 1.8;">​<br/></p><p element-id="3i80g4xw"><br/></p>'}],
	showTemplate: 0,
	templateList: [],//模板列表
	largePreview: false,//附件预览是否是大窗口
	initMoreUEditor:function(){},//多个编辑器
	isEditableViewLargeImage: false,	// 查看大图是否允许编辑
}
// 笔记，小组， 通知下面定义了 ue 对象，这里也定义一下，避免ueditor.all.js里面取不到报错
var ue;

//获取js当前路径
RichTextUitl.currentDomain = function () {
	var jsPath = document.currentScript && document.currentScript.src ? document.currentScript.src : function () {
		var js = document.scripts
			, last = js.length - 1
			, src;
		for (var i = last; i > 0; i--) {
			if (js[i].readyState === 'interactive') {
				src = js[i].src;
				break;
			}
			if (js[i].src.indexOf('rich.text.util.js') > -1) {
				src = js[i].src;
				break;
			}
		}
		return src || js[last].src;
	}();
	RichTextUitl.nowDomain = jsPath.substring(0, jsPath.indexOf('/res/'));
	jsPath = jsPath.substring(jsPath.indexOf('//') + 2, jsPath.lastIndexOf('/') + 1);
	// jsPath = jsPath.substring(0, jsPath.indexOf('/'));
	return jsPath;
}();

/**
 * @param ueditorHeight：编辑器高度
 * @param rtf_content：富文本内容
 * @param customCssurl：自定义css文件url
 * @param callback：编辑器初始化完成后的回调方法
 * @param initTemplateType：初始化模板类型，0、教案
 * @param notScroll：编辑时是否滑动到底部，默认滑动，传 1或者true 表示不滑动
 * @param json:其他参数，不再追加参数，后续添加的参数通过json传过来
 */
RichTextUitl.initUEditor = function (ueditorHeight, rtf_content,
																		 customCssurl, callback, initTemplateType, notScroll, json) {
	//获取镜像附件域名
	RichTextUitl.getAnnexMirrorDomain();

	var height = ueditorHeight || 500;

	// 向ueditor.config.js中添加自定义按钮控件
//	if (typeof RichTextUitl.customToolbars != 'undefined') {
//    	for (var item in RichTextUitl.customToolbars) {
//    		window.UEDITOR_CONFIG.toolbars[0].push(item);
//        }
//    }
	var prefix;
	if (RichTextUitl.intranetMode) {
		prefix = RichTextUitl.prefix;
	} else if(RichTextUitl.prefix){
		prefix = RichTextUitl.prefix + '/res/plugin/ueditor/'
	}else{
		//定制域名单位引入地址转换
		prefix = window.location.protocol + "//noteyd.chaoxing.com/res/plugin/ueditor/";
	}
	UE.getEditor('container', {
		initialFrameHeight: height,
		themePath: prefix + "themes/",
		UEDITOR_HOME_URL: prefix,
		ONLINE_ATTACH_HOME_URL: RichTextUitl.convertUrl(prefix),
		langPath: prefix + "lang/",
		serverUrl: "",
		iframeCssUrl: prefix + "themes/iframe.css",
		topOffset: typeof (RichTextUitl.topOffset) == 'number' ? RichTextUitl.topOffset : '',
		topOffsetScrollDiv: RichTextUitl.topOffsetScrollDiv || '', //滚动的div,用于解决div滚动时工具栏到顶部后滚不下来的问题
		increaseCssurl: customCssurl,
		notScroll: notScroll,
		largePreview: RichTextUitl.largePreview,
	}).ready(function () {
		// 设置内容
		RichTextUitl.ueditor = this;
		// 笔记，小组， 通知下面用的是 ue 对象
		ue = this;
		if(ue.undoManger){//解决教案多次初始化编辑器能继续回撤的问题
			ue.undoManger.reset();
		}
		if (rtf_content && rtf_content != ' ') {
			//附件地址替换
			rtf_content = RichTextUitl.replaceIframeSrc(rtf_content);

			// 客户端的错误图片（将第三方服务的图片上传到云盘失败后显示的图片）使用的本地路径，替换成云盘的地址
			rtf_content = rtf_content.replace(new RegExp("images/img_fail.jpg", "g")
				, RichTextUitl.downloadFailedImg);
			// 将http的云盘图片地址替换成https的
			rtf_content = rtf_content.replace(new RegExp("http://p.ananas.chaoxing.com", "g"),
				'https://p.cldisk.com');
			// 在编辑时将附件设置成了文本链接（a标签）模式，但是为了不影响在客户端上点击卡片页的效果，保存时会替换回卡片（iframe标签）模式
			// 需要显示的时候再改回成文本链接形式
			if (typeof RichTextUitl.replaceIframeWithATag == 'function') {
				rtf_content = RichTextUitl.replaceIframeWithATag(rtf_content);
			}
			this.setContent(rtf_content);
			// 文件设置为预览模式时，保存时地址还是存的insertCloud.html，避免在手机客户端查看有问题，这里显示的时候再替换回来
			if (typeof RichTextUitl.replaceIframeWithPreviewMode == 'function') {
				RichTextUitl.replaceIframeWithPreviewMode()
			}

		} else if (typeof initTemplateType != 'undefined' && initTemplateType) {
			// 没有传富文本内容，且传了模板类型，生成对应的模板内容
			this.setContent(RichTextUitl.getTemplateHtml(initTemplateType));
		} else if (RichTextUitl.showTemplate) {
			RichTextUitl.createTemplate();
		}
		var imgList = RichTextUitl.ueditor.body.querySelectorAll('img');
		RichTextUitl.ueditor.focus(true);
		//setTimeout(function(){$('html').scrollTop($('html').height())}, 200);

		var iframe = this.iframe;
		var doc = this.document;
		if (doc) {
			// 在 ueditor.all.js 里面有用到，用于上传图片后更新对应的查看图片插件中的视图
			$(doc.body).on('click', 'img', function () {
				if ($(this).parent().hasClass('scale')) {
					var index = $(doc.body).find('img').index(this);
					imgViewTool.initViewImage(doc.body,'',index);
					if (typeof sendMessageFadeInOrOut == 'function') {
						// 课程那边图片的额外操作
						sendMessageFadeInOrOut(1)
					}
				}
			})

			// 点击切换课前课中课后的内容
			$(doc.body).on('click', '#ulTab p', function () {
				$(this).parent().siblings().removeClass('cur_li')
				$(this).parent().addClass('cur_li')
				$(this).parents('#ulTab').nextAll().hide();
				var activeDiv;
				if ($(this).hasClass('classBefore')) {
					activeDiv = $(doc.body).find('.classConBefore');
				} else if ($(this).hasClass('classCenter')) {
					activeDiv = $(doc.body).find('.classConCenter');
				} else if ($(this).hasClass('classAfter')) {
					activeDiv = $(doc.body).find('.classConAfter');
				}
				activeDiv.show();
				activeDiv = activeDiv[0];
				var range = ue.selection.getRange();
				if (activeDiv.firstChild) {
					range.setStart(activeDiv.firstChild, 0)
				} else {
					range.setStart(activeDiv, 0)
				}
				range.collapse(true).select()
			});
		}
		$(ue.body).keydown(function (event) {
			if (event.keyCode == 27) {
				$('.cxplugin-imgviewer>.viewer-close').click()
			}
		});
		if (typeof callback == 'function') {
			callback();
		}
	});
}
//初始化多编辑器方法
//json 多编辑器传参
//container 容器
//ueditorHeight 初始化编辑器高度
//rtf_content 富文本内容
//customCssurl 个性化css地址
//callback 编辑器加载完成后的回调
//toolbars 工具栏配置项
//changecallback 内容实时改变监听的回调
//initTemplateType 模板类型
RichTextUitl.initMoreUEditor = function (json, callback, changecallback) {
	var langType = 'zh-cn'
	if (json.lang == undefined) {
		window.cookieLanguage = typeof (window.cookieLanguage) != "undefined" ? window.cookieLanguage : RichTextUitl.getCookie('browserLocale')
		var language = (window.cookieLanguage || navigator.language || 'zh').toLowerCase()
		if (language.indexOf('en') > -1) {
			langType = 'en'
		} else if(language.indexOf('zh_tw') > -1){
			langType = 'zh-tw'
		}else{
			langType = 'zh-cn'
		}
	}
	var container = 'multi' + json.editorid,
		height = json.editorheight || 500,
		rtf_content = json.content || '',
		customCssurl = json.customCssurl || '',
		toolbars = json.toolbars ? [json.toolbars] : null,
		initTemplateType = json.initTemplatetype || '',
		// lang = json.lang || 'zh-cn';
		lang = json.lang || langType;
	var topOffset = typeof (json.topOffset) == 'number' ? json.topOffset : '';
	var prefix;
	if (RichTextUitl.intranetMode) {
		prefix = RichTextUitl.prefix;
	} else if(RichTextUitl.prefix){
		prefix = RichTextUitl.prefix + '/res/plugin/ueditor/'
	} else {
		prefix = window.location.protocol + "//noteyd.chaoxing.com/res/plugin/ueditor/";
	}
	if(json.catalogDiv && typeof updateAllCatalog == 'undefined'){
		RichTextUitl.catalogDiv = json.catalogDiv
		if(typeof json.catalogOptions != 'undefined') {
			RichTextUitl.catalogOptions = json.catalogOptions
		}
		RichTextUitl.loadJSFile((RichTextUitl.prefix || (window.location.protocol + "//noteyd.chaoxing.com")) + '/res/pc/js/noteRichtext/catalog.js');
	}
	//图片均分设置项
	if(json.imageLayout){
		RichTextUitl.imageLayout = json.imageLayout
	}

	var options = {
		initialFrameHeight: height,
		themePath: prefix + "themes/",
		UEDITOR_HOME_URL: prefix,
		ONLINE_ATTACH_HOME_URL: RichTextUitl.convertUrl(prefix), //线上地址
		langPath: prefix + "lang/",
		serverUrl: "",
		iframeCssUrl: prefix + "themes/iframe.css",
		increaseCssurl: customCssurl,
		topOffset: topOffset,
		topOffsetOne: json.topOffsetOne||'',
		topOffsetScrollDiv: json.topOffsetScrollDiv || '', //滚动的div,用于解决div滚动时工具栏到顶部后滚不下来的问题
		showToTop:json.showToTop || '',
		notScroll: json.notScroll || '',
		wordcount: json.wordcount || '',
		minNumWords: json.minNumWords || '',
		maxNumWords: json.maxNumWords || '',
		autoFloatEnabled: false,
		largePreview: json.largePreview || '',
		lang: lang,
		showHoverTools : json.showHoverTools || '',
		whiteList: json.whiteList || '', //白名单
		prdid:'442',
		fileMaxSize: json.fileMaxSize || 1024 * 1024 * 1024 * 2, // 上传大小限制 默认2G
		imageMaxSize: json.imageMaxSize || 1024 * 1024 * 1024 * 2, // 上传大小限制 默认2G
		// fileFieldName: 'uploadFile',
		// imageFieldName: 'uploadFile'
	}
	//以上json未被处理过的参数，都加入options
	for(var key in json){
		if(key != 'editorid' && key != 'editorheight' && key != 'content' && key != 'customCssurl' && key != 'toolbars' && key != 'initTemplatetype' && key != 'lang' && key != 'topOffset' && key != 'catalogDiv' && key != 'catalogOptions' && key != 'imageLayout'){
			options[key] = json[key]
		}
	}
	//支持传自定义字体
	if(json.fontfamily){
		options.fontfamily = json.fontfamily
	}
	//PC端 接收 wordcount 的回调
	if(json.wordcount == true || json.wordcount == 'true' ){
		options['wordcountFun']=json.wordcountFun || ''
	}else{
		options['wordcountFun']=''
	}
	// for(var key in json){
	// 	options[key] = json[key];
	// }
	//定制工具栏
	if (toolbars) {
		options.toolbars = toolbars;
	}
	UE.getEditor(container, options).ready(function () {
		// 设置内容
		// 笔记，小组， 通知下面用的是 ue 对象
		var editor = this;
		if (json.staUniId) {
			this.options.statsAttach = true;
			this.stats = {
				staUniId: json.staUniId, //统计的ID
				staResId1: json.staResId1,  //业务ID1（非必须，比如表单id，小组bbsid）
				staResId2: json.staResId2,  //业务ID2（非必须，业务ID1的补充id，比如小组的话题id，回复id等）
				staResType: json.staResType,  //业务类型（非必须，比如表单：form，小组：group等）
			}
		}


		if (rtf_content && rtf_content.trim() != '') {
			$(editor.container).removeClass('empty');
			//附件地址替换
			rtf_content = RichTextUitl.replaceIframeSrc(rtf_content)

			// 客户端的错误图片（将第三方服务的图片上传到云盘失败后显示的图片）使用的本地路径，替换成云盘的地址
			rtf_content = rtf_content.replace(new RegExp("images/img_fail.jpg", "g")
				, RichTextUitl.downloadFailedImg);
			// 将http的云盘图片地址替换成https的
			rtf_content = rtf_content.replace(new RegExp("http://p.ananas.chaoxing.com", "g"),
				'https://p.cldisk.com');
			// 在编辑时将附件设置成了文本链接（a标签）模式，但是为了不影响在客户端上点击卡片页的效果，保存时会替换回卡片（iframe标签）模式
			// 需要显示的时候再改回成文本链接形式
			if (typeof RichTextUitl.replaceIframeWithATag == 'function') {
				rtf_content = RichTextUitl.replaceIframeWithATag(rtf_content);
			}
			this.setContent(rtf_content);
			// 文件设置为预览模式时，保存时地址还是存的insertCloud.html，避免在手机客户端查看有问题，这里显示的时候再替换回来
			if (typeof RichTextUitl.replaceIframeWithPreviewMode == 'function' && window.location.host.indexOf('chaoxing.com') != -1) {
				RichTextUitl.replaceIframeWithPreviewMode(container)
			}

		} else if (typeof initTemplateType != 'undefined' && initTemplateType) {
			// 没有传富文本内容，且传了模板类型，生成对应的模板内容
			this.setContent(RichTextUitl.getTemplateHtml(initTemplateType));
		} else if (json.templateList) {
			RichTextUitl.createMoreTemplate(json.editorid, json.templateList);
		}
		var imgList = editor.body.querySelectorAll('img');
		if(!json.topOffsetOne){
			editor.focus(true);
		}
		//setTimeout(function(){$('html').scrollTop($('html').height())}, 200);
		if(this.options.placeholder){
			$(editor.container).find('.edui-editor-iframeholder').append('<textarea class="placeholder" disabled></textarea>');
			$(editor.container).find('.placeholder').val(this.options.placeholder);
			isEmpty()
		}
		function isEmpty(){
			var innerText = editor.body.innerText.replace(/\s/g, '').replace(/​/g,'');
			if(!editor.body.querySelector('img,iframe,hr') && innerText === ''){
				$(editor.container).addClass('empty');
			} else{
				$(editor.container).removeClass('empty');
			}
		}

		var iframe = this.iframe;
		var doc = iframe.contentDocument || iframe.document;
		if (doc) {
			// 在 ueditor.all.js 里面有用到，用于上传图片后更新对应的查看图片插件中的视图
			$(doc.body).on('click', 'img', function () {
				if ($(this).parent().hasClass('scale')) {
					var index = $(doc.body).find('img').index(this);
					imgViewTool.initViewImage(doc.body,'',index);
					if (typeof sendMessageFadeInOrOut == 'function') {
						// 课程那边图片的额外操作
						sendMessageFadeInOrOut(1)
					}
				}
			})
			doc.body.oninput = function() {
				$("#edui1_toolbarbox").removeClass("edui-editor-disabled");
				if(typeof updateCatalog != 'undefined'){
					//加目录监听输入
					var range = editor.selection.getRange();
					var start = range.startContainer;
					if(start.nodeType==3 && $(start).parents('h1,h2,h3,h4,h5,h6').length>0 ){
						var h = $(start).parents('h1,h2,h3,h4,h5,h6').eq(0);
						var id = h.attr('element-id');
						// updateAllCatalog(ue.body)
						updateCatalog(doc.body, id)
					}else if($(start).is('h1,h2,h3,h4,h5,h6') && start.innerText.trim()==''){
						// updateAllCatalog(ue.body)
						deleteCatalog(doc.body, $(start).attr('element-id'));
					}
				}
			}
			// 点击切换课前课中课后的内容
			$(doc.body).on('click', '#ulTab p', function () {
				$(this).parent().siblings().removeClass('cur_li')
				$(this).parent().addClass('cur_li')
				$(this).parents('#ulTab').nextAll().hide();
				var activeDiv;
				if ($(this).hasClass('classBefore')) {
					activeDiv = $(doc.body).find('.classConBefore');
				} else if ($(this).hasClass('classCenter')) {
					activeDiv = $(doc.body).find('.classConCenter');
				} else if ($(this).hasClass('classAfter')) {
					activeDiv = $(doc.body).find('.classConAfter');
				}
				activeDiv.show();
				activeDiv = activeDiv[0];
				var range = editor.selection.getRange();
				if (activeDiv.firstChild) {
					range.setStart(activeDiv.firstChild, 0)
				} else {
					range.setStart(activeDiv, 0)
				}
				range.collapse(true).select()
			});
		}
		$(doc.body).keydown(function (event) {
			if (event.keyCode == 27) {
				$('.cxplugin-imgviewer>.viewer-close').click()
			}
		});
		//编辑器加载完成后的回调
		if (typeof callback == 'function') {
			callback();
		}
		//监听到内容改变的回调
		editor.addListener('contentchange', function () {
			if(typeof changecallback == 'function' && (doc.getElementsByClassName("imgprogress").length > 0 || doc.getElementsByClassName("attachprogress").length > 0 || doc.getElementsByClassName("video_fail").length > 0)){
				//有正在上传的内容,去除正在上传的内容
				var html = editor.getContent();
				var div = document.createElement('div');
				div.innerHTML = html;
				$(div).find('.imgprogress,.attachprogress,.video_fail').parent().remove()
				changecallback(div.innerHTML);
			}else	if (typeof changecallback == 'function' && !(doc.getElementsByClassName("imgprogress").length > 0
				|| doc.getElementsByClassName("attachprogress").length > 0
				|| doc.getElementsByClassName("video_fail").length > 0)) {
				changecallback(editor.getContent());
			}
			if(this.options.placeholder){
				isEmpty();
				}
		})
	});

	if(json.addToolbars && json.addToolbars.length > 0){
		for(var i = 0;i < json.addToolbars.length; i++){
			RichTextUitl.addIcons(container,json.addToolbars[i])
		}
	}
}


RichTextUitl.addIcons = function (container, addIconData) {

	//iframe弹窗类型
	UE.registerUI(addIconData.name, function (editor, uiName) {
		if(addIconData.iframeUrl) {
			var buttons = null;
			if (addIconData.needButton) {
				buttons = [{//如果给出了buttons就代表dialog有确定和取消
					className: 'edui-okbutton',
					label: '确定',
					onclick: function () {
						addIconData.confirmFun(editor)
						dialog.close(false);
					},
				},
					{
						className: 'edui-cancelbutton',
						label: '取消',
						onclick: function () {
							dialog.close(false);
						}
					}
				]
			}
			var dialog = new UE.ui.Dialog({
				iframeUrl: addIconData.iframeUrl,//指定弹出层中页面的路径，这里只能支持页面
				editor: editor,//需要指定当前的编辑器实例
				name: uiName,//指定dialog的名字
				title: addIconData.iframeTitle,//dialog的标题
				iframeCssRules: addIconData.iframeCssRules,//指定dialog的样式
				buttons: buttons
			});
		}
		var btn = new UE.ui.Button({
			name: 'dialogbutton' + uiName,
			title: addIconData.iconTitle,
			cssRules: addIconData.iconCssRules,//需要添加的额外样式，指定icon图标
			onclick: function () {
				//执行你的代码
				if(addIconData.iframeUrl){
					dialog.render();
					dialog.open();
				}else{
					addIconData.cmdFun(editor);
				}
			}
		});
		//因为是添加button,所以需要返回这个button
		return btn;
	})
}
//编辑页调整附件地址
RichTextUitl.replaceIframeSrc = function (rtf_content) {
	rtf_content.replace(/<iframe [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
		//capture,返回每个匹配的字符串
		var newStr = '';
		if (capture.indexOf('insert') > -1) {//web链接附件，不是insert附件不转换地址
			if (RichTextUitl.isScreen) {
				// 投屏页使用另一个附件地址
				newStr = window.location.protocol + "//noteyd.chaoxing.com";
				if(window.obj && window.obj.mirrorDomain && (window.obj.mirrorDomain.isMirrorDeploy || window.obj.mirrorDomain.isMirrorDeploy == false && window.obj.mirrorDomain.NoteDomain.indexOf('chaoxing.com') == -1)){
					// 镜像笔记详情页处理
					newStr = window.location.protocol + window.obj.mirrorDomain.NoteDomain.replace('https:','').replace('http:','');
				}
				if (RichTextUitl.setBackground) {
					// 需要设置附件背景
					newStr += '/screen/note_note/attachment/';
				} else {
					newStr += '/screen/note_note/noteDetail/';
				}
				if (capture && capture.indexOf('insert') > 0) { //截取insetCloud.html
					// 包含insert，但是不是以insert开头的，需要进行截取
					newStr += capture.substring(capture.indexOf('insert'));
				} else {
					newStr += capture;
				}
			} else if (RichTextUitl.intranetMode) {
				//镜像的带上镜像前缀
				if (capture.indexOf(RichTextUitl.prefix) == -1) {
					// 当前附件地址里不包含prefix，拼接prefix
					newStr = RichTextUitl.prefix + 'attachment/';
					if (capture && capture.indexOf('insert') > 0) { //截取insetCloud.html
						// 包含insert，但是不是以insert开头的，需要进行截取
						newStr += capture.substring(capture.indexOf('insert'));
					} else {
						newStr += capture;
					}
				} else {
					newStr = capture;
				}
			} else {
				newStr = window.location.protocol + '//noteyd.chaoxing.com/attachment/';
				if(window.obj && window.obj.mirrorDomain && (window.obj.mirrorDomain.isMirrorDeploy || window.obj.mirrorDomain.isMirrorDeploy == false && window.obj.mirrorDomain.NoteDomain.indexOf('chaoxing.com') == -1)){
					// 镜像笔记详情页处理
					newStr = window.location.protocol + window.obj.mirrorDomain.NoteDomain.replace('https:','').replace('http:','') +'/attachment/';
				}
				if (capture && capture.indexOf('insert') > 0) {
					// 包含insert，但是不是以insert开头的，需要进行截取
					newStr += capture.substring(capture.indexOf('insert'));
				} else {
					newStr += capture;
				}
			}
      newStr = newStr.replace('https:','').replace('http:','')
			rtf_content = rtf_content.replace("'" + capture + "'", newStr);
			rtf_content = rtf_content.replace('"' + capture + '"', newStr);
		}
	});
	return rtf_content;
}
//获取arr1和arr2中重复的部分
RichTextUitl.getArrEqual = function (arr1, arr2) {
	var newArr = [];
	for (var i = 0; i < arr1.length; i++) {
		for (var j = 0; j < arr2.length; j++) {
			if (arr2[j] === arr1[i]) {
				newArr.push(arr1[i]);
				break;
			}
		}
	}
	return newArr;
}
// 当页面是嵌入到一个iframe里面时，需要在最外层的页面引用 rich.text.util.js，并在页面渲染之前调用该方法，以便视频能在最外层页面中播放
RichTextUitl.loadForVideoPlay = function () {
	// 加载音视频插件
	loadMediaPlugin();
	// 加载监听附件点击的js
	var prefix = window.location.protocol + "//noteyd.chaoxing.com";
	if(RichTextUitl.prefix){
		prefix = RichTextUitl.prefix
	}
	if (typeof AttachmentListener == 'undefined') {
		RichTextUitl.loadJSFile2(prefix + '/res/pc/js/noteRichtext/attachment_listener.js?_t=' + RichTextUitl.t);
	}
	// 加载处理附件点击事件的js
	if (typeof RichtextAttachmentClickUtils == 'undefined') {
		RichTextUitl.loadJSFile2(prefix + '/res/pc/js/noteRichtext/attachment_click_util.js?_t=' + RichTextUitl.t);
	}
}

RichTextUitl.customDomain = {
	'.gdhkmooc.com': 'http://noteyd',
	'.lsu.edu.cn': 'http://noteyd',
	'.hbqyg.cn': 'http://noteyd',
	'.zhjx.hfut.edu.cn': 'http://noteyd'
}
/**
 * 转换请求地址，部分单位定制了域名，相应的接口地址也要换成定制的域名下的
 * @param url
 * @returns {*}
 */
RichTextUitl.convertUrl = function (url) {
	try {
		if(window.location.origin.indexOf('file:') > -1 || window.location.origin.indexOf('//localhost') > -1){
			return url;
		}
		if(window.obj && window.obj.mirrorDomain){
			var urlDomain = url.replace('http:','').replace('https:','').replace('//','');
			if(urlDomain.indexOf('/') > -1){
				urlDomain = urlDomain.substring(0,urlDomain.indexOf('/'))
			}

			switch (urlDomain) {
				case 'noteyd.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.NoteDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'groupyd.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.GroupDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'groupweb.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.GroupWebDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'notice.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.NoticeDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'mobilelearn.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.mobilelearnDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'cooperateyd.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.cooperateDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'exportyd.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.exportDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'mooc.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.moocDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'passport2.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.passport2DomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'previewyd.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.previewDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'sharewh.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.shareWhDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'appswh.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.appsWhDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'pan-yz.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.panDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'd0.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.d0DomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'p.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.photoDomainHttps.replace('https://','').replace('http://',''));
					break;
				case 'special.chaoxing.com':
					url = url.replace(urlDomain, window.obj.mirrorDomain.specialDomainHttps.replace('https://','').replace('http://',''));
					break;
			}
			return url;
		}
		var protocol = window.location.protocol;
		// 获取当前域名，有一些单位定制了域名，需求请求对应的定制笔记域名
		// 例如: http://groupyd2.ecourse.ucas.ac.cn/pc/activity/activityList
		var domain = window.location.host;
		//处理统一域名+路径访问模式，域名转换为xxxx.com/noteyd/xxx
		if(RichTextUitl.currentDomain.indexOf('/noteyd/') > -1 && url.indexOf('yd.') > -1){
			url = url.substring(url.indexOf('//')+2,url.length);
			urlDomain = url.substring(0,url.indexOf('/'));
			var service = '';
			if(urlDomain.substring(0,urlDomain.indexOf('.')).indexOf('yd') > -1){
				service = '/' + urlDomain.substring(0,urlDomain.indexOf('.'));
			}
			url = url.replace(urlDomain,domain + service);
			return window.location.protocol + '//' + url;
		}else if(RichTextUitl.currentDomain && RichTextUitl.currentDomain.indexOf('bistatic-') > -1 && url.indexOf('chaoxing.com') > -1){
			//超星域名换成ipv6域名bistatic-xx.chaoxing.com,例noteyd.chaoxing.com换成bistatic-noteyd.chaoxing.com
			url = url.substring(url.indexOf('//')+2,url.length);
			return window.location.protocol + '//bistatic-' + url;
		}
		if (domain.indexOf('chaoxing.com') > -1 || domain == 'sharewh.mti100.com' || (typeof isShare != "undefined" && isShare)) {
			// 超星域名，分享服务换了非超星域名的
			if (protocol == 'http:') {
				// 当前协议是http的，之前http页面可以调用https的接口，现在新版的chrome浏览器上面不行了，这里做下域名适配
				url = url.replace('https://', 'http://');
			} else if (protocol == 'https:') {
				// 当前协议是http的，之前http页面可以调用https的接口，现在新版的chrome浏览器上面不行了，这里做下域名适配
				if (url.indexOf('http://note.yd.chaoxing.com') > -1) {
					// 如果请求的笔记地址，替换成笔记的http域名，笔记http和https的域名不同
					url = url.replace('http://note.yd.chaoxing.com', 'https://noteyd.chaoxing.com');
				} else {
					// 其他服务，直接替换协议
					url = url.replace('http://', 'https://');
				}
			}
			return url;
		}
		// 截取域名
		domain = domain.substring(domain.indexOf('.'))
		// 笔记服务和小组，有http页面是两级的，note.yd.chaoxing.com , group.yd.chaoxing.com，去掉yd
		domain = domain.replace('.yd.', '.');


		if (protocol == 'http:' && url.indexOf('https://noteyd.chaoxing.com') > -1) {
			// 当前页面是http协议的，使用的接口地址是笔记的https域名，需要改成笔记http域名，大多定制单位都是配置http的定制域名，没有配https的
			// 部分单位定制的http域名对应的是 http://noteyd
			//当前js地址是非超星域名，noteyd,替换为noteyd,否则还是note.yd
			if(RichTextUitl.currentDomain.indexOf('noteyd') > -1 && RichTextUitl.currentDomain.indexOf('chaoxing.com') == -1){
				url = url.replace('https://noteyd.chaoxing.com', (RichTextUitl.customDomain[domain] || 'http://noteyd') + domain);
			}else{
				url = url.replace('https://noteyd.chaoxing.com', (RichTextUitl.customDomain[domain] || 'http://note.yd') + domain);
			}
		} else {
			if (url.indexOf('mooc1-2.chaoxing.com') > -1) {
				// 目前看一个定制域名的单位（国科大），慕课域名是用的mooc1，mooc1.ecourse.ucas.ac.cn
				url = url.replace('mooc1-2.chaoxing.com', 'mooc1.chaoxing.com')
			}
			url = url.replace('.chaoxing.com', domain);
		}
		if (protocol == 'http:' && url.indexOf('https://') > -1) {
			// 当前页面是http的，请求的地址是https的换，换成http
			url = url.replace('https://', 'http://')
		}
	} catch (e) {
		console.log(e)
	}
	return url;
}
/**
 * 编辑页加载相关配置
 * @param userDefaultMediaPulgin : 是否使用默认的音视频播放插件
 * @param userImgPlugin：是否使用图片插件
 */
RichTextUitl.loadEditorProfile = function (userDefaultMediaPulgin, userImgPlugin) {
	if(window.obj && window.obj.mirrorDomain && !RichTextUitl.prefix){
		RichTextUitl.prefix = window.obj.mirrorDomain.noteDomain || window.obj.mirrorDomain.NoteDomainHttps;
	}else	if((typeof window.obj == "undefined" || typeof window.obj.mirrorDomain == "undefined") && (RichTextUitl.prefix || window.location.host.indexOf('chaoxing.com') == -1) && !RichTextUitl.intranetMode ){
		//整个笔记服务镜像时调用接口获取镜像域名
		$.ajax({
			type:'get',
			url: (RichTextUitl.prefix || RichTextUitl.nowDomain) + '/apis/mirrorConfig',
			async:false,
			success:function(res){
				if(res.result == 1){
					if(!window.obj){
						window.obj = {};
					}
					window.obj.mirrorDomain = res.data.domainMap;
					for(var key in window.obj.mirrorDomain){
						if(window.obj.mirrorDomain[key]){
							window.obj.mirrorDomain[key] = window.location.protocol + window.obj.mirrorDomain[key].replace('https:','').replace('http:','')
						}
					}
					window.obj.mirrorDomain.isMirrorDeploy = res.data.isMirrorDeploy;
					RichTextUitl.photoDomain = window.obj.mirrorDomain.photoDomain;
					RichTextUitl.noteDomain =  window.obj.mirrorDomain.NoteDomainHttps;
				}
			},
		});
	}
	if (typeof userImgPlugin != 'undefined') {
		RichTextUitl.userImgPlugin = userImgPlugin;
	}
	var resprefix,prefix;
	if (RichTextUitl.intranetMode) {
		prefix = RichTextUitl.prefix;
	} else if( RichTextUitl.currentDomain.indexOf('bistatic-') > -1){
		resprefix = window.location.protocol + "//bistatic-noteyd.chaoxing.com/res";
		prefix = resprefix + "/plugin/ueditor/"
	} else if(RichTextUitl.prefix){
		resprefix = RichTextUitl.prefix + "/res";
		prefix = RichTextUitl.prefix + '/res/plugin/ueditor/'
	} else {
		resprefix = window.location.protocol + "//noteyd.chaoxing.com/res";
		prefix = resprefix + "/plugin/ueditor/";
	}
	if (RichTextUitl.intranetMode) {
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'rich.text.common.js');
		if (typeof YunFileUtil == 'undefined') {
			RichTextUitl.loadJSFile(RichTextUitl.prefix + 'yun.file.util.js');
		}
	} else {
		// 加载和笔记里的rich_text_util.js公用的js
		if(typeof MultiEditor == 'undefined'){
			RichTextUitl.loadJSFile(resprefix + '/pc/js/noteRichtext/rich.text.common.js');
		}
		// 附件下载
		if (typeof YunFileUtil == 'undefined') {
			RichTextUitl.loadJSFile(resprefix + '/js/common/yun.file.util.js');
		}
	}
	// 配置用户自定义的按钮
//	RichTextUitl.customToolbars = customToolbars;

	// 多编辑器 异步加载
	if(RichTextUitl.ismultiEditor) {
		RichTextUitl.loadJSFile2(prefix + 'ueditor.config.js?_t=' + RichTextUitl.t, function() {
			// 加载 ueditor 编辑功能相关js
			RichTextUitl.loadJSFile(prefix + 'ueditor.all.js?_t=' + RichTextUitl.t);
		});
	} else {
		// 课程，分组任务使用的笔记编辑器 同步加载
		RichTextUitl.loadJSFile(prefix + 'ueditor.config.js?_t=' + RichTextUitl.t);
		// 加载 ueditor 编辑功能相关js
		RichTextUitl.loadJSFile(prefix + 'ueditor.all.js?_t=' + RichTextUitl.t);
	}
	
	// 加载上传插件相关js和css
	RichTextUitl.loadJSFile(prefix + 'dialogs/onlineattach/js/radialIndicator.min.js?_t=' + RichTextUitl.t);
	if (typeof (WebUploader) == 'undefined') {
		RichTextUitl.loadJSFile(prefix + 'third-party/webuploader/webuploader.min.js?_t=' + RichTextUitl.t)
	}
	RichTextUitl.loadCssFile(prefix + 'third-party/webuploader/webuploader.css?_t=' + RichTextUitl.t);

	// 支持markdown
	if(typeof Marked == 'undefined') {
		RichTextUitl.loadJSFile(prefix + 'third-party/markdown/marked.min.js')
	}
	// 支持markdown公式,Map未被重写才渲染公式
	if(RichTextUitl.needRenderMath && Map.toString() === 'function Map() { [native code] }'){
		RichTextUitl.loadJSFile(prefix + 'third-party/markdown/tex-svg.min.js')
	}

	// 查看图片相关插件
	if (!RichTextUitl.hasLoadViewer) {
		RichTextUitl.hasLoadViewer = true;
		loadImgViewer();
	}
	RichTextUitl.hasLoadViewer = true;
	if (!RichTextUitl.hasLoadAttachmentListener && typeof AttachmentListener == 'undefined') {
		if (RichTextUitl.intranetMode) {
			RichTextUitl.loadJSFile(RichTextUitl.prefix + 'attachment_listener.js?_t=' + RichTextUitl.t);
		} else if(typeof MultiEditor != 'undefined'){
			//引用了多编辑器
			if(!MultiEditor.hasLoadAttachListener){
				RichTextUitl.loadJSFile(resprefix + '/pc/js/noteRichtext/attachment_listener.js?_t=' + RichTextUitl.t);
				MultiEditor.hasLoadAttachListener = true
			}
		} else{
			//muleditor.js已经加载了这个js,不再继续加载
			RichTextUitl.loadJSFile(resprefix + '/pc/js/noteRichtext/attachment_listener.js?_t=' + RichTextUitl.t);
		}
		RichTextUitl.hasLoadAttachmentListener = true;
	}

	// 加载音视频播放插件
	// if (userDefaultMediaPulgin && !RichTextUitl.hasLoadMedia) {
	// 	RichTextUitl.hasLoadMedia = true;
	// 	loadMediaPlugin();
	// }

	// 加载处理附件点击事件的js
	if (typeof RichtextAttachmentClickUtils == 'undefined') {
		if (RichTextUitl.intranetMode) {
			RichTextUitl.loadJSFile(RichTextUitl.prefix + 'attachment_click_util.js?_t=' + RichTextUitl.t);
		} else {
			RichTextUitl.loadJSFile(resprefix + '/pc/js/noteRichtext/attachment_click_util.js?_t=' + RichTextUitl.t);
		}
	}
}

/**
 * 加载详情页样式
 * @param userDefaultMediaPulgin：是否使用默认的音视频播放器，true/false
 * @param 已废弃 loadAttachmentListener：是否加载附件点击相关的监听js，调用了上面的loadEditorProfile 则不用加,
 * @param isScreen：是否是投屏页，投屏页有单独的样式，音视频的播放也是采用投屏页的方法
 * @param setBackground：是否需要设置附件背景
 * @param userImgPlugin：是否使用图片插件
 */
RichTextUitl.loadDetailPageProfile = function (userDefaultMediaPulgin, loadAttachmentListener, isScreen, setBackground, userImgPlugin,json) {
	if(window.obj && window.obj.mirrorDomain && !RichTextUitl.prefix){
		RichTextUitl.prefix = window.obj.mirrorDomain.noteDomain || window.obj.mirrorDomain.NoteDomainHttps;
	}else	if((typeof window.obj == "undefined" || typeof window.obj.mirrorDomain == "undefined") && (RichTextUitl.prefix || window.location.host.indexOf('chaoxing.com') == -1) && !RichTextUitl.intranetMode ){
		//整个笔记服务镜像时调用接口获取镜像域名
		$.ajax({
			type:'get',
			url: (RichTextUitl.prefix || RichTextUitl.nowDomain) + '/apis/mirrorConfig',
			async:false,
			success:function(res){
				if(res.result == 1){
					if(!window.obj){
						window.obj = {};
					}
					window.obj.mirrorDomain = res.data.domainMap;
					for(var key in window.obj.mirrorDomain){
						if(window.obj.mirrorDomain[key]){
							window.obj.mirrorDomain[key] = window.location.protocol + window.obj.mirrorDomain[key].replace('https:','').replace('http:','')
						}
					}
					window.obj.mirrorDomain.isMirrorDeploy = res.data.isMirrorDeploy;
					RichTextUitl.noteDomain =  window.obj.mirrorDomain.NoteDomainHttps;
					RichTextUitl.photoDomain = window.obj.mirrorDomain.photoDomain;
				}
			},
		});
	}

	if (typeof userImgPlugin != 'undefined') {
		RichTextUitl.userImgPlugin = userImgPlugin;
	}
	var prefix;
	if (RichTextUitl.intranetMode) {
		prefix = RichTextUitl.prefix;
	} else if(RichTextUitl.currentDomain.indexOf('bistatic-') > -1){
		prefix = window.location.protocol + '//bistatic-noteyd.chaoxing.com/res'
	} else if(RichTextUitl.prefix){
		prefix = RichTextUitl.prefix + '/res'
	} else{
		prefix = window.location.protocol + "//noteyd.chaoxing.com/res"
	}
	// 查看图片相关插件
	if (!RichTextUitl.hasLoadViewer && !isScreen) {
		RichTextUitl.hasLoadViewer = true;
		loadImgViewer();
	}
	RichTextUitl.isScreen = isScreen;
	RichTextUitl.setBackground = setBackground;

	if (RichTextUitl.intranetMode) {
		// 镜像模式默认使用音视频播放插件
		userDefaultMediaPulgin = true;
		// 内网模式加载相关js
		if (!RichTextUitl.hasLoadAttachmentListener && typeof AttachmentListener == 'undefined') {
			RichTextUitl.loadJSFile(RichTextUitl.prefix + 'attachment_listener.js?_t=' + RichTextUitl.t);
			RichTextUitl.hasLoadAttachmentListener = true;
		}
		if (typeof RichtextAttachmentClickUtils == 'undefined') {
			RichTextUitl.loadJSFile(RichTextUitl.prefix + 'attachment_click_util.js?_t=' + RichTextUitl.t);
		}
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'third-party/clipboard-polyfill.promise.js');
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'rich.text.common.js');
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'yun.file.util.js');
		RichTextUitl.loadCssFile('themes/richtext_detail.css?_t=' + RichTextUitl.t);
		// // 加载音视频播放插件
		// if (userDefaultMediaPulgin && !RichTextUitl.hasLoadMedia) {
		// 	RichTextUitl.hasLoadMedia = true;
		// 	loadMediaPlugin();
		// }
		return;
	} else {
		// 加载富文本中需要用到的样式
		RichTextUitl.loadCssFile(prefix + '/css/pc/note/richtext_detail.css?_t=' + RichTextUitl.t);
		if (isScreen) {
			// 投屏页，加载投屏页的样式
			RichTextUitl.isScreen = true;
			RichTextUitl.loadCssFile(prefix + '/screen/css/special_richtext.css?_t=' + RichTextUitl.t);
		}
		// 附件点击相关
		if (!RichTextUitl.hasLoadAttachmentListener && typeof AttachmentListener == 'undefined') {
			if(typeof MultiEditor != 'undefined'){
				//引用了多编辑器
				if(!MultiEditor.hasLoadAttachListener){
					RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/attachment_listener.js?_t=' + RichTextUitl.t);
					MultiEditor.hasLoadAttachListener = true
				}
			}else{
				RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/attachment_listener.js?_t=' + RichTextUitl.t);
			}
			RichTextUitl.hasLoadAttachmentListener = true;
		}
		var ua = navigator.userAgent.toLowerCase();
		if (ua && ua.indexOf("chaoxingstudy") != -1 && ua.indexOf('_pc_') == -1 && typeof jsBridge == 'undefined') {
			RichTextUitl.loadJSFile(prefix + '/js/common/CXJSBridge.3.0.js?_t' + RichTextUitl.t);
		}
		// 加载处理附件点击事件的js
		if (typeof RichtextAttachmentClickUtils == 'undefined') {
			RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/attachment_click_util.js?_t=' + RichTextUitl.t);
		}
		// 加载和笔记里的rich_text_util.js公用的js
		RichTextUitl.loadJSFile(prefix + '/plugin/ueditor/third-party/clipboard-polyfill.promise.js');
		RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/rich.text.common.js');
		// 附件下载
		if (typeof YunFileUtil == 'undefined') {
			RichTextUitl.loadJSFile(prefix + '/js/common/yun.file.util.js');
		}
	}
	// 支持markdown
	if(RichTextUitl.needRenderMath && Map.toString() === 'function Map() { [native code] }'){
		RichTextUitl.loadJSFile(prefix + '/plugin/ueditor/third-party/markdown/tex-svg.min.js')
	}
// 加载音视频播放插件
// 	if (userDefaultMediaPulgin && !RichTextUitl.hasLoadMedia) {
// 		RichTextUitl.hasLoadMedia = true;
// 		loadMediaPlugin();
// 	}
	// 保存图片和附件到云盘相关js
	if (typeof NiceScroll == 'undefined') {
		RichTextUitl.loadJSFile(prefix + '/js/common/jquery.nicescroll.min.js');
	}
	if (typeof CLOUD_POP == 'undefined') {
		RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/cloudPop.js');
	}
	//目录
	if(RichTextUitl.catalogDiv && typeof updateAllCatalog == 'undefined'){
		RichTextUitl.loadJSFile(prefix + '/pc/js/noteRichtext/catalog.js');
	}
	// 附件转发，单位域名引用公网云盘的，不显示保存到云盘和转发
	if (typeof ForwardUtils == 'undefined' && !RichTextUitl.isPhone() && !(window.location.host.indexOf('chaoxing.com') == -1 && RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
		RichTextUitl.loadJSFile(RichTextUitl.convertUrl(window.location.protocol + '//sharewh.chaoxing.com/res/plugin/forword/js/forward.js'));
	}
//加载微信小程序相关js
	var ua = navigator.userAgent.toLowerCase();
	if(ua.match(/MicroMessenger/i)=="micromessenger" && typeof wx != 'object') {
		RichTextUitl.loadJSFile(prefix + '/js/common/jweixin-1.6.0.js');
	}

	// 点击切换课前课中课后的内容
	$('body').on('click', '#ulTab p', function () {
		$(this).parent().siblings().removeClass('cur_li')
		$(this).parent().addClass('cur_li')
		$(this).parents('#ulTab').nextAll().hide();
		if ($(this).hasClass('classBefore')) {
			$('.classConBefore').show();
		} else if ($(this).hasClass('classCenter')) {
			$('.classConCenter').show();
		} else if ($(this).hasClass('classAfter')) {
			$('.classConAfter').show();
		}
	})
}
//获取附件镜像域名列表
RichTextUitl.getAnnexMirrorDomain = function(){
	if(RichTextUitl.annexMirrorPrefix && RichTextUitl.annexMirrorPrefix != RichTextUitl.prefix){
		$.ajax({
			type:'get',
			url: RichTextUitl.annexMirrorPrefix + '/apis/mirrorConfig',
			async:false,
			success:function(res){
				if(res.result == 1){
					RichTextUitl.annexMirrorDomain = {};
					RichTextUitl.annexMirrorDomain = res.data.domainMap;
					for(var key in RichTextUitl.annexMirrorDomain){
						if(RichTextUitl.annexMirrorDomain[key]){
							RichTextUitl.annexMirrorDomain[key] = window.location.protocol + RichTextUitl.annexMirrorDomain[key].replace('https:','').replace('http:','')
						}
					}
				}
			}
		});
	}
}
/**
 * 自定义附件的点击事件
 * @param customAttachmentType 自己处理的附件的类型，String 类型，多个类型以逗号分隔
 * @param customClickEvent 自己处理点击事件的方法
 */
RichTextUitl.initializeClickEvent = function (customAttachmentType, customClickEvent) {
	RichtextAttachmentClickUtils.customAttachmentType = customAttachmentType;
	RichtextAttachmentClickUtils.customClickEvent = customClickEvent;
}

/**
 * 加载js
 */
RichTextUitl.loadJSFile = function (url) {
	if (!url) {
		return;
	}
	// 课程，分组任务使用的笔记编辑器，加载ueditor.all.js必须使用这样的js加载方法，
	// 不然在执行 initUEditor 时 ueditor.all.js 还未加载完会报错
	if (RichTextUitl.ismultiEditor) {
		RichTextUitl.loadJSFile2(url)
	} else {
		document.write('<script src="' + url + '" type="text/javascript" charset="utf-8"></script>')
	}
}

// 异步加载js
RichTextUitl.loadJSFile2 = function (src, cb) {
	var head = document.head || document.getElementsByTagName('head')[0]
	var script = document.createElement('script')

	cb = cb || function () {}

	script.type = 'text/javascript'
	script.src = src

	if (!('onload' in script)) {
		script.onreadystatechange = function () {
			if (this.readyState !== 'complete' && this.readyState !== 'loaded') return
			this.onreadystatechange = null
			cb(script)
		}
	}

	script.onload = function () {
		this.onload = null
		cb(script)
	}

	head.appendChild(script)
}

RichTextUitl.loadCssFile = function (url) {
	if (!url) {
		return;
	}
	if (RichTextUitl.prefix && url.indexOf('http') == -1 && url.indexOf(RichTextUitl.prefix) == -1) {
		url = RichTextUitl.prefix + url;
	}
	var link = document.createElement("link");
	link.rel = "stylesheet";
	link.type = "text/css";
	link.href = url
	document.getElementsByTagName("head")[0].appendChild(link);
}

//标记富文本内容中的链接
RichTextUitl.addLink = function (html) {
	if (!html) {
		return html;
	}
	var iframeReg = new RegExp('<\\s*iframe([\\s\\S]*?)>[^<>]*<\/iframe>', 'gi');
	html = html.replace(iframeReg, function () {
		return '<iframe' + arguments[1].replace(/</gi, '&lt;').replace(/>/gi, '&gt;') + '></iframe>';
	})
	//匹配出所有标签内的文本内容
	var innertextReg = new RegExp('>(>[^<>]*)*[^<]+(<[^<>]*)*<', 'gi');
	html = '>' + html + '<';
	html = html.replace(innertextReg, function () {
		var str = arguments[0];
		str = str.substr(1, str.length - 2);
		return '>' + matchURL(str) + '<';
	})
	return html.substr(1, html.length - 2);
}

function matchURL(str) {
	//标签内的文本内容判断是url的加<a>标签
	var mailpattern = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (!mailpattern.test(str)) {
		str = str.replace(RichTextUitl.Regex4LinkText, function () {
			var url = arguments[0].replace(/&nbsp;/g, " ").trim();
			if (url.indexOf('http') != 0 && url.indexOf('ftp') != 0) {
				url = 'http://' + url;
			}
			return '<object><a href="' + url + '" class="dynacALink" target="_blank">' + arguments[0] + '</a></object>';
		})
	}
	return str;
}

/**
 * 裁剪图片
 * 预览图：不超过编辑区域宽度的图片，按原图大小显示，超过的取编辑区域最大宽度。清晰度取Q50。
 * 大图：清晰度取Q80。
 * @returns 处理后的富文本内容
 */
RichTextUitl.cropImage = function (rtf_content) {
	if (!rtf_content) {
		return "";
	}
  if (!RichTextUitl.thumbnail2BigImgMap) {
    RichTextUitl.thumbnail2BigImgMap = new RMap();
  }
	var imgReg = /<img.*?(?:>|\/>)/gi //匹配图片中的img标签
	var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i // 匹配图片中的src
	var arr = rtf_content.match(imgReg)  //筛选出所有的img
	var srcArr = []
	if (!arr || arr.length == 0) {
		return rtf_content;
	}
	for (var i = 0; i < arr.length; i++) {
		var src = arr[i].match(srcReg)
		// 获取图片地址
		//srcArr.push(src[1]);
		if (src) {
			var rtf_img = src[1];
			var rw = parseInt(getImgurlParam(rtf_img.replace(/&amp;/g, '&'), 'rw') || '');
			var rh = parseInt(getImgurlParam(rtf_img.replace(/&amp;/g, '&'), 'rh') || '');
			var new_rw = rw;
			var new_rh = rh;
			if ((rtf_img.indexOf("chaoxing.com") > -1 || rtf_img.indexOf("p.cldisk") > -1) && rw && rh && rtf_img.indexOf('.gif') == -1 && rtf_img.indexOf('.svg') == -1 && rtf_img.indexOf('.webp') == -1 && rtf_content.indexOf('<div class="xiumi">') == -1 && rtf_content.indexOf('<div class="unfilter_css">') == -1) {
        // gif图片不裁剪
				var maxImgWidth = 720;
				if (rw > maxImgWidth) {
					// 宽度大于720，按比例缩小
					new_rw = maxImgWidth;
					new_rh = parseInt(maxImgWidth / rw * rh);
				}
				var res_str = "";
				if (rtf_img.indexOf("origin") == -1) {
					res_str = '([0-9]+_[0-9]*[A-z]*[0-9]*)';
				} else {
					res_str = 'origin';
				}
				var origin_reg = new RegExp(res_str);
				var small_img = rtf_img.replace(origin_reg, new_rw + '_' + new_rh + 'Q50');
				// png格式换成jpg
				if (small_img.indexOf('.png') > -1) {
					small_img = small_img.replace('.png', '.jpg')
				}
				// 大图改为用原图
				var big_img = rtf_img;
//    			var big_img = rtf_img.replace(origin_reg,  rw + '_' + rh + 'Q80');
				rtf_content = rtf_content.replace(new RegExp(rtf_img.substr(0, rtf_img.indexOf('?')), 'g'), small_img.substr(0, small_img.indexOf('?')));

				RichTextUitl.thumbnail2BigImgMap.put(small_img.replace(/&amp;/g, '&'), big_img);
			} else {
				RichTextUitl.thumbnail2BigImgMap.put(rtf_img.replace(/&amp;/g, '&'), rtf_img);
			}
			var imgObj = {"imageUrl": rtf_img};
			RichTextUitl.imgArray.push(imgObj);
		}
	}

	return rtf_content;
}

/**
 * 获取图片参数
 */
function getImgurlParam(url, name) {
	if (url.indexOf("?") != -1) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = url.split("?")[1].match(reg);
		if (r != null) return unescape(r[2]);
		return null;
	} else {
		return null;
	}
}

/**
 * 获取cookie
 * @param name
 * @returns {string}
 */
RichTextUitl.getCookie = function (str) {
	var cookie = document.cookie.split(';');
	for (var i = 0; i < cookie.length; i++) {
		if (cookie[i].split('=')[0].trim() === str) {
			return cookie[i].split('=')[1];
		}
	}

	if(str == 'browserLocale'){
		return ''
	}
	//如果通过cookie取不到，调接口获取
	var item = '';
	var url = (RichTextUitl.prefix || RichTextUitl.noteDomain || window.location.protocol + '//noteyd.chaoxing.com') + '/apis/getCookie?name='+str;
	$.ajax({
		type:'get',
		url: url,
		async:false,
		//设置跨域允许携带cookie
		xhrFields: {
			withCredentials: true
		},
		success:function(res){
			if(res.result == 1){
				item = res.data[str];
			}
		},
	});
	if(item){
		return item
	}
	return '';
}

/**
 * 将富文本内容设置到页面之前执行的操作
 * 1、给附件的src添加笔记域名
 * 2、对图片进行裁剪
 * 3、标记富文本内容中的链接
 *
 * @param rtf_content：富文本内容
 */
RichTextUitl.beforeSetRtfContent = function (rtf_content,json) {
	if (!rtf_content) {
		return rtf_content;
	}
	if(json){
		//调用自定义预览的方法
		if(json.openPreview){
			RichTextUitl.openPreview = json.openPreview;
		}
	}
	//获取镜像附件域名
	RichTextUitl.getAnnexMirrorDomain();

	rtf_content = rtf_content.replace(RichTextUitl.xssReg,function(){
		return arguments[0] + '　';
	})
	rtf_content = RichTextUitl.subAttchEditMode(rtf_content);
	var note_domain = "https://noteyd.chaoxing.com";
	if (window.location.protocol == 'http:') {
		note_domain = 'http://note.yd.chaoxing.com';
	}
	//附件地址替换
	rtf_content = RichTextUitl.replaceIframeSrc(rtf_content);
	// 替换转义字符
	rtf_content = rtf_content.replace(/\b(&nbsp;)+\b/gi, function () {
		rtf_content = arguments[0].replace(/&nbsp;/gi, ' ');
		return rtf_content;
	});
	// 客户端的错误图片（将第三方服务的图片上传到云盘失败后显示的图片）使用的本地路径，替换成云盘的地址
	rtf_content = rtf_content.replace(new RegExp("images/img_fail.jpg", "g"),
		RichTextUitl.downloadFailedImg)
	// 将http的云盘图片地址替换成https的
	rtf_content = rtf_content.replace(new RegExp("http://p.ananas.chaoxing.com", "g"),
		'https://p.cldisk.com');
	// 编辑页到此为止
	if(json && json.type && json.type == 'edit'){
		return rtf_content
	}

	// if(rtf_content.indexOf('<div class="xiumi">') == -1 && rtf_content.indexOf('<div class="unfilter_css">') == -1){
		rtf_content = RichTextUitl.cropImage(rtf_content);
	// }
	// return RichTextUitl.addLink(rtf_content);
	if(RichTextUitl.autoAddLink){
		rtf_content = RichTextUitl.addLink(rtf_content);
	}
	return rtf_content
}
/**
 * 将富文本内容设置到页面之前执行的操作
 * 1、给附件的src添加笔记域名
 * 2、对图片不进行裁剪（去掉该操作）
 * 3、标记富文本内容中的链接
 *
 * @param rtf_content：富文本内容
 */
RichTextUitl.beforeSetUncutRtfContent = function(rtf_content) {
	if(!rtf_content) {
		return rtf_content;
	}
	rtf_content = RichTextUitl.subAttchEditMode(rtf_content);
	var note_domain = "https://noteyd.chaoxing.com";
	if (window.location.protocol == 'http:') {
		note_domain = 'http://note.yd.chaoxing.com';
	}
	//附件地址替换
	rtf_content = RichTextUitl.replaceIframeSrc(rtf_content);
	// 替换转义字符
	rtf_content = rtf_content.replace(/\b(&nbsp;)+\b/gi,function() {
		rtf_content = arguments[0].replace(/&nbsp;/gi,' ');
		return rtf_content;
	});
	// 客户端的错误图片（将第三方服务的图片上传到云盘失败后显示的图片）使用的本地路径，替换成云盘的地址
	rtf_content = rtf_content.replace(new RegExp("images/img_fail.jpg", "g"),
		RichTextUitl.downloadFailedImg)
	// 将http的云盘图片地址替换成https的
	rtf_content = rtf_content.replace(new RegExp("http://p.ananas.chaoxing.com", "g"),
		'https://p.cldisk.com');
	// return RichTextUitl.addLink(rtf_content);
	return rtf_content
}
/**
 *  填充页面后执行的操作
 *  1、图片在加载的过程中先采用灰色背景框的占位符显示，加载完成后再显示对应的图片
 *  2、初始化查看图片插件
 *  3、解决转发到笔记的附件上面显示三个空行的问题
 *  4、手机端IOS附件重新设置宽度
 *
 *  @param selector：包含图片标签的dom节点
 */
RichTextUitl.afterPageRendered = function (selector,json) {
	if (selector) {
		//设置自定义字体颜色
		if(json && json.themeColor){
			$(selector).css('color',json.themeColor)
		}
		// 加载图片
		imgList = $(selector).find('img');
		if (imgList && RichTextUitl.thumbnail2BigImgMap) {
			//默认先去掉排版图片特定标识，否则第一张会被删除
			$(selector).find(".drag-image-wrap").removeClass("column-img-b")
			var index = 0;
			imgList.each(function () {
				// 遍历图片标签，给图片添加data_original属性，内容为原图大小Q80图片
				var src = $(this).attr('src');
				if(src){
					$(this).attr('data-original', RichTextUitl.thumbnail2BigImgMap.get(src));
				}
				if (RichTextUitl.isScreen) {
					$(this).attr('index', index);
					index++;
					RichTextUitl.imageArray.push(RichTextUitl.thumbnail2BigImgMap.get(src));
					$(this)[0].onclick = function () {
						RichTextUitl.openImageScreen($(this));
					};
				}
				// 处理固定宽高图片排版的老数据图片结构
				if($(this).is(".width-column-img")){
					var node;
					if (!$(this).parent().hasClass('editor-image')) {
						node = document.createElement('div');
						node.className = 'editor-image';
						$(this).before(node);
						node.appendChild($(this)[0])
					} else {
						node = $(this).parent(".editor-image")[0];
					}
					node.setAttribute("class","editor-image column-img-block");
					if( $(selector).find(".column-img-b").length == 0){
						var div = document.createElement('div');
						var divClass = "drag-image-wrap column-img-b";
						div.setAttribute('element-id', RichTextUitl.getRandomId());
						div.setAttribute('class', divClass);
						div.setAttribute('contenteditable', 'false');
						div.appendChild(node.cloneNode(true));
						selector.appendChild(div);
					}else{
						$(selector).find(".column-img-b").append(node.cloneNode(true));
					}
					node.parentNode.remove()
                    imgList = $(selector).find('img');
				}
			});
			RichTextUitl.loadImg(imgList,selector,json);
		}
		//渲染公式
		RichTextUitl.renderLatex(selector)
		//解决视频不能全屏的问题
		$(selector).find('iframe').each(function (index, iframe) {
			if (!iframe.getAttribute('allowfullscreen')) {
				iframe.setAttribute('allowfullscreen', "true");
			}
			var src = iframe.getAttribute('src')
			if (!src)  return;
			var attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'))
			if(iframe.getAttribute('fileType') && RichTextUitl.attachMode == 'preview' && (iframe.getAttribute('fileType').indexOf('word') > -1 || iframe.getAttribute('fileType').indexOf('excel') > -1 || iframe.getAttribute('fileType').indexOf('pdf') > -1 || iframe.getAttribute('fileType').indexOf('ppt') > -1)){
				//预览模式
				src = RichTextUitl.convertUrl(window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid=' +
					attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(RichTextUitl.getCloudFileName(iframe.getAttribute('name'))));
				if(RichTextUitl.useWpsPreview){ //使用wps预览的
					iframeSrc += '&type=wps'
				}
				iframe.setAttribute('src', src);
				iframe.setAttribute('preview', 'true');
			}else if(iframe.getAttribute('fileType') && RichTextUitl.attachMode == 'text'){
				//文本模式
				var href = attachment.att_clouddisk.downPath || ('https://d0.cldisk.com/download/' + attachment.att_clouddisk.fileId);
				html = '<div element-id="' + RichTextUitl.getRandomId() + '"><a href="' +
					href + '" ' +
					'class="dynacALink iframe" target="_blank" module="' + iframe.getAttribute('module') + '" ' +
					' name="' + iframe.getAttribute('name') + '" cid="' + iframe.getAttribute('cid') + '" ' +
					'element-id="' + RichTextUitl.getRandomId() + '" fileType="' + iframe.getAttribute('fileType') + '">' + attachment.att_clouddisk.name + '</a></div>';
				$(iframe).replaceWith(html);
			}else{
				iframe.setAttribute('src', src);
			}
		});
		//文本附件修改模式
		$(selector).find('a.iframe.dynacALink').each(function (index, iframe) {
			var attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'))
			var src = iframe.getAttribute('src')
			if(iframe.getAttribute('fileType') && (iframe.getAttribute('fileType').indexOf('word') > -1 || iframe.getAttribute('fileType').indexOf('excel') > -1 || iframe.getAttribute('fileType').indexOf('pdf') > -1 || iframe.getAttribute('fileType').indexOf('ppt') > -1)){
				if(RichTextUitl.attachMode == 'preview'){
					//预览模式
					src = RichTextUitl.convertUrl(window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid=' +
						attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(RichTextUitl.getCloudFileName(iframe.getAttribute('name'))));
					if(iframe.parentNode && !iframe.parentNode.className){
						iframe.parentNode.className = 'editor-iframe'
					}else{
						$(iframe).wrap("<div class='editor-iframe' contenteditable='false' element-id='"+RichTextUitl.getRandomId()+"'>")
					}
					var cid = iframe.cid;
					if(!cid){
						cid = RichTextUitl.randomUUID()
						attachment.cid = cid;
					}

					var html = "<iframe frameborder='0' scrolling='no' cid='" + cid + "' src='" + src + "' name='" + iframe.getAttribute('name') + "' class='attach-module attach-" + iframe.getAttribute('module') + "' module='" + iframe.getAttribute('module') + "' fileType='"+ iframe.getAttribute('fileType') +"' preview='true'></iframe>";
					$(iframe).replaceWith(html);
				}
			}
		});
		// 记录是否登录了
		RichTextUitl.isLogin = RichTextUitl.getCookie('UID') != '';
		// 将配置信息发给附件iframe页面，主要是是否登录了才能下载，是否使用了iframe悬浮事件
		RichTextUitl.postConfigMessage(selector);
		// 学习通里面打开的课程页，不用Viewer插件，通过客户端协议查看图片，其他情况通过插件查看
		$(selector).on('click', '.editor-image img', function (e) {
			if ($(this).attr('data-link')) {
				var link = $(this).attr('data-link');
				var openType = $(this).attr('opentype'); //有openType属性的是在当前窗口打开链接
				if (link.indexOf('http') == -1 && link.indexOf('ftp') == -1) {
					link = 'https://' + link;
				}
				if (openType) {
					window.location.href = link;
				} else {
					window.open(link);
				}
				return;
			}
			if ((isInXXT() || isAIScreen()) && window.self == window.top) {
				var index = $(selector).find('.editor-image img').index(this);
				var imgArray = new Array();
				$(selector).find('.editor-image img').each(function () {
					var imgUrl = $(this).attr('data-original')
					if(!imgUrl || imgUrl.indexOf('http') != 0) {
						imgUrl = $(this).attr('src')
					}
					var imgObj = {"imageUrl": imgUrl};
					imgArray.push(imgObj);
				})
				clientPreviewImages(imgArray, index);
			} else if (!RichTextUitl.isScreen && RichTextUitl.userImgPlugin) {
				// 课堂活动--分组任务里面会同时加载老师和学生的内容，需要同时用到多个图片插件对象
				if ($(this).attr('data-link')) {
					window.open($(this).attr('data-link'))
					return;
				}

				// RichTextUitl.imageViewer = new Viewer(selector, {
				// 	tooltip: true, container: document.body, navbar: false, toolbar: false, url: "data-original",
				// 	shown: function () {
				// 		var img = RichTextUitl.imageViewer.images[RichTextUitl.imageViewer.index];
				// 		if ($(img).hasClass('noSelect')) {
				// 			$('#viewDownload,#imgDownload,#imgEdit').hide();
				// 		}
				// 	},
				// 	viewed: function () {
				// 		var img = RichTextUitl.imageViewer.images[RichTextUitl.imageViewer.index];
				// 		if ($(img).hasClass('noSelect')) {
				// 			$('#viewDownload,#imgDownload,#imgEdit').hide();
				// 			$('.viewer-canvas img').addClass('noSelect').on('contextmenu', function () {
				// 				return false;
				// 			});
				// 		} else {
				// 			$('#viewDownload,#imgDownload,#imgEdit').show();
				// 			$('.viewer-canvas img').removeClass('noSelect').off('contextmenu');
				// 		}
				// 	},
				// 	hide: function () {
				// 		$('.viewBtnWrap,#imgtoolWrap').hide();
				// 	}
				// });

				var index = $(selector).find('.editor-image img').index(this);
				imgViewTool.initViewImage(selector,'',index);

				if (typeof sendMessageFadeInOrOut == 'function') {
					// 课程那边图片的额外操作
					sendMessageFadeInOrOut(1)
				}
			}
		})
	}

	// 去除不是表格的元素上包裹的div class="table"
	//RichTextUitl.removetablewrap();

	RichTextUitl.isDetailPage = true;
	RichTextUitl.imgSelector = selector;
	if (!RichTextUitl.isPhone() && !RichTextUitl.isScreen) {
		// 附件操作按钮通过悬浮模式显示在附件外部显示（默认是在附件iframe里面显示）,PC端才通过悬浮模式显示
		RichTextUitl.setIframeHover = true;
	}
	// 在编辑时将附件设置成了文本链接（a标签）模式，但是为了不影响在客户端上点击卡片页的效果，保存是会替换回卡片（iframe标签）模式
	// 详情页显示的时候再改回成文本链接形式
	$(selector).find('.editor-iframe.textlink').each(function () {
		var $iframe = $(this).find('iframe');
		$(this).replaceWith(RichTextUitl.changeAttachmentModel($iframe.attr('name'), $iframe.attr('module'), 'a'))
	})
	var ua = navigator.userAgent.toLowerCase();
	var isIOS = ua.indexOf('iphone') >= 0 || ua.indexOf('ipad') >= 0 || ua.indexOf('ipod') >= 0; //ios终端
	if (isIOS) {
		$('.richtext').addClass('ios');
	}
	RichTextUitl.updateAllIframeWidth(selector, $(selector).width() || ($('body').width() - 30))
	// 设置详情页事件
	// if (typeof RichTextUitl.detailPageEvent == 'function') {
	// 	RichTextUitl.detailPageEvent();
	// } else {
	// 	setTimeout(function () {
	// 		RichTextUitl.detailPageEvent();
	// 	}, 1500)
	// }
	// 加载公用js里面的方法
	var interval = setInterval(function () {
		if (typeof RichTextUitl.commonEventAfterPageRendered == 'function') {
			clearInterval(interval);
			RichTextUitl.commonEventAfterPageRendered(selector);

			//有序列表转新格式
			if (typeof normaloldlist == 'function') {
				normaloldlist();
			}
		}
	}, 200)

	//没有加上dynacALink的加上dynacALink和target
	$(selector).find('a:not(.dynacALink):not([type="anchor"])').attr('target', '_blank').addClass('dynacALink').css('cursor', '');
	// a标签套a标签的，移除外层a标签和object
	$(selector).find('.dynacALink').each(function (index, item) {

		if ($(this).parents('a').length > 0) {
			while (this.firstChild) {
				$(this.firstChild).insertAfter($(this))
			}
			$(this).remove()
		} else if ($(this).parent().is('object')) {
			//原本没有a标签的，加上object和a标签后，要去掉object
			$(this).unwrap();
			if ($(this).find('object').length == 0) {
				if ((($(this).parents('span').attr('style') && $(this).parents('span').attr('style').indexOf('color') != -1) || $(this).parents('span').attr('color'))
					&& $(this).text().replace(/\u200B/gi, '').trim() == $(this).parents('span').text().replace(/\u200B/g, '').trim()) {
					$(this).css('color', $(this).parents('span').css('color'))
				}
			}
		}
	});
	//去除a标签内层的object
	$(selector).find('object').each(function () {
		if ($(this).parents('a').length > 0) {
			while (this.firstChild) {
				$(this.firstChild).insertAfter($(this))
			}
			$(this).remove()
		}
	});
	$(selector).find('.dynacALink').each(function (index, item) {
		//去除链接前的8203
		if (item.previousSibling && item.previousSibling.nodeType == 3 && item.previousSibling.nodeValue == "​") {
			item.parentNode.removeChild(item.previousSibling);
		}
	});


	// if (typeof NiceScroll != 'undefined') {
	// 	// 给表格加滚动条
	// 	$(".table").niceScroll({cursorborder:"",cursorwidth:8,cursorcolor:"#dadfe5",boxzoom:false,autohidemode:true});
	// }

	/**
	 * 编辑页已经给链接加上a标签的情况下，详情页的addLink方法会在链接外面包一个a标签，导致编辑页加的a标签不显示
	 * 在将卡片附件转成文本链接附件时，数据放在a标签上，操作方法也是绑定在了a标签的特定样式样式
	 * 遍历卡片附件转成的a标签，如果他的后面也是一个a
	 */
	// $('.dynacALink.iframe').each(function () {
	// 	var $next = $(this).next();
	// 	if ($next.hasClass('dynacALink') && $next.attr('href') == $(this).attr('href')) {
	// 		$(this).text($next.text());
	// 		$next.remove();
	// 	}
	// })

	// 无障碍：详情页富文本内容整块读取
	$(selector).attr('tabindex',0)

	if(RichTextUitl.catalogDiv && typeof updateAllCatalog == 'undefined'){
		RichTextUitl.loadJSFile2((RichTextUitl.prefix || (window.location.protocol + "//noteyd.chaoxing.com")) + '/res/pc/js/noteRichtext/catalog.js',function () {
			updateAllCatalog('.richtext');
		});
	}

}
/*手机端IOS的iframe宽度重新设置*/
RichTextUitl.updateAllIframeWidth = function (selector, width) {
	$(selector).find('iframe').each(function () {
		var wid = width, node;
		if ($(this).parents('.record-iframe').length > 0) {
			wid = width - 8;
		} else if ($(this).parents('.record-box').length > 0) {
			wid = width - 20;
			if ($(this).parents('ol').length > 0 || $(this).parents('ul').length > 0) {
				if ($(this).parents('ol').length > 0) {
					node = $(this).parents('ol');
				} else if ($(this).parents('ul').length > 0) {
					node = $(this).parents('ul');
				}
				var level = node.attr("level") || 1;
				wid = wid - 26 - 26 * (level - 1);
			}
		} else if ($(this).parents('ol').length > 0 || $(this).parents('ul').length > 0) {
			if ($(this).parents('ol').length > 0) {
				node = $(this).parents('ol');
			} else if ($(this).parents('ul').length > 0) {
				node = $(this).parents('ul');
			}
			var level = node.attr("level") || 1;
			wid = wid - 26 - 26 * (level - 1);
		}
		$(this).attr('width', wid).css('width', wid + 'px');
	});
}

//云盘附件加载完成后给附件内部发送消息
function iframeOnload(iframe,body){
	var attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'))
	var allowDownload = true;
	var nonsupportPreview = !RichTextUitl.showPreview(attachment,$(iframe)); // 部分镜像项目不支持预览
	// 属性赋值放到iframe加载后发消息的地方，
	// 避免还没发消息之前，downloadAfterLogin 和 allowDownload就被后一个iframe的值覆盖了

	if (iframe.getAttribute('allowdownload') == 'false' && iframe.getAttribute('download') == 'false') {
		allowDownload = 'no'
	} else if (iframe.getAttribute('download') == 'true') {
		allowDownload = 'login'
	} else {
		allowDownload = 'all'
	}
	var attach = getAttchMirror(iframe.getAttribute('name'))
	if(attach.isMirror && RichTextUitl.annexMirrorDomain && RichTextUitl.annexMirrorDomain.NoteDomain.indexOf('chaoxing.com') == -1 && RichTextUitl.annexMirrorDomain.previewDomainHttps.indexOf('chaoxing.com') > -1) {
		//镜像附件，笔记是单位域名，预览是超星域名，不允许预览
		nonsupportPreview = true;
	}
	//只有指定id内的附件用自定义预览，解决分组任务中老师上传的文档不需要跳编辑，学生的需要跳编辑，但都会跳到编辑页的问题
	var openPreview= '';
	if(RichTextUitl.openPreview && document.getElementById(RichTextUitl.openPreview.id) && document.getElementById(RichTextUitl.openPreview.id).querySelector('iframe[cid="' + iframe.getAttribute('cid') + '"]') ) {
		openPreview= RichTextUitl.openPreview;
	}else if(RichTextUitl.openPreview && body && body.querySelector('iframe[cid="' + iframe.getAttribute('cid') + '"]')){
		openPreview= RichTextUitl.openPreview;
	}
	iframe.contentWindow.postMessage(
		{
			'msgType': 'config',
			'cid': attachment.cid,
			'downloadAfterLogin': iframe.getAttribute('download') == 'true',
			'isLogin': RichTextUitl.isLogin,
			'setIframeHover': RichTextUitl.setIframeHover,
			'isDetailPage': RichTextUitl.isDetailPage,
			'allowDownload': allowDownload,
			'allowPreview': iframe.getAttribute('allowpreview') || 'all',
			'nonsupportPreview': nonsupportPreview,
			'isIntranetMode': RichTextUitl.intranetMode,
			'isMirror': attach.isMirror || '',
			'mirrorPrefix': attach.mirrorPrefix || '',
			'isGetVideoDataFromCenter': RichTextUitl.isGetVideoDataFromCenter,
			'mirrorDomain': window.obj.mirrorDomain,
			'openPreview': openPreview,
			'unAllowOpenAttach':RichTextUitl.unAllowOpenAttach,
			'unAllowOpenAttachTips':RichTextUitl.unAllowOpenAttachTips,
			'useWpsPreview': RichTextUitl.useWpsPreview || '',
			'cloudUrl': RichTextUitl.cloudUrl || '',
		}, '*');
}
//视频加载完成后给视频内部发送消息
function videoOnload(iframe,selector){
	var attach = getAttchMirror(iframe.getAttribute('name'))
	var message = {
		'msgType': 'config',
		'cid': iframe.getAttribute('cid'),
		'isDetailPage': RichTextUitl.isDetailPage,
		'isGetVideoDataFromCenter': RichTextUitl.isGetVideoDataFromCenter,
		'isMirror': attach.isMirror || '',
		'mirrorPrefix': attach.mirrorPrefix || '',
		'mirrorDomain': window.obj.mirrorDomain,
		'unAllowOpenAttach':RichTextUitl.unAllowOpenAttach,
		'unAllowOpenAttachTips':RichTextUitl.unAllowOpenAttachTips,
		'cloudUrl': RichTextUitl.cloudUrl || '',
		'isHdVideo': window.obj.mirrorDomain && window.obj.mirrorDomain.isMirrorDeploy ? true : '',
		'videoWidthMax': RichTextUitl.videoWidthMax ? selector.clientWidth || 0 : 0,
	}
	if(selector && selector.querySelector('iframe[module="insertVideo"]') == iframe){
		message.isAutoPlayVideo = RichTextUitl.isAutoPlayVideo ? RichTextUitl.isAutoPlayVideo : '';
	}
	iframe.contentWindow.postMessage(message, '*');
	//视频并排
	if(RichTextUitl.iframeDragColumn){
		RichTextUitl.rangeVideoIframe(iframe,selector);
	}
}

/**
 * 加载页面后，发消息给云盘附件iframe，传递参数是否开启了登录后才能下载的属性
 */
RichTextUitl.postConfigMessage = function (selector) {
	try {
		var iframes = selector.querySelectorAll('iframe');
		for (i = 0; i < iframes.length; i++) {
			var iframe = iframes[i];
			var src = iframe.getAttribute('src');
			if (!src) {
				continue;
			}
			var attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'))
			//设置了不允许下载附件
			if(RichTextUitl.hideIframeTool && RichTextUitl.hideIframeTool.length > 0){
				if(RichTextUitl.hideIframeTool.length == 1 && RichTextUitl.hideIframeTool[0] == '*' || attachment.attachmentType == 29 && RichTextUitl.hideIframeTool.indexOf('video') > -1 ||
					attachment.attachmentType == 26 && RichTextUitl.hideIframeTool.indexOf('voice') > -1 || attachment.attachmentType == 18 && RichTextUitl.hideIframeTool.indexOf($(iframe).attr('filetype')) > -1){
					$(iframe).attr('download','false').attr('allowdownload','false')
				}
			}
			if (src.indexOf("insertCloud") > -1) {
				if (iframe.attachEvent) {
					iframe.attachEvent("onload", function () {
						var attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'))
						iframeOnload(this)
					});
				} else {
					iframe.onload = function () {
						iframeOnload(this)
					};
				}
			} else if (src.indexOf("insertVideo") > -1) {
				// 视频附件在编辑页要显示”编辑封面“的按钮
				if (iframe.attachEvent) {
					iframe.attachEvent("onload", function () {
						videoOnload(this,selector)
					});
				} else {
					iframe.onload = function () {
						videoOnload(this,selector)
					};
				}
			}
		}
	} catch(e) {}
}


RichTextUitl.b64DecodeUnicode = function (str) {
	if (!str) {
		return str;
	}
	try {
		str = decodeURIComponent(atob(str));
		str=str.replace(RichTextUitl.xssReg,function(){
			return arguments[0] + '　';
		})
	} catch (e) {

	}
	try {
		return JSON.parse(str);
	} catch (e) {

	}
	return '';
}
//获取附件镜像信息
function getAttchMirror(name){
	var attachment = RichTextUitl.b64DecodeUnicode(name);
	var isMirror = '' , mirrorPrefix = '',content;
	switch (attachment.attachmentType) {
		case 1:
			// 话题
			content = attachment.att_topic;
			break;
		case 2:
			// 笔记
			content = attachment.att_note;
			break;
		case 3:
			// 专题
			content = attachment.att_subject;
			break;
		case 6:
			// 期刊
			content = attachment.att_subject;
			break;
		case 8:
			// 通知
			content = attachment.att_notice;
			break;
		case 10:
			// 笔记文件夹
			content = attachment.att_notebook;
			break;
		case 11:
			// 收藏文件夹
			content = attachment.att_resource;
			break;
		case 15:
			// 课程附件
			content = attachment.att_chat_course;
			break;
		case 17:
			// 课程章节
			content = attachment.att_course;
			break;
		case 18:
			// 文件，本地上传或从云盘中选择
			content = attachment.att_clouddisk;
			break;
		case 25:
			// 网页
			content = attachment.att_web;
			break;
		case 26:
			// 音频
			content = attachment.att_voice;
			break;
		case 29:
			// 视频
			content = attachment.att_video;
			break;
		case 38:
			// 云盘文件夹
			content = attachment.att_cloudFolder;
			break;
		case 49:
			// 本地文件夹
			content = attachment.att_localFolder;
			break;
	}
	if(content && content.isMirror){
		isMirror = content.isMirror;
		mirrorPrefix = RichTextUitl.annexMirrorPrefix || RichTextUitl.prefix || window.obj.mirrorDomain.NoteDomain;
	}
	return {attachment:attachment,isMirror:isMirror,mirrorPrefix:mirrorPrefix}
}
//详情页重新计算视频iframe宽度
RichTextUitl.rangeVideoIframe = function (iframe,selector) {
	if(RichTextUitl.isPhone()) return
	setTimeout(function () {
		var totalWidth = 0;
		var iframeList = $(iframe).parents('.drag-iframe-wrap').find('iframe')
		iframeList.each(function (i, iframe) {
			totalWidth += iframe.getAttribute('video-width') / (iframe.getAttribute('video-height') - 36)
		})
		var height = ($(selector).width() - iframeList.length * 29) / totalWidth;

		for (var i = 0; i < iframeList.length; i++) {
			var width = parseInt((iframeList[i].clientWidth / (iframeList[i].clientHeight - 36)) * height);
			iframeList[i].parentNode.style.width = (width + 4) + 'px';
			iframeList[i].parentNode.style.height = (parseInt(height) + 46) + 'px';
			// 设置视频封面高度
			iframeList[i].contentWindow.postMessage({
				msgType: 'changeVideoCoverHeight',
				cid: iframeList[i].getAttribute('cid'),
				coverHeight: parseInt(height),
			}, '*')
		}
	},200)
}

//显示图片投屏
RichTextUitl.openImageScreen = function (_this) {
	var index = _this.attr('index');
	if (index) {
		var imgPreviewInfo = {"showIndex": index, "optNo": 0};
		var data = {'cmd': 'resourceToScreen'};
		var content = {'opt': 1, 'urls': RichTextUitl.imageArray, 'type': 1, "imgPreviewInfo": imgPreviewInfo};
		data.content = content;
		var body = {'body': JSON.stringify(data)};
		parent.postMessage(JSON.stringify({'cmd': 'resourceToScreen', 'body': body}), '*');
	}
}


/**
 * 获取 UUID
 */
RichTextUitl.randomUUID = function () {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}
RichTextUitl.getRandomId = function(){
	var str = "abcdefghijklmnopqrstuvwxyz0123456789";
	var tmp = [];
	var random;
	for (var i = 0; i < 8; i++) {
		random = Math.floor(Math.random() * (str.length));
		if (tmp.indexOf(str[random]) === -1) {
			tmp.push(str[random])
		} else {
			i--;
		}
	}
	return tmp.join('');
}
/**
 * 加载图片方法，加载过程中用灰色背景框代替
 * @param img标签对象数组
 */
RichTextUitl.loadImg = function (imgList,selector,json) {
	if (!imgList || imgList.length == 0) {
		return;
	}
	if($(selector).find('.xiumi').length > 0 || $(selector).find('.unfilter_css').length > 0) return;
	for (var i = 0; i < imgList.length; i++) {
		var div;
		if (!imgList.eq(i).parent().hasClass('editor-image')) {
			div = document.createElement('div');
			div.className = 'editor-image';
			imgList.eq(i).before(div);
			div.appendChild(imgList[i])
		} else {
			div = imgList[i].parentNode;
		}
		// 计算固定宽高图片排版的老数据操作
		if($(imgList[i]).parents('.column-img-b').find('img').length > 1){
			resetColumnImgWdith(imgList[i],2,selector);
			continue;
		}else if(json && json.imageLayout == true){
			if($(imgList[i]).parents('.drag-image-wrap').find('img').length > 1){
				var width = parseInt($(imgList[i]).parents('.drag-image-wrap').width()/$(imgList[i]).parents('.drag-image-wrap').find('img').length) - 14;
				imgList[i].style.width = width + 'px';
				imgList[i].style.height = parseInt(width / 1.5) + 'px';
			}
			continue;
		}
		if (!$(div).parent().hasClass('drag-image-wrap')) {
			var divwrap = document.createElement('div');
			divwrap.className = 'drag-image-wrap';
			divwrap.contentEditable = 'false';
			$(div).before(divwrap);
			divwrap.appendChild(div)
		} else if (imgList.eq(i).parents('.drag-image-wrap').find('img').length > 1 && !imgList.eq(i).parents('.drag-image-wrap').attr('totalWidth')) {
			//计算并排图片的总宽度，记录原始图片宽度
			var totalWidth = 0;
			imgList.eq(i).parents('.drag-image-wrap').find('img').each(function (index, item) {
				totalWidth += parseInt(item.getAttribute('width') || item.style.width.replace('px', ''));
				item.setAttribute('owidth', parseInt(item.getAttribute('width') || item.style.width.replace('px', '')) + 2);
			})
			imgList.eq(i).parents('.drag-image-wrap').attr('totalWidth', totalWidth)
		}
		if (div.getAttribute('contenteditable') == '') {
			div.setAttribute('contenteditable', 'false')
		}
		if ((imgList.eq(i).attr('download') && (imgList.eq(i).attr('download') == 'false' || !RichTextUitl.isLogin)) && !(typeof (WinInitConfig) != 'undefined' && WinInitConfig.isCreator == '1')) {
			//不是自己的笔记，不允许下载或未登录不允许下载
			$(div).addClass('noSelect');
			imgList.eq(i).addClass('noSelect');
		}
		//设置了不重新计算图片宽度的，不重新计算图片宽度,只把并排图片重新计算宽度
		if(typeof RichTextUitl.useLoadImg != "undefined" && RichTextUitl.useLoadImg == false){
			continue
		}
		if(imgList[i].style.width && (imgList[i].style.width == '100%' || imgList[i].style.width == 'auto')){
			imgList[i].style.width = ''
		}

		var winWidth = imgList.eq(i).parents('.drag-image-wrap').width() || $('.richtext').width() || '100%';//最大宽度
		var attrwidth = imgList[i].getAttribute("width") || imgList[i].style.width;
		attrwidth = attrwidth && attrwidth.split('.')[0] ? parseInt(attrwidth.split('.')[0]) : '';
		var attrheight = imgList[i].getAttribute("height") || imgList[i].style.height;
		attrheight = attrheight && attrheight.split('.')[0] ? parseInt(attrheight.split('.')[0]) : '';
		var addr = imgList[i].getAttribute("src");
		addr = addr.replace(/&amp;/g, '&');

		var imgW1 = getImgurlParam(addr, 'rw') || imgList[i].naturalWidth || imgList[i].clientWidth ||  '';//原始图片宽度
		var imgH1 = getImgurlParam(addr, 'rh') || imgList[i].naturalHeight || imgList[i].clientHeight ||  '';//原始图片高度
		if (attrwidth && attrheight) {
			imgW1 = attrwidth;
			imgH1 = attrheight;
		}
		var imgW2, imgH2;
		if (imgW1 && typeof imgW1 == 'string' && imgW1.indexOf('%') > -1) {
			imgList[i].style.width = imgW1;
			imgList[i].style.height = 'auto';
			imgList[i].onload = function () {
				this.parentNode.style.backgroundColor = "";
			}
		}else if (imgW1 && imgH1) {
			imgList[i].parentNode.style.backgroundColor = "#F5F6F8";
			if (attrwidth && attrwidth < winWidth) {
				imgW2 = attrwidth;
			} else if (imgW1 >= 750) {
				if(selector && $(selector).length > 0 && $(selector).find('.xiumi').length > 0){
					imgW2 = winWidth;
				} else {
					imgW2 = winWidth;
				}
			} else {
				imgW2 = imgW1;
			}
			if (imgW2 == '100%') {
				imgList[i].style.width = imgW2;
				imgList[i].style.height = 'auto';
			} else {
				imgH2 = parseInt(imgW2 * imgH1 / imgW1);
				imgList[i].style.width = imgW2 + 'px';
				imgList[i].style.height = imgH2 + 'px';
			}
			//imgList[i].style.opacity=0;
			imgList[i].onload = function () {
				this.style.opacity = 1;
				this.parentNode.style.backgroundColor = "";
				//导出设置过图片宽高的图时需要图片高度，否则导出的是大图;秀米图片和表格里的图片设置高度会导致图片变形，需要把高度去掉
				//所以，先把高度去掉，再根据渲染出来的正常图片大小设置宽度和高度
				this.style.height = "";
				this.setAttribute('height', '');
				this.style.width = this.offsetWidth + 'px';
				this.style.height = this.offsetHeight + 'px';

				if ($(this).parents('.drag-image-wrap').find('img').length > 1) {
					resetImgWidth($(this).parents('.drag-image-wrap').find('img'))
				}

			}
		} else {
			imgList[i].parentNode.style.backgroundColor = "#F5F6F8";
			if (!(imgList[i].style.width && imgList[i].style.width.replace('px', ''))) {
				imgList[i].style.height = "auto";
				imgList[i].style.minHeight = "200px";
			} else {
				imgList[i].style.height = "auto";
			}
			imgList[i].onload = function () {
				this.style.opacity = 1;
				this.style.minHeight = "";
				this.parentNode.style.backgroundColor = "";
				if (this.getAttribute("width")) {
					var newwidth = this.getAttribute("width") > $('.richtext').width() ? $('.richtext').width() : this.getAttribute("width");
					this.style.width = newwidth + 'px';
					this.style.height = parseInt(newwidth * this.clientHeight / this.clientWidth) + 'px';
					this.setAttribute('height', parseInt(newwidth * this.clientHeight / this.clientWidth));
				} else {
					this.style.height = "";
					this.setAttribute('height', '');
				}
				if ($(this).parents('.drag-image-wrap').find('img').length > 1) {
					resetImgWidth($(this).parents('.drag-image-wrap').find('img'))
				}
			}
		}
	}

	setTimeout(function () {
		RichTextUitl.limpidImg();
	}, 100)
}
// 计算固定宽高图片排版
function resetColumnImgWdith(img,columnNum,selector){
	var me = this;
	var scale = 589/415;
	var width = parseInt($(selector).width()/columnNum) - 10;
	img.style.width = width + 'px';
	img.style.height = parseInt(width / scale) + 'px';
}
//并排图片按比例设置图片宽度
function resetImgWidth(imgList) {
	if (!imgList.parents('.drag-image-wrap').attr('totalWidth')) {
		return
	}
	var totalWidth = parseInt(imgList.parents('.drag-image-wrap').attr('totalWidth'));
	if (totalWidth + imgList.length * 6 > $('.richtext').width()) {
		//防止图片没加载完就开始计算宽度
		for (var i = 0; i < imgList.length; i++) {
			if (!imgList[i].clientHeight) return
		}
		for (var i = 0; i < imgList.length; i++) {
			var scale = imgList[i].clientWidth / imgList[i].clientHeight;
			var width = parseInt(($('.richtext').width() - imgList.length * 6) * imgList.eq(i).attr('owidth') / totalWidth);
			imgList[i].width = width;
			imgList[i].style.width = width + 'px';
			imgList[i].style.height = parseInt(width / scale) + 'px';
			imgList[i].height = '';
		}
		imgList.parents('.drag-image-wrap').removeAttr('totalWidth');
		imgList.removeAttr('owidth');
	}
}

//编辑器初始加载时不显示，没有宽度，等编辑器显示时，重新计算并排图片宽度
RichTextUitl.reRangeImgs = function (editorid){
	var imgWrapList = $('#' + editorid + ' .drag-image-wrap');
	imgWrapList.each(function (index, item) {
		var imgList = $(item).find('img');
		resetImgWidth(imgList);
	})
}

//图片变清晰
RichTextUitl.limpidImg = function () {
	// 笔记
	var imgList = $('body .editor-image img');
	var imgsize_reg = new RegExp('([0-9]+_[0-9]*[A-z]*[0-9]*)');
	for (var i = 0; i < imgList.length; i++) {
		var src = imgList[i].src;
		if (src.indexOf('p.ananas.chaoxing.com') == -1 && src.indexOf('p.cldisk.com') == -1) {
			continue;
		}
		var imgW1 = getImgurlParam(src, 'rw');//原始图片宽度
		var imgH1 = getImgurlParam(src, 'rh');//原始图片高度
		if (imgW1 && imgH1) {
			var img = new Image();
			img.setAttribute('index', i);
			src = src.replace(imgsize_reg, imgW1 + '_' + imgH1 + 'Q50').replace('.jpg', '.png')

			img.src = src;
			img.onload = function () {
				index = this.getAttribute('index');
				imgList[index].src = this.src;
//				imgList[index].classList.remove('thumbnails');
				$(img).remove();
			}
		}
	}
}

/**
 * 还原被转义的字符 < > & " '
 */
function restoresEscapedCharacter(content) {
	if (content) {
		return content.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
	}
	return "";
}
/**
 *  加载音视频播放插件
 * @returns
 */
function loadMediaPlugin() {
	if (RichTextUitl.intranetMode) {
		RichTextUitl.loadCssFile(RichTextUitl.prefix + "medisPlugins/media.css");
		RichTextUitl.loadCssFile(RichTextUitl.prefix + "medisPlugins/smusic.css");
		RichTextUitl.loadCssFile(RichTextUitl.prefix + "medisPlugins/easydialog.css");
		RichTextUitl.loadJSFile(RichTextUitl.prefix + "medisPlugins/smusic.js");
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'medisPlugins/ckplayer.js')
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'medisPlugins/media.js"');
		RichTextUitl.loadJSFile(RichTextUitl.prefix + 'medisPlugins/easydialog.min.js');
	} else {
		var prefix = window.location.protocol + '//noteyd.chaoxing.com'
		if(RichTextUitl.currentDomain.indexOf('bistatic-') > -1){
			prefix = window.location.protocol + '//bistatic-noteyd.chaoxing.com'
		} else if(RichTextUitl.prefix){
			prefix = RichTextUitl.prefix
		}
		RichTextUitl.loadCssFile(prefix + "/res/pc/cssnew/media.css");
		RichTextUitl.loadCssFile(prefix + "/res/plugin/smusic/css/smusic.css");
		RichTextUitl.loadCssFile(prefix + "/res/pc/css/easydialog.css");
		RichTextUitl.loadJSFile2(prefix + "/res/plugin/smusic/js/smusic.js");
		RichTextUitl.loadJSFile2(prefix + '/res/plugin/ckplayer/ckplayer.js')
		RichTextUitl.loadJSFile2(prefix + '/res/pc/js/media.js');
		RichTextUitl.loadJSFile2(prefix + '/res/js/common/easydialog.min.js');
	}
	var pluginHtml =
//	视频播放器
		'<div id="videoDiv" style="display:none;">'
		+ '<span class="videoCloseBtn"></span>'
		+ '<div id="video"></div>'
		+ '</div>'
		//	音频播放容器
		+ '<div id="audioDiv" style="display:none;">'
		+ '<div class="headBar"><span class="audioCloseBtn"></span></div>'
		+ '<div class="grid-music-container f-usn">'
		+ '<div class="m-music-play-wrap">'
		+ '<div class="u-cover"></div>'
		+ '<div class="m-now-info">'
		+ '<h1 class="u-music-title"><strong></strong></h1>'
		+ '<div class="m-now-controls">'
		+ '<div class="startTime">00:00&nbsp;&nbsp;</div>'
		+ '<div class="u-control u-process ">'
		+ '<div class="old-bar"></div>'
		+ '<span class="buffer-process"></span>'
		+ '<span class="current-bar"  ></span>'
		+ '<span class="current-process"></span>'
		+ '</div>'
		+ '<div class="u-control u-time">00:00</div>'
		+ '<div class="u-control u-volume new-volume">'
		+ '<div class="volume">'
		+ '<span class="volume-event">'
		+ '<div class="volume-process" data-volume="0.50"></div> '
		+ '<span class="volume-current"></span>'
		+ '<span class="volume-bar"></span>'
		+ '</span>'
		+ '<a class="volume-control"></a>'
		+ '</div>'
		+ '</div>'
		+ '<div class="m-play-controls">'
		+ '<div class="musicOrder">'
		+ '<a  class="u-play-btn mode mode-list  " title="列表循环"></a>  '
		+ '<!-- <a class="u-play-btn mode mode-random  " title="随机播放"></a>'
		+ '<a class="u-play-btn mode mode-single " title="单曲循环"></a>  -->'
		+ '</div>'
		+ '<a class="u-play-btn prev" title="上一曲"></a>'
		+ '<a class="u-play-btn ctrl-play play" title="暂停"></a>'
		+ '<a class="u-play-btn next" title="下一曲"></a>'
		+ '</div>'
		+ '</div>'
		+ '</div>'
		+ '<div class="f-cb">&nbsp;</div>'
		+ '<div class="m-music-list-wrap"></div>'
		+ '<div class="m-music-lyric-wrap">'
		+ '<div class="inner">'
		+ '<ul class="js-music-lyric-content">'
		+ '<li class="eof">暂无歌词...</li>'
		+ '</ul>'
		+ '</div>'
		+ '</div>'
		+ '</div>'
		+ '</div>'
		+ '</div>';
	setTimeout(function () {
		// 门户那边有的页面自己在页面上加了音视频播放容器，判断下页面上没有的才追加
		if ($('#videoDiv').length == 0) {
			$('body').append(pluginHtml);
		}
	}, 500);
}
/**
 * 通过客户端协议查看图片
 * @param img_urlArray
 * @param index
 * @returns
 */
function clientPreviewImages(img_urlArray, index) {
	jsBridge.postNotification('CLIENT_PREVIEW_IMAGES', {
		imageUrls: img_urlArray,
		showIndex: index
	});
};

/**
 * 判断是否是课程域名，且是在学习通里面打开的
 * @returns
 */
function isInXXT() {
	var ua = navigator.userAgent.toLowerCase();
	return ua && ua.indexOf("chaoxingstudy") != -1 && ua.indexOf('_pc_') == -1
}

//是否是智能体屏
function isAIScreen(){
	var ua = navigator.userAgent.toLowerCase();
	return ua && (ua.indexOf("digital_human") != -1 && ua.indexOf('touchmachine') != -1)
}
/**
 * 加载查看图片需要的插件
 * @returns
 */
function loadImgViewer() {
	if (!RichTextUitl.userImgPlugin) {
		return;
	}

	if (RichTextUitl.intranetMode) {
		// RichTextUitl.loadCssFile(RichTextUitl.prefix + 'third-party/viewer/viewer.min.css');
		// RichTextUitl.loadJSFile(RichTextUitl.prefix + 'third-party/viewer/viewer-jquery.min.js?_t=' + RichTextUitl.t);
		// RichTextUitl.loadJSFile(RichTextUitl.prefix + 'third-party/viewer/custom.js?_t=' + RichTextUitl.t);
		// RichTextUitl.loadJSFile(RichTextUitl.prefix + 'third-party/viewer/viewer.js?_t=' + RichTextUitl.t);
		// RichTextUitl.loadCssFile(RichTextUitl.prefix + 'third-party/viewer/view-button.css');
		RichTextUitl.loadJSFile2(RichTextUitl.prefix + 'imgviewer.js?_t=' + RichTextUitl.t, function () {
			$(function(){
				imgViewTool.init(RichTextUitl.isEditableViewLargeImage);
			})
		});
	} else {
		var prefix = window.location.protocol + "//noteyd.chaoxing.com";

		if(RichTextUitl.currentDomain.indexOf('bistatic-') > -1){
			prefix = window.location.protocol + '//bistatic-noteyd.chaoxing.com'
		} else if(RichTextUitl.prefix){
			prefix = RichTextUitl.prefix
		}

		// 表单页面引用了高版本viewer.js版本不兼容 手动引入viewer.js
		if ($('.cxplugin-imgviewer').length == 0) {
			RichTextUitl.loadJSFile(prefix + '/res/plugin/viewer/js/viewer.js?_t=' + RichTextUitl.t);
		}

		RichTextUitl.loadJSFile(prefix + '/res/plugin/viewer2/custom.js?_t=' + RichTextUitl.t);
		RichTextUitl.loadJSFile2(prefix + '/res/plugin/viewer/js/imgviewer.js?_t=' + RichTextUitl.t, function () {
			$(function(){
				imgViewTool.init(RichTextUitl.isEditableViewLargeImage);
			})
		});
	}
}

// 设置已有的图片，编辑模式下调用，用户上传第三方地址图片失败后，不修改之前已保存的第三方图片地址，只将新上传的地址替换成下载失败的图片
RichTextUitl.setExistingImg = function () {
	var iframe = RichTextUitl.ueditor.iframe;
	var doc = iframe.contentDocument || iframe.document;
	if (doc) {
		var imgs = doc.getElementsByTagName("img");
		if (imgs.length > 0) {
			for (var i = 0; i < imgs.length; i++) {
				RichTextUitl.existingImg += imgs[i].src + ";";
			}
		}
	}

}

/**
 * 往页面中加入附件
 * @param attachmentArray 附件数组
 */
RichTextUitl.insertAttachments = function (attachmentArray) {
	if (!attachmentArray || attachmentArray.length == 0) {
		return;
	}
	RichTextUitl.ueditor.execCommand('insertfile', attachmentArray);
}

/**
 * 修改附件内容
 * @param cid：附件cid
 * @param data：新的数据
 */
RichTextUitl.updateAttachment = function (data) {
	if (!data || !data.cid) {
		return;
	}
	var iframe = '';
	if (typeof RichTextUitl.ueditor != 'undefined') {
		iframe = RichTextUitl.ueditor.iframe;
	}
	if (iframe) {
		// 编辑页
		var doc = iframe.contentDocument || iframe.document;
		var targetIframe = $(doc).find('iframe[cid="' + data.cid + '"]');
	} else {
		var targetIframe = $('body').find('iframe[cid=' + data.cid + ']')
	}
	if (targetIframe && targetIframe.length > 0) {
		targetIframe[0].contentWindow.postMessage({'msgType':'dataChanged','cid':data.cid, 'name':RichTextUitl.b64EncodeUnicode(JSON.stringify(data))}, "*");
		targetIframe[0].name = RichTextUitl.b64EncodeUnicode(JSON.stringify(data));
	}
}

/**
 * 取模板页面
 * type 0：教案模板
 */
RichTextUitl.getTemplateHtml = function (type) {
	var html = '';
	if (type == 0) {
		html = '<div class="ulTab" id="ulTab" contenteditable="false">' +
			'<div class="classul">' +
			'<div class="cur_li">' +
			'<p class="classBefore">课前</p></div>' +
			'<div>' +
			'<p class="classCenter">课中</p></div>' +
			'<div>' +
			'<p class="classAfter">课后</p></div>' +
			'</div>' +
			'</div>' +
			'<div class="classConBefore">' +
			'<p>​<br/></p></div>' +
			'<div class="classConCenter" style="display:none">' +
			'<p><br/></p>' +
			'</div>' +
			'<div class="classConAfter" style="display:none">' +
			'<p><br/></p>' +
			'</div>'
	}

	return html;
}

// 教案详情页默认显示课前
RichTextUitl.dealWithTeachPlan = function () {
	$('body').find('#ulTab .classBefore').parent().addClass('cur_li').siblings('div').removeClass('cur_li');
	$('body').find('.classConCenter,.classConAfter').hide();
	$('body').find('.classConBefore').show();
}

RichTextUitl.createPPTcallback = function (data) {
	if (!data || data.length == 0) {
		return;
	}
	data = data[0];
	var iframe = ue.iframe;
	if (iframe) {
		var doc = iframe.contentDocument || iframe.document;
		var targetIframe = $(doc).find('iframe[cid="' + data.cid + '"]');
		if (targetIframe.length > 0) {
			var name = RichTextUitl.b64EncodeUnicode(JSON.stringify(data));
			var pptAttHtml = "<iframe frameborder='0' scrolling='no' cid='" + data.cid + "' src='https://noteyd.chaoxing.com/attachment/insertVote.html' name='" + name + "' class='attach-module attach-insertVote' module='insertVote'></iframe>";
			targetIframe.parent().html(pptAttHtml);
		}
	}
}

/**
 * 获取云盘文件objectId
 * @param name
 * @returns {string}
 */
RichTextUitl.getCloudFileObjectId = function (name) {
	var attachmentData;
	try {
		attachmentData = JSON.parse(decodeURIComponent(atob(name)));
	} catch (e) {
	}
	if (!attachmentData || !attachmentData.att_clouddisk) {
		return '';
	}

	return attachmentData.att_clouddisk.fileId || '';
}

/**
 * 获取文件名
 * @param name
 * @returns {string|*|string}
 */
RichTextUitl.getCloudFileName = function (name) {
	var attachmentData;
	try {
		attachmentData = JSON.parse(decodeURIComponent(atob(name)));
	} catch (e) {
	}
	if (!attachmentData || !attachmentData.att_clouddisk) {
		return '';
	}
	var fileName = attachmentData.att_clouddisk.name;
	if (fileName.indexOf('.' + attachmentData.att_clouddisk.suffix) > -1) {
		fileName = fileName.substring(0, fileName.indexOf('.' + attachmentData.att_clouddisk.suffix));
	}

	return fileName || '';
}



/**
 * 获取后缀
 * @param name
 * @returns {string|*|string}
 */
RichTextUitl.getCloudFileSuffix = function (name) {
	var attachmentData;
	try {
		attachmentData = JSON.parse(decodeURIComponent(atob(name)));
	} catch (e) {
	}
	if (!attachmentData || !attachmentData.att_clouddisk) {
		return '';
	}
	return attachmentData.att_clouddisk.suffix || '';
}
/**
 * 判断是否是手机端
 */
RichTextUitl.isPhone = function () {
	var u = navigator.userAgent;
	var isAndroid = u.indexOf('Android') > -1; //android终端
	var isIOS = !!u.match(/(iPhone|iPad|iPod)/i); //ios终端
	var isHarmony = navigator.userAgent.indexOf('harmony') > -1 && navigator.userAgent.indexOf('phone') > -1;
	return isAndroid || isIOS || isHarmony;
}

/**
 * 保存富文本内容时将 文本链接附件转成 卡片附件，显示的时候改回成 a 标签
 * 目的是避免文本链接附件在客户端上点击时跳转到的PC端网页地址
 * 卡片页形式可以走客户端协议打开
 * @param name
 * @param module
 * @param tag
 * @returns {string}
 */
RichTextUitl.changeAttachmentModel = function (name, module, tag) {
	var html = '';
	var attachmentData = RichTextUitl.b64DecodeUnicode(name)
	if (tag == 'iframe') {
		html = '<div class="editor-iframe textlink" contenteditable="false">' +
			'<iframe frameborder="0" scrolling="no" cid="' + attachmentData.cid + '"' +
			' src="' + module + '.html"' +
			' name="' + name + '"' +
			' class="attach-module attach-' + module + '" module="' + module + '">' +
			'</iframe></div>';
	} else if (tag == 'a') {
		var linkClass = '';
		var title = '';
		switch (attachmentData.attachmentType) {
			case 18 :
				// 云盘文件
				href = attachmentData.att_clouddisk.downPath;
				title = attachmentData.att_clouddisk.name;
				linkClass = 'iframe';
				break;
			case 25 :
				href = attachmentData.att_web.url;
				title = attachmentData.att_web.title;
				linkClass = 'link';
				break;
		}
		if (!href) {
			return;
		}
		html = '<div class="editor-textiframe" contenteditable="false"><a href="'
			+ href + '" ' +
			'class="dynacALink ' + linkClass + '" target="_blank" module="' + module + '" '
			+ ' name="' + name + '">' + title + '</a></div>';
	}
	return html;
}


/**
 * 详情页去掉附件的可编辑链接参数 enableEdit=1
 */
RichTextUitl.subAttchEditMode = function (rtf_content) {
	if (!rtf_content) {
		return '';
	}

	var iframeReg = /<iframe.*?(?:<\/iframe>)/gi; //匹配iframe标签
	var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配iframe中的src
	var arr = rtf_content.match(iframeReg);  //筛选出所有的iframe
	if (arr) {
		for (var i = 0; i < arr.length; i++) {
			var src = arr[i].match(srcReg)
			if (src) {
				iframe_src = src[1];
				if (iframe_src && iframe_src.indexOf("enableEdit=1") > 0) {
					rtf_content = rtf_content.replace(iframe_src, iframe_src.replace('enableEdit=1', 'enableEdit=0'));
				}
			}
		}
	}
	return rtf_content;
}


/*
 * MAP对象，实现MAP功能
 *
 * 接口：
 * size()     获取MAP元素个数
 * isEmpty()    判断MAP是否为空
 * clear()     删除MAP所有元素
 * put(key, value)   向MAP中增加元素（key, value)
 * remove(key)    删除指定KEY的元素，成功返回True，失败返回False
 * get(key)    获取指定KEY的元素值VALUE，失败返回NULL
 * element(index)   获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL
 * containsKey(key)  判断MAP中是否含有指定KEY的元素
 * containsValue(value) 判断MAP中是否含有指定VALUE的元素
 * values()    获取MAP中所有VALUE的数组（ARRAY）
 * keys()     获取MAP中所有KEY的数组（ARRAY）
 *
 * 例子：
 * var map = new Map();
 *
 * map.put("key", "value");
 * var val = map.get("key")
 * ……
 *
 */
function RMap() {
	this.elements = new Array();

	//获取MAP元素个数
	this.size = function () {
		return this.elements.length;
	};

	//判断MAP是否为空
	this.isEmpty = function () {
		return (this.elements.length < 1);
	};

	//删除MAP所有元素
	this.clear = function () {
		this.elements = new Array();
	};

	//向MAP中增加元素（key, value)
	this.put = function (_key, _value) {
		this.removeByKey(_key);
		this.elements.push({
			key: _key,
			value: _value
		});
	};
	//向MAP中增加元素（key, value)
	this.set = function (_key, _value) {
		this.removeByKey(_key);
		this.elements.push({
			key: _key,
			value: _value
		});
	};

	//删除指定KEY的元素，成功返回True，失败返回False
	this.removeByKey = function (_key) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	//删除指定VALUE的元素，成功返回True，失败返回False
	this.removeByValue = function (_value) {//removeByValueAndKey
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	//删除指定VALUE的元素，成功返回True，失败返回False
	this.removeByValueAndKey = function (_key, _value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value && this.elements[i].key == _key) {
					this.elements.splice(i, 1);
					return true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	//获取指定KEY的元素值VALUE，失败返回NULL
	this.get = function (_key) {
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					return this.elements[i].value;
				}
			}
		} catch (e) {
			return false;
		}
		return false;
	};

	//获取指定索引的元素（使用element.key，element.value获取KEY和VALUE），失败返回NULL
	this.element = function (_index) {
		if (_index < 0 || _index >= this.elements.length) {
			return null;
		}
		return this.elements[_index];
	};

	//判断MAP中是否含有指定KEY的元素
	this.containsKey = function (_key) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};
	//判断MAP中是否含有指定KEY的元素
	this.has = function (_key) {
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].key == _key) {
					return true;
				}
			}
		} catch (e) {
			return false;
		}
		return false;
	};

	//判断MAP中是否含有指定VALUE的元素
	this.containsValue = function (_value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	//判断MAP中是否含有指定VALUE的元素
	this.containsObj = function (_key, _value) {
		var bln = false;
		try {
			for (i = 0; i < this.elements.length; i++) {
				if (this.elements[i].value == _value && this.elements[i].key == _key) {
					bln = true;
				}
			}
		} catch (e) {
			bln = false;
		}
		return bln;
	};

	//获取MAP中所有VALUE的数组（ARRAY）
	this.values = function () {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].value);
		}
		return arr;
	};

	//获取MAP中所有VALUE的数组（ARRAY）
	this.valuesByKey = function (_key) {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			if (this.elements[i].key == _key) {
				arr.push(this.elements[i].value);
			}
		}
		return arr;
	};

	//获取MAP中所有KEY的数组（ARRAY）
	this.keys = function () {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			arr.push(this.elements[i].key);
		}
		return arr;
	};

	//获取key通过value
	this.keysByValue = function (_value) {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			if (_value == this.elements[i].value) {
				arr.push(this.elements[i].key);
			}
		}
		return arr;
	};

	//获取MAP中所有KEY的数组（ARRAY）
	this.keysRemoveDuplicate = function () {
		var arr = new Array();
		for (i = 0; i < this.elements.length; i++) {
			var flag = true;
			for (var j = 0; j < arr.length; j++) {
				if (arr[j] == this.elements[i].key) {
					flag = false;
					break;
				}
			}
			if (flag) {
				arr.push(this.elements[i].key);
			}
		}
		return arr;
	};
}

RichTextUitl.createTemplate = function () {

	var html = '<div class="templatePop">' +
		'<div class="template-wrap">' +
		'<div class="templateHead">可选择一个模板</div>' +
		'<div class="templateList">' +
		'</div>' +
		'</div>' +
		'</div>'
	if (RichTextUitl.templateContainer) {
		$(RichTextUitl.templateContainer).append(html);
	} else {
		$('body').append(html);
	}

	html = '';
	if (RichTextUitl.templateList.length > 0) {
		$.each(RichTextUitl.templateList, function (idx, val) {
			html += '<div class="template" data-type="' + idx + '">' +
				'<div class="tit">' +
				'<h3>' + val.title + '</h3>' +
				'</div>' +
				'<span class="tem" style="background:url(' + val.background + ');background-size: 100%;"></span>' +
				'</div>'
		})
	} else {
		$.each(RichTextUitl.template, function (idx, val) {
			html += '<div class="template" data-type="' + idx + '">' +
				'<div class="tit">' +
				'<h3>' + val.title + '</h3>' +
				'</div>' +
				'<span class="tem" style="background:url(' + val.background + ');background-size: 100%;"></span>' +
				'</div>'
		})
	}
	$('.templateList').append(html)
	$('.templatePop').show();

	//20210401 模板
	$('.templatePop').on('click', '.template', function () {
		var rtfContent;
		if (RichTextUitl.templateList.length > 0) {
			rtfContent = RichTextUitl.templateList[parseInt($(this).attr('data-type'))].rtf_content;
		} else {
			rtfContent = RichTextUitl.template[parseInt($(this).attr('data-type'))].rtf_content;
		}
		if (rtfContent) {
			ue.setContent(rtfContent);
		}
		RichTextUitl.hidetemplate();
	});

	interval = setInterval(function () {
		// 定时任务检测是否有内容
		if(!ue || !ue.body) return
		if (typeof ue != 'undefined' && ue.getContent() == "") {
			// 创建页，删除页面所有内容后，显示模板
			$('.templatePop').show();
		} else {
			RichTextUitl.hidetemplate();
		}
	}, 1000);
}

RichTextUitl.hidetemplate = function () {
	$('.templatePop').fadeOut();
}

/*支持多编辑器多个模板*/
RichTextUitl.createMoreTemplate = function (editorId, templateList) {
	var html = '<div class="templatePop">' +
		'<div class="template-wrap">' +
		'<div class="templateHead">可选择一个模板</div>' +
		'<div class="templateList">' +
		'</div>' +
		'</div>' +
		'</div>'
	$('#' + editorId).append(html);

	html = '';
	$.each(templateList, function (idx, val) {
		html += '<div class="template" data-type="' + idx + '">' +
			'<div class="tit">' +
			'<h3>' + val.title + '</h3>' +
			'</div>' +
			'<span class="tem" style="background:url(' + val.background + ');background-size: 100%;"></span>' +
			'</div>'
	})
	$('#' + editorId).find('.templateList').append(html)
	$('#' + editorId).find('.templatePop').show();
	//20210401 模板
	$('#' + editorId).find('.templatePop').on('click', '.template', function () {
		var rtfContent;
		ue = UE.getEditor('multi' + editorId);
		rtfContent = templateList[parseInt($(this).attr('data-type'))].rtf_content;
		if (rtfContent) {
			ue.setContent(rtfContent);
		}
		$('#' + editorId).find('.templatePop').fadeOut();
	});

}


//渲染公式
RichTextUitl.renderLatex = function (dom){
	if(!dom) return
	if(typeof MathJax == 'undefined') return
	// 查找所有需要渲染的元素
	var mathElements = dom.querySelectorAll('span[data-latexstr]');
	mathElements.forEach(el => {
		const tex = decodeURIComponent(el.dataset.latexstr); // 解码
		const display = el.tagName === 'latex_math_block';// 默认块级
		el.textContent = '';// 清空旧内容
		el.style.transform = '';
		MathJax.tex2svgPromise(tex, { display: display })
			.then(function(node) {
				el.appendChild(node);
				//超长公式需要缩小
				var scale = el.clientWidth / node.offsetWidth; // 计算所需比例
				if(scale < 1 && scale > 0){
					el.style.transformOrigin = 'left center';        // 以左上角为基准
					el.style.transform = `scale(${Math.min(scale, 1)})`; // ≤1 保证不放大
				}
			})
	});
}