Files
XueXiTongSrtDownloads/学生学习页面_files/rich.text.common.js.下载
2025-10-11 18:15:20 +08:00

3445 lines
134 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var i18nDetailData = {
'zh': {
'uploadText': '有正在上传的内容!',
'uploadImg': '有正在上传的图片!',
'download': '下载',
'preview': '预览',
'fullscreen': '全屏',
'exitFullscreen': '退出全屏',
'saveToCloud': '保存到云盘',
'Share': '转发',
'bultEdit': '批量编辑',
'more': '更多',
'copy': '复制',
'copySuccess': '复制成功',
'copyFailed': '复制失败',
},
'en': {
'uploadText': 'Content is being uploaded!',
'uploadImg': 'Image is being uploaded!',
'download': 'Download',
'preview': 'Preview',
'fullscreen': 'Full Screen',
'exitFullscreen': 'Exit Full Screen',
'saveToCloud': 'Save to Cloud disk',
'Share': 'Share',
'bultEdit': 'Bulk Edit',
'more': 'More',
'copy': 'Copy',
'copySuccess': 'Copy successfully',
'copyFailed': 'Failed to copy',
},
'zh_tw': {
'uploadText': '有正在上傳的內容!',
'uploadImg': '有正在上傳的圖片!',
'download': '下載',
'preview': '預覽',
'fullscreen': '全屏',
'exitFullscreen': '退出全屏',
'saveToCloud': '保存到雲盤',
'Share': '轉發',
'bultEdit': '批量編輯',
'more': '更多',
'copy': '複製',
'copySuccess': '複製成功',
'copyFailed': '複製失敗',
}
}
if (typeof RichTextUitl.noteDomain == 'undefined') {
RichTextUitl.noteDomain = 'https://noteyd.chaoxing.com'
}
RichTextUitl.uploadUrl = 'https://pan-yz.chaoxing.com/upload';
RichTextUitl.language = window.cookieLanguage = typeof (window.cookieLanguage) != "undefined" ? window.cookieLanguage : RichTextUitl.getCookie('browserLocale')
var language = (window.cookieLanguage || navigator.language || 'zh').toLowerCase()
/**
* 获取国际化内容
* @param content
* @returns {string|*}
*/
RichTextUitl.getI18nContent = function (content) {
if (!content) {
return '';
}
// 获取设置的语言
var language = (window.language || navigator.language || 'zh').toLocaleLowerCase() // 这是获取浏览器的语言
if (language.indexOf('en') > -1) {
language = 'en'
} else if (language.indexOf('zh_tw') > -1 || language.indexOf('zh-tw') > -1) {
language = 'zh_tw'
} else {
language = 'zh'
}
content = i18nDetailData[language][content]
return content;
}
var ua = navigator.userAgent.toLowerCase();
// 是否在手机学习通里面
RichTextUitl.isXXT = ua && ua.indexOf("chaoxingstudy") != -1 && ua.indexOf('_pc_') == -1;
// 是否是微信端
RichTextUitl.isWeiXin = ua.match(/MicroMessenger/i) == 'micromessenger';
var isIosQQ = (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) && /\sQQ/i.test(navigator.userAgent));
var isAndroidQQ = (/(Android)/i.test(navigator.userAgent) && /MQQBrowser/i.test(navigator.userAgent) && /\sQQ/i.test((navigator.userAgent).split('MQQBrowser')));
var isHarmonyQQ = navigator.userAgent.indexOf('harmony') > -1 && /\sQQ/i.test(navigator.userAgent) //鸿蒙终端
RichTextUitl.isQQ = isIosQQ || isAndroidQQ || isHarmonyQQ;
/**
* 参数:显示错误提示的方法, function(msg){}
*
* 返回json串
* content : 普通文本内容
* content_imgs : 图片
* attachment : 附件
* rtf_content : 富文本内容
* istestContent:是否是检测数据
*/
RichTextUitl.getRichText = function (showTipsFunction, editorId, istestContent) {
var return_data = {};
if (editorId) {
ue = UE.getEditor(editorId);
}
var iframe = ue.iframe;
var doc = iframe.contentDocument || iframe.document;
var attachments;
var $noteImgs;
var isVideoUploadFail = false;
if (doc) {
attachments = doc.getElementsByTagName('iframe');
$noteImgs = doc.getElementsByTagName("img");
if (!istestContent && (doc.getElementsByClassName("imgprogress").length > 0
|| doc.getElementsByClassName("attachprogress").length > 0
|| doc.getElementsByClassName("video_fail").length > 0)) {
// 有未上传完的图片
if (typeof showTipsFunction == 'function') {
showTipsFunction(RichTextUitl.getI18nContent('uploadText'), 0);
return;
}
return_data.isuploading = true;
// 判断是否存在上传失败视频
$.each(doc.querySelectorAll('.video_fail'), function (_, elm) {
if ($(elm).css('display') !== 'none') {
isVideoUploadFail = true;
}
})
if (doc.querySelector(".imgprogress.failed") || doc.querySelector('.attachprogress.fail') || isVideoUploadFail) {
return_data.hasUploadFailed = true;
}
}
// 卡片附件改为文本链接附件后,可以修改链接内容,保存时需要获取链接内容然后修改对应的附件里面的数据
var aTags = doc.getElementsByTagName("a");
$.each(aTags, function (idx, val) {
var name = val.getAttribute('name');
var module = val.getAttribute('module');
if (name && module) {
var hasChange = false;
var attachmentContent = RichTextUitl.b64DecodeUnicode(name);
if (attachmentContent) {
if (module == 'insertCloud' && attachmentContent.att_clouddisk
&& attachmentContent.att_clouddisk.name != val.text) {
// 云盘附件
attachmentContent.att_clouddisk.name = val.text;
attachmentContent.att_clouddisk.infoJsonStr.name = val.text;
hasChange = true;
} else if (module == 'insertWeb' && attachmentContent.att_web
&& attachmentContent.att_web.title != val.text) {
// 网页附件
attachmentContent.att_web.title = val.text;
hasChange = true;
}
}
if (hasChange) {
attachmentContent = RichTextUitl.b64EncodeUnicode(JSON.stringify(attachmentContent));
val.setAttribute('name', attachmentContent);
}
}
})
}
// 获取带格式的文本内容去掉了文本标签转义了换行和空格、图片标签、iframe标签
var content = '', rtf_content = '', full_content = '';
try {
content = ue.getPlainTxt();
} catch (e) {
content = doc.body.innerText;
}
full_content = content;
try {
// 获取html内容包含所有标签
rtf_content = ue.getContent();
} catch (e) {
rtf_content = doc.body.innerHTML;
}
var content_imgs = '';
// 需要移除的图片
var needRemoveImgs = new Array();
// 处理图片
if ($noteImgs.length > 0) {
for (var i = 0; i < $noteImgs.length; i++) {
var imgSrc = $.trim($noteImgs[i].getAttribute("src"));
if (imgSrc.indexOf('/images/spacer.gif') > 0) {
if ($noteImgs[i].getAttribute('class') == 'loadingclass') {
// 包含编辑器里面在复制图片时用的占位图,需要去掉
// 有未上传完的图片
if (typeof showTipsFunction == 'function') {
showTipsFunction(RichTextUitl.getI18nContent('uploadImg'), 0);
return;
}
return_data.isuploading = true;
} else {
needRemoveImgs.push($noteImgs[i].parentNode);
}
}else if (!imgSrc && $noteImgs[i].getAttribute("_src")){
//未替换完成图片
return_data.hasUnReplaceImg = true;
}
}
// 匹配 img 标签的正则表达
var imgReg = /<img.*?(?:>|\/>)/gi;
// 匹配 img 标签 src 属性的正则表达
var srcReg = / src=[\'\"]?([^\'\"]*)[\'\"]?/i;
// 匹配 img 标签 objectid 属性的正则表达
var objectidReg = /objectid=[\'\"]?([^\'\"]*)[\'\"]?/i;
// 包含所有img标签的数组
var imgArr = content.match(imgReg);
// app下面写总结用到了编辑器获取的content要和笔记的一样
var isNoteDomain = window.location.host.indexOf('noteyd') > -1 || window.location.host.indexOf('note.yd') > -1
|| window.location.host.indexOf('appswh') > -1;
// 如果是镜像模式isNoteDomain 也为true
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.hasOwnProperty('isMirrorDeploy')) {
if (window.obj.mirrorDomain.isMirrorDeploy == true) {
if (window.location.href.indexOf('noteyd') != -1) {
isNoteDomain = true;
}
}
}
if (isNoteDomain) {
// 笔记服务特殊处理
content_imgs = {};
for (var i = 0; i < imgArr.length; i++) {
//获取图片地址
var imgSrc = imgArr[i].match(srcReg);
// 获取objectid
var objectId = imgArr[i].match(objectidReg);
if (imgSrc && imgSrc[1] && imgSrc[1].indexOf('http') == 0 && imgSrc[1].indexOf('/images/spacer.gif') == -1) {
// 默认用uuid避免有的图片标签上没有objectid时
var placeholder = RichTextUitl.randomUUID();
if (objectId && objectId[1]) {
placeholder = objectId[1];
}
content_imgs[placeholder] = imgSrc[1];
content = content.replace(imgArr[i], "(№♂◎┟ξψ┽" + placeholder + "");
full_content = full_content.replace(imgArr[i], imgSrc[1])
} else {
content = content.replace(imgArr[i], "");
full_content = full_content.replace(imgArr[i], "")
}
}
} else {
content_imgs = "";
for (var i = 0; i < imgArr.length; i++) {
//获取图片地址
var imgSrc = imgArr[i].match(srcReg);
if (imgSrc && imgSrc[1] && imgSrc[1].indexOf('http') == 0 && imgSrc[1].indexOf('/images/spacer.gif') == -1) {
content_imgs += imgSrc[1] + ";";
}
content = content.replace(imgArr[i], "");
if (imgSrc && imgSrc[1]) {
full_content = full_content.replace(imgArr[i], imgSrc[1])
}
}
}
}
if (needRemoveImgs.length > 0) {
for (var i = 0; i < needRemoveImgs.length; i++) {
if (needRemoveImgs[i].getAttribute('class') == 'editor-image') {
needRemoveImgs[i].remove();
} else {
// 火狐浏览器复制QQ聊天框里面的内容是图片和文字在同一个div里面且div上没有editor-image只删除图片不删除整个div
needRemoveImgs[i].getElementsByTagName('img')[0].remove();
}
}
// 包含有问题的图片,重新获取富文本内容
rtf_content = ue.getContent();
}
// 处理附件
var attachmentStr = "";
if (attachments.length > 0) {
var attachmentArray = new Array();
for (i = 0; i < attachments.length; i++) {
// 获取附件内容
var att = attachments[i].getAttribute('name');
var att_json = RichTextUitl.b64DecodeUnicode(att);
try {
if (att_json) {
if (att_json.attachmentType == 18) {
// 云盘内容在iframe上存储时需要将 infoJsonStr 和 parentPath 转成json客户端目前这样做的在最终保存附件时需要把 infoJsonStr 和 parentPath 转回成string客户端要求
att_json.att_clouddisk.infoJsonStr = JSON.stringify(att_json.att_clouddisk.infoJsonStr);
att_json.att_clouddisk.parentPath = JSON.stringify(att_json.att_clouddisk.parentPath);
}
attachmentArray.push(JSON.stringify(att_json));
}
} catch (e) {
console.log(e);
}
// var att_text = attachments[i].outerHTML;
// // 替换掉文本内容里面的附件
// content = content.replace(att_text.replace("</iframe>",""),"");
}
if (attachmentArray.length > 0) {
attachmentStr = "[" + attachmentArray.join() + "]";
}
}
// 替换掉文本内容里面的附件
content = content.replace(/<[^>]+>/g, '');
full_content = full_content.replace(/<[^>]+>/g, '');
//PC编辑器之间复制附件会带上当前页面的路径需要去掉
if (rtf_content && !RichTextUitl.intranetMode) {
var iframeReg = /<iframe.*?(?:<\/iframe>)/gi; //匹配iframe标签
var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配iframe中的src
var arr = rtf_content.match(iframeReg); //筛选出所有的iframe
var srcArr = [];
if (arr) {
for (var i = 0; i < arr.length; i++) {
var src = arr[i].match(srcReg);
var module = arr[i].match(/module=[\'\"]?([^\'\"]*)[\'\"]?/i);
// 获取iframe src
if (src && src[1]) {
//srcArr.push(src[1]);
iframe_src = src[1];
if (iframe_src.indexOf("insert") > 0) {
// 包含insert且不是以insert开头的才需要替换
rtf_content = rtf_content.replace(iframe_src, iframe_src.substring(iframe_src.indexOf("insert"), iframe_src.length));
}
if (module && module.length > 1 && module[1] == 'insertCloud') {
if (iframe_src.indexOf('//previewyd.chaoxing.com/res/view/view.html') > -1) {
// 文件开启原位预览后保存时地址要改回成insertCloud.html避免影响手机上查看
rtf_content = rtf_content.replace(iframe_src, 'insertCloud.html');
}
}
if (iframe_src.indexOf('appswh.chaoxing.com/res/Spreadsheets/wpsPC.html') > -1) {
// 在线表格,保存时地址要改成 insertWeb.html避免影响手机上查看
rtf_content = rtf_content.replace(iframe_src, 'insertWeb.html');
}
}
}
}
// 匹配卡片附件转换成的文本附件,为了不影响客户端的附件点击逻辑,保存时需要改回成卡片附件
// 门户那边不需要做这个处理,只处理笔记,话题,通知,课程那边
// 取消将a标签改回卡片附件的逻辑
// var currentHost = location.host;
// if (currentHost.indexOf('note') > -1 || currentHost.indexOf('notice') > -1
// || currentHost.indexOf('groupweb') > -1 || currentHost.indexOf('mobilelearn') > -1) {
// try {
// rtf_content = RichTextUitl.replaceATagWithIframe(rtf_content);
// } catch (e) {
// console.log(e);
// }
// }
// var divReg = /<div [^>/]*?class="editor-textiframe" [^>/]*>(.*?)<\/div>/gi;
// var aReg = /<a[^>]*name=['"]([^"]*)['"][^>]*>(.*?)<\/a>/gi;
// //var aReg=/<a([\s]+|[\s]+[^<>]+[\s]+)name=(\"([^<>"\']*)\"|\'([^<>"\']*)\')[^<>]*>/gi;
// var nameReg = /name=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配iframe中的src
// var moduleReg = /module=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配iframe中的src
// var divTag = rtf_content.match(divReg);
// if (divTag && divTag.length > 0) {
// for (var i = 0; i < divTag.length; i++) {
// var aTag = divTag[i].match(aReg);
// if (aTag && aTag.length > 0) {
// for(var j = 0; j < aTag.length; j++) {
// var name = aTag[j].match(nameReg);
// var module = aTag[j].match(moduleReg);
// if (name && name[1] && module && module[1]) {
// rtf_content = rtf_content.replace(divTag[i], RichTextUitl.changeAttachmentModel(name[1], module[1], 'iframe'))
// }
// }
// }
// }
// }
}
return_data.content = restoresEscapedCharacter(content);
return_data.full_content = restoresEscapedCharacter(full_content);
if (isNoteDomain) {
// 笔记服务的content_imgs 为json 结构
return_data.content_imgs = JSON.stringify(content_imgs);
} else {
return_data.content_imgs = content_imgs;
}
return_data.attachment = attachmentStr.replace(/&apos;/g, "'");// 附件中的内容包含单引号时进行了转换,保存时替换回来;
return_data.rtf_content = rtf_content.replace(/&apos;/g, "'"); // 附件中的内容包含单引号时进行了转换,保存时替换回来;
return return_data;
}
// 根据html获取图片附件和纯文本
RichTextUitl.getAllContent = function (html) {
function _(s) {
for (var k in s) {
s[k.toUpperCase()] = s[k];
}
return s;
}
var dtd = _({
address: 1,
blockquote: 1,
center: 1,
dir: 1,
div: 1,
dl: 1,
fieldset: 1,
form: 1,
h1: 1,
h2: 1,
h3: 1,
h4: 1,
h5: 1,
h6: 1,
hr: 1,
isindex: 1,
menu: 1,
noframes: 1,
ol: 1,
p: 1,
pre: 1,
table: 1,
ul: 1
});
// 获取带格式的文本内容去掉了文本标签转义了换行和空格、图片标签、iframe标签
var div = document.createElement('div');
div.innerHTML = html;
$(div).find("ol li").each(function () {
$(this).prepend($(this).attr('serialnum') + ". ");
});
$(div).find("ul li").each(function () {
var level = parseInt($(this).parent().attr('level')) || 1;
switch (level % 3) {
case 0:
$(this).prepend(" ▪ ");
break;
case 1:
$(this).prepend("• ");
break;
case 2:
$(this).prepend(" ◦ ");
break;
default:
break;
}
});
//避免生成的图片后多一个空行
$(div).find(".drag-image-wrap .editor-image").each(function () {
$(this).unwrap();
});
html = $(div).html();
var reg = new RegExp('\u200B', 'g');
html = html.replace(/[\n\r]/g, ''); //ie要先去了\n在处理
html = html.replace(/<(ol|ul|li)[^>]*>/g, '').replace(/<(\/ol|\/ul|\/li)>/g, '');
html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
.replace(/<br\/?>/gi, '\n')
.replace(/<[^>/]+>/g, '')
.replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
return dtd[c] ? '\n' : b ? b : '';
})
// .replace(/<[^(img)][^>]+>/g, '');
//取出来的空格会有c2a0会变成乱码处理这种情况\u00a0
html = html.replace(reg, '').replace(/\u00a0/g, ' ').replace(/&nbsp;/g, ' ');
var attachments;
var $noteImgs;
if (doc) {
attachments = doc.getElementsByTagName('iframe');
$noteImgs = doc.getElementsByTagName("img");
if (!istestContent && (doc.getElementsByClassName("imgprogress").length > 0
|| doc.getElementsByClassName("attachprogress").length > 0
|| doc.getElementsByClassName("video_fail").length > 0)) {
// 有未上传完的图片
if (typeof showTipsFunction == 'function') {
showTipsFunction(RichTextUitl.getI18nContent('uploadText'), 0);
}
return;
}
// 卡片附件改为文本链接附件后,可以修改链接内容,保存时需要获取链接内容然后修改对应的附件里面的数据
var aTags = doc.getElementsByTagName("a");
$.each(aTags, function (idx, val) {
var name = val.getAttribute('name');
var module = val.getAttribute('module');
if (name && module) {
var hasChange = false;
var attachmentContent = RichTextUitl.b64DecodeUnicode(name);
if (attachmentContent) {
if (module == 'insertCloud' && attachmentContent.att_clouddisk
&& attachmentContent.att_clouddisk.name != val.text) {
// 云盘附件
attachmentContent.att_clouddisk.name = val.text;
attachmentContent.att_clouddisk.infoJsonStr.name = val.text;
hasChange = true;
} else if (module == 'insertWeb' && attachmentContent.att_web
&& attachmentContent.att_web.title != val.text) {
// 网页附件
attachmentContent.att_web.title = val.text;
hasChange = true;
}
}
if (hasChange) {
attachmentContent = RichTextUitl.b64EncodeUnicode(JSON.stringify(attachmentContent));
val.setAttribute('name', attachmentContent);
}
}
})
}
// 获取带格式的文本内容去掉了文本标签转义了换行和空格、图片标签、iframe标签
var content = '', full_content = '';
var content_imgs = '';
// 需要移除的图片
var needRemoveImgs = new Array();
// 处理图片
if ($noteImgs.length > 0) {
for (var i = 0; i < $noteImgs.length; i++) {
var imgSrc = $.trim($noteImgs[i].getAttribute("src"));
if (imgSrc.indexOf('/images/spacer.gif') > 0) {
needRemoveImgs.push($noteImgs[i].parentNode);
}
}
// 匹配 img 标签的正则表达
var imgReg = /<img.*?(?:>|\/>)/gi;
// 匹配 img 标签 src 属性的正则表达
var srcReg = / src=[\'\"]?([^\'\"]*)[\'\"]?/i;
// 包含所有img标签的数组
var imgArr = content.match(imgReg);
content_imgs = "";
for (var i = 0; i < imgArr.length; i++) {
//获取图片地址
var imgSrc = imgArr[i].match(srcReg);
if (imgSrc && imgSrc[1] && imgSrc[1].indexOf('http') == 0 && imgSrc[1].indexOf('/images/spacer.gif') == -1) {
content_imgs += imgSrc[1] + ";";
}
content = content.replace(imgArr[i], "");
full_content = full_content.replace(imgArr[i], imgSrc[1])
}
}
if (needRemoveImgs.length > 0) {
for (var i = 0; i < needRemoveImgs.length; i++) {
if (needRemoveImgs[i].getAttribute('class') == 'editor-image') {
needRemoveImgs[i].remove();
} else {
// 火狐浏览器复制QQ聊天框里面的内容是图片和文字在同一个div里面且div上没有editor-image只删除图片不删除整个div
needRemoveImgs[i].getElementsByTagName('img')[0].remove();
}
}
// 包含有问题的图片,重新获取富文本内容
rtf_content = ue.getContent();
}
// 处理附件
var attachmentStr = "";
if (attachments.length > 0) {
var attachmentArray = new Array();
for (i = 0; i < attachments.length; i++) {
// 获取附件内容
var att = attachments[i].getAttribute('name');
var att_json = RichTextUitl.b64DecodeUnicode(att);
try {
if (att_json) {
if (att_json.attachmentType == 18) {
// 云盘内容在iframe上存储时需要将 infoJsonStr 和 parentPath 转成json客户端目前这样做的在最终保存附件时需要把 infoJsonStr 和 parentPath 转回成string客户端要求
att_json.att_clouddisk.infoJsonStr = JSON.stringify(att_json.att_clouddisk.infoJsonStr);
att_json.att_clouddisk.parentPath = JSON.stringify(att_json.att_clouddisk.parentPath);
}
attachmentArray.push(JSON.stringify(att_json));
}
} catch (e) {
console.log(e);
}
}
if (attachmentArray.length > 0) {
attachmentStr = "[" + attachmentArray.join() + "]";
}
}
// 替换掉文本内容里面的附件
content = content.replace(/<[^>]+>/g, '');
full_content = full_content.replace(/<[^>]+>/g, '');
//PC编辑器之间复制附件会带上当前页面的路径需要去掉
var iframeReg = /<iframe.*?(?:<\/iframe>)/gi; //匹配iframe标签
var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // 匹配iframe中的src
var arr = rtf_content.match(iframeReg); //筛选出所有的iframe
var srcArr = [];
if (arr) {
for (var i = 0; i < arr.length; i++) {
var src = arr[i].match(srcReg)
// 获取iframe src
if (src && src[1]) {
//srcArr.push(src[1]);
iframe_src = src[1];
if (iframe_src.indexOf("insert") > 0) {
// 包含insert且不是以insert开头的才需要替换
rtf_content = rtf_content.replace(iframe_src, iframe_src.substring(iframe_src.indexOf("insert"), iframe_src.length));
}
if (iframe_src.indexOf('//previewyd.chaoxing.com/res/view/view.html') > -1) {
// 文件开启原位预览后保存时地址要改回成insertCloud.html避免影响手机上查看
rtf_content = rtf_content.replace(iframe_src, 'insertCloud.html');
}
if (iframe_src.indexOf('appswh.chaoxing.com/res/Spreadsheets/wpsPC.html') > -1) {
// 在线表格,保存时地址要改成 insertWeb.html避免影响手机上查看
rtf_content = rtf_content.replace(iframe_src, 'insertWeb.html');
}
}
}
}
return_data.content = restoresEscapedCharacter(content);
return_data.full_content = restoresEscapedCharacter(full_content);
return_data.content_imgs = content_imgs;
return_data.attachment = attachmentStr.replace(/&apos;/g, "'");// 附件中的内容包含单引号时进行了转换,保存时替换回来;
return return_data;
}
/**
* 匹配卡片附件转换成的文本附件,为了不影响客户端的附件点击逻辑,保存时需要改回成卡片附件
* @param name
* @param module
* @param tag
*/
RichTextUitl.replaceATagWithIframe = function (rtf_content) {
if (!rtf_content) {
return rtf_content;
}
//var divReg = /<div [^>/]*?class="editor-textiframe" [^>/]*>(.*?)<\/div>/gi;
var aReg = /<a[^>]*name=['"]([^"]*)['"][^>]*>(.*?)<\/a>/gi;
// 匹配name属性
var nameReg = /name=[\'\"]?([^\'\"]*)[\'\"]?/i;
// 匹配 module 属性
var moduleReg = /module=[\'\"]?([^\'\"]*)[\'\"]?/i;
var aTag = rtf_content.match(aReg);
if (!aTag || aTag.length == 0) {
return rtf_content;
}
for (var j = 0; j < aTag.length; j++) {
var name = aTag[j].match(nameReg);
var module = aTag[j].match(moduleReg);
if (name && name.length > 1 && name[1] && module && module.length > 1 && module[1]) {
rtf_content = rtf_content.replace(aTag[j]
, RichTextUitl.changeAttachmentModel(name[1], module[1], 'iframe'));
}
}
// var divTag = rtf_content.match(divReg);
// if (!divTag || divTag.length == 0) {
// return rtf_content;
// }
// 遍历div将文本链接替换成卡片形式
// for (var i = 0; i < divTag.length; i++) {
// var aTag = divTag[i].match(aReg);
// if (!aTag || aTag.length == 0) {
// continue;
// }
// for(var j = 0; j < aTag.length; j++) {
// var name = aTag[j].match(nameReg);
// var module = aTag[j].match(moduleReg);
// if (name && name.length > 1 && name[1] && module && module.length > 1 && module[1]) {
// rtf_content = rtf_content.replace(divTag[i]
// , RichTextUitl.changeAttachmentModel(name[1], module[1], 'iframe'));
// }
// }
// }
return rtf_content;
}
/**
* 文本链接附件保存时是转成成了卡片附件,显示的时候再调换回来,
* 目的是为了客户端上面还是显示成卡片形式,不影响客户端的附件点击效果
* @param name
* @param module
* @param tag
*/
RichTextUitl.replaceIframeWithATag = function (rtf_content) {
if (!rtf_content) {
return rtf_content;
}
var divReg = /<div [^>/]*?class="editor-iframe textlink" [^>/]*>(.*?)<\/div>/gi;
var iframeReg = /<iframe[^>]*name=['"]([^"]*)['"][^>]*>(.*?)<\/iframe>/gi;
// 匹配 name属性
var nameReg = /name=[\'\"]?([^\'\"]*)[\'\"]?/i;
// 匹配 module 属性
var moduleReg = /module=[\'\"]?([^\'\"]*)[\'\"]?/i;
var divTag = rtf_content.match(divReg);
if (!divTag || divTag.length == 0) {
return rtf_content;
}
// 遍历div将卡片附件iframe标签替换成文本链接附件a标签
for (var i = 0; i < divTag.length; i++) {
var iframeTag = divTag[i].match(iframeReg);
if (!iframeTag || iframeTag.length == 0) {
continue;
}
for (var j = 0; j < iframeTag.length; j++) {
var name = iframeTag[j].match(nameReg);
var module = iframeTag[j].match(moduleReg);
if (name && name.length > 1 && name[1] && module && module.length > 1 && module[1]) {
rtf_content = rtf_content.replace(divTag[i]
, RichTextUitl.changeAttachmentModel(name[1], module[1], 'a'));
}
}
}
return rtf_content;
}
/**
* 文件设置为预览模式时保存时地址还是存的insertCloud.html避免在手机客户端查看有问题这里显示的时候再替换回来
* @param editorid 编辑器id
* @returns {*}
*/
RichTextUitl.replaceIframeWithPreviewMode = function (editorid) {
var editor;
if (editorid) {
editor = UE.getEditor(editorid);
} else if (ue) {
editor = ue;
} else {
return;
}
var attachments = editor.body.getElementsByTagName('iframe');
if (attachments && attachments.length > 0) {
$.each(attachments, function (idx, val) {
var allowDownload = true;
if ((($(this).attr('allowdownload') == 'false' && $(this).attr('download') == 'false')
|| ($(this).attr('allowdownload') == 'true' && !RichTextUitl.isLogin)) || ($(this).attr('download') == 'no') || ($(this).attr('download') == 'login' && !RichTextUitl.isLogin)) {
// 不允许下载
allowDownload = false;
}
if ($(this).attr('preview') == 'true' && $(this).attr('module') == 'insertCloud') {
// 开启了原位预览
var att_clouddisk = RichTextUitl.getCloudFileData($(this).attr('name'));
var iframeSrc = window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid='
+ att_clouddisk.fileId
+ '&fileName=' + encodeURIComponent(RichTextUitl.getCloudFileName($(this).attr('name')));
if (att_clouddisk.suffix == 'xlsx' || att_clouddisk.suffix == 'xls') {
// excel附件预览模式使用在线表格的页面
iframeSrc = window.location.protocol + '//appswh.chaoxing.com/res/Spreadsheets/wpsPC.html?type=attachment&cid='
+ $(this).attr('cid') + '&resid=' + (att_clouddisk.residstr || att_clouddisk.resid) + '&title=' + encodeURIComponent(att_clouddisk.name) + '&editorid=' + editorid;
}
//设置了高级预览的显示时加上高级预览的参数
if (att_clouddisk.suffix == 'pdf' && $(this).attr('advancedpreview')) {
iframeSrc += '&mode=advancedpreview';
if ($(this).attr('advancedpreview') != 'true') {
iframeSrc += '&page=' + $(this).attr('advancedpreview');
}
}
if (!allowDownload) {
iframeSrc += '&download=false';
}
if (!RichTextUitl.isGetVideoDataFromCenter) {
resid = att_clouddisk.resid
iframeSrc += '&resid=' + resid;
}
$(this).attr('src', iframeSrc);
} else if ($(this).attr('excel') == 'true' && $(this).attr('module') == 'insertWeb') {
// 在线表格
var onlineExcelUrl = window.location.protocol + '//appswh.chaoxing.com/res/Spreadsheets/wpsPC.html?isEditorStatus=1&cid='
+ $(this).attr('cid') + '&editorid=' + editorid;
if (typeof WinInitConfig != 'undefined' && WinInitConfig.noteCid) {
onlineExcelUrl += '&noteCid=' + WinInitConfig.noteCid;
}
if (!allowDownload) {
onlineExcelUrl += '&download=0';
}
$(this).attr('src', onlineExcelUrl);
}
})
}
}
/**
* msg 显示的内容
* type 0、失败提示1、成功提示
*/
RichTextUitl.showTips = function (msg, type) {
if (!msg) {
return;
}
var iconPrefix = RichTextUitl.prefix
// 前缀只含笔记域名 手动拼接路径
if (iconPrefix && iconPrefix.replace("https://", '').replace('http://', '') === 'noteyd.chaoxing.com') {
iconPrefix = iconPrefix + '/res/plugin/ueditor/'
}
if ($('.toolTipBox').length == 0) {
$(document.body).append('<div class="toolTipBox" style="display:none;"><i class="popicon"><img src="' + (iconPrefix || 'https://noteyd.chaoxing.com/res/plugin/ueditor/') + 'themes/default/images/right.png" /></i><span class="tipstext">' + msg + '<span></div>')
} else {
$('.toolTipBox .popicon').removeClass('loading')
$('.toolTipBox .tipstext').text(msg);
}
if (type == 0) {
$('.toolTipBox img').attr('src', (iconPrefix || 'https://noteyd.chaoxing.com/res/plugin/ueditor/') + 'themes/default/images/wrong.png');
} else {
$('.toolTipBox img').attr('src', (iconPrefix || 'https://noteyd.chaoxing.com/res/plugin/ueditor/') + 'themes/default/images/right.png');
}
$('.toolTipBox').show();
setTimeout(function () {
$('.toolTipBox').fadeOut();
}, 3000)
}
RichTextUitl.showPreview = function (attachment, $iframe) {
// 镜像不支持预览
// if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.isMirrorDeploy) {
// return false;
// }
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
return false;
}
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.NoteDomain.indexOf('chaoxing.com') == -1 && window.obj.mirrorDomain.previewDomainHttps.indexOf('chaoxing.com') > -1) {
//笔记是单位域名,预览是超星域名,不允许预览
if (!(RichTextUitl.cloudUrl && RichTextUitl.cloudUrl.indexOf('pan-yz.chaoxing.com') > -1)) {
return false
}
}
if (typeof RichTextUitl.cloudUrl != 'undefined' && RichTextUitl.cloudUrl.indexOf('pan-yz.chaoxing.com') == -1) {
//使用非公网云盘的不允许预览
return false;
}
//设置了预览设置的,登录后允许预览,允许预览的才可以预览,不允许预览的不能预览
var icon = (attachment.att_clouddisk.suffix || '').toLowerCase();
if ((icon.indexOf('ppt') > -1 || icon.indexOf('doc') > -1
|| icon.indexOf('xls') > -1 || icon.indexOf('pdf') > -1)
&& attachment.att_clouddisk && $iframe.attr('preview') != 'true'
&& !($iframe.attr('allowpreview') == 'no' || $(this).attr('preview') == 'no' || (($iframe.attr('allowpreview') == 'login' || $(this).attr('preview') == 'login') && !RichTextUitl.isLogin))) {
return true;
}
return false;
}
// 文件类型:显示复制、下载、保存到云盘、转发、批量编辑,
// 其中PPT、Word、Excel、PDF显示复制、预览、下载、保存到云盘、转发、批量编辑下载是否显示根据文档是否设置了“登录后可下载”。
// 视频:显示复制、下载、保存到云盘、转发
// 录音、音频和笔记、话题等其他附件:显示复制、保存到云盘、转发
RichTextUitl.iframehover = function (selector) {
if (RichTextUitl.unAllowOpenAttach) {
//不允许打开附件
return;
}
var isNote = typeof WinInitConfig != 'undefined' && WinInitConfig.note;
RichTextUitl.isCreator = isNote && WinInitConfig.user.puid == WinInitConfig.note.createrPuid;
var iframe = $(selector).find('iframe.attach-module');
for (var i = 0; i < iframe.length; i++) {
if (!iframe.eq(i).parent().hasClass('editor-iframe')) {
var div = document.createElement('div');
div.className = 'editor-iframe';
iframe.eq(i).before(div);
div.appendChild(iframe.eq(i)[0])
}
iframe.parent().css('position', 'relative');
if ((iframe.eq(i).attr('download') && (iframe.eq(i).attr('download') == 'false' || !RichTextUitl.isLogin)) && !(typeof (WinInitConfig) != 'undefined' && WinInitConfig.isCreator == '1')) {
//不是自己的笔记,不允许下载或未登录不允许下载
iframe.eq(i).parent().addClass('noSelect');
} else if (((iframe.eq(i).attr('download') == 'no') || (iframe.eq(i).attr('download') == 'login' && !RichTextUitl.isLogin)) && !(typeof (WinInitConfig) != 'undefined' && WinInitConfig.isCreator == '1')) {
//协作笔记转化:不是自己的笔记,不允许下载或未登录不允许下载
iframe.eq(i).parent().addClass('noSelect');
}
if (iframe.eq(i).attr('allowPreview') == 'no') { //禁止预览改为登录后允许预览
iframe.eq(i).attr('allowPreview', 'login')
}
//登录后允许预览的,下载改为登录后允许下载
if (iframe.eq(i).attr('allowPreview') == 'login' && ((!iframe.eq(i).attr('allowdownload') && !iframe.eq(i).attr('download')) || (iframe.eq(i).attr('allowdownload') == 'true' && iframe.eq(i).attr('download') == 'false'))) {
iframe.eq(i).attr('allowdownload', false);
iframe.eq(i).attr('download', true);
}
}
var attachment = '';
// 判断是否登录了
$(selector).find('iframe,.iframehover').unbind();
$(selector).find('iframe,.iframehover').on('mouseover', function () {
if ($(this).parent().find('.iframehover').length > 0) {
$(this).parent().find('.iframehover').show()
return;
}
var $iframe = $(this).parent().find('iframe');
var iframeDiv = $iframe.parent()
attachment = RichTextUitl.b64DecodeUnicode($iframe.attr('name'))
if (!attachment) {
return;
}
// $('.iframehover.attachhover').remove();
var partcommenthtml = '';
if (window.location.host.indexOf('note') > -1 && window.location.host.indexOf('chaoxing') > -1) {
partcommenthtml = '<i class="spliteline"></i><div class="opitem partCommentBtn"></div>';
}
var downloadHtml = '';
switch (attachment.attachmentType) {
case 18 :
// 云盘,云盘附件的所有按钮:复制、预览、下载、保存到云盘、转发、批量编辑
// 判断是否显示下载按钮
// download 控制是否可以登录后下载, allowdownload 控制是否可以下载
downloadHtml = '<div class="opitem download">' + RichTextUitl.getI18nContent('download') + '</div>';
if ($iframe.attr('download') == 'true') {
if (!RichTextUitl.isLogin) {
// 设置了登录后才能下载,未登录时,不能下载
downloadHtml = '';
}
} else if ($iframe.attr('allowdownload') == 'false') {
// 既没有开启允许下载的选项,也没开启登录后允许下载的选项
downloadHtml = '';
} else if (($iframe.attr('download') == 'no') || ($iframe.attr('download') == 'login' && !RichTextUitl.isLogin)) {
downloadHtml = ''
}
var downloadAttr = true;
if (!downloadHtml) {
downloadAttr = false;
}
var iframeFullscreenHtml = '';
if ($iframe.attr('advancedpreview') && $iframe.attr('advancedpreview') == 'true') {
iframeFullscreenHtml = '<div class="opitem iframefullscreen">' + RichTextUitl.getI18nContent('fullscreen') + '</div>'
}
// 判断是否支持预览
var previewHtml = '';
if (RichTextUitl.showPreview(attachment, $iframe)) {
previewHtml = '<div class="opitem preview" download="' + downloadAttr + '">' + RichTextUitl.getI18nContent('preview') + '</div>'
}
var html = '<div class="iframehover attachhover operatehover">'
+ iframeFullscreenHtml
+ '<div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>'
+ previewHtml
+ downloadHtml;
if (RichTextUitl.isLogin) {
// 登录了
if (previewHtml && downloadHtml) {
// 有预览按钮
html += '<i class="spliteline"></i><div class="opitem opmore">' + RichTextUitl.getI18nContent('more') + '</div>'
+ '<div class="moreList">'
+ '<div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div>'
+ '<div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div>'
+ '<div class="opitem batch">' + RichTextUitl.getI18nContent('bultEdit') + '</div>'
+ '</div>'
} else {
html += '<div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div>'
+ '<i class="spliteline"></i><div class="opitem opmore">' + RichTextUitl.getI18nContent('more') + '</div>'
+ '<div class="moreList">';
if (!(window.obj && window.obj.mirrorDomain && (window.obj.mirrorDomain.isMirrorDeploy || window.obj.mirrorDomain.isMirrorDeploy == false && window.obj.mirrorDomain.NoteDomain.indexOf('chaoxing.com') == -1))) {
html += '<div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div>';
}
html += '<div class="opitem batch">' + RichTextUitl.getI18nContent('bultEdit') + '</div></div>'
}
} else {
// 未登录不允许批量编辑批量编辑需要puid和token,分享页不登录的情况下取不到puid和token
// if (previewHtml && downloadHtml) {
// // 有预览按钮和下载按钮
// html += '<i class="spliteline"></i><div class="opitem opmore">' + RichTextUitl.getI18nContent('more') + '</div>'
// + '<div class="moreList">'
// + '<div class="opitem batch">' + RichTextUitl.getI18nContent('bultEdit') + '</div>'
// + '</div>'
// } else {
// html += '<div class="opitem batch">' + RichTextUitl.getI18nContent('bultEdit') + '</div>'
// }
}
html += '</div>';
// if ($(this)[0].tagName === "A") {
// // 文本链接形式的弹框和附件的不同
// $(this).addClass('textHover');
// var textWidth = Number($(this).css('width').slice(0,-2))+Number($(this).css('padding-left').slice(0,-2))+Number($(this).css('padding-right').slice(0,-2));
// var textHtml = '<div class="textMoreHover operatehover"><div class="cutLine"></div>更多<div class="menuCtrl">';
// if (previewHtml) {
// // 支持预览
// textHtml += '<div class="preview">预览</div>'
// }
// if (downloadHtml) {
// // 支持下载
// textHtml += '<div class="download">下载</div>';
// }
// if (RichTextUitl.isLogin) {
// // 登录了才显示保存到云盘
// textHtml += '<div class="save">保存到云盘</div>';
// }
// textHtml += '<div class="forwardiframe">转发</div><div class="batch">批量编辑</div></div></div>';
// $(this).parent().addClass('hover').append(textHtml);
// var textMoreHeight = Number($('.textMoreHover').css('height').slice(0,-2));
// $(this).parent().children('.textMoreHover').css('left',textWidth+'px')
// $(this).parent().children('.textMoreHover').children('.menuCtrl').css('top',textMoreHeight+'px')
// } else {
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>' + previewHtml + '</div>'
}
$(this).parent().addClass('hover').append(html);
$(this).parent().find('.opmore,.moreList').on('mouseover', function () {
$('.moreList').show();
}).on('mouseleave', function () {
$('.moreList').hide();
});
$(this).parent().find('.moreList .opitem').on('click', function () {
$('.moreList').hide();
})
// }
break;
case 26 :
//音频
// 判断是否显示下载按钮
var downloadHtml = '<div class="opitem download">' + RichTextUitl.getI18nContent('download') + '</div>';
if ($iframe.attr('download') == 'true') {
if (!RichTextUitl.isLogin) {
// 设置了登录后才能下载,未登录时,不能下载
downloadHtml = '';
}
} else if ($iframe.attr('allowdownload') == 'false') {
// 既没有开启允许下载的选项,也没开启登录后允许下载的选项
downloadHtml = '';
} else if (($iframe.attr('download') == 'no') || ($iframe.attr('download') == 'login' && !RichTextUitl.isLogin)) {
downloadHtml = '';
}
var html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>' + downloadHtml + '<div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div><div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div></div>'
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div></div>'
}
$(this).parent().addClass('hover').append(html);
break;
case 1 :
case 2 :
case 8 :
//音频,话题,笔记,通知
var html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div><div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div><div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div></div>'
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div></div>'
}
$(this).parent().addClass('hover').append(html);
break;
case 29 :
// 视频
// 判断是否显示下载按钮
var downloadHtml = '<div class="opitem download">' + RichTextUitl.getI18nContent('download') + '</div>';
if ($iframe.attr('download') == 'true') {
if (!RichTextUitl.isLogin) {
// 设置了登录后才能下载,未登录时,不能下载
downloadHtml = '';
}
} else if ($iframe.attr('allowdownload') == 'false') {
// 既没有开启允许下载的选项,也没开启登录后允许下载的选项
downloadHtml = '';
} else if (($iframe.attr('download') == 'no') || ($iframe.attr('download') == 'login' && !RichTextUitl.isLogin)) {
downloadHtml = '';
}
var html = '<div class="iframehover attachhover operatehover">'
+ '<div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>'
+ downloadHtml
+ '<div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div>'
+ '<div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div>';
// if (RichTextUitl.isLogin) {
// html += '<div class="opitem save">保存到云盘</div>'
// + '<i class="spliteline"></i><div class="opmore"></div>'
// + '<div class="moreList">'
// + '<div class="opitem forwardiframe">转发</div>'
// + '<div class="opitem batch">批量编辑</div>'
// + '</div>'
// } else {
// html += '<div class="opitem batch">批量编辑</div>'
// }
html += '</div>'
if (!downloadHtml) {
// 不允许下载时,不显示所有操作按钮
html = '';
}
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>' + downloadHtml + '</div>'
}
$(this).parent().addClass('hover').append(html);
$(this).parent().find('.opmore,.moreList').on('mouseover', function () {
$('.moreList').show();
}).on('mouseleave', function () {
$('.moreList').hide();
});
$(this).parent().find('.moreList .opitem').on('click', function () {
$('.moreList').hide();
})
break;
case 25 :
// 网页附件
var html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div><div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div></div>';
if ($iframe.attr('excel') == 'true') {
// 在线表格
// 判断是否显示转发和下载按钮
var downloadHtml = '<div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div><div class="opitem download">' + RichTextUitl.getI18nContent('download') + '</div>';
if ($iframe.attr('download') == 'true') {
if (!RichTextUitl.isLogin) {
// 设置了登录后才能下载,未登录时,不能下载
downloadHtml = '';
}
} else if ($iframe.attr('allowdownload') == 'false') {
// 既没有开启允许下载的选项,也没开启登录后允许下载的选项
downloadHtml = '';
} else if (($iframe.attr('download') == 'no') || ($iframe.attr('download') == 'login' && !RichTextUitl.isLogin)) {
downloadHtml = ''
}
var html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div>' + downloadHtml + '</div>';
}
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div></div>'
}
$(this).parent().addClass('hover').append(html);
break;
case 15 :
// if (!(attachment.att_chat_course.type && attachment.att_chat_course.type == 4)) {
// break;
// }
case 3 :
case 4 :
case 6 :
case 7 :
case 8 :
case 10 :
case 11 :
case 17 :
case 20 :
case 24 :
case 33 :
case 38 :
case 40 :
case 41 :
case 44 :
case 47 :
case 48 :
// 云盘文件夹, 笔记文件夹、小组、话题文件夹、课程附件、位置、个人名片
// 收藏文件夹、专题、课程、课程章节、小组资料文件夹、网页附件、速课
var html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div><div class="opitem forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div></div>';
if (window.location.host.indexOf('course.ustc.edu.cn') > -1 && !(RichTextUitl.prefix && RichTextUitl.prefix.indexOf('chaoxing.com') > -1)) {
html = '<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div></div>'
}
$(this).parent().addClass('hover').append(html);
break;
default :
$(this).parent().addClass('hover').append('<div class="iframehover attachhover operatehover"><div class="opitem copy">' + RichTextUitl.getI18nContent('copy') + '</div></div>');
}
/*
*@Description: 附件悬浮工具栏 屏蔽除下载外的所有按钮的无障碍焦点
*@Author:LiChangChang
*@Date: 2022-10-24 11:55:39
*/
$('.iframehover .opitem').attr("tabindex", "-1")
$('.iframehover .download').attr("tabindex", "0")
$('.iframehover .download').attr("role", "button")
//镜像只显示下载和复制
if (RichTextUitl.intranetMode) {
$('.attachhover .save,.attachhover .opmore,.attachhover .forwardiframe,.attachhover .batch,.attachhover .preview,.attachhover .spliteline').hide();
}
//镜像或cname笔记域名是单位域名分享域名是超星域名不显示转发按钮
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.shareWhDomainHttps.indexOf('chaoxing.com') > -1 && window.obj.mirrorDomain.NoteDomainHttps.indexOf('chaoxing.com') == -1) {
$('.attachhover .forwardiframe,.attachhover .spliteline').hide();
}
if (!RichTextUitl.isLogin || typeof ForwardUtils == 'undefined') {
// 未登录时,不显示保存到云盘,转发
$('.attachhover .save').hide();
$('.attachhover .forwardiframe,.attachhover .opmore,.attachhover .spliteline').hide();
} else if (window.location.host.indexOf('note') > -1 && window.location.host.indexOf('chaoxing.com') > -1) {
//部分评论暂时不上,先注释
// $(this).parent().find('.iframehover').append(partcommenthtml);
}
//设置了不允许下载附件
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) {
iframeDiv.find('.iframehover').remove();
}
}
if (!RichTextUitl.isCreator && attachment.attachmentType == 18 && !downloadHtml) {
// 不能下载时
iframeDiv.find('.attachhover .copy,.attachhover .save,.attachhover .forwardiframe,.attachhover .batch,.attachhover .opmore,.attachhover .spliteline').hide();
}
if (!iframeDiv.find('.iframehover .opitem').is(':visible')) {
// 所有的操作按钮都被隐藏了,隐藏当前弹框
iframeDiv.find('.iframehover').remove();
}
});
$(selector).find('.editor-iframe').on('mouseleave', function () {
$(this).removeClass('hover').find('.iframehover').hide();
});
$(selector).find('a.iframe').on('click', '.textMoreHover', function (e) {
e.stopPropagation();
e.preventDefault();
})
//文本附件点击
RichTextUitl.linkAttachClick(selector);
$(selector).find('a.iframe').on('mouseover', function () {
if ($(this).parent().find('.textMoreHover').length > 0) {
$(this).parent().find('.textMoreHover').show()
return;
}
attachment = RichTextUitl.b64DecodeUnicode($(this).attr('name'))
var downloadHtml = '<div class="opitem download">' + RichTextUitl.getI18nContent('download') + '</div>';
if ($(this).attr('download') == 'true') {
// 设置了登录后才能下载,未登录时,不能下载
if (!RichTextUitl.isLogin) {
downloadHtml = '';
}
} else if ($(this).attr('allowdownload') == 'false') {
// 既没有开启允许下载的选项,也没开启登录后允许下载的选项
downloadHtml = '';
} else if ($(this).attr('download') == 'no' || $(this).attr('download') == 'login' && !RichTextUitl.isLogin) {
downloadHtml = ''
}
var previewHtml = ''
if (RichTextUitl.showPreview(attachment, $(this))) {
previewHtml = '<div class="opitem preview">' + RichTextUitl.getI18nContent('preview') + '</div>'
}
$(this).addClass('textHover');
var textWidth = $(this).outerWidth();
var textHtml = '<div class="textMoreHover operatehover"><span>' + RichTextUitl.getI18nContent('more') + '</span><div class="menuCtrl">';
if (previewHtml) {
// 支持预览
textHtml += '<div class="preview">' + RichTextUitl.getI18nContent('preview') + '</div>'
}
if (downloadHtml) {
// 支持下载
textHtml += '<div class="download">' + RichTextUitl.getI18nContent('download') + '</div>';
}
if (RichTextUitl.isLogin) {
// 登录了才显示保存到云盘
textHtml += '<div class="save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div>';
}
textHtml += '<div class="forwardiframe">' + RichTextUitl.getI18nContent('Share') + '</div><div class="batch">' + RichTextUitl.getI18nContent('bultEdit') + '</div></div></div>';
$(this).addClass('hover').append(textHtml);
if (downloadHtml == '' || (!RichTextUitl.isLogin || typeof ForwardUtils == 'undefined')) {
// 未登录时,不显示保存到云盘,转发
$('.textMoreHover .save,.textMoreHover .forwardiframe,.textMoreHover .batch').hide();
}
var textMoreHeight = Number($('.textMoreHover').css('height').slice(0, -2));
// 文本附件悬浮框的位置
var rects = this.getClientRects();
var aLeft = rects.length > 1 ? -(rects[0].left - selector.getClientRects()[0].left) + rects[rects.length - 1].width - 4 : textWidth;
var aTop = rects.length > 1 ? (rects.length - 1) * ($(this).height() / rects.length) + 4 + 'px' : '-1px';
$(this).children('.textMoreHover').css({'left': aLeft + 'px', 'top': aTop})
$(this).find('.menuCtrl').css('top', textMoreHeight + 'px');
if (!downloadHtml) {
// 不能下载时
$('.textMoreHover.operatehover').hide();
}
//设置了不允许下载附件
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($(this).attr('filetype')) > -1) {
$(this).parent().find('.textMoreHover').remove();
$(this).attr('download', 'false').attr('allowdownload', 'false')
}
}
if ($(this).parent().find('.textMoreHover .menuCtrl>div:not([style])').length == 0) {
// 所有的操作按钮都被隐藏了,隐藏当前弹框
$(this).parent().find('.textMoreHover').remove();
}
});
$(selector).find('a.iframe').on('mouseleave', function () {
$(this).removeClass('hover').removeClass('textHover').find('.textMoreHover').hide();
});
//全屏
$(selector).find('.editor-iframe')
.off("click", ".operatehover .iframefullscreen")
.on('click', '.operatehover .iframefullscreen', function () {
var iframeSrc = $(this).parents('.editor-iframe').find('iframe').attr('src');
window.open(iframeSrc)
})
// 复制
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .copy")
.on('click', '.operatehover .copy', function () {
window.dt = new clipboard.DT();
var iframediv;
if ($(this).parents('.editor-iframe').length > 0) {
iframediv = $(this).parents('.editor-iframe')
} else if (this.tagName == 'A') {
iframediv = $(this);
}
if (!iframediv) {
return;
}
iframediv.find('.operatehover').remove();
dt.setData("text/html", iframediv[0].outerHTML);
clipboard.write(dt).then(function () {
if ($('.toolTipBox').length > 0) {
$('.toolTipBox').remove()
}
$(document.body).append('<div class="toolTipBox" style="display:none;"><i class="popicon"><img src="https://noteyd.chaoxing.com/res/plugin/ueditor/themes/default/images/right.png" /></i><span class="tipstext">' + RichTextUitl.getI18nContent('copySuccess') + '<span></div>')
$('.toolTipBox .tipstext').text(RichTextUitl.getI18nContent('copySuccess'));
$('.toolTipBox').show();
setTimeout(function () {
$('.toolTipBox').fadeOut();
}, 1500)
}, function (err) {
console.log(err);
});
})
/*
*@Description: 点击下载按钮适配无障碍
*@Author:LiChangChang
*@Date: 2022-10-26 13:49:33
*/
document.onkeyup = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 32) {
if ($(':focus').attr('class') == "opitem download") {
$(':focus').click()
}
}
};
// 下载
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .download")
.on('click', '.operatehover .download', function () {
if ($(this).parents('a.iframe').length > 0) {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('a.iframe').attr('name'))
} else {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('.editor-iframe').find('iframe').attr('name'))
}
if (attachment.attachmentType == 25 && attachment.att_web.excel) {
// 在线表格
$('iframe[cid="' + attachment.cid + '"]')[0].contentWindow.postMessage({'msgType': 'download'}, '*')
return;
}
if (RichTextUitl.intranetMode) {
//镜像模式,直接下载
var downloadUrl, playUrl, objectId;
switch (attachment.attachmentType) {
case 18 :
// 云盘
downloadUrl = attachment.att_clouddisk.downPath || attachment.att_clouddisk.downloadUrl;
playUrl = attachment.att_clouddisk.playUrl;
objectId = attachment.att_clouddisk.fileId;
break;
case 26 :
//音频
downloadUrl = attachment.att_voice.downloadUrl;
playUrl = attachment.att_voice.playUrl;
objectId = attachment.att_voice.objectId;
break;
case 29 :
// 视频
downloadUrl = attachment.att_video.downloadUrl;
playUrl = attachment.att_video.playUrl;
objectId = attachment.att_video.objectId2;
break;
}
if (downloadUrl) {
//如果是云盘地址,接口实时获取下载地址
if (downloadUrl.indexOf('d0.ananas.chaoxing.com') > -1 || downloadUrl.indexOf('d0.cldisk.com') > -1) {
YunFileUtil.downloadYunFile(attachment);
} else {
if (self != top && location.protocol.indexOf('https') != -1) {
// 嵌入在iframe里面// https服务下下载地址换成https的
downloadUrl = downloadUrl.replace("http://", 'https://');
} else {
downloadUrl = downloadUrl.replace("http://", 'https://');
}
window.location.href = downloadUrl;
}
} else if (!objectId && playUrl) {
//视频没有下载地址的,用播放地址下载
var a = document.createElement('a');
$('body').append('<a style="display:none;" download id="open_attachment" target="_blank" href="' + playUrl + '"></a>');
var el = document.getElementById('open_attachment');
el.click();//触发打开事件
$(el).remove();
} else {
YunFileUtil.downloadYunFile(attachment);
}
} else {
YunFileUtil.downloadYunFile(attachment);
}
})
// 预览
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .preview")
.on('click', '.operatehover .preview', function () {
// window.open("https://pan-yz.chaoxing.com/screen/fileinfo_"+attachment.att_clouddisk.resid)
// $(this).parent().siblings('iframe').eq(0).attr("src"
// , "https://previewyd.chaoxing.com/res/view/view.html?opentype=full&objectid="+attachment.att_clouddisk.fileId)
if ($(this).parents('a.iframe').length > 0) {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('a.iframe').attr('name'))
} else {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('.editor-iframe').find('iframe').attr('name'))
}
var fileName = attachment.att_clouddisk.name;
if (fileName.indexOf('.' + attachment.att_clouddisk.suffix) > -1) {
fileName = fileName.substring(0, fileName.indexOf('.' + attachment.att_clouddisk.suffix));
}
var puid = attachment.att_clouddisk.puid;
if (!puid) {
puid = attachment.att_clouddisk.infoJsonStr ? (attachment.att_clouddisk.infoJsonStr.puid || '') : '';
}
if ($(this).parents('.dynacALink').length == 0 && $(this).parents('.editor-iframe').length > 0) {
//获取iframe的域名作为获取预览地址的域名解决部分单位编辑页超星域名详情页单位域名未配置单位域名点预览打不开
var iframeSrc = $(this).parents('.operatehover').siblings('iframe').attr('src');
var iframeDomain = '';
if (iframeSrc.indexOf('//') > -1) {
iframeSrc = iframeSrc.substring(iframeSrc.indexOf('//') + 2, iframeSrc.length)
iframeDomain = iframeSrc.substring(0, iframeSrc.indexOf('/'))
}
}
//实现ppt、word点击掉“调用方”传过来的方法
if (RichTextUitl.openPreview && typeof RichTextUitl.openPreview === "object" && RichTextUitl.openPreview.type.indexOf(attachment.att_clouddisk.suffix) > -1) {
if (RichTextUitl.openPreview.name && typeof window[RichTextUitl.openPreview.name] == 'function' && attachment.cid) {
window[RichTextUitl.openPreview.name](attachment.cid, attachment.att_clouddisk)
return;
}
}
//调接口获取enc
RichTextUitl.getPreviewUrl(attachment.att_clouddisk.fileId, encodeURIComponent(fileName), $(this).attr('download'), null, iframeDomain, attachment.att_clouddisk.resid);
/*window.open(window.location.protocol + "//previewyd.chaoxing.com/res/view/view.html?opentype=full&objectid="
+attachment.att_clouddisk.fileId + '&fileName='+encodeURIComponent(fileName)
+ '&download=' + $(this).attr('download');*/
})
// 保存到云盘
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .save")
.on('click', '.operatehover .save', function () {
if ($(this).parents('a.iframe').length > 0) {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('a.iframe').attr('name'))
} else {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('.editor-iframe').find('iframe').attr('name'))
}
var obj = ''
switch (attachment.attachmentType) {
case 18 :
// 云盘
obj = {
fileId: attachment.att_clouddisk.fileId,
name: attachment.att_clouddisk.name
}
break;
case 26 :
//音频
obj = {
fileId: attachment.att_voice.objectId2,
name: attachment.att_voice.fileTitle
}
break;
case 29 :
// 视频
obj = {
fileId: attachment.att_video.objectId2,
name: attachment.att_video.fileTitle
}
break;
case 1 : // 话题
case 2 : // 笔记
case 8 : // 通知
obj = attachment;
break;
}
var array = new Array();
array.push(obj)
CLOUD_POP.openCloudPop(array);
})
// 批量编辑
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .batch")
.on('click', '.operatehover .batch', function () {
CLOUD_POP.openBatchPop();
})
// 转发
$(selector).find('.editor-iframe,a.iframe')
.off("click", ".operatehover .forwardiframe")
.on('click', '.operatehover .forwardiframe', function () {
if ($(this).parents('a.iframe').length > 0) {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('a.iframe').attr('name'))
} else {
attachment = RichTextUitl.b64DecodeUnicode($(this).parents('.editor-iframe').find('iframe').attr('name'))
}
ForwardUtils.forward(attachment);
})
}
// 文本附件的点击事件
RichTextUitl.linkAttachClick = function (selector) {
$(selector).find('a.iframe').on('click', function (e) {
e.stopPropagation();
e.preventDefault();
attachment = RichTextUitl.b64DecodeUnicode($(this).attr('name'))
if ($(this).attr('href')) {
$(this).attr('_href', $(this).attr('href'))
$(this).attr('href', '')
}
if (!RichTextUitl.isSupportPreview($(this).attr('name'))) {
//不可预览的附件
if ((($(this).attr('download') == 'true' && $(this).attr('allowdownload') == 'false') || ($(this).attr('download') == 'login') && !RichTextUitl.isLogin)) {
//登录后下载
RichTextUitl.showTips('作者设置该附件登录后允许下载', 0);
} else if (($(this).attr('download') == 'false' && $(this).attr('allowdownload') == 'false') || $(this).attr('download') == 'no') {
//禁止下载
RichTextUitl.showTips('作者设置该附件禁止下载', 0);
return;
} else {
//允许下载
if (RichTextUitl.intranetMode) {
window.open($(this).attr('_href'));
} else {
var url = RichTextUitl.noteDomain + '/res/plugin/mnote/attachInterface.html?fileId=' + attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(attachment.att_clouddisk.name) + '&allowDownload=false&fileSize=' + attachment.att_clouddisk.fileSize + '&originUrl=' + encodeURIComponent(window.location.href);
if (RichTextUitl.isXXT && window.self == window.top) {
//学习通里调用协议
if (window.location.host.indexOf('mobilelearn') > -1 || window.location.host.indexOf('sharewh') > -1
|| attachment.attachmentType != 29) {
try {
jsBridge.postNotification('CLIENT_OPEN_ATTACHMENT', attachment);
} catch (e) {
}
}
} else if (RichTextUitl.isXXT && window.self != window.top) {
//客户端里打开,给
if (window.location.host.indexOf('mobilelearn') > -1 || window.location.host.indexOf('sharewh') > -1
|| attachment.attachmentType != 29) {
try {
if (top.jsBridge) {
top.jsBridge.postNotification('CLIENT_OPEN_ATTACHMENT', attachment);
} else {
window.top.location.href = url
}
} catch (e) {
window.top.location.href = url
}
}
} else if (RichTextUitl.isWeiXin || RichTextUitl.isQQ) {
//微信或QQ打开中间页
window.location.href = url
} else {
YunFileUtil.downloadYunFile(attachment);
}
}
}
} else if ($(this).attr('download') == 'false' && $(this).attr('allowdownload') == 'false' || $(this).attr('download') == 'no' || !RichTextUitl.isLogin && (($(this).attr('download') == 'true' && $(this).attr('allowdownload') == 'false') || $(this).attr('download') == 'login')) {
//上传的文档,设置成文本模式时,如果该附件设置了不允许下载,点击的时候进预览页
if (($(this).attr('download') == 'true' && $(this).attr('allowdownload') == 'false') || $(this).attr('download') == 'login') {
//登录后下载
if (!RichTextUitl.isLogin && ($(this).attr('allowpreview') == 'login' || $(this).attr('preview') == 'login')) {
//登录后下载登录后预览
RichTextUitl.showTips('作者设置该附件登录后允许预览、下载', 0);
return;
} else if ($(this).attr('allowpreview') == 'no' || $(this).attr('preview') == 'no') {
//登录后下载,禁止预览
RichTextUitl.showTips('作者设置该附件登录后允许下载', 0);
return;
}
} else if (!RichTextUitl.isLogin && ($(this).attr('allowpreview') == 'login' || $(this).attr('preview') == 'login')) {
//禁止下载,登录后预览
RichTextUitl.showTips('作者设置该附件登录后允许预览', 0);
return;
} else if ($(this).attr('allowpreview') == 'no' || $(this).attr('preview') == 'no') {
//禁止下载禁止预览
RichTextUitl.showTips('作者设置该附件禁止下载、预览', 0);
return;
}
var attachment = RichTextUitl.b64DecodeUnicode($(this).attr('name'))
if (RichTextUitl.intranetMode && attachment.att_clouddisk && attachment.att_clouddisk.previewUrl) {
e.stopPropagation();
e.preventDefault();
$(this).attr('_href', attachment.att_clouddisk.previewUrl);
window.open($(this).attr('_href'))
} else {
var iframeSrc = window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid=' +
attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(attachment.att_clouddisk.name.split('.')[0]);
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.previewDomainHttps) {
iframeSrc = window.obj.mirrorDomain.previewDomainHttps + '/res/view/view.html?objectid=' +
attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(attachment.att_clouddisk.name.split('.')[0]);
}
if (!RichTextUitl.isGetVideoDataFromCenter) {
resid = attachment.att_clouddisk.resid
iframeSrc += '&resid=' + resid;
}
if (RichTextUitl.useWpsPreview) {
iframeSrc += '&type=wps';
}
window.open(iframeSrc)
}
} else {
//能预览,能下载
if (RichTextUitl.intranetMode) {
window.open($(this).attr('_href'));
} else if (RichTextUitl.isXXT && window.self == window.top) {
//学习通里调用协议
if (window.location.host.indexOf('mobilelearn') > -1 || window.location.host.indexOf('sharewh') > -1
|| attachment.attachmentType != 29) {
try {
jsBridge.postNotification('CLIENT_OPEN_ATTACHMENT', attachment);
} catch (e) {
}
}
} else if (RichTextUitl.isWeiXin || RichTextUitl.isQQ) {
//微信或QQ打开中间页
url = RichTextUitl.noteDomain + '/res/plugin/mnote/attachInterface.html?fileId=' + attachment.att_clouddisk.fileId + '&fileName=' + encodeURIComponent(attachment.att_clouddisk.name) + '&allowPreview=true&allowDownload=true&fileSize=' + attachment.att_clouddisk.fileSize + '&originUrl=' + encodeURIComponent(window.location.href);
window.location.href = RichTextUitl.convertUrl(url)
} else {
YunFileUtil.downloadYunFile(attachment);
}
return;
}
})
}
//鼠标移上图片时,图片上方显示复制、下载的菜单
RichTextUitl.imgHover = function (selector) {
var img = $(selector).find('img');
$('body').on('contextmenu', '.richtext img,.viewer-canvas img', function () {
//判断如果不允许下载
if ($(this).hasClass('noSelect') || RichTextUitl.disableImageContextMenu) {
//不是自己的笔记,不允许下载或未登录不允许下载
return false;
}
});
img.unbind();
img.parent().unbind();
$(selector).find('.imghover').unbind();
img.parent().css('position', 'relative');
var saveHtml = '';
if (RichTextUitl.isLogin) {
saveHtml = '<div class="opitem save">' + RichTextUitl.getI18nContent('saveToCloud') + '</div>';
}
$('body').click(function (e) {
if (e.target.nodeName != 'IMG' && !$(e.target).hasClass('viewer-canvas') && !$(e.target).hasClass('viewBtnWrap') && $(e.target).parents('.viewBtnWrap').length == 0) {
$('.editor-image').removeClass('active').removeClass('hover')
$('.imghover.attachhover').remove();
}
});
img.on('mouseover', function () {
$(this).parent().addClass('hover');
})
//PC端才会执行
img.on('click', function (e) {
if ($(this).attr('data-link')) {
//如果图片上有链接,直接打开
e.stopPropagation();
e.preventDefault();
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 (this.id && this.id == "signImg") {
return;
}
if (typeof isShare != "undefined" && isShare) {//分享页不出现图片工具栏
return;
}
if (window.location.host.indexOf('note') > -1 && $('.partCommentWrap').length > 0) {
//笔记部分评论,点击图片滚动到评论位置
if ($('.partCommentWrap').length == 0) return;
$('.partCommentItem').removeClass('active');
partCommentPlugin.hideInputComment();
$('.selectedComment').removeClass('selectedComment');
if ($(this).hasClass('hasPartComment')) {
$(this).parent().addClass('selectedComment');
}
var objectId = $(this).attr('objectId');
var elementId = $(this).parent().attr('element-id');
var partCm;
if (elementId) {
partCm = $('.partCommentItem[objectId=' + objectId + '][elementId=' + elementId + ']');
} else {
partCm = $('.partCommentItem[objectId=' + objectId + ']');
}
if (partCm.length > 0) {
//显示右侧评论列表弹窗
$('.partCommentWrap .partCommentDiv').css('left', '0');
$('.partCommentWrap .navDiv').fadeOut();
//滚动到当前位置
var targetToTop = $(this).offset().top - document.scrollingElement.scrollTop - 100; //图片距离页面顶部的距离
targetToTop = targetToTop > 0 ? targetToTop : 0;
$('.partCommentMain')[0].scrollTo({
top: partCm[0].offsetTop - targetToTop,
behavior: "smooth"
});
partCm.eq(0).addClass('active');
}
}
if (!$(this).parent().hasClass('active')) {
if($(this).parents('a').length == 0){ //秀米a链接里是图片时点击事件冒泡到上层话题要获取a链接的点击事件这里阻止冒泡后就不会触发上层的点击事件
e.stopPropagation();
}
$(this).parent().attr('focus','true');
} else {
$(this).parent().removeAttr('focus');
return;
}
$('.editor-image').removeClass('active').removeClass('hover')
$('.imghover.attachhover').remove();
// var linkhtml = '';
// if($(this).attr('data-link')){
// linkhtml = '<div class="opitem imglink">'+RichTextUitl.getI18nContent('打开链接')+'</div>';
// }
//图片全屏--笔记项目
var fullimghtml = "", partcommenthtml = '';
if (window.location.host.indexOf('note') > -1) {
if ($(this).parent().hasClass('full')) {
fullimghtml = '<div class="opitem fullimg">' + RichTextUitl.getI18nContent('exitFullscreen') + '</div>';
} else {
fullimghtml = '<div class="opitem fullimg">' + RichTextUitl.getI18nContent('fullscreen') + '</div>';
}
//部分评论
partcommenthtml = '<i class="spliteline"></i><div class="opitem partCommentBtn"></div>';
}
//20210928 设置是否允许下载不允许下载的不允许显示复制、下载和保存到云盘禁用右键禁用ctrl+c
var downloadhtml = '';
if (($(this).attr('download') && ($(this).attr('download') == 'false' || !RichTextUitl.isLogin)) && !(typeof (WinInitConfig) != 'undefined' && WinInitConfig.isCreator == '1')) {
//不是自己的笔记,不允许下载或未登录不允许下载
} else { //允许下载
downloadhtml = '<div class="opitem copy" >' + RichTextUitl.getI18nContent('copy') + '</div>' +
'<div class="opitem download" >' + RichTextUitl.getI18nContent('download') + '</div>' + saveHtml + partcommenthtml;
}
$(this).parent().addClass('hover').addClass('active').append('<div class="imghover attachhover">' + fullimghtml + downloadhtml + '</div>');
//镜像只显示下载和复制
if (RichTextUitl.intranetMode) {
$('.attachhover .save,.attachhover .opmore,.attachhover .batch,.attachhover .fullimg,.attachhover .spliteline').hide();
$('.imghover').hide();
}
//20210318
if ($(this).parents('.editor-image').css('float') === 'left' || $(this).parents('.editor-image').css('text-align') === 'left') {//居左
$('.imghover').css('right', $(this).parents('.editor-image').width() - $(this).width())
} else if ($(this).parents('.editor-image').css('float') === 'right' || $(this).parents('.editor-image').css('text-align') === 'right') {//居右
$('.imghover').css('right', 0)
} else {//居中
if ($(this).width() > $('.imghover').width()) {
$('.imghover').css('right', ($(this).parents('.editor-image').width() - $(this).width()) / 2 - 2)
} else {//图片宽度小于工具栏宽度
$('.imghover').css({
'top': '-40px',
'right': 'unset',
'left': $(this).parents('.editor-image').width() / 2 - $('.imghover').width() / 2
});
}
}
if ($(this).parents('.editor-image').length > 0) {
var offsetleft = $(this).parents('.editor-image').offset().left - $('.richtext').offset().left;
if (offsetleft + $(this).parents('.editor-image').width() < $('.imghover').width()) {
$('.imghover').css({'right': 'unset', 'left': '0'})
} else if (offsetleft + $('.imghover').width() > $('.richtext').width()) {
$('.imghover').css({'left': 'unset', 'right': '0'})
}
}
});
// img.on('mouseover',function(){
// let html = '<div class="imghover attachhover">' +
// '<div class="opitem copy" >复制</div>' +
// '<div class="opitem download" >下载</div>' +
// '<div class="opitem save">保存到云盘</div>' +
// '<div class="opitem batch">批量编辑</div>' +
// '</div>';
// $(this).parent().addClass('hover').append(html);
//
// $(this).parent().find('.opmore,.moreList').on('mouseover',function(){
// $('.moreList').show();
// }).on('mouseleave',function(){
// $('.moreList').hide();
// });
// $(this).parent().find('.moreList .opitem').on('click',function(){
// $('.moreList').hide();
// })
// });
img.parent().on('mouseleave', function () {
if (!$(this).hasClass('active')) {
$(this).removeClass('hover');
}
});
//图片全屏
img.parent().on('click', '.imghover .fullimg', function () {
if ($(this).parents('.editor-image').eq(0).hasClass('full')) {
//退出全屏
$(this).parents('.editor-image').eq(0).removeClass('full').css('left', '0');
} else if ($(this).parents('.editor-image').css('float') === 'right' || $(this).parents('.editor-image').css('text-align') === 'right') {
$(this).parents('.editor-image').eq(0).addClass('full').css('left', '0px');
} else {
// var left = $(this).parents('.editor-image').eq(0).offset().left - $('.richtext').offset().left;
$(this).parents('.editor-image').eq(0).addClass('full').css('left', '0px');
}
$(this).parents('.editor-image').eq(0).removeClass('hover').removeClass('active');
})
// 打开链接
img.parent().on('click', '.imghover .imglink', function () {
var link = $(this).parent().siblings('img').attr('data-link');
var openType = $(this).parent().siblings('img').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);
}
});
// 批量编辑
img.parent().on('click', '.imghover .batch', function () {
CLOUD_POP.openBatchPop();
})
img.parent().on('click', '.imghover .copy', function () {
window.dt = new clipboard.DT();
var img = $(this).parent().siblings('img')[0].cloneNode();
var div = document.createElement('div');
div.className = 'editor-image';
div.contentEditable = false;
div.appendChild(img);
dt.setData("text/html", div.outerHTML);
clipboard.write(dt).then(function () {
RichTextUitl.showTips(RichTextUitl.getI18nContent('copySuccess'));
}, function (err) {
console.log(err);
});
});
// 图片点击下载
$(selector).on('click', '.imghover .download', function () {
var imgSrc = $(this).parent().prev().attr('src');
if (RichTextUitl.intranetMode) {
//镜像模式,直接下载
if (self != top && location.protocol.indexOf('https') != -1) {
// 嵌入在iframe里面// https服务下下载地址换成https的
imgSrc = imgSrc.replace("http://", 'https://');
} else {
imgSrc = imgSrc.replace("http://", 'https://');
}
window.location.href = imgSrc;
} else {
// 客户端生成的图片标签上的objectid有问题不要直接用图片标签上的根据图片地址截取
var objectid = RichTextUitl.getObjectIdByImgSrc(imgSrc);
if (objectid) {
//需要加图片水印的
if(RichTextUitl.watermarkOptions && RichTextUitl.watermarkOptions.watermarkImageUrl){
objectid = RichTextUitl.generateWatermark(objectid, RichTextUitl.watermarkOptions) || objectid;
}
YunFileUtil.downloadYunFile('', objectid);
}
}
});
// 图片保存到云盘
$(selector).on('click', '.imghover .save', function () {
var obj = {};
var imgSrc = $(this).parent().prev().attr('src');
var objectid = RichTextUitl.getObjectIdByImgSrc(imgSrc);
if (!objectid) {
return;
}
var src = $(this).parents('.editor-image').find('img').attr('src');
var name = '';
if (src.indexOf('?')) {
name = src.substring(src.lastIndexOf('/') + 1, src.indexOf('?'))
} else {
name = src.substring(src.lastIndexOf('/') + 1);
}
obj = {
fileId: objectid,
name: name
}
var array = new Array();
array.push(obj)
CLOUD_POP.openCloudPop(array);
})
}
//调用接口生成带水印图片
RichTextUitl.generateWatermark = function (objectid, watermarkOptions) {
var newObjectId = '';
var data = {
objectid: objectid,
imageWatermarkConfig: watermarkOptions
}
$.ajax({
url: window.obj.mirrorDomain.NoteDomainHttps + '/pc/resource/imageWatermark',
type: 'post',
async: false,
contentType: 'application/json',
data: JSON.stringify(data),
success: function (data) {
if (data.result == 1) {
newObjectId = data.data
}
}
})
return newObjectId
}
/**
* base64编码和btoa编码
* @param str
* @returns {string}
*/
RichTextUitl.b64EncodeUnicode = function (str) {
str = str.replace(RichTextUitl.xssReg, function () {
return arguments[0] + ' ';
})
return btoa(encodeURIComponent(str))
}
/**
* base64解码码和atob
* @param str
* @returns {string}
*/
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 '';
}
/*
* @param selector包含图片标签的dom节点
* */
RichTextUitl.detailPageEvent = function (selector) {
// 记录是否登录了
RichTextUitl.isLogin = RichTextUitl.getCookie('UID') != '';
//点击录音打点时通知对应的音频iframe跳转到对应的时间点
$(".record-list-time").unbind("click");
$('body').on('click', '.record-list-time', function () {
var time = $(this).text();
if (!time) {
return;
}
var timeArray = time.split(':');
var seconds = 0;
if (timeArray.length > 2) {
// 时:分:秒
seconds = parseInt(timeArray[0]) * 3600 + parseInt(timeArray[1]) * 60 + parseInt(timeArray[2]);
} else {
// 分:秒
seconds = parseInt(timeArray[0]) * 60 + parseInt(timeArray[1]);
}
var $recordbox = $(this).parents('.record-box')[0]
if ($recordbox) {
var iframe = $recordbox.getElementsByTagName('iframe')[0];
if (iframe) {
var attachment;
try {
attachment = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name'));
} catch (e) {
console.log(e)
}
if (attachment.attachmentType == 54) {
var openUrl = attachment.att_course_video.transferLink + '&host=' + window.location.hostname + '&mid=' + attachment.att_course_video.mid + '&time=' + seconds + '&toflag=1';
if (typeof WinInitConfig != 'undefined' && WinInitConfig.note && WinInitConfig.note.cid) {
openUrl += '&cid=' + WinInitConfig.note.cid;
}
window.open(openUrl);
} else {
iframe.contentWindow.postMessage({
'cid': iframe.getAttribute('cid'),
'type': 'play_time_jump',
'seconds': seconds
}, '*');
}
}
}
/*var mark_id = $(this).parents('.record-box').attr('id') || "";
var iframe = $('body')[0].getElementsByTagName('iframe')[0];
var array = mark_id.split('_');
if(iframe && array && array.length == 2) {
iframe.contentWindow.postMessage({'cid': array[1], 'type':'play_time_jump', 'seconds': seconds}, 'https://noteyd.chaoxing.com');
}*/
});
if (RichTextUitl.setIframeHover) {
// 设置鼠标悬浮在图片和附件上的事件
RichTextUitl.iframehover(selector);
RichTextUitl.imgHover(selector);
} else {
//文本链接的点击事件
RichTextUitl.linkAttachClick(selector);
$('body').on('contextmenu', '.richtext img,.viewer-canvas img', function () {
//判断如果不允许下载
if ($(this).hasClass('noSelect') || RichTextUitl.disableImageContextMenu) {
//不是自己的笔记,不允许下载或未登录不允许下载
return false;
}
});
}
//代码工具栏
RichTextUitl.codeHover(selector);
/**
* 获取云盘token
*/
if (!(typeof isShare != "undefined" && isShare)) {
RichTextUitl.getUploadConfig(true)
}
// 云盘下载地址现在要动态获取,对于加的文本链接附件,点击时调接口取地址然后下载
$(selector).find('a:not(.iframe):not([type="anchor"]).dynacALink,a:not(.dynacALink):not([type="anchor"])').unbind("click").click(function (e) {
if (($(this).attr('download') == 'true' && !RichTextUitl.isLogin)
|| ($(this).attr('allowdownload') == 'false' && $(this).attr('download') == 'false')) {
// 设置了登录后才能下载,未登录时,不能下载,或者未开启下载,也不能下载
return false;
}
var href = $(this).attr('href') || $(this).attr('_href');
if (!href || href.indexOf('javascript') > -1) {
return false;
}
e.preventDefault();
// e.stopPropagation();
if ($(this).hasClass('iframe') && $(this).attr('href')) {
$(this).attr('_href', $(this).attr('href'))
$(this).attr('href', '')
}
if (href.indexOf('d0.ananas.chaoxing.com/download') > -1
|| href.indexOf('cs.ananas.chaoxing.com/download') > -1
|| href.indexOf('d0.cldisk.com/download') > -1
|| href.indexOf('cs.cldisk.com/download') > -1) {
var attachment = RichTextUitl.b64DecodeUnicode($(this).attr('name'));
if (typeof YunFileUtil == 'undefined') {
window.open(href);
return false;
}
if (attachment && attachment.att_clouddisk && attachment.att_clouddisk.fileId) {
// 云盘附件转成的a标签
YunFileUtil.downloadYunFile(attachment);
} else {
// 直接输入的下载地址
var objectId = href.substring(href.lastIndexOf('/') + 1);
if (objectId.indexOf('?') > -1) {
objectId = objectId.substring(0, objectId.indexOf('?'))
}
YunFileUtil.downloadYunFile('', objectId);
}
} else {
//打开微信小程序秀米中配置的链接是https://wxminiUrl_/hotBook/pages/xxx
if (ua.match(/MicroMessenger/i) == "micromessenger" && href.replace(/https:\/\//g, '').indexOf('wxminiUrl') > -1) {
var wxminiurl = href.split('_')[1];
RichTextUitl.openWxminiUrl(wxminiurl);
return false;
}
window.open(href);
}
// return false;
});
//2022-7-26 监听复制操作: 富文本粘贴到非富文本框去除多余空行复制时去除display:none的元素
var richtextList = document.getElementsByClassName('richtext')
for (var i = 0; i < richtextList.length; i++) {
richtextList[i].addEventListener('copy', function (e) {
var clipboardData = (e.clipboardData || window.clipboardData);
if (!clipboardData) return;
//获取选中的非富文本内容
var selectedText = window.getSelection().toString();
// if (selectedText.trim() == "" || selectedText.indexOf('\n') == -1) return;
//部分空格复制到办公同事的软件里时,会变成问号或方框,制表符会变成|,要替换一下
if (selectedText.indexOf('\t\n') == 0) {
selectedText = selectedText.replace('\t\n', '');
}
var copyText = selectedText.replace(/\r/g, '').replace(/\t/g, '').replace(/\n\n/g, '\n').replace(/\u200B/gi, '').replace(/ /g, ' ').replace(/ /g, ' ').replace(/ /g, '');
//获取选中的富文本内容
var range = window.getSelection().getRangeAt(0);
var tempDiv = document.createElement('div');
tempDiv.appendChild(range.cloneContents());
//标题折叠的隐藏元素显示
var node = tempDiv.firstChild;
while (node && node.nodeType == 1) {
if (node.style.display == 'none') {
node.style.display = ''
}
node = node.nextElementSibling;
}
//复制时过滤掉折叠标题的辅助元素三角
$(tempDiv).find('.foldtitle-tri-wrap').remove();
//复制去除代码工具栏和格式化代码
$(tempDiv).find('.code-tool-wrap').remove();
$(tempDiv).find('code').each(function (index, item) {
$(item).html($(item).text().replace(/\n/g, '<br>'))
})
//课程活动不允许粘贴
$(tempDiv).find('iframe').each(function (index, item) {
var iframename = RichTextUitl.b64DecodeUnicode(item.getAttribute('name'));
if (iframename.attachmentType == 15 && !(iframename.att_chat_course.type && iframename.att_chat_course.type == 4)) {
$(item).parent().remove()
}
})
//详情页禁止下载的附件不允许复制
if (!RichTextUitl.isCreator) {
tempDiv = removeForbidDownloadAttach(tempDiv);
}
var selectHtml = tempDiv.innerHTML;
clipboardData.setData('text/plain', copyText);
clipboardData.setData('text/html', selectHtml);
e.preventDefault();
});
}
}
/**
* 根据图片地址获取 objectId
* @param imgSrc
* @returns {string|*}
*/
RichTextUitl.getObjectIdByImgSrc = function (imgSrc) {
if (!imgSrc) {
return '';
}
var objectId = '';
if (imgSrc.indexOf(".") > -1) {
objectId = imgSrc.substring(imgSrc.lastIndexOf("/") + 1, imgSrc.lastIndexOf("."));
} else {
// 部分图片可能没有后缀
objectId = imgSrc.substring(imgSrc.lastIndexOf("/") + 1);
}
return objectId;
}
/**
* 笔记之前 http 域名是 http://note.yd.chaoxing.comhttps 域名是 https://noteyd.chaoxing.com
* 之前 https 域名不支持 http 的,要根据协议换不同的域名,
* 单位做映射的时候也是 http 的映射到 http://note.yd.chaoxing.comhttps的映射到 https://noteyd.chaoxing.com
* 例如:
* http://note.yd.test.com 映射到 http://note.yd.chaoxing.com
* https://noteyd.test.com 映射到 http://noteyd.test.com
* 但是现在2021-12-06 https的域名支持了httphttp://noteyd.chaoxing.com
* 现在有单位是 http 的域名,然后映射到的是 noteyd.chaoxing.com 上
* http://noteyd.gdhkmooc.com 映射到 http://noteyd.chaoxing.com
* 按照之前的替换逻辑http域名是会使用 http://note.yd.chaoxing.com将 chaoxing.com 替换成地址栏里面的域名,
* 就会导致这个单位下,替换后的笔记地址是 http://note.yd.gdhkmooc.com然后出现访问不了的情况
* 现在会导致一个问题,有的单位 http 用的是 http://note.yd.chaoxing.com有的单位 http 用的是 http://noteyd.chaoxing.com
* 当其他项目引用了笔记js时涉及到接口请求时在外层页面是 http 的情况下,
* 无法知道是在 http://note.yd.chaoxing.com 基础上替换 chaoxing.com还是在 http://noteyd.chaoxing.com 的基础上替换
* 为了保证原来已经映射了的单位能正常使用,只能将映射到 http://noteyd.chaoxing.com 上的单位在下面的配置里面记录一下,
* 记录单位定制的一级域名对应的笔记域名
* @type {{}}
*/
RichTextUitl.customDomain = {
'.gdhkmooc.com': 'http://noteyd',
'.lsu.edu.cn': 'http://noteyd',
'.hbqyg.cn': 'http://noteyd', //湖北群艺馆
'.zhjx.hfut.edu.cn': 'http://noteyd', //合肥工业大学
'.istudy.szpt.edu.cn': 'http://noteyd', //深职院1
'.hejtxy.edu.cn': 'http://noteyd.jxjy'
}
RichTextUitl.mirrorDomainList = {
'jxjy.hejtxy.edu.cn': 'noteyd.hejtxy.edu.cn'
}
/**
* 转换请求地址,部分单位定制了域名,相应的接口地址也要换成定制的域名下的
* @param url
* @returns {*}
*/
RichTextUitl.convertUrl = function (url, domain) {
try {
// 武大CNAME特殊处理通知没有支持镜像所以只能在js先处理支持了
if (window.location.host == 'www.mooc.whu.edu.cn') {
if (url.startsWith('https')) {
return url.replace('https://noteyd.chaoxing.com', 'http://www.mooc.whu.edu.cn/noteyd');
} else if (url.startsWith('http')) {
return url.replace('http://noteyd.chaoxing.com', 'http://www.mooc.whu.edu.cn/noteyd');
}
}
// 不是超星域名,有配置走配置
if (window.location.host.indexOf('chaoxing.com' == -1)) {
if (Object.keys(RichTextUitl.mirrorDomainList).indexOf(window.location.host) != -1) {
url = url.replace('http:', '');
url = url.replace('https:', '');
url = url.replace('noteyd.chaoxing.com', RichTextUitl.mirrorDomainList[window.location.host]);
url = url.replace('note.yd.chaoxing.com', RichTextUitl.mirrorDomainList[window.location.host]);
return url;
}
}
if (RichTextUitl.prefix && !RichTextUitl.intranetMode) {
RichTextUitl.currentDomain = RichTextUitl.prefix + '/'
} else if (typeof RichTextUitl.currentDomain == 'undefined') {
RichTextUitl.currentDomain = window.location.host;
}
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('/'))
}
url = window.location.protocol + url.replace('http:', '').replace('https:', '')
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':
case 'pan-yz.cldisk.com':
url = url.replace(urlDomain, window.obj.mirrorDomain.panDomainHttps.replace('https://', '').replace('http://', ''));
break;
case 'd0.ananas.chaoxing.com':
case 'd0.cldisk.com':
url = url.replace(urlDomain, window.obj.mirrorDomain.d0DomainHttps.replace('https://', '').replace('http://', ''));
break;
case 'p.ananas.chaoxing.com':
case 'p.cldisk.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;
if (!domain) {
domain = window.location.host;
}
//处理统一域名+路径访问模式域名转换为xxxx.com/noteyd/xxx
if (RichTextUitl.currentDomain && 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' || 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) {
// 目前看一个定制域名的单位国科大慕课域名是用的mooc1mooc1.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) {
}
return url;
}
/**
* 笔记详情页和其他第三方引用了笔记富文本插件的页面共用的页面渲染后的js处理逻辑
* @param selector包含图片标签的dom节点,为了防止多编辑器处理多次、绑定多次事件
*/
RichTextUitl.commonEventAfterPageRendered = function (selector) {
// 去除不是表格的元素上包裹的div class="table"
RichTextUitl.removetablewrap(selector);
//mac系统标题字号用500
if (RichTextUitl.OSnow() == 'mac') {
$('body').addClass('mac');
}
$(selector).find('p,div,h1,h2,h3,h4,h5,h6').each(function (index, item) {
if ($(item).css('font-size') == '14px' && ($(item).parents('.richtext li').length == 0 || ($(item).parents('.richtext li').length > 0 && $(item).parents('.richtext li').css('font-size') != ''))) {
$(item).css('font-size', '');
}
if ($(item).css('position') === 'fixed') {
$(item).css({'position': '','background-color': '','background': ''});
}
});
//解决xss问题防止产生引导性界面
$(selector).find('section,iframe,li').each(function (index, item) {
if ($(item).css('position') === 'fixed') {
$(item).css({'position': '','background-color': '','background': ''});
}
});
// RichTextUitl.blockEleHover(selector);
//标题折叠
RichTextUitl.hTitleHover(selector);
//代码块颜色高亮
if ($(selector).find('code').length > 0) {
var prefix = window.location.protocol + "//noteyd.chaoxing.com/res/plugin/ueditor/";
if (RichTextUitl.intranetMode) {
prefix = RichTextUitl.prefix;
}
if (typeof (hljs) == 'undefined') {
RichTextUitl.loadCssFile(prefix + 'third-party/highlight/highlight.css?_t=' + RichTextUitl.t);
RichTextUitl.loadJSFile2(prefix + 'third-party/highlight/highlight.min.js?_t=' + RichTextUitl.t, function () {
hljs.highlightAll()
})
}
}
// 给表格加滚动条
if (typeof NiceScroll != 'undefined' && $(selector).find(".table").length > 0 && typeof $(selector).find(".table").niceScroll != 'undefined' && !RichTextUitl.isPhone()) {
$(selector).find(".table").niceScroll({
cursorborder: "",
cursorwidth: 8,
cursorcolor: "#DADFE5",
boxzoom: false,
autohidemode: true
});
}
//附件预览使用大窗口
if (RichTextUitl.largePreview) {
$(selector).addClass('largePreview');
}
//去除列表li下元素的行距
$(selector).find('li').children().each(function (index, item) {
if (item.nodeType == 1 && item.style.lineHeight) {
item.style.lineHeight = '';
}
})
$(selector).find('iframe').each(function (index, iframe) {
var jsonOld = RichTextUitl.b64DecodeUnicode(iframe.getAttribute('name') || '');
if (!jsonOld || jsonOld.attachmentType != 18) return;
var fileSuffix = jsonOld.att_clouddisk.suffix;
if (fileSuffix == 'xls' || fileSuffix == 'xlsx') {
iframe.setAttribute('fileType', 'excel');
} else if (fileSuffix == 'pdf') {
iframe.setAttribute('fileType', 'pdf');
} else if (fileSuffix == 'doc' || fileSuffix == 'docx') {
iframe.setAttribute('fileType', 'word');
} else if (fileSuffix == 'ppt' || fileSuffix == 'pptx') {
iframe.setAttribute('fileType', 'ppt');
}
})
var appDomain = window.location.protocol + '//appswh.chaoxing.com'
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.appsWhDomainHttps) {
appDomain = window.location.protocol + window.obj.mirrorDomain.appsWhDomainHttps.replace('https:', '').replace('http:', '');
}
// 开启了原位预览的云盘文件地址改成对应预览地址只改PC端手机端不改还是采用附件模式
$(selector).find('.editor-iframe iframe[preview=true]').each(function () {
var att_clouddisk = RichTextUitl.getCloudFileData($(this).attr('name'));
var iframeSrc = window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid='
+ att_clouddisk.fileId
+ '&fileName=' + encodeURIComponent(RichTextUitl.getCloudFileName($(this).attr('name')))
// cname和镜像的要改成定制域名
if (window.obj && window.obj.mirrorDomain && window.obj.mirrorDomain.previewDomainHttps) {
iframeSrc = window.obj.mirrorDomain.previewDomainHttps + '/res/view/view.html?objectid='
+ att_clouddisk.fileId
+ '&fileName=' + encodeURIComponent(RichTextUitl.getCloudFileName($(this).attr('name')));
}
if (att_clouddisk.suffix == 'xlsx' || att_clouddisk.suffix == 'xls') {
// excel附件预览模式使用在线表格的页面
iframeSrc = appDomain + '/res/Spreadsheets/wpsPC.html?type=attachment&cid='
+ $(this).attr('cid') + '&resid=' + (att_clouddisk.residstr || att_clouddisk.resid) + '&title=' + encodeURIComponent(att_clouddisk.name);
}
//设置了高级预览的显示时加上高级预览的参数
if (att_clouddisk.suffix == 'pdf' && $(this).attr('advancedpreview')) {
iframeSrc += '&mode=advancedpreview';
if ($(this).attr('advancedpreview') != 'true') {
iframeSrc += '&page=' + $(this).attr('advancedpreview');
}
}
var downloadConfig = ''
if (($(this).attr('allowdownload') == 'false' && $(this).attr('download') == 'false')
|| ($(this).attr('allowdownload') == 'true' && !RichTextUitl.isLogin)) {
// 不允许下载
downloadConfig = '&download=false';
}
iframeSrc += downloadConfig;
if (!RichTextUitl.isGetVideoDataFromCenter) {
resid = att_clouddisk.resid
iframeSrc += '&resid=' + resid;
}
$(this).attr('src', iframeSrc);
})
$(selector).find('.editor-iframe iframe[excel=true]').each(function () {
var downloadConfig = ''
if (($(this).attr('allowdownload') == 'false' && $(this).attr('download') == 'false')
|| ($(this).attr('allowdownload') == 'true' && !RichTextUitl.isLogin)) {
// 不允许下载
downloadConfig = '&download=0';
}
$(this).attr('src', appDomain + '/res/Spreadsheets/wpsPC.html?cid='
+ $(this).attr('cid') + downloadConfig)
})
// }
/**
* 编辑页已经给链接加上a标签的情况下详情页的addLink方法会在链接外面包一个a标签导致编辑页加的a标签不显示
* 在将卡片附件转成文本链接附件时数据放在a标签上操作方法也是绑定在了a标签的特定样式样式
* 遍历卡片附件转成的a标签如果他的后面也是一个a
*/
$(selector).find('.dynacALink.iframe').each(function () {
var $next = $(this).next();
if ($next.hasClass('dynacALink') && $next.attr('href') == $(this).attr('href')) {
$(this).text($next.text());
$next.remove();
}
})
// 设置详情页事件
RichTextUitl.detailPageEvent(selector);
}
// markdown转html
RichTextUitl.markDownToHtml = function (markdownText) {
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
return marked.parse(markdownText);
}
//去除不是表格的元素上包裹的div class="table"
RichTextUitl.removetablewrap = function (selector) {
$(selector).find('.table').each(function (index, item) {
if (item.nodeName == 'TABLE') {
return
}
var hastable = false;
while (item.firstChild) {
var dom = item.firstChild;
if (dom.nodeType == 3 || (dom.nodeType == 1 && dom.tagName == 'BR') || $(dom).css('display') == 'inline' || $(dom).css('display') == 'inline-table') {
$(dom).wrap('<p></p>');
dom = dom.parentNode;
} else if (dom.nodeType == 1 && dom.tagName == 'TABLE') {
hastable = true;
}
// if (hastable == false) {
$(item).before($(dom))
// } else {
// $(item).after($(dom))
// }
if (!item.firstChild) {
item.remove();
break;
}
}
})
$(selector).find('table').wrap('<div class="table"></div>')
}
/**
* 获取上传相关配置
* @param sync 是否同步调用, true 同步false 异步
*/
RichTextUitl.getUploadConfig = function (sync) {
if (RichTextUitl.intranetMode) {
return;
}
if (RichTextUitl.puid && RichTextUitl.yunToken) {
return;
}
if (typeof jQuery != 'undefined') {
// 之前http页面可以调用https的接口现在新版的chrome浏览器上面不行了这里做下域名适配
// 如果是同步,直接加载,不延迟
if (sync) {
try {
if (window.obj && window.obj.mirrorDomain && typeof window.obj.mirrorDomain.NoteDomainHttps != 'undefined') {
// 如果镜像域名有了,就赋值在加载
if (window.location.protocol == 'http:') {
RichTextUitl.noteDomain = window.obj.mirrorDomain.NoteDomainHttps.replace(/https/g, 'http');
} else {
RichTextUitl.noteDomain = window.obj.mirrorDomain.NoteDomainHttps;
}
}
} catch (e) {
}
var json = {
url: RichTextUitl.convertUrl(RichTextUitl.noteDomain + "/pc/files/getUploadConfig"),
type: "get",
xhrFields: {
withCredentials: true
},
headers: {"Content-Type": "application/x-www-form-urlencoded"},
data: {},
dataType: "json",
success: function (resultData) {
if (resultData && resultData.result == 1) {
RichTextUitl.puid = resultData.msg.puid;
RichTextUitl.yunToken = resultData.msg.token || RichTextUitl.yunToken || '';
}
},
error: function () {
}
}
if (sync) {
// 同步调用
json.async = false;
}
try {
$.ajax(json);
} catch (e) {
console.error(e)
}
return;
}
// 如果是异步,延迟一下在加载防止有些服务的RichTextUitl.noteDomain还没加载完这里就执行了导致获取不到cname域名而无法获取云盘token
setTimeout(function () {
try {
if (window.obj && window.obj.mirrorDomain && typeof window.obj.mirrorDomain.NoteDomainHttps != 'undefined') {
// 如果镜像域名有了,就赋值在加载
if (window.location.protocol == 'http:') {
RichTextUitl.noteDomain = window.obj.mirrorDomain.NoteDomainHttps.replace(/https/g, 'http');
} else {
RichTextUitl.noteDomain = window.obj.mirrorDomain.NoteDomainHttps;
}
}
} catch (e) {
console.error(e)
}
var json = {
url: RichTextUitl.convertUrl(RichTextUitl.noteDomain + "/pc/files/getUploadConfig"),
type: "get",
xhrFields: {
withCredentials: true
},
headers: {"Content-Type": "application/x-www-form-urlencoded"},
data: {},
dataType: "json",
success: function (resultData) {
if (resultData && resultData.result == 1) {
RichTextUitl.puid = resultData.msg.puid;
RichTextUitl.yunToken = resultData.msg.token || RichTextUitl.yunToken || '';
}
},
error: function () {
}
}
if (sync) {
// 同步调用
json.async = false;
}
try {
$.ajax(json);
} catch (e) {
console.error(e)
}
}, 200)
}
}
/**
* 字符转义
* @param content
* @returns {string|*}
*/
RichTextUitl.escapedCharacter = function (content) {
if (content) {
return content.replace(/</g, "&lt;").replace(/>/g, "&gt;")
.replace(/"/g, '&quot;').replace(/'/g, "&apos;");
}
return "";
}
RichTextUitl.loadScript = 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)
}
//有序列表转编号
//旧格式的列表改为新格式的列表
function normaloldlist() {
$('.richtext ol:not([level]),.richtext ul:not([level])').each(function (index, list) {
if (!list.firstChild) {
list.remove();
return
}
$(this).removeAttr('class').removeAttr('style');
if ($(list).parents('ol,ul').length > 0 && $(list).parents('ol,ul').eq(0).parents('.richtext').length > 0) {
var listnext = list.nextSibling;
$(list).attr('level', 1 + parseInt($(list).parents('ol,ul').eq(0).attr('level')));
RichTextUitl.breakParent(list, $(list).parents('ol,ul')[0]);
if (listnext) {
list.nextSibling.remove();
}
if (list.nextSibling && list.nextSibling.firstChild && !list.nextSibling.firstChild.firstChild) {
list.nextSibling.firstChild.remove();
}
if (list.nextSibling && !list.nextSibling.firstChild) {
list.nextSibling.remove();
}
if (list.previousSibling && list.previousSibling.firstChild && !list.previousSibling.firstChild.firstChild) {
list.previousSibling.firstChild.remove();
}
if (list.previousSibling && !list.previousSibling.firstChild) {
list.previousSibling.remove();
}
}
if (!$(this).attr('level')) {
$(list).attr('level', '1');
if (list.tagName == 'OL') {
$(list).attr('serialnum', '1').attr('data-origin-start', '1');
}
}
if ($(this).parents('ol,ul').length > 0 && $(list).parents('ol,ul').eq(0).parents('.richtext').length > 0) {
$(list).attr('level', 1 + parseInt($(list).parents('ol,ul').eq(0).attr('level')));
}
var level = $(list).attr('level');
var listnext = list.nextSibling;
var oldlist = list;
var i = 0;
$(list).children('li').each(function (index, li) {
if (!(li.children.length == 1 && (li.firstChild.nodeName == 'OL' || li.firstChild.nodeName == 'UL'))) {
i++;
}
var serialnum = serialnumToString(i, level);
$(li).parent().attr('level', level);
if (list.tagName == 'OL') {
$(li).attr('serialnum', serialnum);
}
if (index > 0) {
var newlist = document.createElement(oldlist.tagName);
if (oldlist.tagName == 'OL') {
$(newlist).attr('serialnum', li.getAttribute('serialnum'));
}
$(newlist).attr('level', level);
if (listnext) {
oldlist.parentNode.insertBefore(newlist, listnext);
} else {
oldlist.parentNode.appendChild(newlist);
}
newlist.appendChild(li);
list = newlist;
} else {
if (list.tagName == 'OL') {
$(list).attr('serialnum', li.getAttribute('serialnum'));
}
$(list).attr('level', level);
}
//序号颜色大小根据文字大小改变
var firsttag = list.firstChild.firstChild;
if (list.firstChild.nodeType === 1) {
list.firstChild.style.cssText = '';
}
while (firsttag) {
if (firsttag.nodeType == 1 && firsttag.nodeName == "SPAN" && firsttag.id.indexOf('bookmark') > -1) {
firsttag = firsttag.nextSibling;
} else if (firsttag.nodeType == 1 && firsttag.nodeName == "SPAN" && firsttag.style.cssText != "") {
firsttag.style.fontFamily != "" ? list.firstChild.style.fontFamily = firsttag.style.fontFamily : '';
firsttag.style.fontSize != "" ? list.firstChild.style.fontSize = firsttag.style.fontSize : '';
firsttag.style.color != "" ? list.firstChild.style.color = firsttag.style.color : '';
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 1 && firsttag.nodeName == 'H1') {
list.firstChild.style.cssText += 'font-size:24px;font-weight:' + fontweight;
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 1 && firsttag.nodeName == 'H2') {
list.firstChild.style.cssText += 'font-size:20px;font-weight:' + fontweight;
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 1 && firsttag.nodeName == 'H3') {
list.firstChild.style.cssText += 'font-size:18px;font-weight:' + fontweight;
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 1 && firsttag.nodeName == 'H4') {
list.firstChild.style.cssText += 'font-size:16px;font-weight:' + fontweight;
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 1 && $(firsttag).css('display') == 'block') {
list.firstChild.style.fontFamily = '';
list.firstChild.style.fontSize = '';
list.firstChild.style.color = '';
$(list.firstChild).children().css({'font-size': '', 'color': '', 'font-family': ''});
firsttag = firsttag.firstChild;
} else if (firsttag.nodeType == 3 && firsttag.innerText == "") {
firsttag = firsttag.nextSibling;
} else if (firsttag.nodeType == 3 || firsttag.nodeName == 'BR') {
break;
} else {
firsttag = firsttag.firstChild;
}
}
})
});
//给有大小颜色的li下的块状子元素添加原始样式,保证后面没有大小颜色的文字样式不被改变
$('.richtext li').children().each(function (index, node) {
if (node.parentNode.style.cssText != '' && $(node).css('display') == 'block' && $(node).text().trim() != '' && node.firstChild) {
if (node.tagName.indexOf('H') == -1) { //不是标题
if ($(node).parents('table').length == -1) {
$(node).css({'font-size': $(me.body).css('font-size')});
} else {
$(node).css({'font-size': $(node).parents('table').css('font-size')});
}
}
if (node.parentNode.style.cssText.indexOf('color') > -1) {
$(node).css({'color': '#333333'});
}
}
})
// $('.richtext li').each(function(index,li){
// var lifirst = li.firstChild;
// if(lifirst.nodeType == 1 && !lifirst.firstChild && lifirst.firstChild.nextSibling){
// lifirst.remove();
// lifirst = li.firstChild;
// }
// if(li.children.length>1){
// var listnext = li.parentNode.nextSibling;
// while(lifirst.nextSibling){
// if(lifirst.nextSibling.nodeType == 1 && !lifirst.nextSibling.firstChild){
// lifirst.nextSibling.remove();
// }else if(lifirst.nextSibling.nodeType == 1 && window.getComputedStyle(lifirst.nextSibling).display == 'block'){
// if(listnext){
// li.parentNode.parentNode.insertBefore(lifirst.nextSibling,listnext);
// }else{
// li.parentNode.parentNode.appendChild(lifirst.nextSibling);
// }
// }
// }
// }
// })
}
/**
* 判断云盘附件是否支持预览
* @param name
* @returns {boolean}
*/
RichTextUitl.isSupportPreview = function (name) {
var attachmentData = RichTextUitl.b64DecodeUnicode(name);
if (!attachmentData || !attachmentData.att_clouddisk) {
return false;
}
if (RichTextUitl.intranetMode && !RichTextUitl.supportPreview) {
return false;
}
var icon = (attachmentData.att_clouddisk.suffix || '').toLowerCase();
if (icon.indexOf('ppt') > -1 || icon.indexOf('doc') > -1
|| icon.indexOf('xls') > -1 || icon.indexOf('pdf') > -1
&& attachmentData.att_clouddisk.fileId) {
return true;
}
return false;
}
/**
* 获取云盘附件数据
* @param name
* @returns {string|*}
*/
RichTextUitl.getCloudFileData = function (name) {
var attachmentData;
try {
attachmentData = JSON.parse(decodeURIComponent(atob(name)));
} catch (e) {
}
if (!attachmentData || !attachmentData.att_clouddisk) {
return '';
}
return attachmentData.att_clouddisk
}
/**
* 获取云盘文件objectId
* @param name
* @returns {string}
*/
RichTextUitl.getCloudFileObjectId = function (name) {
return RichTextUitl.getCloudFileData(name).fileId || '';
}
/**
* 获取云盘文件resid
* @param name
* @returns {string}
*/
RichTextUitl.getCloudFileResId = function (name) {
return RichTextUitl.getCloudFileData(name).resid || '';
}
/**
* 获取文件名
* @param name
* @returns {string|*|string}
*/
RichTextUitl.getCloudFileName = function (name) {
var att_clouddisk = RichTextUitl.getCloudFileData(name);
var fileName = att_clouddisk.name;
if (fileName.indexOf('.' + att_clouddisk.suffix) > -1) {
fileName = fileName.substring(0, fileName.indexOf('.' + att_clouddisk.suffix));
}
return fileName || '';
}
/**
* 获取后缀
* @param name
* @returns {string|*|string}
*/
RichTextUitl.getCloudFileSuffix = function (name) {
return RichTextUitl.getCloudFileData(name).suffix || '';
}
/**
* 获取url参数
* @param name
* @returns {string|*}
*/
RichTextUitl.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return r[2];
return ''; //返回参数值
}
function intToRoman(num) {
var result = "";
if (num >= 1000) {
result = repeatC('m', Math.floor(num / 1000));
num %= 1000;
}
if (num >= 100) {
result += generBase(Math.floor(num / 100), ['c', 'd', 'm']);
num %= 100;
}
if (num >= 10) {
result += generBase(Math.floor(num / 10), ['x', 'l', 'c']);
num %= 10;
}
if (num >= 1) {
result += generBase(Math.floor(num), ['i', 'v', 'x']);
}
return result;
}
function generBase(num, arr) {
var result = "";
if (num >= 1 && num <= 3) {
result = repeatC(arr[0], num);
}
if (num === 4) {
result = arr[0] + '' + arr[1];
}
if (num >= 5 && num <= 8) {
result = arr[1] + '' + repeatC(arr[0], num - 5);
}
if (num === 9) {
result = arr[0] + "" + arr[2];
}
return result;
}
function repeatC(char, count) {
var result = "";
for (var i = 0; i < count; i++) {
result += char;
}
return result;
}
//小写罗马数字转数字
function romanToInt(s) {
//定义一个对象来存放数据
var map = {'i': 1, 'v': 5, 'x': 10, 'l': 50, 'c': 100, 'd': 500, 'm': 1000};
//罗马数分割成数组
var sArr = s.split('');
//总数
var sum = 0;
for (var i = 0; i < sArr.length; i++) {
//sArr[i]拿到的是key只要比较前一个比后一个小就行大的话相减并且这个时候i+1已经不用计算了我们可以把i+1跳过下一个数字的比对操作
var value = map[sArr[i]]
if (value < map[sArr[i + 1]]) {
value = map[sArr[i + 1]] - value;
i++;
}
sum += value;
}
return sum;
}
//整数转字母
function intToAlpha(num) {
var str = "";
while (num > 0) {
var m = num % 26;
if (m == 0) {
m = 26;
}
str = String.fromCharCode(m + 96) + str;
num = (num - m) / 26;
}
return str;
}
function alphaToInt(str) {
var n = 0;
var s = str.match(/./g);//求出字符数组
var j = 0;
for (var i = str.length - 1, j = 1; i >= 0; i--, j *= 26) {
var c = s[i].toLowerCase();
if (c < 'a' || c > 'z') {
return 0;
}
n += (c.charCodeAt(0) - 96) * j;
}
return n;
}
//列表序号转整数
function serialnumToInt(serialstr, level) {
var serialnum;
level = parseInt(level);
if (level % 3 == 0) {
serialnum = romanToInt(serialstr);
} else if (level % 3 == 1) {
serialnum = parseInt(serialstr);
} else {
serialnum = alphaToInt(serialstr);
}
return serialnum;
}
//列表序号转字符串
function serialnumToString(serialnum, level) {
var serialstr;
level = parseInt(level);
if (level % 3 == 0) {
serialstr = intToRoman(serialnum);
} else if (level % 3 == 1) {
serialstr = serialnum.toString();
} else {
serialstr = intToAlpha(serialnum);
}
return serialstr;
}
//列表序号加1
function addSerialNum(serialstr, level) {
var serialnum;
serialnum = serialnumToInt(serialstr, level);
serialnum++;
serialstr = serialnumToString(serialnum, level);
return serialstr;
}
//列表序号减1
function minusSerialNum(serialstr, level) {
var serialnum;
serialnum = serialnumToInt(serialstr, level);
if (serialnum > 1) {
serialnum--;
}
serialstr = serialnumToString(serialnum, level);
return serialstr;
}
/**
* 以node节点为分界将该节点的指定祖先节点parent拆分成两个独立的节点
* 拆分形成的两个节点之间是node节点
* @method breakParent
* @param { Node } node 作为分界的节点对象
* @param { Node } parent 该节点必须是node节点的祖先节点 且是block节点。
* @return { Node } 给定的node分界节点
* */
RichTextUitl.breakParent = function (node, parent) {
var tmpNode,
parentClone = node,
clone = node,
leftNodes,
rightNodes;
do {
parentClone = parentClone.parentNode;
if (leftNodes) {
tmpNode = parentClone.cloneNode(false);
tmpNode.appendChild(leftNodes);
leftNodes = tmpNode;
tmpNode = parentClone.cloneNode(false);
tmpNode.appendChild(rightNodes);
rightNodes = tmpNode;
} else {
leftNodes = parentClone.cloneNode(false);
rightNodes = leftNodes.cloneNode(false);
}
while (tmpNode = clone.previousSibling) {
leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
}
while (tmpNode = clone.nextSibling) {
rightNodes.appendChild(tmpNode);
}
clone = parentClone;
} while (parent !== parentClone);
tmpNode = parent.parentNode;
tmpNode.insertBefore(leftNodes, parent);
tmpNode.insertBefore(rightNodes, parent);
tmpNode.insertBefore(node, rightNodes);
parent.parentNode.removeChild(parent);
return node;
}
//判断系统
RichTextUitl.OSnow = function () {
var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
var isWindows = /windows|win32/i.test(navigator.userAgent);
if (isWindows) {
return 'windows';
}
if (isMac) {
return 'mac';
}
}
/**
* 获取预览页地址
* @param cid:附件cid
*/
RichTextUitl.executePreview = function (data) {
var targetIframe = $('body').find('iframe[cid=' + data.cid + ']')
if (targetIframe && targetIframe.length > 0 && targetIframe[0].name) {
var attachment = RichTextUitl.b64DecodeUnicode(targetIframe[0].name)
var fileName = attachment.att_clouddisk.name;
if (fileName.indexOf('.' + attachment.att_clouddisk.suffix) > -1) {
fileName = fileName.substring(0, fileName.indexOf('.' + attachment.att_clouddisk.suffix));
}
var puid = attachment.att_clouddisk.puid;
if (!puid) {
puid = attachment.att_clouddisk.infoJsonStr ? (attachment.att_clouddisk.infoJsonStr.puid || '') : '';
}
if ($(this).parents('.dynacALink').length == 0 && $(this).parents('.editor-iframe').length > 0) {
//获取iframe的域名作为获取预览地址的域名解决部分单位编辑页超星域名详情页单位域名未配置单位域名点预览打不开
var iframeSrc = $(this).parents('.operatehover').siblings('iframe').attr('src');
var iframeDomain = '';
if (iframeSrc.indexOf('//') > -1) {
iframeSrc = iframeSrc.substring(iframeSrc.indexOf('//') + 2, iframeSrc.length)
iframeDomain = iframeSrc.substring(0, iframeSrc.indexOf('/'))
}
}
//调接口获取enc
RichTextUitl.getPreviewUrl(attachment.att_clouddisk.fileId, encodeURIComponent(fileName), $(this).attr('download'), null, iframeDomain, attachment.att_clouddisk.resid);
}
}
/**
* 获取预览页地址
* @param objectId
* @param fileName
* @param download
* @param callback
*/
RichTextUitl.getPreviewUrl = function (objectId, fileName, download, callback, domain, resid) {
var url = window.location.protocol + '//previewyd.chaoxing.com/res/view/view.html?objectid=' +
objectId + '&fileName=' + encodeURIComponent(fileName)
var posturl = 'https://noteyd.chaoxing.com/screen/note_note/getPreviewUrl';
//nticct.cahe.edu.cn 没有映射笔记域名编辑页用的chaoxing域名不走域名转换
if (window.location.host.indexOf('nticct.cahe.edu.cn') == -1) {
posturl = RichTextUitl.convertUrl(posturl, domain)
}
//镜像附件地址
if (RichTextUitl.annexMirrorPrefix) {
YunFileUtil.url = RichTextUitl.annexMirrorPrefix + '/screen/note_note/getPreviewUrl';
}
if (RichTextUitl.isGetVideoDataFromCenter) {
resid = ''
}
var json = {
'objectId': objectId,
'fileName': fileName,
'download': download,
'resid': resid
}
if (RichTextUitl.useWpsPreview) {
json.type = 'wps'
}
//有的单位做了镜像云盘但课程那边的附件是上传到公网的,需要获取公网的预览地址
if (RichTextUitl.cloudUrl) {
json.cloudUrl = RichTextUitl.cloudUrl;
}
$.ajax({
type: 'POST',
headers: {"Content-Type": "application/x-www-form-urlencoded"},
url: posturl,
data: json,
success: function (data) {
if (data && data.result && data.msg) {
url = data.msg;
if (resid) {
url += '&resid=' + resid
}
if (typeof callback == "function") {
callback(url);
return;
}
window.open(url);
return;
} else if (data.result == 0 && data.msg) {
//如果云盘文件被删除,取不到下载地址,给错误提示
RichTextUitl.showTips(data.msg, 0)
}
}
});
}
//块状元素悬浮事件
// RichTextUitl.blockEleHover = function(selector){
// $(selector).find('p,div,h1,h2,h3,h4,h5,h6,pre,blockquote,section,table').each(function (index, node) {
// //鼠标移上段落显示评论框
// $(node).on('mouseover',function (e) {
// if($(this).find('img,iframe,hr,p,div,h1,h2,h3,h4,h5,h6,pre,code,blockquote,section,li').length == 0 && $(this).parents('table,code,.signDiv').length == 0 || $(this).is('table')){
// var totop = $(this).offset().top - $(selector).offset().top + parseInt($(this).css('line-height').replace('px','')/2) - 10;
// var toleft = $(selector).offset().left + $(this).offset().left;
// $(this).append('<div class="pCommentBtn" style="top:'+totop+'px"></div>')
// }
// });
// $(node).on('mouseleave',function () {
// $(this).find('.pCommentBtn').remove();
// })
// })
// }
//标题折叠
RichTextUitl.hTitleHover = function (selector) {
//标题折叠如果h在div里移出表格、录音打点、课程报告、勾选框里的不移出
$(selector).find('h1,h2,h3,h4,h5,h6').each(function (index, node) {
node.classList.remove('hover');
node.classList.remove('fold');
if (node.parentNode != selector && node.parentNode.nodeName != 'LI'
&& $(node).parents('.richtext .record-box').length == 0 && $(node).parents('.richtext table').length == 0 && $(node).parents('.richtext .notice_main').length == 0
&& !$(node).hasClass('top-cover-title') && $(node).parents('.richtext .todo-view').length == 0 && $(node).parents('.richtext .signDiv').length == 0 && $(node).parents('.richtext .callout-block').length == 0 && $(node).parents('.report_main').length == 0) {
var parent = node.parentNode;
while (!$(parent.parentNode).hasClass('richtext')) {
parent = parent.parentNode;
}
RichTextUitl.breakParent(node, parent);
//20200323 清除上一个li里的最后一个空标签
var pre = node.previousSibling;
if (pre && pre.nodeType == 1 && pre.innerText == '' && $(pre).find('hr,br,img,iframe,canvas').length == 0) {
$(pre).remove()
}
var next = node.previousSibling;
if (next && next.nodeType == 1 && next.innerText == '' && $(next).find('hr,br,img,iframe,canvas').length == 0) {
$(next).remove();
}
}
if ($(node).parents('li,ul,ol').length > 0) {
return
}
if ($(node).find('.foldtitle-tri-wrap').length == 0) {
$(node).find('.foldtitle-tri-wrap').remove();
}
//给标题加折叠三角
$(node).prepend('<div class="foldtitle-tri-wrap">' +
'<i class="tri"></i>' +
'<div class="hoverTips"><span>收起</span><i></i></div>' +
'</div>');
if (typeof isShare != 'undefined' && isShare && RichTextUitl.isPhone()) {
$(selector).find('h1,h2,h3,h4,h5,h6').removeClass('hover')
$(node).addClass('hover');
var totop = parseInt($(node).css('line-height').replace('px', '') / 2) - 16
var toleft = $(selector).offset().left - $(node).offset().left - 30 - parseInt($(node).css('border-left-width').replace('px', ''));
$(node).find('.foldtitle-tri-wrap').css({'top': totop + 'px', 'left': toleft + 'px'});
}
});
//鼠标移上显示折叠
$(selector).on('mouseover', function (e) {
var hTitle;
if (/h\d/i.test(e.target.nodeName)) {
hTitle = e.target;
} else if ($(e.target).parents('h1,h2,h3,h4,h5,h6').length > 0) {
hTitle = $(e.target).parents('h1,h2,h3,h4,h5,h6')[0];
} else if ((e.target.nodeName == 'OL' || e.target.nodeName == 'UL') && e.target.firstChild && e.target.firstChild.firstChild && /h\d/i.test(e.target.firstChild.firstChild.nodeName)) {
hTitle = e.target.firstChild.firstChild;
}
if (hTitle) {
//表格、课程报告、勾选框、录音打点 不显示折叠三角
if ($(hTitle).parents('.richtext table').length > 0 || $(hTitle).parents('.richtext .top-cover-bot').length > 0 || $(hTitle).parents('.richtext .callout-block').length > 0
|| $(hTitle).parents('.richtext .todo-view').length > 0 || $(hTitle).parents('.richtext .record-box').length > 0 || $(hTitle).parents('.richtext #signDiv').length > 0) {
return
}
if (hTitle.innerText.trim() == '') {
return
}
$(selector).find('h1,h2,h3,h4,h5,h6').removeClass('hover')
$(hTitle).addClass('hover');
var totop = parseInt($(hTitle).css('line-height').replace('px', '') / 2) - 16
var toleft = $(selector).offset().left - $(hTitle).offset().left - 30 - parseInt($(hTitle).css('border-left-width').replace('px', ''));
$(hTitle).find('.foldtitle-tri-wrap').css({'top': totop + 'px', 'left': toleft + 'px'});
} else {
$(selector).find('h1.hover,h2.hover,h3.hover,h4.hover,h5.hover,h6.hover').removeClass('hover')
}
});
$(selector).on('mouseleave', function (e) {
$('.foldtitle-tri-wrap').parent().removeClass('hover');
});
//点击展开收起
$(selector).on('click', '.foldtitle-tri-wrap', function (e) {
var target = e.currentTarget.parentNode;
var nowHeadLevel = parseInt(target.tagName.replace(/h/i, ''));
var next = target.nextElementSibling;
if ($(target).parents('.richtext ol,.richtext ul').length > 0) {
next = $(target).parents('.richtext ol,.richtext ul')[0].nextElementSibling;
}
$(target).find('.tri')[0].style.transition = 'all 0.3s';
setTimeout(function () {
$(target).find('.tri')[0].style.transition = '';
}, 400)
if ($(target).hasClass('fold')) {
//展开
$(target).removeClass('fold');
target.classList.remove('fold');
$(this).find('.hoverTips span').text('收起');
if (!next) return;
while (next) {
var tagName = next.nodeName;
var headLevel;
if (/h\d/i.test(tagName)) {
headLevel = parseInt(tagName.replace(/h/i, ''));
next.classList.remove('fold');
if (headLevel <= nowHeadLevel) {
//标题等级等于或者大于当前标题,结束循环
break;
}
} else if (tagName == 'UL' || tagName == 'OL') {
if (next.firstChild && next.firstChild.firstChild && next.firstChild.firstChild.nodeType == 1 && /h\d/i.test(next.firstChild.firstChild.nodeName)) {
headLevel = parseInt(next.firstChild.firstChild.nodeName.replace(/h/i, ''));
$(next.firstChild.firstChild).removeClass('fold');
if (headLevel <= nowHeadLevel) {
//标题等级等于或者大于当前标题,结束循环
break;
}
}
}
next.style.display = '';
next.classList.remove('fold');
next = next.nextElementSibling;
}
} else {
//收起
$(target).addClass('fold');
target.classList.add('fold');
$(this).find('.hoverTips span').text('展开');
if (!next) return;
while (next) {
var tagName = next.nodeName;
var headLevel;
if (/h\d/i.test(tagName)) {
headLevel = parseInt(tagName.replace(/h/i, ''));
next.classList.remove('fold');
if (headLevel <= nowHeadLevel) {
//标题等级等于或者大于当前标题,结束循环
break;
}
} else if (tagName == 'UL' || tagName == 'OL') {
if (next.firstChild && next.firstChild.firstChild && next.firstChild.firstChild.nodeType == 1 && /h\d/i.test(next.firstChild.firstChild.nodeName)) {
headLevel = parseInt(next.firstChild.firstChild.nodeName.replace(/h/i, ''));
$(next.firstChild.firstChild).removeClass('fold');
if (headLevel <= nowHeadLevel) {
//标题等级等于或者大于当前标题,结束循环
break;
}
}
}
next.style.display = 'none';
next = next.nextElementSibling;
}
}
})
}
/*代码块工具栏*/
RichTextUitl.codeHover = function (selector) {
$(selector).find('pre').each(function (index, node) {
var lang = $(node).find('code').attr('lang') || 'PlainText';
$(node).prepend('<div class="code-tool-wrap clearfix"><div class="code-lang fl">' + lang + '</div><div class="copy fr"><i></i><span>' + RichTextUitl.getI18nContent('copy') + '</span></div></div>');
})
$(selector).on('click', '.copy', function () {
window.dt = new clipboard.DT();
var code = $(this).parents('.richtext pre').find('code')[0];
if (!code) return
var lang = $(code).attr('lang') || 'PlainText';
var html = '<pre><code class="language-' + lang + '" lang="' + lang + '">' + code.innerText.replace(/\n/g, '<br>') + '</code></pre>';
dt.setData("text/html", html);
dt.setData("text/plain", code.innerText);
clipboard.write(dt).then(function () {
if ($('.toolTipBox').length > 0) {
$('.toolTipBox').remove()
}
$(document.body).append('<div class="toolTipBox"><i class="popicon"><img src="https://noteyd.chaoxing.com/res/plugin/ueditor/themes/default/images/right.png" /></i><span class="tipstext">' + RichTextUitl.getI18nContent('copySuccess') + '<span></div>')
$('.toolTipBox').show();
setTimeout(function () {
$('.toolTipBox').fadeOut();
}, 1500)
}, function (err) {
console.log(err);
});
})
}
//禁止下载的附件不允许复制
function removeForbidDownloadAttach(tempDiv) {
$(tempDiv).find('iframe').each(function (index, item) {
var iframename = RichTextUitl.b64DecodeUnicode(item.getAttribute('name'));
if (item.getAttribute('module') == 'insertCloud' && iframename.att_clouddisk.forbidDownload && iframename.att_clouddisk.forbidDownload == 1) {
$(item).parent().remove()
} else if (item.getAttribute('module') == 'insertVideo' && iframename.att_video.forbidDownload && iframename.att_video.forbidDownload == 1) {
$(item).parent().remove()
} else if (item.getAttribute('module') == 'insertVoice' && iframename.att_voice.forbidDownload && iframename.att_voice.forbidDownload == 1) {
$(item).parent().remove()
} else if (item.getAttribute('download') == 'false' && item.attr('allowdownload') == 'false') {
$(item).parent().remove()
}
})
return tempDiv;
}
// 打开微信小程序
RichTextUitl.openWxminiUrl = function (miniUrl, url) {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
//ios的ua中无miniProgram但都有MicroMessenger表示是微信浏览器
wx.miniProgram.getEnv(function (res) {
if (res.miniprogram) {
//小程序打开 redirectTo navigateTourl对应具体页面的地址和参数
wx.miniProgram.navigateTo({url: miniUrl});
} else if (url) {
//微信内置浏览器打开
window.location.href = url;
}
})
} else if (url) {
//非微信打开
window.location.href = url;
}
}