2017-04-26 18:17:38 +08:00
|
|
|
|
$(function () {
|
2018-03-01 11:28:21 +08:00
|
|
|
|
editormd.katexURL = {
|
2018-08-07 18:29:15 +08:00
|
|
|
|
js : window.katex.js,
|
|
|
|
|
css : window.katex.css
|
2018-03-01 11:28:21 +08:00
|
|
|
|
};
|
2017-04-28 18:08:01 +08:00
|
|
|
|
window.addDocumentModalFormHtml = $(this).find("form").html();
|
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,
|
|
|
|
|
placeholder: "本编辑器支持 Markdown 编辑,左边编写,右边预览。",
|
|
|
|
|
imageUpload: true,
|
|
|
|
|
imageFormats: ["jpg", "jpeg", "gif", "png", "JPG", "JPEG", "GIF", "PNG"],
|
|
|
|
|
imageUploadURL: window.imageUploadURL,
|
|
|
|
|
toolbarModes: "full",
|
|
|
|
|
fileUpload: true,
|
|
|
|
|
fileUploadURL: window.fileUploadURL,
|
|
|
|
|
taskList: true,
|
|
|
|
|
flowChart: true,
|
|
|
|
|
htmlDecode: "style,script,iframe,title,onmouseover,onmouseout,style",
|
|
|
|
|
lineNumbers: false,
|
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",
|
2018-03-01 11:28:21 +08:00
|
|
|
|
tex:true,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
saveHTMLToTextarea: true,
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
2018-01-08 16:36:30 +08:00
|
|
|
|
onload: function() {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
this.hideToolbar();
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var keyMap = {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"Ctrl-S": function(cm) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
saveDocument(false);
|
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
"Cmd-S": function(cm){
|
2017-04-29 21:28:09 +08:00
|
|
|
|
saveDocument(false);
|
|
|
|
|
},
|
|
|
|
|
"Ctrl-A": function(cm) {
|
|
|
|
|
cm.execCommand("selectAll");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.addKeyMap(keyMap);
|
|
|
|
|
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var $select_node_id = window.treeCatalog.get_selected();
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if ($select_node_id) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
var $select_node = window.treeCatalog.get_node($select_node_id[0])
|
|
|
|
|
if ($select_node) {
|
|
|
|
|
$select_node.node = {
|
|
|
|
|
id: $select_node.id
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadDocument($select_node);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
|
|
|
|
uploadImage("docEditor", function ($state, $res) {
|
|
|
|
|
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") {
|
|
|
|
|
if ($res.errcode === 0) {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
var value = '![](' + $res.url + ')';
|
|
|
|
|
window.editor.insertValue(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-04-28 18:08:01 +08:00
|
|
|
|
},
|
2018-01-08 16:36:30 +08:00
|
|
|
|
onchange: function () {
|
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
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
|
/**
|
|
|
|
|
* 实现标题栏操作
|
|
|
|
|
*/
|
2017-12-21 18:38:19 +08:00
|
|
|
|
$("#editormd-tools").on("click", "a[class!='disabled']", function () {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
var name = $(this).find("i").attr("name");
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (name === "attachment") {
|
2017-05-13 12:12:37 +08:00
|
|
|
|
$("#uploadAttachModal").modal("show");
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "history") {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
window.documentHistory();
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "save") {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
saveDocument(false);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "template") {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$("#documentTemplateModal").modal("show");
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "sidebar") {
|
|
|
|
|
$("#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();
|
|
|
|
|
});
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "release") {
|
|
|
|
|
if (Object.prototype.toString.call(window.documentCategory) === '[object Array]' && window.documentCategory.length > 0) {
|
|
|
|
|
if ($("#markdown-save").hasClass('change')) {
|
2017-09-15 18:12:40 +08:00
|
|
|
|
var comfirm_result = confirm("编辑内容未保存,需要保存吗?")
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (comfirm_result) {
|
|
|
|
|
saveDocument(false, releaseBook);
|
|
|
|
|
return;
|
2017-09-15 18:12:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
|
|
|
|
|
releaseBook();
|
|
|
|
|
} else {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
layer.msg("没有需要发布的文档")
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if (name === "tasks") {
|
|
|
|
|
// 插入 GFM 任务列表
|
2017-04-26 18:17:38 +08:00
|
|
|
|
var cm = window.editor.cm;
|
|
|
|
|
var selection = cm.getSelection();
|
|
|
|
|
|
|
|
|
|
if (selection === "") {
|
|
|
|
|
cm.replaceSelection("- [x] " + selection);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
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"));
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-26 18:17:38 +08:00
|
|
|
|
var action = window.editor.toolbarHandlers[name];
|
|
|
|
|
|
|
|
|
|
if (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
|
|
|
|
|
*/
|
2017-05-25 15:19:17 +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
|
|
|
|
});
|
|
|
|
|
|
2017-04-28 18:08:01 +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);
|
|
|
|
|
window.editor.setCursor({line: 0, ch: 0});
|
|
|
|
|
}catch(e){
|
|
|
|
|
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);
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
layer.msg("文档加载失败");
|
|
|
|
|
}
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
layer.close(index);
|
|
|
|
|
layer.msg("文档加载失败");
|
|
|
|
|
});
|
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) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
layer.msg("获取当前文档信息失败");
|
|
|
|
|
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'] });
|
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",
|
2018-02-02 23:12:29 +08:00
|
|
|
|
timeout : 30000,
|
2018-01-08 16:36:30 +08:00
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (res) {
|
2017-04-28 18:08:01 +08:00
|
|
|
|
layer.close(index);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if (typeof callback === "function") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
callback();
|
|
|
|
|
}
|
2017-12-21 18:38:19 +08:00
|
|
|
|
} else if(res.errcode === 6005) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var confirmIndex = layer.confirm('文档已被其他人修改确定覆盖已存在的文档吗?', {
|
2018-01-08 16:36:30 +08:00
|
|
|
|
btn: ['确定', '取消'] // 按钮
|
2017-12-21 18:38:19 +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
|
|
|
|
},
|
|
|
|
|
error : function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
layer.close(index);
|
|
|
|
|
layer.msg("服务器错误:" + errorThrown);
|
2017-04-28 18:08:01 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-01-25 19:18:59 +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
|
|
|
|
/**
|
|
|
|
|
* 添加顶级文档
|
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 === "") {
|
|
|
|
|
return showError("目录名称不能为空", "#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-01-08 16:36:30 +08:00
|
|
|
|
var data = { "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-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);
|
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,
|
|
|
|
|
"label": "添加文档",
|
|
|
|
|
"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,
|
|
|
|
|
"label": "编辑",
|
|
|
|
|
"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,
|
|
|
|
|
"label": "删除",
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).on('loaded.jstree', function () {
|
|
|
|
|
window.treeCatalog = $(this).jstree();
|
2017-04-28 18:28:08 +08:00
|
|
|
|
}).on('select_node.jstree', function (node, selected, event) {
|
2018-01-18 19:54:05 +08:00
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
if ($("#markdown-save").hasClass('change')) {
|
|
|
|
|
if (confirm("编辑内容未保存,需要保存吗?")) {
|
|
|
|
|
saveDocument(false, function () {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
loadDocument(selected);
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2017-04-28 18:28:08 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 18:38:19 +08:00
|
|
|
|
loadDocument(selected);
|
|
|
|
|
}).on("move_node.jstree", jstree_save);
|
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");
|
|
|
|
|
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');
|
|
|
|
|
});
|
2017-04-26 18:17:38 +08:00
|
|
|
|
});
|