修改前端 Markdown 编辑器脚本文件,目的在于解决以下问题:如果点击“发布”按钮时文档处于未保存状态,则在提示框中选择保存后,可能出现并未将最新版本成功发布的情况。推测原因在于发布的命令发送到服务端时之前的保存操作可能尚未完成,因此将发布命令置于保存完成后的回调中执行。

This commit is contained in:
Dandy Cheung
2017-12-21 18:38:19 +08:00
parent 15ad23a030
commit 87f7fd29ed

View File

@@ -5,7 +5,7 @@ $(function () {
height : "100%",
path : "/static/editor.md/lib/",
toolbar : true,
placeholder: "本编辑器支持Markdown编辑左边编写右边预览",
placeholder : "本编辑器支持 Markdown 编辑,左边编写,右边预览",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "JPG", "JPEG", "GIF", "PNG"],
imageUploadURL : window.imageUploadURL,
@@ -19,6 +19,7 @@ $(function () {
tocStartLevel : 1,
tocm : true,
saveHTMLToTextarea : true,
onload : function() {
this.hideToolbar();
var keyMap = {
@@ -45,6 +46,7 @@ $(function () {
loadDocument($select_node);
}
}
uploadImage("docEditor", function ($state, $res) {
if ($state === "before") {
return layer.load(1, {
@@ -78,7 +80,6 @@ $(function () {
$("#documentTemplateModal").modal("show");
} else if (name === "sidebar") {
$("#manualCategory").toggle(0, "swing", function () {
var $then = $("#manualEditorContainer");
var left = parseInt($then.css("left"));
if (left > 0) {
@@ -94,22 +95,12 @@ $(function () {
if ($("#markdown-save").hasClass('change')) {
var comfirm_result = confirm("编辑内容未保存,需要保存吗?")
if (comfirm_result) {
saveDocument();
saveDocument(false, releaseBook);
return;
}
}
$.ajax({
url : window.releaseURL,
data :{"identify" : window.book.identify },
type : "post",
dataType : "json",
success : function (res) {
if(res.errcode === 0){
layer.msg("发布任务已推送到任务队列,稍后将在后台执行。");
}else{
layer.msg(res.message);
}
}
});
releaseBook();
} else {
layer.msg("没有需要发布的文档")
}
@@ -120,8 +111,7 @@ $(function () {
if (selection === "") {
cm.replaceSelection("- [x] " + selection);
}
else {
} else {
var selectionText = selection.split("\n");
for (var i = 0, len = selectionText.length; i < len; i++) {
@@ -185,6 +175,7 @@ $(function () {
layer.msg("获取当前文档信息失败");
return;
}
var doc_id = parseInt(node.id);
for (var i in window.documentCategory) {
@@ -232,8 +223,23 @@ $(function () {
});
}
function resetEditor($node) {
function releaseBook() {
$.ajax({
url : window.releaseURL,
data : { "identify" : window.book.identify },
type : "post",
dataType : "json",
success : function (res) {
if (res.errcode === 0) {
layer.msg("发布任务已推送到任务队列,稍后将在后台执行。");
} else {
layer.msg(res.message);
}
}
});
}
function resetEditor($node) {
}
/**
@@ -248,6 +254,7 @@ $(function () {
}
window.isLoad = false;
}
/**
* 添加顶级文档
*/
@@ -262,13 +269,11 @@ $(function () {
},
success : function (res) {
if (res.errcode === 0) {
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 };
var node = window.treeCatalog.get_node(data.id);
if (node) {
window.treeCatalog.rename_node({ "id" : data.id }, data.text);
} else {
window.treeCatalog.create_node(data.parent, data);
window.treeCatalog.deselect_all();
@@ -278,7 +283,7 @@ $(function () {
$("#markdown-save").removeClass('change').addClass('disabled');
$("#addDocumentModal").modal('hide');
} else {
showError(res.message,"#add-error-message")
showError(res.message, "#add-error-message");
}
$("#btnSaveDocument").button("reset");
}
@@ -311,7 +316,6 @@ $(function () {
"label" : "添加文档",
"icon" : "fa fa-plus",
"action" : function (data) {
var inst = $.jstree.reference(data.reference),
node = inst.get_node(data.reference);
@@ -355,8 +359,8 @@ $(function () {
return true;
}
}
loadDocument(selected);
loadDocument(selected);
}).on("move_node.jstree", jstree_save);
$("#documentTemplateModal").on("click", ".section>a[data-type]", function () {