1
This commit is contained in:
@@ -47,14 +47,14 @@ var i18nDetailData = {
|
||||
}
|
||||
|
||||
if (typeof RichTextUitl.noteDomain == 'undefined') {
|
||||
RichTextUitl.noteDomain = 'https://noteyd.chaoxing.com'
|
||||
RichTextUitl.noteDomain = window.location.protocol + '//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|*}
|
||||
@@ -76,6 +76,9 @@ RichTextUitl.getI18nContent = function (content) {
|
||||
return content;
|
||||
}
|
||||
var ua = navigator.userAgent.toLowerCase();
|
||||
RichTextUitl.isIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent); //ios终端
|
||||
RichTextUitl.isAndroid = /(Android)/i.test(navigator.userAgent); //android终端
|
||||
RichTextUitl.isHarmony = navigator.userAgent.indexOf('harmony') > -1 && navigator.userAgent.indexOf('phone') > -1; //鸿蒙终端
|
||||
// 是否在手机学习通里面
|
||||
RichTextUitl.isXXT = ua && ua.indexOf("chaoxingstudy") != -1 && ua.indexOf('_pc_') == -1;
|
||||
// 是否是微信端
|
||||
@@ -104,6 +107,7 @@ RichTextUitl.getRichText = function (showTipsFunction, editorId, istestContent)
|
||||
var attachments;
|
||||
var $noteImgs;
|
||||
var isVideoUploadFail = false;
|
||||
|
||||
if (doc) {
|
||||
attachments = doc.getElementsByTagName('iframe');
|
||||
$noteImgs = doc.getElementsByTagName("img");
|
||||
@@ -177,7 +181,7 @@ RichTextUitl.getRichText = function (showTipsFunction, editorId, istestContent)
|
||||
|
||||
|
||||
// 需要移除的图片
|
||||
var needRemoveImgs = new Array();
|
||||
var needRemoveImgs = [];
|
||||
|
||||
// 处理图片
|
||||
if ($noteImgs.length > 0) {
|
||||
@@ -195,7 +199,7 @@ RichTextUitl.getRichText = function (showTipsFunction, editorId, istestContent)
|
||||
} else {
|
||||
needRemoveImgs.push($noteImgs[i].parentNode);
|
||||
}
|
||||
}else if (!imgSrc && $noteImgs[i].getAttribute("_src")){
|
||||
} else if (!imgSrc && $noteImgs[i].getAttribute("_src")) {
|
||||
//未替换完成图片
|
||||
return_data.hasUnReplaceImg = true;
|
||||
}
|
||||
@@ -742,6 +746,8 @@ RichTextUitl.replaceIframeWithPreviewMode = function (editorid) {
|
||||
if ($(this).attr('advancedpreview') != 'true') {
|
||||
iframeSrc += '&page=' + $(this).attr('advancedpreview');
|
||||
}
|
||||
} else if (RichTextUitl.useWpsPreview) {
|
||||
iframeSrc += '&type=wps';
|
||||
}
|
||||
if (!allowDownload) {
|
||||
iframeSrc += '&download=false';
|
||||
@@ -777,23 +783,19 @@ RichTextUitl.showTips = function (msg, type) {
|
||||
if (!msg) {
|
||||
return;
|
||||
}
|
||||
var iconPrefix = RichTextUitl.prefix
|
||||
var iconPrefix = window.location.protocol + window.obj.mirrorDomain.NoteDomainHttps.replace("https:", '').replace('http:', '')
|
||||
|
||||
// 前缀只含笔记域名 手动拼接路径
|
||||
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>')
|
||||
$(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">' + 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');
|
||||
$('.toolTipBox img').attr('src', iconPrefix + '/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 img').attr('src', iconPrefix + '/res/plugin/ueditor/themes/default/images/right.png');
|
||||
}
|
||||
$('.toolTipBox').show();
|
||||
setTimeout(function () {
|
||||
@@ -819,6 +821,9 @@ RichTextUitl.showPreview = function (attachment, $iframe) {
|
||||
//使用非公网云盘的不允许预览
|
||||
return false;
|
||||
}
|
||||
if (!attachment.att_clouddisk) {
|
||||
return false
|
||||
}
|
||||
//设置了预览设置的,登录后允许预览,允许预览的才可以预览,不允许预览的不能预览
|
||||
var icon = (attachment.att_clouddisk.suffix || '').toLowerCase();
|
||||
if ((icon.indexOf('ppt') > -1 || icon.indexOf('doc') > -1
|
||||
@@ -1695,10 +1700,10 @@ RichTextUitl.imgHover = function (selector) {
|
||||
}
|
||||
|
||||
if (!$(this).parent().hasClass('active')) {
|
||||
if($(this).parents('a').length == 0){ //秀米a链接里是图片时点击事件冒泡到上层,话题要获取a链接的点击事件,这里阻止冒泡后,就不会触发上层的点击事件
|
||||
if ($(this).parents('a').length == 0) { //秀米a链接里是图片时点击事件冒泡到上层,话题要获取a链接的点击事件,这里阻止冒泡后,就不会触发上层的点击事件
|
||||
e.stopPropagation();
|
||||
}
|
||||
$(this).parent().attr('focus','true');
|
||||
$(this).parent().attr('focus', 'true');
|
||||
} else {
|
||||
$(this).parent().removeAttr('focus');
|
||||
return;
|
||||
@@ -1848,7 +1853,7 @@ RichTextUitl.imgHover = function (selector) {
|
||||
var objectid = RichTextUitl.getObjectIdByImgSrc(imgSrc);
|
||||
if (objectid) {
|
||||
//需要加图片水印的
|
||||
if(RichTextUitl.watermarkOptions && RichTextUitl.watermarkOptions.watermarkImageUrl){
|
||||
if (RichTextUitl.watermarkOptions && RichTextUitl.watermarkOptions.watermarkImageUrl) {
|
||||
objectid = RichTextUitl.generateWatermark(objectid, RichTextUitl.watermarkOptions) || objectid;
|
||||
}
|
||||
YunFileUtil.downloadYunFile('', objectid);
|
||||
@@ -2016,9 +2021,9 @@ RichTextUitl.detailPageEvent = function (selector) {
|
||||
/**
|
||||
* 获取云盘token
|
||||
*/
|
||||
if (!(typeof isShare != "undefined" && isShare)) {
|
||||
RichTextUitl.getUploadConfig(true)
|
||||
}
|
||||
// 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) {
|
||||
@@ -2077,6 +2082,8 @@ RichTextUitl.detailPageEvent = function (selector) {
|
||||
var clipboardData = (e.clipboardData || window.clipboardData);
|
||||
if (!clipboardData) return;
|
||||
|
||||
var range = window.getSelection().getRangeAt(0);
|
||||
|
||||
//获取选中的非富文本内容
|
||||
var selectedText = window.getSelection().toString();
|
||||
// if (selectedText.trim() == "" || selectedText.indexOf('\n') == -1) return;
|
||||
@@ -2086,7 +2093,7 @@ RichTextUitl.detailPageEvent = function (selector) {
|
||||
}
|
||||
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());
|
||||
//标题折叠的隐藏元素显示
|
||||
@@ -2111,6 +2118,10 @@ RichTextUitl.detailPageEvent = function (selector) {
|
||||
$(item).parent().remove()
|
||||
}
|
||||
})
|
||||
//去掉公式中的内容
|
||||
$(tempDiv).find('span[data-latexstr]').each(function (index, item) {
|
||||
item.innerHTML = '';
|
||||
})
|
||||
//详情页禁止下载的附件不允许复制
|
||||
if (!RichTextUitl.isCreator) {
|
||||
tempDiv = removeForbidDownloadAttach(tempDiv);
|
||||
@@ -2137,6 +2148,9 @@ RichTextUitl.getObjectIdByImgSrc = function (imgSrc) {
|
||||
var objectId = '';
|
||||
if (imgSrc.indexOf(".") > -1) {
|
||||
objectId = imgSrc.substring(imgSrc.lastIndexOf("/") + 1, imgSrc.lastIndexOf("."));
|
||||
if (imgSrc.indexOf('star4') > -1) {
|
||||
objectId = imgSrc.substring(imgSrc.indexOf("star4") + 6, imgSrc.lastIndexOf("/"))
|
||||
}
|
||||
} else {
|
||||
// 部分图片可能没有后缀
|
||||
objectId = imgSrc.substring(imgSrc.lastIndexOf("/") + 1);
|
||||
@@ -2347,6 +2361,11 @@ RichTextUitl.convertUrl = function (url, domain) {
|
||||
* @param selector:包含图片标签的dom节点,为了防止多编辑器处理多次、绑定多次事件
|
||||
*/
|
||||
RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
if (RichTextUitl.isIOS) {
|
||||
//解决IOS上滚动后touch事件不触发的问题
|
||||
document.addEventListener('touchstart', function () {
|
||||
});
|
||||
}
|
||||
// 去除不是表格的元素上包裹的div class="table"
|
||||
RichTextUitl.removetablewrap(selector);
|
||||
|
||||
@@ -2359,13 +2378,13 @@ RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
$(item).css('font-size', '');
|
||||
}
|
||||
if ($(item).css('position') === 'fixed') {
|
||||
$(item).css({'position': '','background-color': '','background': ''});
|
||||
$(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': ''});
|
||||
$(item).css({'position': '', 'background-color': '', 'background': ''});
|
||||
}
|
||||
});
|
||||
// RichTextUitl.blockEleHover(selector);
|
||||
@@ -2380,7 +2399,37 @@ RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
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()
|
||||
// 转义 HTML 并保留换行
|
||||
$(selector).find('code').each(function () {
|
||||
var codeElement = this;
|
||||
// 将 <br> 标签替换为换行符,然后获取文本
|
||||
var html = codeElement.innerHTML;
|
||||
if (html && html.match(/<[^>]+>/) && !html.match(/</)) {
|
||||
// 先将 <br> 转换为换行符
|
||||
var textWithNewlines = html.replace(/<br\s*\/?>/gi, '\n');
|
||||
// 创建临时元素获取纯文本(保留换行)
|
||||
var temp = document.createElement('div');
|
||||
temp.innerHTML = textWithNewlines;
|
||||
var textContent = temp.textContent || temp.innerText;
|
||||
// 转义 HTML 标签
|
||||
var escaped = textContent.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
// 设置回去
|
||||
codeElement.textContent = escaped;
|
||||
}
|
||||
// 处理 plain 语言标识
|
||||
var $code = $(codeElement);
|
||||
if ($code.attr('lang') === 'plain') {
|
||||
$code.attr('lang', 'plaintext');
|
||||
}
|
||||
if (codeElement.className.indexOf('language-plain') > -1) {
|
||||
codeElement.className = codeElement.className.replace(/language-plain\b/g, 'language-plaintext');
|
||||
}
|
||||
});
|
||||
try {
|
||||
hljs.highlightAll();
|
||||
} catch (e) {
|
||||
console.warn('highlight.js error:', e);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2448,6 +2497,8 @@ RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
if ($(this).attr('advancedpreview') != 'true') {
|
||||
iframeSrc += '&page=' + $(this).attr('advancedpreview');
|
||||
}
|
||||
} else if (RichTextUitl.useWpsPreview) {
|
||||
iframeSrc += '&type=wps';
|
||||
}
|
||||
var downloadConfig = ''
|
||||
if (($(this).attr('allowdownload') == 'false' && $(this).attr('download') == 'false')
|
||||
@@ -2460,6 +2511,7 @@ RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
resid = att_clouddisk.resid
|
||||
iframeSrc += '&resid=' + resid;
|
||||
}
|
||||
|
||||
$(this).attr('src', iframeSrc);
|
||||
})
|
||||
$(selector).find('.editor-iframe iframe[excel=true]').each(function () {
|
||||
@@ -2490,8 +2542,30 @@ RichTextUitl.commonEventAfterPageRendered = function (selector) {
|
||||
// 设置详情页事件
|
||||
RichTextUitl.detailPageEvent(selector);
|
||||
}
|
||||
|
||||
// 格式化markdown数据
|
||||
function escapeBrackets(text) {
|
||||
var pattern = /\\\[([\s\S]*?)\\]|\\\(([\s\S]*?)\\\)/g;
|
||||
var result = text.replace(pattern, function (match, squareBracket, roundBracket, offset, origin) {
|
||||
const prefix = origin.slice(offset - 1, offset)
|
||||
const isNewLine = prefix === "\n"
|
||||
if (squareBracket) {
|
||||
if (isNewLine) {
|
||||
return "$$" + squareBracket.trim() + "$$";
|
||||
}
|
||||
return "$" + squareBracket.trim() + "$";
|
||||
} else if (roundBracket) {
|
||||
return "$" + roundBracket.trim() + "$";
|
||||
}
|
||||
return match
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// markdown转html
|
||||
RichTextUitl.markDownToHtml = function (markdownText) {
|
||||
markdownText = escapeBrackets(markdownText);
|
||||
marked.setOptions({
|
||||
renderer: new marked.Renderer(),
|
||||
gfm: true,
|
||||
@@ -2502,9 +2576,25 @@ RichTextUitl.markDownToHtml = function (markdownText) {
|
||||
smartLists: true,
|
||||
smartypants: false
|
||||
});
|
||||
return marked.parse(markdownText);
|
||||
var html = marked.parse(markdownText);
|
||||
|
||||
//把转换后的html中的>和<替换为>和<
|
||||
html = html.replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&')
|
||||
|
||||
// 处理公式,将公式转换为span标签
|
||||
html = html.replace(/\$(.*?)\$/g, function (match, p1) {
|
||||
return '<span class="latex_math_inline" data-latexstr="' + encodeURIComponent(p1) + '">' + p1 + '</span>';
|
||||
});
|
||||
|
||||
// 匹配块级公式 $$...$$
|
||||
html = html.replace(/\$\$(.*?)\$\$/g, function (match, p1) {
|
||||
return '<span class="latex_math_block" data-latexstr="' + encodeURIComponent(p1) + '">' + p1 + '</span>';
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
//去除不是表格的元素上包裹的div class="table"
|
||||
RichTextUitl.removetablewrap = function (selector) {
|
||||
$(selector).find('.table').each(function (index, item) {
|
||||
@@ -2640,6 +2730,27 @@ RichTextUitl.getUploadConfig = function (sync) {
|
||||
}
|
||||
}
|
||||
|
||||
//获取v2上传地址
|
||||
RichTextUitl.getV2UploadUrl = function () {
|
||||
var from = RichTextUitl.from || 'old_note_editor';
|
||||
var url = window.location.protocol + window.obj.mirrorDomain.NoteDomainHttps.replace("https:", '').replace('http:', '') + '/pc/files/getYunPanUploadUrl?from=' + from;
|
||||
var uploadUrl = '';
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'get',
|
||||
async: false,
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
success: function (res) {
|
||||
if (res.result) {
|
||||
uploadUrl = res.data
|
||||
}
|
||||
}
|
||||
})
|
||||
return uploadUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符转义
|
||||
* @param content
|
||||
@@ -3442,4 +3553,24 @@ RichTextUitl.openWxminiUrl = function (miniUrl, url) {
|
||||
//非微信打开
|
||||
window.location.href = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//编辑页根据cid修改附件信息 - 分组任务使用wps编辑后替换附件使用
|
||||
RichTextUitl.updateAttachmentByCid = function (editorid, cid, html) {
|
||||
var editor;
|
||||
if (editorid) {
|
||||
editor = UE.getEditor(editorid);
|
||||
} else if (ue) {
|
||||
editor = ue;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
var iframe = editor.body.querySelector('iframe[cid="' + cid + '"]');
|
||||
if (iframe) {
|
||||
var parentNode = iframe.parentNode
|
||||
iframe.outerHTML = html
|
||||
parentNode.querySelector('iframe').onload = function () {
|
||||
iframeOnload(this)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user