2017-04-26 18:17:38 +08:00
|
|
|
|
$(function () {
|
2018-03-01 11:28:21 +08:00
|
|
|
|
editormd.katexURL = {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
js: window.katex.js,
|
|
|
|
|
css: window.katex.css
|
2018-03-01 11:28:21 +08:00
|
|
|
|
};
|
2023-07-01 23:20:10 +08:00
|
|
|
|
var drawio = new Object()
|
|
|
|
|
|
|
|
|
|
drawio.processMarkers = function (from, to) {
|
|
|
|
|
var _this = this
|
|
|
|
|
var found = null
|
|
|
|
|
var foundStart = 0
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
cm.doc.getAllMarks().forEach(mk => {
|
|
|
|
|
if (mk.__kind) {
|
|
|
|
|
mk.clear()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
cm.eachLine(from, to, function (ln) {
|
|
|
|
|
const line = ln.lineNo()
|
|
|
|
|
|
|
|
|
|
if (ln.text.startsWith('```drawio')) {
|
|
|
|
|
found = 'drawio'
|
|
|
|
|
foundStart = line
|
|
|
|
|
} else if (ln.text === '```' && found) {
|
|
|
|
|
switch (found) {
|
|
|
|
|
// -> DRAWIO
|
|
|
|
|
case 'drawio': {
|
|
|
|
|
if (line - foundStart !== 2) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
_this.addMarker({
|
|
|
|
|
kind: 'drawio',
|
|
|
|
|
from: { line: foundStart, ch: 3 },
|
|
|
|
|
to: { line: foundStart, ch: 10 },
|
|
|
|
|
text: 'drawio',
|
|
|
|
|
action: (function (start, end) {
|
|
|
|
|
return function (ev) {
|
|
|
|
|
cm.doc.setSelection({ line: start, ch: 0 }, { line: end, ch: 3 })
|
|
|
|
|
try {
|
|
|
|
|
// save state data
|
|
|
|
|
const raw = cm.doc.getLine(end - 1)
|
|
|
|
|
window.sessionStorage.setItem("drawio", raw);
|
|
|
|
|
_this.show()
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})(foundStart, line)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (ln.height > 0) {
|
|
|
|
|
cm.foldCode(foundStart)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
found = null
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawio.addMarker = function ({ kind, from, to, text, action }) {
|
|
|
|
|
|
|
|
|
|
const markerElm = document.createElement('span')
|
|
|
|
|
markerElm.appendChild(document.createTextNode(text))
|
|
|
|
|
markerElm.className = 'CodeMirror-buttonmarker'
|
|
|
|
|
markerElm.addEventListener('click', action)
|
|
|
|
|
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
cm.markText(from, to, { replacedWith: markerElm, __kind: kind })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawio.show = function () {
|
|
|
|
|
|
2023-12-19 13:19:31 +08:00
|
|
|
|
const drawUrl = 'https://embed.diagrams.net/?embed=1&libraries=1&proto=json&spin=1&saveAndExit=1&noSaveBtn=1&noExitBtn=0'; // TODO: with Tomcat & https://github.com/jgraph/drawio
|
2023-07-01 23:20:10 +08:00
|
|
|
|
this.div = document.createElement('div');
|
|
|
|
|
this.div.id = 'diagram';
|
|
|
|
|
this.gXml = '';
|
|
|
|
|
this.div.innerHTML = '';
|
|
|
|
|
this.iframe = document.createElement('iframe');
|
|
|
|
|
this.iframe.setAttribute('frameborder', '0');
|
|
|
|
|
this.iframe.style.zIndex = 9999;
|
|
|
|
|
this.iframe.style.width = "100%";
|
|
|
|
|
this.iframe.style.height = "100%";
|
|
|
|
|
this.iframe.style.position = "absolute";
|
|
|
|
|
this.iframe.style.top = window.scrollY + "px";
|
|
|
|
|
binded = this.postMessage.bind(this);
|
|
|
|
|
window.addEventListener("message", binded, false);
|
|
|
|
|
this.iframe.setAttribute('src', drawUrl);
|
|
|
|
|
document.body.appendChild(this.iframe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawio.postMessage = function (evt) {
|
|
|
|
|
if (evt.data.length < 1) return
|
|
|
|
|
var msg = JSON.parse(evt.data)
|
|
|
|
|
var svg = '';
|
|
|
|
|
|
|
|
|
|
switch (msg.event) {
|
|
|
|
|
case "configure":
|
|
|
|
|
this.iframe.contentWindow.postMessage(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
action: "configure",
|
|
|
|
|
config: {
|
|
|
|
|
defaultFonts: ["Humor Sans", "Helvetica", "Times New Roman"],
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
"*"
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "init":
|
|
|
|
|
code = window.sessionStorage.getItem("drawio")
|
|
|
|
|
svg = decodeURIComponent(escape(window.atob(code)))
|
|
|
|
|
this.iframe.contentWindow.postMessage(
|
|
|
|
|
JSON.stringify({ action: "load", autosave: 1, xml: svg }),
|
|
|
|
|
"*"
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "autosave":
|
|
|
|
|
window.sessionStorage.setItem("drawio", svg);
|
|
|
|
|
break;
|
|
|
|
|
case "save":
|
|
|
|
|
this.iframe.contentWindow.postMessage(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
action: "export",
|
|
|
|
|
format: "xmlsvg",
|
|
|
|
|
xml: msg.xml,
|
|
|
|
|
spin: "Updating page",
|
|
|
|
|
}),
|
|
|
|
|
"*"
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case "export":
|
|
|
|
|
svgData = msg.data.substring(msg.data.indexOf(',') + 1);
|
|
|
|
|
// clean event bind
|
|
|
|
|
window.removeEventListener("message", this.binded);
|
|
|
|
|
document.body.removeChild(this.iframe);
|
|
|
|
|
|
|
|
|
|
// write back svg data
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
cm.doc.replaceSelection('```drawio\n' + svgData + '\n```', 'start')
|
|
|
|
|
// clean state data
|
|
|
|
|
window.sessionStorage.setItem("drawio", '');
|
|
|
|
|
break;
|
|
|
|
|
case "exit":
|
|
|
|
|
window.removeEventListener("message", this.binded);
|
|
|
|
|
document.body.removeChild(this.iframe);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-14 18:17:46 +08:00
|
|
|
|
|
2021-04-15 19:25:02 +08:00
|
|
|
|
window.editormdLocales = {
|
|
|
|
|
'zh-CN': {
|
|
|
|
|
placeholder: '本编辑器支持 Markdown 编辑,左边编写,右边预览。',
|
|
|
|
|
contentUnsaved: '编辑内容未保存,需要保存吗?',
|
|
|
|
|
noDocNeedPublish: '没有需要发布的文档',
|
|
|
|
|
loadDocFailed: '文档加载失败',
|
|
|
|
|
fetchDocFailed: '获取当前文档信息失败',
|
|
|
|
|
cannotAddToEmptyNode: '空节点不能添加内容',
|
|
|
|
|
overrideModified: '文档已被其他人修改确定覆盖已存在的文档吗?',
|
|
|
|
|
confirm: '确定',
|
|
|
|
|
cancel: '取消',
|
|
|
|
|
contentsNameEmpty: '目录名称不能为空',
|
|
|
|
|
addDoc: '添加文档',
|
|
|
|
|
edit: '编辑',
|
|
|
|
|
delete: '删除',
|
|
|
|
|
loadFailed: '加载失败请重试',
|
|
|
|
|
tplNameEmpty: '模板名称不能为空',
|
|
|
|
|
tplContentEmpty: '模板内容不能为空',
|
|
|
|
|
saveSucc: '保存成功',
|
|
|
|
|
serverExcept: '服务器异常',
|
|
|
|
|
paramName: '参数名称',
|
|
|
|
|
paramType: '参数类型',
|
|
|
|
|
example: '示例值',
|
|
|
|
|
remark: '备注',
|
|
|
|
|
},
|
|
|
|
|
'en': {
|
|
|
|
|
placeholder: 'This editor supports Markdown editing, writing on the left and previewing on the right.',
|
|
|
|
|
contentUnsaved: 'The edited content is not saved, need to save it?',
|
|
|
|
|
noDocNeedPublish: 'No Document need to be publish',
|
|
|
|
|
loadDocFailed: 'Load Document failed',
|
|
|
|
|
fetchDocFailed: 'Fetch Document info failed',
|
|
|
|
|
cannotAddToEmptyNode: 'Cannot add content to empty node',
|
|
|
|
|
overrideModified: 'The document has been modified by someone else, are you sure to overwrite the document?',
|
|
|
|
|
confirm: 'Confirm',
|
|
|
|
|
cancel: 'Cancel',
|
|
|
|
|
contentsNameEmpty: 'Document Name cannot be empty',
|
|
|
|
|
addDoc: 'Add Document',
|
|
|
|
|
edit: 'Edit',
|
|
|
|
|
delete: 'Delete',
|
|
|
|
|
loadFailed: 'Failed to load, please try again',
|
|
|
|
|
tplNameEmpty: 'Template name cannot be empty',
|
|
|
|
|
tplContentEmpty: 'Template content cannot be empty',
|
|
|
|
|
saveSucc: 'Save success',
|
|
|
|
|
serverExcept: 'Server Exception',
|
|
|
|
|
paramName: 'Parameter',
|
|
|
|
|
paramType: 'Type',
|
|
|
|
|
example: 'Example',
|
|
|
|
|
remark: 'Remark',
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-07-03 09:41:27 +08:00
|
|
|
|
var htmlDecodeList = ["style", "script", "title", "onmouseover", "onmouseout", "style"];
|
2021-10-09 18:22:43 +08:00
|
|
|
|
if (!window.IS_ENABLE_IFRAME) {
|
|
|
|
|
htmlDecodeList.unshift("iframe");
|
|
|
|
|
}
|
2017-04-26 18:17:38 +08:00
|
|
|
|
window.editor = editormd("docEditor", {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
2018-08-07 18:29:15 +08:00
|
|
|
|
path: window.editormdLib,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
toolbar: true,
|
2021-04-15 19:25:02 +08:00
|
|
|
|
placeholder: window.editormdLocales[window.lang].placeholder,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
imageUpload: true,
|
2023-07-03 09:41:27 +08:00
|
|
|
|
imageFormats: ["jpg", "jpeg", "gif", "png", "svg", "JPG", "JPEG", "GIF", "PNG", "SVG"],
|
2018-01-08 16:36:30 +08:00
|
|
|
|
imageUploadURL: window.imageUploadURL,
|
|
|
|
|
toolbarModes: "full",
|
|
|
|
|
fileUpload: true,
|
|
|
|
|
fileUploadURL: window.fileUploadURL,
|
|
|
|
|
taskList: true,
|
|
|
|
|
flowChart: true,
|
2021-10-09 18:22:43 +08:00
|
|
|
|
htmlDecode: htmlDecodeList.join(','),
|
|
|
|
|
lineNumbers: true,
|
2018-01-27 11:27:11 +08:00
|
|
|
|
sequenceDiagram: true,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
tocStartLevel: 1,
|
|
|
|
|
tocm: true,
|
2018-08-07 17:19:56 +08:00
|
|
|
|
previewCodeHighlight: 1,
|
|
|
|
|
highlightStyle: window.highlightStyle ? window.highlightStyle : "github",
|
2023-07-03 09:41:27 +08:00
|
|
|
|
tex: true,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
saveHTMLToTextarea: true,
|
2023-07-01 23:20:10 +08:00
|
|
|
|
codeFold: true,
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
2018-01-08 16:36:30 +08:00
|
|
|
|
onload: function() {
|
2023-07-01 23:20:10 +08:00
|
|
|
|
this.registerHelper()
|
2017-04-26 18:17:38 +08:00
|
|
|
|
this.hideToolbar();
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var keyMap = {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
"Ctrl-S": function (cm) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
saveDocument(false);
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
"Cmd-S": function (cm) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
saveDocument(false);
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
"Ctrl-A": function (cm) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
cm.execCommand("selectAll");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.addKeyMap(keyMap);
|
|
|
|
|
|
2018-08-17 17:33:45 +08:00
|
|
|
|
//如果没有选中节点则选中默认节点
|
|
|
|
|
openLastSelectedNode();
|
2024-07-05 15:31:34 +08:00
|
|
|
|
uploadResource("docEditor", function ($state, $res) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if ($state === "before") {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
return layer.load(1, {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
shade: [0.1, '#fff'] // 0.1 透明度的白色背景
|
2017-06-09 18:14:55 +08:00
|
|
|
|
});
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if ($state === "success") {
|
2024-07-05 15:31:34 +08:00
|
|
|
|
if ($res.errcode === 0) {
|
|
|
|
|
if ($res.resource_type === 'video') {
|
|
|
|
|
let value = `<video controls><source src="${$res.url}" type="video/mp4"></video>`;
|
|
|
|
|
window.editor.insertValue(value);
|
|
|
|
|
} else {
|
|
|
|
|
let value = '![](' + $res.url + ')';
|
|
|
|
|
window.editor.insertValue(value);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
layer.msg("上传失败:" + $res.message);
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
|
2018-09-03 15:39:01 +08:00
|
|
|
|
window.isLoad = true;
|
2023-06-30 23:30:43 +08:00
|
|
|
|
this.tableEditor = TableEditor.initTableEditor(this.cm)
|
2017-04-28 18:08:01 +08:00
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
onchange: function () {
|
2023-07-01 23:20:10 +08:00
|
|
|
|
/**
|
|
|
|
|
* 实现画图的事件注入
|
|
|
|
|
*
|
|
|
|
|
* 1. 分析文本,添加点击编辑事件,processMarkers
|
|
|
|
|
* 2. 获取内容,存储状态数据
|
|
|
|
|
* 3. 打开编辑画面
|
|
|
|
|
* 4. 推出触发变更事件,并回写数据
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
drawio.processMarkers(cm.firstLine(), cm.lastLine() + 1)
|
|
|
|
|
|
2017-04-28 18:08:01 +08:00
|
|
|
|
resetEditorChanged(true);
|
2017-04-26 18:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-04-28 18:08:01 +08:00
|
|
|
|
|
2023-07-01 23:20:10 +08:00
|
|
|
|
editormd.fn.registerHelper = function () {
|
|
|
|
|
|
|
|
|
|
const maxDepth = 100
|
|
|
|
|
const codeBlockStartMatch = /^`{3}[a-zA-Z0-9]+$/
|
|
|
|
|
const codeBlockEndMatch = /^`{3}$/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editormd.$CodeMirror.registerHelper('fold', 'markdown', function (cm, start) {
|
|
|
|
|
const firstLine = cm.getLine(start.line)
|
|
|
|
|
const lastLineNo = cm.lastLine()
|
|
|
|
|
let end
|
|
|
|
|
|
|
|
|
|
function isHeader(lineNo) {
|
|
|
|
|
const tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0))
|
|
|
|
|
return tokentype && /\bheader\b/.test(tokentype)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function headerLevel(lineNo, line, nextLine) {
|
|
|
|
|
let match = line && line.match(/^#+/)
|
|
|
|
|
if (match && isHeader(lineNo)) return match[0].length
|
|
|
|
|
match = nextLine && nextLine.match(/^[=-]+\s*$/)
|
|
|
|
|
if (match && isHeader(lineNo + 1)) return nextLine[0] === '=' ? 1 : 2
|
|
|
|
|
return maxDepth
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -> CODE BLOCK
|
|
|
|
|
|
|
|
|
|
if (codeBlockStartMatch.test(cm.getLine(start.line))) {
|
|
|
|
|
end = start.line
|
|
|
|
|
let nextNextLine = cm.getLine(end + 1)
|
|
|
|
|
while (end < lastLineNo) {
|
|
|
|
|
if (codeBlockEndMatch.test(nextNextLine)) {
|
|
|
|
|
end++
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
end++
|
|
|
|
|
nextNextLine = cm.getLine(end + 1)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// -> HEADER
|
|
|
|
|
|
|
|
|
|
let nextLine = cm.getLine(start.line + 1)
|
|
|
|
|
const level = headerLevel(start.line, firstLine, nextLine)
|
|
|
|
|
if (level === maxDepth) return undefined
|
|
|
|
|
|
|
|
|
|
end = start.line
|
|
|
|
|
let nextNextLine = cm.getLine(end + 2)
|
|
|
|
|
while (end < lastLineNo) {
|
|
|
|
|
if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break
|
|
|
|
|
++end
|
|
|
|
|
nextLine = nextNextLine
|
|
|
|
|
nextNextLine = cm.getLine(end + 2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
from: CodeMirror.Pos(start.line, firstLine.length),
|
|
|
|
|
to: CodeMirror.Pos(end, cm.getLine(end).length)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 18:07:24 +08:00
|
|
|
|
function insertToMarkdown(body) {
|
|
|
|
|
window.isLoad = true;
|
|
|
|
|
window.editor.insertValue(body);
|
|
|
|
|
window.editor.setCursor({ line: 0, ch: 0 });
|
|
|
|
|
resetEditorChanged(true);
|
|
|
|
|
}
|
|
|
|
|
function insertAndClearToMarkdown(body) {
|
|
|
|
|
window.isLoad = true;
|
|
|
|
|
window.editor.clear();
|
|
|
|
|
window.editor.insertValue(body);
|
|
|
|
|
window.editor.setCursor({ line: 0, ch: 0 });
|
|
|
|
|
resetEditorChanged(true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
|
/**
|
|
|
|
|
* 实现标题栏操作
|
|
|
|
|
*/
|
2017-12-21 18:38:19 +08:00
|
|
|
|
$("#editormd-tools").on("click", "a[class!='disabled']", function () {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
var name = $(this).find("i").attr("name");
|
|
|
|
|
if (name === "attachment") {
|
|
|
|
|
$("#uploadAttachModal").modal("show");
|
|
|
|
|
} else if (name === "history") {
|
|
|
|
|
window.documentHistory();
|
|
|
|
|
} else if (name === "save") {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
saveDocument(false);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else if (name === "template") {
|
|
|
|
|
$("#documentTemplateModal").modal("show");
|
|
|
|
|
} else if (name === "save-template") {
|
|
|
|
|
$("#saveTemplateModal").modal("show");
|
|
|
|
|
} else if (name === 'json') {
|
|
|
|
|
$("#convertJsonToTableModal").modal("show");
|
|
|
|
|
} else if (name === "sidebar") {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
$("#manualCategory").toggle(0, "swing", function () {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
var $then = $("#manualEditorContainer");
|
|
|
|
|
var left = parseInt($then.css("left"));
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (left > 0) {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
window.editorContainerLeft = left;
|
2017-12-21 18:38:19 +08:00
|
|
|
|
$then.css("left", "0");
|
|
|
|
|
} else {
|
|
|
|
|
$then.css("left", window.editorContainerLeft + "px");
|
2017-04-26 18:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
window.editor.resize();
|
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else if (name === "release") {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0) {
|
|
|
|
|
if ($("#markdown-save").hasClass('change')) {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
var confirm_result = confirm(editormdLocales[lang].contentUnsaved);
|
2018-08-13 19:05:49 +08:00
|
|
|
|
if (confirm_result) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
saveDocument(false, releaseBook);
|
|
|
|
|
return;
|
2017-09-15 18:12:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
|
|
|
|
releaseBook();
|
|
|
|
|
} else {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(editormdLocales[lang].noDocNeedPublish)
|
2017-04-29 21:28:09 +08:00
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else if (name === "tasks") {
|
|
|
|
|
// 插入 GFM 任务列表
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
var selection = cm.getSelection();
|
|
|
|
|
var cursor = cm.getCursor();
|
|
|
|
|
if (selection === "") {
|
|
|
|
|
cm.setCursor(cursor.line, 0);
|
|
|
|
|
cm.replaceSelection("- [x] " + selection);
|
|
|
|
|
cm.setCursor(cursor.line, cursor.ch + 6);
|
|
|
|
|
} else {
|
|
|
|
|
var selectionText = selection.split("\n");
|
|
|
|
|
|
|
|
|
|
for (var i = 0, len = selectionText.length; i < len; i++) {
|
|
|
|
|
selectionText[i] = (selectionText[i] === "") ? "" : "- [x] " + selectionText[i];
|
|
|
|
|
}
|
|
|
|
|
cm.replaceSelection(selectionText.join("\n"));
|
|
|
|
|
}
|
2023-07-01 23:20:10 +08:00
|
|
|
|
} else if (name === "drawio") {
|
|
|
|
|
/**
|
|
|
|
|
* TODO: 画图功能实现
|
|
|
|
|
*
|
|
|
|
|
* 1. 获取光标处数据,存储数据
|
|
|
|
|
* 2. 打开画图页面,初始化数据(获取数据)
|
|
|
|
|
*/
|
|
|
|
|
window.sessionStorage.setItem("drawio", '');
|
|
|
|
|
|
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
const selStartLine = cm.getCursor('from').line
|
|
|
|
|
const selEndLine = cm.getCursor('to').line + 1
|
|
|
|
|
|
|
|
|
|
drawio.processMarkers(selStartLine, selEndLine)
|
|
|
|
|
drawio.show()
|
2024-07-12 09:52:20 +08:00
|
|
|
|
} else if (name === 'wordToContent') {
|
|
|
|
|
let converter = new WordToHtmlConverter();
|
|
|
|
|
converter.handleFileSelect(function (response) {
|
|
|
|
|
if (response.messages.length) {
|
|
|
|
|
let messages = response.messages.map((item)=>{
|
|
|
|
|
return item.message + "<br/>";
|
|
|
|
|
}).join('\n');
|
|
|
|
|
layer.msg(messages);
|
|
|
|
|
}
|
|
|
|
|
converter.replaceHtmlBase64(response.value).then((html)=>{
|
2024-07-15 16:35:12 +08:00
|
|
|
|
let cm = window.editor.cm;
|
|
|
|
|
cm.replaceSelection(html);
|
2024-07-12 09:52:20 +08:00
|
|
|
|
});
|
|
|
|
|
})
|
2024-07-15 16:35:12 +08:00
|
|
|
|
} else if (name === 'htmlToMarkdown') {
|
|
|
|
|
let converter = new HtmlToMarkdownConverter();
|
|
|
|
|
converter.handleFileSelect(function (response) {
|
|
|
|
|
let cm = window.editor.cm;
|
|
|
|
|
cm.replaceSelection(response);
|
|
|
|
|
})
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else {
|
|
|
|
|
var action = window.editor.toolbarHandlers[name];
|
|
|
|
|
|
|
|
|
|
if (!!action && action !== "undefined") {
|
|
|
|
|
$.proxy(action, window.editor)();
|
|
|
|
|
window.editor.focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-04-27 18:19:37 +08:00
|
|
|
|
|
2017-04-28 18:08:01 +08:00
|
|
|
|
/***
|
|
|
|
|
* 加载指定的文档到编辑器中
|
|
|
|
|
* @param $node
|
|
|
|
|
*/
|
2023-07-03 09:41:27 +08:00
|
|
|
|
window.loadDocument = function ($node) {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
var index = layer.load(1, {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
shade: [0.1, '#fff'] // 0.1 透明度的白色背景
|
2017-04-27 18:19:37 +08:00
|
|
|
|
});
|
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$.get(window.editURL + $node.node.id).done(function (res) {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
layer.close(index);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2017-04-28 18:19:03 +08:00
|
|
|
|
window.isLoad = true;
|
2018-01-18 19:54:05 +08:00
|
|
|
|
try {
|
|
|
|
|
window.editor.clear();
|
|
|
|
|
window.editor.insertValue(res.data.markdown);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
window.editor.setCursor({ line: 0, ch: 0 });
|
|
|
|
|
} catch (e) {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
2018-01-08 16:36:30 +08:00
|
|
|
|
var node = { "id": res.data.doc_id, 'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id, "text": res.data.doc_name, "identify": res.data.identify, "version": res.data.version };
|
2017-04-28 18:08:01 +08:00
|
|
|
|
pushDocumentCategory(node);
|
2017-04-28 18:28:08 +08:00
|
|
|
|
window.selectNode = node;
|
2017-05-13 12:12:37 +08:00
|
|
|
|
pushVueLists(res.data.attach);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
setLastSelectNode($node);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(editormdLocales[lang].loadDocFailed);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
layer.close(index);
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(editormdLocales[lang].loadDocFailed);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
});
|
2017-05-26 14:19:27 +08:00
|
|
|
|
};
|
2017-04-28 18:08:01 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2017-04-29 21:28:09 +08:00
|
|
|
|
* 保存文档到服务器
|
|
|
|
|
* @param $is_cover 是否强制覆盖
|
2017-04-28 18:08:01 +08:00
|
|
|
|
*/
|
2017-12-21 18:38:19 +08:00
|
|
|
|
function saveDocument($is_cover, callback) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var index = null;
|
2017-04-28 18:28:08 +08:00
|
|
|
|
var node = window.selectNode;
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var content = window.editor.getMarkdown();
|
|
|
|
|
var html = window.editor.getPreviewedHTML();
|
|
|
|
|
var version = "";
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (!node) {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(editormdLocales[lang].fetchDocFailed);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (node.a_attr && node.a_attr.disabled) {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(editormdLocales[lang].cannotAddToEmptyNode);
|
2019-05-20 17:38:37 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
2017-04-28 18:28:08 +08:00
|
|
|
|
var doc_id = parseInt(node.id);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
for (var i in window.documentCategory) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var item = window.documentCategory[i];
|
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (item.id === doc_id) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
version = item.version;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$.ajax({
|
2018-01-08 16:36:30 +08:00
|
|
|
|
beforeSend: function () {
|
|
|
|
|
index = layer.load(1, { shade: [0.1, '#fff'] });
|
2018-08-17 17:33:45 +08:00
|
|
|
|
window.saveing = true;
|
2017-04-28 18:08:01 +08:00
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
url: window.editURL,
|
|
|
|
|
data: { "identify": window.book.identify, "doc_id": doc_id, "markdown": content, "html": html, "cover": $is_cover ? "yes" : "no", "version": version },
|
|
|
|
|
type: "post",
|
2023-07-03 09:41:27 +08:00
|
|
|
|
timeout: 30000,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (res) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
resetEditorChanged(false);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
for (var i in window.documentCategory) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var item = window.documentCategory[i];
|
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (item.id === doc_id) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
window.documentCategory[i].version = res.data.version;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$.each(window.documentCategory, function (i, item) {
|
2018-08-17 18:42:20 +08:00
|
|
|
|
var $item = window.documentCategory[i];
|
|
|
|
|
|
|
|
|
|
if (item.id === doc_id) {
|
|
|
|
|
window.documentCategory[i].version = res.data.version;
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (typeof callback === "function") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
callback();
|
|
|
|
|
}
|
2018-08-17 17:33:45 +08:00
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else if (res.errcode === 6005) {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
var confirmIndex = layer.confirm(editormdLocales[lang].overrideModified, {
|
|
|
|
|
btn: [editormdLocales[lang].confirm, editormdLocales[lang].cancel] // 按钮
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}, function () {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
layer.close(confirmIndex);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
saveDocument(true, callback);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
});
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
layer.msg(res.message);
|
|
|
|
|
}
|
2018-02-02 23:12:29 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
layer.msg(window.editormdLocales[window.lang].serverExcept + errorThrown);
|
2018-08-17 18:05:04 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
complete: function () {
|
2018-08-17 18:05:04 +08:00
|
|
|
|
layer.close(index);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
window.saveing = false;
|
2017-04-28 18:08:01 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
|
2017-04-28 18:08:01 +08:00
|
|
|
|
|
2017-04-29 21:28:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* 设置编辑器变更状态
|
|
|
|
|
* @param $is_change
|
|
|
|
|
*/
|
2017-04-28 18:08:01 +08:00
|
|
|
|
function resetEditorChanged($is_change) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if ($is_change && !window.isLoad) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
$("#markdown-save").removeClass('disabled').addClass('change');
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
$("#markdown-save").removeClass('change').addClass('disabled');
|
|
|
|
|
}
|
2017-04-28 18:19:03 +08:00
|
|
|
|
window.isLoad = false;
|
2017-04-28 18:08:01 +08:00
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
2017-04-28 18:08:01 +08:00
|
|
|
|
/**
|
2018-08-14 18:17:46 +08:00
|
|
|
|
* 添加文档
|
2017-04-27 18:19:37 +08:00
|
|
|
|
*/
|
|
|
|
|
$("#addDocumentForm").ajaxForm({
|
2018-01-08 16:36:30 +08:00
|
|
|
|
beforeSubmit: function () {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
var doc_name = $.trim($("#documentName").val());
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (doc_name === "") {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
return showError(editormdLocales[lang].contentsNameEmpty, "#add-error-message")
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
2017-05-02 18:09:46 +08:00
|
|
|
|
$("#btnSaveDocument").button("loading");
|
2017-04-27 18:19:37 +08:00
|
|
|
|
return true;
|
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
success: function (res) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2018-08-14 18:17:46 +08:00
|
|
|
|
var data = {
|
|
|
|
|
"id": res.data.doc_id,
|
2023-07-03 09:41:27 +08:00
|
|
|
|
'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id,
|
2018-08-14 18:17:46 +08:00
|
|
|
|
"text": res.data.doc_name,
|
|
|
|
|
"identify": res.data.identify,
|
2023-07-03 09:41:27 +08:00
|
|
|
|
"version": res.data.version,
|
|
|
|
|
state: { opened: res.data.is_open == 1 },
|
|
|
|
|
a_attr: { is_open: res.data.is_open == 1 }
|
2018-08-14 18:17:46 +08:00
|
|
|
|
};
|
2017-04-27 18:19:37 +08:00
|
|
|
|
|
|
|
|
|
var node = window.treeCatalog.get_node(data.id);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (node) {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
window.treeCatalog.rename_node({ "id": data.id }, data.text);
|
2018-08-14 18:17:46 +08:00
|
|
|
|
$("#sidebar").jstree(true).get_node(data.id).a_attr.is_open = data.state.opened;
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
window.treeCatalog.create_node(data.parent, data);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
window.treeCatalog.deselect_all();
|
|
|
|
|
window.treeCatalog.select_node(data);
|
|
|
|
|
}
|
2017-04-28 18:08:01 +08:00
|
|
|
|
pushDocumentCategory(data);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
$("#markdown-save").removeClass('change').addClass('disabled');
|
|
|
|
|
$("#addDocumentModal").modal('hide');
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
showError(res.message, "#add-error-message");
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
2017-05-02 18:09:46 +08:00
|
|
|
|
$("#btnSaveDocument").button("reset");
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文档目录树
|
|
|
|
|
*/
|
|
|
|
|
$("#sidebar").jstree({
|
2018-01-08 16:36:30 +08:00
|
|
|
|
'plugins': ["wholerow", "types", 'dnd', 'contextmenu'],
|
|
|
|
|
"types": {
|
|
|
|
|
"default": {
|
|
|
|
|
"icon": false // 删除默认图标
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
'core': {
|
|
|
|
|
'check_callback': true,
|
|
|
|
|
"multiple": false,
|
|
|
|
|
'animation': 0,
|
|
|
|
|
"data": window.documentCategory
|
2017-04-27 18:19:37 +08:00
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"contextmenu": {
|
|
|
|
|
show_at_node: false,
|
|
|
|
|
select_node: false,
|
|
|
|
|
"items": {
|
|
|
|
|
"添加文档": {
|
|
|
|
|
"separator_before": false,
|
|
|
|
|
"separator_after": true,
|
|
|
|
|
"_disabled": false,
|
2021-04-15 19:25:02 +08:00
|
|
|
|
"label": window.editormdLocales[window.lang].addDoc,//"添加文档",
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"icon": "fa fa-plus",
|
|
|
|
|
"action": function (data) {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
var inst = $.jstree.reference(data.reference),
|
|
|
|
|
node = inst.get_node(data.reference);
|
|
|
|
|
|
|
|
|
|
openCreateCatalogDialog(node);
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"编辑": {
|
|
|
|
|
"separator_before": false,
|
|
|
|
|
"separator_after": true,
|
|
|
|
|
"_disabled": false,
|
2021-04-15 19:25:02 +08:00
|
|
|
|
"label": window.editormdLocales[window.lang].edit,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"icon": "fa fa-edit",
|
|
|
|
|
"action": function (data) {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
var inst = $.jstree.reference(data.reference);
|
|
|
|
|
var node = inst.get_node(data.reference);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
openEditCatalogDialog(node);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"删除": {
|
|
|
|
|
"separator_before": false,
|
|
|
|
|
"separator_after": true,
|
|
|
|
|
"_disabled": false,
|
2021-04-15 19:25:02 +08:00
|
|
|
|
"label": window.editormdLocales[window.lang].delete,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"icon": "fa fa-trash-o",
|
|
|
|
|
"action": function (data) {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
var inst = $.jstree.reference(data.reference);
|
|
|
|
|
var node = inst.get_node(data.reference);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
openDeleteDocumentDialog(node);
|
2017-04-27 18:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("ready.jstree", function () {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
window.treeCatalog = $("#sidebar").jstree(true);
|
|
|
|
|
|
|
|
|
|
//如果没有选中节点则选中默认节点
|
|
|
|
|
// openLastSelectedNode();
|
2019-05-20 17:38:37 +08:00
|
|
|
|
}).on('select_node.jstree', function (node, selected) {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if ($("#markdown-save").hasClass('change')) {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
if (confirm(window.editormdLocales[window.lang].contentUnsaved)) {
|
2017-12-21 18:38:19 +08:00
|
|
|
|
saveDocument(false, function () {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
loadDocument(selected);
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2017-04-28 18:28:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
//如果是空目录则直接出发展开下一级功能
|
|
|
|
|
if (selected.node.a_attr && selected.node.a_attr.disabled) {
|
|
|
|
|
selected.instance.toggle_node(selected.node);
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 18:28:08 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
loadDocument(selected);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("move_node.jstree", jstree_save).on("delete_node.jstree", function ($node, $parent) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
openLastSelectedNode();
|
|
|
|
|
});
|
2018-01-18 19:54:05 +08:00
|
|
|
|
/**
|
|
|
|
|
* 打开文档模板
|
|
|
|
|
*/
|
2017-12-21 18:38:19 +08:00
|
|
|
|
$("#documentTemplateModal").on("click", ".section>a[data-type]", function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var $this = $(this).attr("data-type");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if ($this === "customs") {
|
2018-08-13 19:05:49 +08:00
|
|
|
|
$("#displayCustomsTemplateModal").modal("show");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var body = $("#template-" + $this).html();
|
|
|
|
|
if (body) {
|
|
|
|
|
window.isLoad = true;
|
|
|
|
|
window.editor.clear();
|
|
|
|
|
window.editor.insertValue(body);
|
2018-01-08 16:36:30 +08:00
|
|
|
|
window.editor.setCursor({ line: 0, ch: 0 });
|
2017-05-26 14:19:27 +08:00
|
|
|
|
resetEditorChanged(true);
|
|
|
|
|
}
|
|
|
|
|
$("#documentTemplateModal").modal('hide');
|
|
|
|
|
});
|
2018-08-14 15:57:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 展示自定义模板列表
|
|
|
|
|
*/
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$("#displayCustomsTemplateModal").on("show.bs.modal", function () {
|
|
|
|
|
window.sessionStorage.setItem("displayCustomsTemplateList", $("#displayCustomsTemplateList").html());
|
2018-08-13 19:05:49 +08:00
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
var index;
|
2018-08-13 19:05:49 +08:00
|
|
|
|
$.ajax({
|
|
|
|
|
beforeSend: function () {
|
|
|
|
|
index = layer.load(1, { shade: [0.1, '#fff'] });
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
url: window.template.listUrl,
|
|
|
|
|
data: { "identify": window.book.identify },
|
|
|
|
|
type: "POST",
|
|
|
|
|
dataType: "html",
|
2018-08-13 19:05:49 +08:00
|
|
|
|
success: function ($res) {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
$("#displayCustomsTemplateList").html($res);
|
2018-08-13 19:05:49 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function () {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(window.editormdLocales[window.lang].loadFailed);
|
2018-08-13 19:05:49 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
complete: function () {
|
2018-08-13 19:05:49 +08:00
|
|
|
|
layer.close(index);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#documentTemplateModal").modal("hide");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("hidden.bs.modal", function () {
|
2018-08-13 19:05:49 +08:00
|
|
|
|
var cache = window.sessionStorage.getItem("displayCustomsTemplateList");
|
|
|
|
|
$("#displayCustomsTemplateList").html(cache);
|
|
|
|
|
});
|
2018-08-14 15:57:52 +08:00
|
|
|
|
/**
|
|
|
|
|
* 添加模板
|
|
|
|
|
*/
|
|
|
|
|
$("#saveTemplateForm").ajaxForm({
|
|
|
|
|
beforeSubmit: function () {
|
|
|
|
|
var doc_name = $.trim($("#templateName").val());
|
|
|
|
|
if (doc_name === "") {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
return showError(window.editormdLocales[window.lang].tplNameEmpty, "#saveTemplateForm .show-error-message");
|
2018-08-14 15:57:52 +08:00
|
|
|
|
}
|
|
|
|
|
var content = $("#saveTemplateForm").find("input[name='content']").val();
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (content === "") {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
return showError(window.editormdLocales[window.lang].tplContentEmpty, "#saveTemplateForm .show-error-message");
|
2018-08-14 15:57:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#btnSaveTemplate").button("loading");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
success: function ($res) {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if ($res.errcode === 0) {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
$("#saveTemplateModal").modal("hide");
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(window.editormdLocales[window.lang].saveSucc);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
return showError($res.message, "#saveTemplateForm .show-error-message");
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
complete: function () {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
$("#btnSaveTemplate").button("reset");
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-08-15 15:33:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* 当添加模板弹窗事件发生
|
|
|
|
|
*/
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$("#saveTemplateModal").on("show.bs.modal", function () {
|
|
|
|
|
window.sessionStorage.setItem("saveTemplateModal", $(this).find(".modal-body").html());
|
2018-08-14 15:57:52 +08:00
|
|
|
|
var content = window.editor.getMarkdown();
|
|
|
|
|
$("#saveTemplateForm").find("input[name='content']").val(content);
|
2018-08-15 15:33:22 +08:00
|
|
|
|
$("#saveTemplateForm .show-error-message").html("");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("hidden.bs.modal", function () {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
$(this).find(".modal-body").html(window.sessionStorage.getItem("saveTemplateModal"));
|
|
|
|
|
});
|
2018-08-15 15:33:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* 插入自定义模板内容
|
|
|
|
|
*/
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$("#displayCustomsTemplateList").on("click", ".btn-insert", function () {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
var templateId = $(this).attr("data-id");
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: window.template.getUrl,
|
2023-07-03 09:41:27 +08:00
|
|
|
|
data: { "identify": window.book.identify, "template_id": templateId },
|
2018-08-14 15:57:52 +08:00
|
|
|
|
dataType: "json",
|
|
|
|
|
type: "get",
|
2023-07-03 09:41:27 +08:00
|
|
|
|
success: function ($res) {
|
|
|
|
|
if ($res.errcode !== 0) {
|
|
|
|
|
layer.msg($res.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-08-14 15:57:52 +08:00
|
|
|
|
window.isLoad = true;
|
|
|
|
|
window.editor.clear();
|
|
|
|
|
window.editor.insertValue($res.data.template_content);
|
|
|
|
|
window.editor.setCursor({ line: 0, ch: 0 });
|
|
|
|
|
resetEditorChanged(true);
|
|
|
|
|
$("#displayCustomsTemplateModal").modal("hide");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}, error: function () {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(window.editormdLocales[window.lang].serverExcept);
|
2018-08-14 15:57:52 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("click", ".btn-delete", function () {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
var $then = $(this);
|
|
|
|
|
var templateId = $then.attr("data-id");
|
|
|
|
|
$then.button("loading");
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
url: window.template.deleteUrl,
|
|
|
|
|
data: { "identify": window.book.identify, "template_id": templateId },
|
2018-08-14 15:57:52 +08:00
|
|
|
|
dataType: "json",
|
|
|
|
|
type: "post",
|
|
|
|
|
success: function ($res) {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if ($res.errcode !== 0) {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
layer.msg($res.message);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else {
|
2018-08-14 15:57:52 +08:00
|
|
|
|
$then.parents("tr").empty().remove();
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}, error: function () {
|
2021-04-15 19:25:02 +08:00
|
|
|
|
layer.msg(window.editormdLocales[window.lang].serverExcept);
|
2018-08-14 15:57:52 +08:00
|
|
|
|
},
|
|
|
|
|
complete: function () {
|
|
|
|
|
$then.button("reset");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$("#btnInsertTable").on("click", function () {
|
|
|
|
|
var content = $("#jsonContent").val();
|
|
|
|
|
if (content !== "") {
|
|
|
|
|
try {
|
|
|
|
|
var jsonObj = $.parseJSON(content);
|
|
|
|
|
var data = foreachJson(jsonObj, "");
|
|
|
|
|
var table = "| " + window.editormdLocales[window.lang].paramName
|
|
|
|
|
+ " | " + window.editormdLocales[window.lang].paramType
|
|
|
|
|
+ " | " + window.editormdLocales[window.lang].example
|
|
|
|
|
+ " | " + window.editormdLocales[window.lang].remark
|
|
|
|
|
+ " |\n| ------------ | ------------ | ------------ | ------------ |\n";
|
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
|
table += "|" + item.key + "|" + item.type + "|" + item.value + "| |\n";
|
|
|
|
|
});
|
2018-11-21 18:07:24 +08:00
|
|
|
|
insertToMarkdown(table);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
showError("Json 格式错误:" + e.toString(), "#json-error-message");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$("#convertJsonToTableModal").modal("hide");
|
2018-11-21 18:07:24 +08:00
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$("#convertJsonToTableModal").on("hidden.bs.modal", function () {
|
2018-11-21 18:10:25 +08:00
|
|
|
|
$("#jsonContent").val("");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("shown.bs.modal", function () {
|
2018-11-21 18:10:25 +08:00
|
|
|
|
$("#jsonContent").focus();
|
|
|
|
|
});
|
2023-07-01 23:20:10 +08:00
|
|
|
|
});
|