724 lines
24 KiB
Plaintext
724 lines
24 KiB
Plaintext
var MultiEditor = {
|
||
puid: '',
|
||
yunToken: '',
|
||
prdid: '442',//产品号,云盘那边给我们分配的,区分数据是那个团队传过去的
|
||
isPhone: false, //是否是移动端
|
||
idList: [],//编辑器id列表,防止重复调用initEditor
|
||
hasLoadAttachListener: false, //是否加载了附件监听js
|
||
nowDomain: '',//引用当前js的域名
|
||
noteDomain: 'https://noteyd.chaoxing.com',//默认的js前缀
|
||
passport2Domain: 'https://passport2.chaoxing.com',
|
||
hasLoadedEditor: false, //编辑器是否加载完成
|
||
init: function () {
|
||
type, ua, options
|
||
}, //加载配置文件
|
||
initEditor: function (json, callback, changecallback) {
|
||
}, //编辑页初始化编辑器
|
||
loadJSFile: function (src, cb) {
|
||
},
|
||
getRichText: function (editorid) {
|
||
}, // 获取富文本内容
|
||
setRichText: function (editorid, content) {
|
||
}, // 设置富文本内容
|
||
renderRichtext: function (editorId, content, ua) {
|
||
}, //详情页渲染富文本内容
|
||
getUploadConfig: function (editorId) {
|
||
}, //获取上传信息
|
||
unescapeHTML: function (content) {
|
||
}, //还原html脚本
|
||
randomUUID: function () {
|
||
}, //生成随机id
|
||
pcLoadProfile: function () {
|
||
},//加载PC配置文件
|
||
loadUE: function (editorid, cb) {
|
||
},//加载完编辑器
|
||
focus: function () {
|
||
},//光标定到编辑器
|
||
insertHTML: function (editorid, html) {
|
||
},//插入到编辑器
|
||
insertTeacherCommentAttach: function (editorid, data) {
|
||
},//题目编辑器-插入教师批注附件
|
||
execCommand: function (editorid, cmd, data) {
|
||
},//编辑器-执行命令
|
||
destoryEditor: function (editorid) {
|
||
}, //销毁编辑器
|
||
hasLoadEditFile: false, //是否已经加载过编辑页配置文件
|
||
hasLoadDetailFile: false, //是否已经加载过详情页配置文件
|
||
hasLoadRichTextUitl: false, //是否已经加载过Richtextutil文件
|
||
intranetMode: false,//镜像编辑器,不是镜像笔记
|
||
options: {},//传过来的参数
|
||
mirrorDomainList:{},//镜像接口获取的域名信息
|
||
mirrorPanDomain:'',//云盘镜像地址
|
||
mirrorPhotoDomain:'',//图片服务镜像地址
|
||
isMirrorDeploy:'',//是镜像笔记服务
|
||
isFileDownloadPageJump: false, // 是否是下载文件触发的页面跳转
|
||
}
|
||
|
||
/*加载配置文件
|
||
*type: edit 或者 detail
|
||
* ua: 指定是app还是pc
|
||
* options: isIntranetMode:是否是镜像模式
|
||
* prefix 前缀
|
||
* */
|
||
MultiEditor.init = function (type, ua, options) {
|
||
var uaInfor = navigator.userAgent.toLowerCase();
|
||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) || navigator.userAgent.indexOf('harmony') > -1) {
|
||
MultiEditor.isPhone = true;
|
||
} else if (ua == 'app') {
|
||
MultiEditor.isPhone = true;
|
||
}
|
||
if (options) {
|
||
MultiEditor.options = options;
|
||
}
|
||
//如果已经加载过,不再加载配置文件
|
||
if (type == 'edit') {
|
||
if (MultiEditor.hasLoadEditFile) {
|
||
return;
|
||
}
|
||
MultiEditor.hasLoadEditFile = true;
|
||
} else if (type == 'detail') {
|
||
if (MultiEditor.hasLoadDetailFile) {
|
||
return;
|
||
}
|
||
MultiEditor.hasLoadDetailFile = true;
|
||
}
|
||
if (MultiEditor.currentHref && MultiEditor.currentHref.indexOf('bistatic-') > -1) {
|
||
MultiEditor.noteDomain = window.location.protocol + '//bistatic-' + MultiEditor.noteDomain.replace('http:','').replace('https:','');
|
||
}
|
||
let prefix = ''
|
||
if (options && options.isIntranetMode) {
|
||
//是镜像
|
||
MultiEditor.intranetMode = true;
|
||
if (options && options.prefix) {
|
||
MultiEditor.prefix = options.prefix;
|
||
} else {
|
||
MultiEditor.prefix = 'ueditor4thirdparty/';
|
||
}
|
||
prefix = MultiEditor.prefix;
|
||
MultiEditor.isPhone = false; //镜像还没有支持移动端
|
||
} else {
|
||
if (options && options.prefix) {
|
||
MultiEditor.prefix = options.prefix;
|
||
} else {
|
||
MultiEditor.prefix = window.location.protocol + '//' + MultiEditor.nowDomain;
|
||
}
|
||
prefix = MultiEditor.prefix + '/res/plugin/ueditor4thirdparty/'
|
||
}
|
||
|
||
if (MultiEditor.isPhone) { //移动端
|
||
if(!window.obj){
|
||
window.obj = {};
|
||
}
|
||
if(window.location.host.indexOf('chaoxing.com') == -1){
|
||
//非超星域名获取镜像域名列表
|
||
MultiEditor.getMirrorDomain();
|
||
}
|
||
if (ua == 'xxt' && uaInfor.indexOf("chaoxingstudy") != -1) {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/plugin/meditor/js/mrich.text.util.js?_t=' + new Date().getTime(), function () {
|
||
if (type == 'edit') {
|
||
MrichTextUitl.loadEditorProfile2();
|
||
} else if (type == 'detail') {
|
||
MrichTextUitl.loadDetailPageProfile2();
|
||
}
|
||
});
|
||
} else {
|
||
//防止attachment_listener加载多次
|
||
if (MultiEditor.hasLoadAttachListener == false && typeof AttachmentListener == 'undefined') {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/pc/js/noteRichtext/attachment_listener.js?_t=' + new Date().getTime())
|
||
AttachmentListener = {};
|
||
MultiEditor.hasLoadAttachListener = true;
|
||
}
|
||
if (type == 'edit') {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/plugin/meditor/js/mrich.text.util.js?_t=' + new Date().getTime(), function () {
|
||
for (var key in MultiEditor.options) {
|
||
MrichTextUitl[key] = MultiEditor.options[key];
|
||
}
|
||
MrichTextUitl.loadMoreEditorProfile();
|
||
});
|
||
} else if (type == 'detail') {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/plugin/ueditor4thirdparty/rich.text.util.js?_t=' + new Date().getTime(), function () {
|
||
MultiEditor.pcLoadProfile(type);
|
||
})
|
||
}
|
||
}
|
||
} else { //PC
|
||
//防止attachment_listener加载多次
|
||
if (MultiEditor.hasLoadAttachListener == false && typeof AttachmentListener == 'undefined') {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/pc/js/noteRichtext/attachment_listener.js?_t=' + new Date().getTime())
|
||
AttachmentListener = {};
|
||
MultiEditor.hasLoadAttachListener = true;
|
||
}
|
||
if (typeof RichTextUitl == 'undefined') {
|
||
if (MultiEditor.hasLoadRichTextUitl) {
|
||
//防止两次调用期间js还没加载完成
|
||
var timer = setInterval(function () {
|
||
if (typeof RichTextUitl != 'undefined') {
|
||
clearInterval(timer)
|
||
MultiEditor.pcLoadProfile(type);
|
||
}
|
||
}, 500);
|
||
} else {
|
||
MultiEditor.hasLoadRichTextUitl = true;
|
||
MultiEditor.loadJSFile(prefix + 'rich.text.util.js?_t=' + new Date().getTime(), function () {
|
||
MultiEditor.pcLoadProfile(type);
|
||
})
|
||
}
|
||
} else {
|
||
MultiEditor.pcLoadProfile(type);
|
||
}
|
||
}
|
||
}
|
||
//获取镜像域名
|
||
MultiEditor.getMirrorDomain = function(){
|
||
if (typeof jQuery != 'undefined') {
|
||
var json = {
|
||
url: MultiEditor.prefix + '/apis/mirrorConfig',
|
||
type: "get",
|
||
xhrFields: {
|
||
withCredentials: true
|
||
},
|
||
data: {},
|
||
dataType: "json",
|
||
success: function (res) {
|
||
if(res.result){
|
||
let result = res.data
|
||
MultiEditor.mirrorDomainList = result.domainMap;
|
||
for(var key in MultiEditor.mirrorDomainList){
|
||
if(MultiEditor.mirrorDomainList[key]){
|
||
MultiEditor.mirrorDomainList[key] = window.location.protocol + MultiEditor.mirrorDomainList[key].replace('https:','').replace('http:','')
|
||
}
|
||
}
|
||
MultiEditor.isMirrorDeploy = result.isMirrorDeploy;
|
||
window.obj.mirrorDomain = MultiEditor.mirrorDomainList;
|
||
window.obj.mirrorDomain.isMirrorDeploy = result.isMirrorDeploy
|
||
MultiEditor.noteDomain = MultiEditor.mirrorDomainList.NoteDomainHttps
|
||
MultiEditor.mirrorPanDomain = MultiEditor.mirrorDomainList.panDomainHttps
|
||
MultiEditor.mirrorPhotoDomain = MultiEditor.mirrorDomainList.photoDomainHttps
|
||
MultiEditor.passport2Domain = MultiEditor.mirrorDomainList.passport2DomainHttps
|
||
}
|
||
},
|
||
error: function () {
|
||
}
|
||
}
|
||
// 同步调用
|
||
json.async = false;
|
||
$.ajax(json);
|
||
}
|
||
}
|
||
//加载PC配置文件
|
||
MultiEditor.pcLoadProfile = function (type) {
|
||
RichTextUitl.ismultiEditor = true;
|
||
if (MultiEditor.options) {
|
||
for (var key in MultiEditor.options) {
|
||
RichTextUitl[key] = MultiEditor.options[key];
|
||
}
|
||
if (MultiEditor.intranetMode) {
|
||
RichTextUitl.intranetMode = true;
|
||
}
|
||
RichTextUitl.prefix = MultiEditor.prefix
|
||
// 查看大图时是否可编辑 默认为false
|
||
if(MultiEditor.options.isEditableViewLargeImage === true) {
|
||
RichTextUitl.isEditableViewLargeImage = true
|
||
}
|
||
}
|
||
//提前加载js,避免ueditor报错
|
||
if (MultiEditor.intranetMode) {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + 'rich.text.common.js');
|
||
} else if (MultiEditor.prefix) {
|
||
MultiEditor.loadJSFile(MultiEditor.prefix + '/res/pc/js/noteRichtext/rich.text.common.js');
|
||
} else {
|
||
MultiEditor.loadJSFile(window.location.protocol + '//' + MultiEditor.nowDomain + '/res/pc/js/noteRichtext/rich.text.common.js');
|
||
}
|
||
if (type == 'edit') {
|
||
RichTextUitl.loadEditorProfile(true, true)
|
||
} else if (type == 'detail') {
|
||
RichTextUitl.loadDetailPageProfile(true, true, false, false, true);
|
||
}
|
||
}
|
||
/*
|
||
* param editorid: 编辑器id、
|
||
* param content: 富文本内容、
|
||
* param editorheight: 初始高度
|
||
* param callback:回调方法(编辑器加载完成后的回调)
|
||
* param changecallback: 监听内容改变的时候回调
|
||
*/
|
||
MultiEditor.initEditor = function (json, callback, changecallback) {
|
||
var editorid = json.editorid;
|
||
|
||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) || navigator.userAgent.indexOf('harmony') > -1) {
|
||
MultiEditor.isPhone = true;
|
||
}
|
||
if (MultiEditor.isPhone) { //移动端
|
||
var loadfiletimer = setInterval(function () {
|
||
if (typeof (MrichTextUitl) != 'undefined' && typeof (zss_editor) != 'undefined' && $('body').length > 0) {
|
||
clearInterval(loadfiletimer);
|
||
MrichTextUitl.initMoreEditor(json, callback, changecallback);
|
||
if (typeof callback == 'function') {
|
||
callback();
|
||
MultiEditor.hasLoadedEditor = true;
|
||
}
|
||
}
|
||
}, 500)
|
||
} else { //PC
|
||
//不允许同一个id多次初始化
|
||
if (MultiEditor.idList.indexOf(editorid) > -1) {
|
||
return;
|
||
}
|
||
MultiEditor.idList.push(editorid);
|
||
// if (document.getElementById(editorid) && document.getElementById(editorid).querySelector('.edui-editor')) {
|
||
// //已经初始化过的,不再初始化
|
||
// return;
|
||
// }
|
||
document.getElementById(editorid).innerHTML = '<script id="multi' + editorid + '" name="content" type="text/plain"></script>';
|
||
var loadfiletimer = setInterval(function () {
|
||
if (typeof (RichTextUitl) != 'undefined' && typeof (UE) != "undefined" && typeof (UE.getEditor) != "undefined") {
|
||
clearInterval(loadfiletimer);
|
||
RichTextUitl.initMoreUEditor(json, callback, changecallback);
|
||
MultiEditor.hasLoadedEditor = true;
|
||
}
|
||
}, 500)
|
||
}
|
||
}
|
||
//编辑页插入编辑器内容
|
||
MultiEditor.setRichText = function (editorid, content) {
|
||
if (MultiEditor.isPhone) { //移动端
|
||
if(typeof MrichTextUitl == 'undefined'){
|
||
console.log('请等待编辑器加载完成...')
|
||
return
|
||
}
|
||
content = MrichTextUitl.beforeSetRtfContent(content,{type:'edit'});
|
||
MrichTextUitl.setRichtext({'content': content}, editorid);
|
||
} else { //PC
|
||
if(typeof RichTextUitl == 'undefined'){
|
||
console.log('请等待编辑器加载完成...')
|
||
return
|
||
}
|
||
content = RichTextUitl.beforeSetRtfContent(content,{type:'edit'});
|
||
MultiEditor.loadUE(editorid, function (editor) {
|
||
editor.setContent(content);
|
||
})
|
||
}
|
||
}
|
||
/*插入富文本内容
|
||
* editorid 编辑器id
|
||
* cmd 命令
|
||
* data Object类型
|
||
* */
|
||
MultiEditor.insertHTML = function (editorid, html) {
|
||
if (MultiEditor.isPhone) { //移动端
|
||
html = MrichTextUitl.beforeSetRtfContent(html);
|
||
} else {
|
||
html = RichTextUitl.beforeSetRtfContent(html);
|
||
}
|
||
MultiEditor.execCommand(editorid, 'inserthtml', html);
|
||
}
|
||
/*执行编辑器内部命令
|
||
* editorid 编辑器id
|
||
* cmd 命令
|
||
* data
|
||
* */
|
||
MultiEditor.execCommand = function (editorid, cmd, data) {
|
||
if (MultiEditor.isPhone) { //移动端
|
||
if (typeof (zss_editor) != 'undefined' && $('body').length > 0) {
|
||
zss_editor.updateEnterRange(editorid);
|
||
zss_editor.insertHTML(data)
|
||
zss_editor.backupRange();
|
||
}
|
||
} else { //PC
|
||
MultiEditor.loadUE(editorid, function (editor) {
|
||
editor.execCommand(cmd, data);
|
||
})
|
||
}
|
||
}
|
||
|
||
//移动端插入图片
|
||
MultiEditor.insertImage = function (editorid, imgurl, objectId) {
|
||
if (MultiEditor.isPhone) { //移动端
|
||
if (typeof (zss_editor) != 'undefined' && $('body').length > 0) {
|
||
zss_editor.updateEnterRange(editorid);
|
||
zss_editor.insertImage(imgurl, objectId, '', '', true);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
MultiEditor.getEditor = function (editorid) {
|
||
var editor = UE.getEditor('multi' + editorid);
|
||
return editor;
|
||
}
|
||
//编辑器加载完成事件后回调
|
||
MultiEditor.loadUE = function (editorid, cb) {
|
||
if (typeof (UE) == 'undefined') {
|
||
var loadfiletimer = setInterval(function () {
|
||
if (typeof (UE) != 'undefined') {
|
||
clearInterval(loadfiletimer);
|
||
var editor = UE.getEditor('multi' + editorid);
|
||
if (typeof (editor.body) == 'undefined') {
|
||
var loadfiletimer2 = setInterval(function () {
|
||
if (typeof (editor.body) != 'undefined') {
|
||
clearInterval(loadfiletimer2);
|
||
if (cb) cb(editor)
|
||
}
|
||
}, 500)
|
||
} else {
|
||
if (cb) cb(editor)
|
||
}
|
||
}
|
||
}, 500)
|
||
} else {
|
||
var editor = UE.getEditor('multi' + editorid);
|
||
if (typeof (editor.body) == 'undefined') {
|
||
var loadfiletimer2 = setInterval(function () {
|
||
if (typeof (editor.body) != 'undefined') {
|
||
clearInterval(loadfiletimer2);
|
||
if (cb) cb(editor)
|
||
}
|
||
}, 500)
|
||
} else {
|
||
if (cb) cb(editor)
|
||
}
|
||
}
|
||
}
|
||
|
||
//编辑页获取编辑器内容
|
||
MultiEditor.getRichText = function (editorid) {
|
||
if (MultiEditor.isPhone) { //移动端
|
||
return MrichTextUitl.getRichtextObj(editorid)
|
||
} else { //PC
|
||
if (typeof (UE) == 'undefined' || typeof UE.getEditor('multi' + editorid).body == "undefined") {
|
||
console.log('编辑器未加载完成,请稍后再获取数据')
|
||
return null;
|
||
} else {
|
||
var richtext = RichTextUitl.getRichText(null, 'multi' + editorid);
|
||
if (!richtext) {
|
||
richtext = {attachment: "", content: "", content_imgs: "", rtf_content: "", isuploading: true,hasUploadFailed:''}
|
||
}
|
||
return richtext;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**详情页渲染富文本内容
|
||
* param richtextId 文本容器的id
|
||
* param content 文本内容
|
||
* param ua 浏览器
|
||
* params options 其他参数
|
||
*/
|
||
MultiEditor.renderRichtext = function (richtextId, content, ua, options) {
|
||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) || navigator.userAgent.indexOf('harmony') > -1) {
|
||
MultiEditor.isPhone = true;
|
||
}
|
||
|
||
var uaInfor = navigator.userAgent.toLowerCase();
|
||
if (ua == 'xxt' && uaInfor.indexOf("chaoxingstudy") != -1) {
|
||
if (typeof (MrichTextUitl) == 'undefined') {
|
||
var loadfiletimer = setInterval(function () {
|
||
if (typeof (MrichTextUitl) != 'undefined') {
|
||
clearInterval(loadfiletimer);
|
||
zss_editor.changeClientType();
|
||
zss_editor.init();
|
||
//渲染富文本内容
|
||
MrichTextUitl.insertDetailContent(content);
|
||
}
|
||
}, 500)
|
||
} else {
|
||
zss_editor.changeClientType();
|
||
zss_editor.init();
|
||
//渲染富文本内容
|
||
MrichTextUitl.insertDetailContent(content);
|
||
}
|
||
} else {
|
||
|
||
if (typeof (RichTextUitl) == 'undefined' || typeof (RichTextUitl.b64DecodeUnicode) == 'undefined') {
|
||
var loadfiletimer = setInterval(function () {
|
||
if (typeof (RichTextUitl) != 'undefined' && typeof (RichTextUitl.b64DecodeUnicode) != 'undefined') {
|
||
clearInterval(loadfiletimer);
|
||
MultiEditor.pcLoadRichText(richtextId, content, options)
|
||
}
|
||
}, 500)
|
||
} else {
|
||
MultiEditor.pcLoadRichText(richtextId, content, options)
|
||
}
|
||
}
|
||
|
||
// 详情页是否显示图片边框
|
||
if(MultiEditor.options && MultiEditor.options.showImageBorder === false) {
|
||
$('#' + richtextId).attr('show-image-border', false)
|
||
}
|
||
}
|
||
// pc中js加载完成后的操作
|
||
MultiEditor.pcLoadRichText = function (richtextId, content, options) {
|
||
if(options && options.catalogDiv) {
|
||
RichTextUitl.catalogDiv = options.catalogDiv
|
||
}
|
||
if(options && typeof options.catalogOptions != 'undefined') {
|
||
RichTextUitl.catalogOptions = options.catalogOptions
|
||
}
|
||
<!-- 富文本内容渲染到页面之前进行的操作-->
|
||
content = RichTextUitl.beforeSetRtfContent(content);
|
||
document.getElementById(richtextId).innerHTML = content;
|
||
<!-- 富文本内容渲染到页面之后进行的操作-->
|
||
RichTextUitl.afterPageRendered(document.getElementById(richtextId),options);
|
||
}
|
||
|
||
//获取编辑器对象,编辑器加载完成后调用
|
||
MultiEditor.focus = function (richtextId, toEnd) {
|
||
if (MultiEditor.isPhone) {
|
||
$('#' + richtextId).find('.editor_main').focus()
|
||
} else {
|
||
MultiEditor.loadUE(richtextId, function (editor) {
|
||
editor.focus(toEnd);
|
||
});
|
||
}
|
||
}
|
||
//销毁编辑器
|
||
MultiEditor.destoryEditor = function (editorid) {
|
||
$('#' + editorid).empty();
|
||
MultiEditor.idList.splice(MultiEditor.idList.indexOf(editorid), 1)
|
||
if (!MultiEditor.isPhone && typeof (UE) != 'undefined' && typeof UE.getEditor('multi' + editorid).body != "undefined") {
|
||
UE.getEditor('multi' + editorid).destroy();
|
||
}
|
||
}
|
||
|
||
//编辑器markdown转html
|
||
MultiEditor.insertMarkdown = function (editorid, text) {
|
||
UE.getEditor('multi' + editorid).execCommand('inserthtml', RichTextUitl.markDownToHtml(text));
|
||
}
|
||
|
||
//修改PC编辑器内容 id为dom查询条件,如#id,text为要修改的内容
|
||
MultiEditor.updatePCEditorText = function (editorid, id, text) {
|
||
var editor = MultiEditor.getEditor(editorid)
|
||
if(editor){
|
||
editor.body.querySelector(id).innerText = text;
|
||
editor.fireEvent('contentchange');
|
||
editor.fireEvent('saveScene');
|
||
}
|
||
}
|
||
//修改PC编辑器内容 id为dom查询条件,如#id,html为要修改的内容
|
||
MultiEditor.updatePCEditorHTML = function (editorid, id, html) {
|
||
var editor = MultiEditor.getEditor(editorid)
|
||
if(editor){
|
||
editor.body.querySelector(id).outerHTML = html;
|
||
editor.fireEvent('contentchange');
|
||
editor.fireEvent('saveScene');
|
||
}
|
||
}
|
||
|
||
//移动光标至指定节点后面
|
||
MultiEditor.moveCursorAfterNode = function (editor, node) {
|
||
// 获取当前选区
|
||
var range = editor.selection.getRange();
|
||
// 获取当前光标所在的节点
|
||
var currentNode = range.startContainer;
|
||
// 将光标移动到span标签的后面
|
||
range.setStartAfter(node);
|
||
range.collapse(true).select(); // 设置新的选区
|
||
}
|
||
|
||
/*题目编辑器 - 插入教师批注附件
|
||
* editorid:编辑器id
|
||
* data:json对象,示例{data1:'xxx',data2:'xxx'},data1 data2是课程业务数据的id 作答记录 题目
|
||
* */
|
||
MultiEditor.insertTeacherCommentAttach = function (editorid, data) {
|
||
var cid = MultiEditor.randomUUID();
|
||
var json = {
|
||
"att_web": {
|
||
"content": "",
|
||
"logo": window.location.protocol + "//mooc2-ans.chaoxing.com/mooc2-ans/module/work/images/viewAttach.png",
|
||
"title": '教师批注',
|
||
"url": '',
|
||
data1: data.data1,
|
||
data2: data.data2,
|
||
},
|
||
"attachmentType": 25,
|
||
"cid": cid
|
||
}
|
||
var html = "<br><div element-id='" + MultiEditor.randomUUID() + "' class='editor-iframe' contenteditable='false'><iframe frameborder='0' scrolling='no' cid='" + cid + "' src='"+window.location.protocol +"//noteyd.chaoxing.com/attachment/insertWeb.html' name='" + btoa(encodeURIComponent(JSON.stringify(json))) + "' class='attach-module attach-insertWeb' module='insertWeb'></iframe></div>"
|
||
MultiEditor.insertHTML(editorid, html);
|
||
}
|
||
|
||
//章节笔记--插入章节视频打点
|
||
/** pointData:{id:'aaa',time:40}
|
||
* attachment: { "cid": cid,
|
||
* "attachmentType": 54,
|
||
* "att_course_video": data.att_course_video }
|
||
* */
|
||
MultiEditor.insertCourseVideoMark = function (editorid, pointData, attachment) {
|
||
if (!MultiEditor.hasLoadedEditor) return
|
||
if (MultiEditor.isPhone) {
|
||
if (typeof (zss_editor) != 'undefined' && $('body').length > 0) {
|
||
zss_editor.updateEnterRange(editorid);
|
||
zss_editor.insertCourseVideo(pointData, attachment)
|
||
}
|
||
} else {
|
||
let editor = MultiEditor.getEditor(editorid)
|
||
if (editor) {
|
||
editor.insertCourseVideo(pointData, attachment)
|
||
}
|
||
}
|
||
}
|
||
|
||
//加载外部js
|
||
MultiEditor.loadJSFile = 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)
|
||
}
|
||
|
||
MultiEditor.getUploadConfig = function (sync) {
|
||
if (MultiEditor.puid && MultiEditor.yunToken) {
|
||
return;
|
||
}
|
||
if (typeof jQuery != 'undefined') {
|
||
var json = {
|
||
url: window.location.protocol+"//"+MultiEditor.noteDomain.replace('https://','').replace('http://','') + "/pc/files/getUploadConfig",
|
||
type: "get",
|
||
xhrFields: {
|
||
withCredentials: true
|
||
},
|
||
data: {},
|
||
dataType: "json",
|
||
success: function (resultData) {
|
||
if (resultData && resultData.result == 1) {
|
||
MultiEditor.puid = resultData.msg.puid;
|
||
MultiEditor.yunToken = resultData.msg.token || '';
|
||
}
|
||
},
|
||
error: function () {
|
||
}
|
||
}
|
||
if (sync) {
|
||
// 同步调用
|
||
json.async = false;
|
||
}
|
||
$.ajax(json);
|
||
}
|
||
}
|
||
//获取js当前路径
|
||
MultiEditor.currentHref = function () {
|
||
var jsPath = document.currentScript && document.currentScript.src ? document.currentScript.src : function () {
|
||
var js = document.scripts
|
||
, last = js.length - 1
|
||
, src;
|
||
for (var i = last; i > 0; i--) {
|
||
if (js[i].readyState === 'interactive') {
|
||
src = js[i].src;
|
||
break;
|
||
}
|
||
if (js[i].src.indexOf('multieditor.js') > -1) {
|
||
src = js[i].src;
|
||
break;
|
||
}
|
||
}
|
||
return src || js[last].src;
|
||
}();
|
||
jsPath = jsPath.substring(jsPath.indexOf('//') + 2, jsPath.lastIndexOf('/') + 1);
|
||
MultiEditor.nowDomain = jsPath.substring(0, jsPath.indexOf('/res/'));
|
||
return jsPath;
|
||
}();
|
||
|
||
/**
|
||
* 还原html脚本 < > & " '
|
||
*/
|
||
MultiEditor.unescapeHTML = function (content) {
|
||
if (content) {
|
||
return content.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'");
|
||
}
|
||
return "";
|
||
}
|
||
|
||
MultiEditor.randomUUID = function () {
|
||
var s = [];
|
||
var hexDigits = "0123456789abcdef";
|
||
for (var i = 0; i < 36; i++) {
|
||
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
||
}
|
||
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
||
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
||
s[8] = s[13] = s[18] = s[23] = "-";
|
||
|
||
var uuid = s.join("");
|
||
return uuid;
|
||
}
|
||
|
||
//加载转发数据
|
||
MultiEditor.localTransferData = ''
|
||
//初始化加载转发数据方法
|
||
MultiEditor.initForwardData = function(type,callback){
|
||
var isPcClient = RegExp("\\(schild:(\\w+).*ChaoXingStudy_(\\d+)_(\\d+[^_]*)_([^_]*)_([pc]*)_([^ ]*)?( \\([^)]*\\))?.*_(.*[-]?\\w+).*").test(navigator.userAgent);
|
||
// pc客户端定制需求(逐条转发)
|
||
if(isPcClient) {
|
||
jsBridge.bind('CLIENT_GET_INIT_DATA', function(data) {
|
||
console.log('富文本数据', data)
|
||
if(data && data.content) {
|
||
MultiEditor.localTransferData = data
|
||
MultiEditor.loadForwardData(callback)
|
||
}
|
||
})
|
||
jsBridge.postNotification('CLIENT_GET_INIT_DATA');
|
||
}else{
|
||
MultiEditor.localTransferData = getCookie('localTransferData')
|
||
if(MultiEditor.localTransferData){
|
||
MultiEditor.localTransferData = JSON.parse(MultiEditor.localTransferData)
|
||
MultiEditor.loadForwardData(callback)
|
||
delCookie('localTransferData')
|
||
}
|
||
window.addEventListener('message',function (e) {
|
||
if(e.data.type == 'localTransferData'){
|
||
MultiEditor.localTransferData = JSON.parse(e.data.data)
|
||
try{
|
||
window.opener.postMessage({msgType:'transferDataloaded',type:type},'*')
|
||
}catch(e){
|
||
console.log(e)
|
||
}
|
||
console.log(e.data.data)
|
||
MultiEditor.loadForwardData(callback)
|
||
}
|
||
})
|
||
}
|
||
function getCookie(name){
|
||
var arr,reg=new RegExp("(^| )*"+name+"=([^;]*)(;|$)");
|
||
if(arr = document.cookie.match(reg)){
|
||
return unescape(arr[2]);
|
||
}else{
|
||
return null;
|
||
}
|
||
}
|
||
//删除cookie
|
||
function delCookie(name){
|
||
document.cookie = name+"=;expires="+(new Date(0)).toGMTString()+ ";path=/;domain=chaoxing.com;";
|
||
}
|
||
}
|
||
//处理转发数据
|
||
MultiEditor.loadForwardData = function (callback) {
|
||
var localTransferData = MultiEditor.localTransferData;
|
||
if(localTransferData){
|
||
var rtf_content = localTransferData.content;
|
||
var ForwardTitle = ''
|
||
if(rtf_content && rtf_content.indexOf('<') == -1){
|
||
rtf_content = decodeURIComponent(rtf_content)
|
||
}
|
||
if (localTransferData.title) {
|
||
ForwardTitle = localTransferData.title
|
||
}
|
||
if(callback){
|
||
callback(rtf_content,ForwardTitle)
|
||
}
|
||
}
|
||
}
|