mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-20 02:37:59 +08:00
markdown编辑器增加cherryMarkdown
* 使用cherryMarkdown替换editorMd * 支持历史&边栏 * 优化代码&支持html格式渲染为预览格式&保存主题配置 * 修复drawio异常 * 优化drawio异常改法 * 自定义提示面板主题颜色 * drawio增加样式,并且更新到最新版本 * 增加代码块复制功能&&修复drawio渲染图片过大&&drawio生成图片背景改为透明 * 恢复原有markdown编辑器,新增cherry markdown编辑器 * 修复复制功能异常 * 修复drawio偶尔无法编辑 --------- Co-authored-by: zhangsheng.93 <zhangsheng.93@bytedance.com>
This commit is contained in:
@@ -19,7 +19,7 @@ var events = function () {
|
||||
|
||||
$(".manual-right").scrollTop(0);
|
||||
//使用layer相册功能查看图片
|
||||
layer.photos({photos: "#page-content"});
|
||||
layer.photos({ photos: "#page-content" });
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -65,13 +65,13 @@ function pageClicked($page, $docid) {
|
||||
}
|
||||
$("#articleComment").removeClass('not-show-comment');
|
||||
$.ajax({
|
||||
url : "/comment/lists?page=" + $page + "&docid=" + $docid,
|
||||
type : "GET",
|
||||
success : function ($res) {
|
||||
url: "/comment/lists?page=" + $page + "&docid=" + $docid,
|
||||
type: "GET",
|
||||
success: function ($res) {
|
||||
console.log($res.data);
|
||||
loadComment($res.data.page, $res.data.doc_id);
|
||||
},
|
||||
error : function () {
|
||||
error: function () {
|
||||
layer.msg("加载失败");
|
||||
}
|
||||
});
|
||||
@@ -84,15 +84,15 @@ function loadComment($page, $docid) {
|
||||
var c = $page.List;
|
||||
for (var i = 0; c && i < c.length; i++) {
|
||||
html += "<div class=\"comment-item\" data-id=\"" + c[i].comment_id + "\">";
|
||||
html += "<p class=\"info\"><a class=\"name\">" + c[i].author + "</a><span class=\"date\">" + timeFormat(c[i].comment_date) + "</span></p>";
|
||||
html += "<div class=\"content\">" + c[i].content + "</div>";
|
||||
html += "<p class=\"util\">";
|
||||
if (c[i].show_del == 1) html += "<span class=\"operate toggle\">";
|
||||
else html += "<span class=\"operate\">";
|
||||
html += "<span class=\"number\">" + c[i].index + "#</span>";
|
||||
if (c[i].show_del == 1) html += "<i class=\"delete e-delete glyphicon glyphicon-remove\" style=\"color:red\" onclick=\"onDelComment(" + c[i].comment_id + ")\"></i>";
|
||||
html += "</span>";
|
||||
html += "</p>";
|
||||
html += "<p class=\"info\"><a class=\"name\">" + c[i].author + "</a><span class=\"date\">" + timeFormat(c[i].comment_date) + "</span></p>";
|
||||
html += "<div class=\"content\">" + c[i].content + "</div>";
|
||||
html += "<p class=\"util\">";
|
||||
if (c[i].show_del == 1) html += "<span class=\"operate toggle\">";
|
||||
else html += "<span class=\"operate\">";
|
||||
html += "<span class=\"number\">" + c[i].index + "#</span>";
|
||||
if (c[i].show_del == 1) html += "<i class=\"delete e-delete glyphicon glyphicon-remove\" style=\"color:red\" onclick=\"onDelComment(" + c[i].comment_id + ")\"></i>";
|
||||
html += "</span>";
|
||||
html += "</p>";
|
||||
html += "</div>";
|
||||
}
|
||||
$("#commentList").append(html);
|
||||
@@ -103,7 +103,7 @@ function loadComment($page, $docid) {
|
||||
totalPages: $page.TotalPage,
|
||||
bootstrapMajorVersion: 3,
|
||||
size: "middle",
|
||||
onPageClicked: function(e, originalEvent, type, page){
|
||||
onPageClicked: function (e, originalEvent, type, page) {
|
||||
pageClicked(page, $docid);
|
||||
}
|
||||
});
|
||||
@@ -116,10 +116,10 @@ function loadComment($page, $docid) {
|
||||
function onDelComment($id) {
|
||||
console.log($id);
|
||||
$.ajax({
|
||||
url : "/comment/delete",
|
||||
data : {"id": $id},
|
||||
type : "POST",
|
||||
success : function ($res) {
|
||||
url: "/comment/delete",
|
||||
data: { "id": $id },
|
||||
type: "POST",
|
||||
success: function ($res) {
|
||||
if ($res.errcode == 0) {
|
||||
layer.msg("删除成功");
|
||||
$("div[data-id=" + $id + "]").remove();
|
||||
@@ -127,7 +127,7 @@ function onDelComment($id) {
|
||||
layer.msg($res.message);
|
||||
}
|
||||
},
|
||||
error : function () {
|
||||
error: function () {
|
||||
layer.msg("删除失败");
|
||||
}
|
||||
});
|
||||
@@ -143,10 +143,19 @@ function renderPage($data) {
|
||||
$("#doc_id").val($data.doc_id);
|
||||
if ($data.page) {
|
||||
loadComment($data.page, $data.doc_id);
|
||||
|
||||
}
|
||||
else {
|
||||
pageClicked(-1, $data.doc_id);
|
||||
}
|
||||
|
||||
if ($data.is_markdown) {
|
||||
if ($("#view_container").hasClass($data.markdown_theme)) {
|
||||
return
|
||||
}
|
||||
$("#view_container").removeClass("theme__dark theme__green theme__light theme__red theme__default")
|
||||
$("#view_container").addClass($data.markdown_theme)
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -157,19 +166,19 @@ function renderPage($data) {
|
||||
*/
|
||||
function loadDocument($url, $id, $callback) {
|
||||
$.ajax({
|
||||
url : $url,
|
||||
type : "GET",
|
||||
beforeSend : function () {
|
||||
url: $url,
|
||||
type: "GET",
|
||||
beforeSend: function () {
|
||||
var data = events.data($id);
|
||||
if(data) {
|
||||
if (data) {
|
||||
if (typeof $callback === "function") {
|
||||
data.body = $callback(data.body);
|
||||
}else if(data.version && data.version != $callback){
|
||||
} else if (data.version && data.version != $callback) {
|
||||
return true;
|
||||
}
|
||||
renderPage(data);
|
||||
|
||||
events.trigger('article.open', {$url: $url, $id: $id});
|
||||
events.trigger('article.open', { $url: $url, $id: $id });
|
||||
|
||||
return false;
|
||||
|
||||
@@ -177,28 +186,29 @@ function loadDocument($url, $id, $callback) {
|
||||
|
||||
NProgress.start();
|
||||
},
|
||||
success : function ($res) {
|
||||
success: function ($res) {
|
||||
if ($res.errcode === 0) {
|
||||
renderPage($res.data);
|
||||
|
||||
$body = $res.data.body;
|
||||
if (typeof $callback === "function" ) {
|
||||
if (typeof $callback === "function") {
|
||||
$body = $callback(body);
|
||||
}
|
||||
loadCopySnippets();
|
||||
|
||||
events.data($id, $res.data);
|
||||
|
||||
events.trigger('article.open', { $url : $url, $id : $id });
|
||||
events.trigger('article.open', { $url: $url, $id: $id });
|
||||
} else if ($res.errcode === 6000) {
|
||||
window.location.href = "/";
|
||||
} else {
|
||||
layer.msg("加载失败");
|
||||
}
|
||||
},
|
||||
complete : function () {
|
||||
complete: function () {
|
||||
NProgress.done();
|
||||
},
|
||||
error : function () {
|
||||
error: function () {
|
||||
layer.msg("加载失败");
|
||||
}
|
||||
});
|
||||
@@ -216,7 +226,7 @@ function initHighlighting() {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
// hljs.initLineNumbersOnLoad();
|
||||
}catch (e){
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
@@ -233,41 +243,41 @@ $(function () {
|
||||
} else {
|
||||
$(".view-backtop").removeClass("active");
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
var scrollTop = $("body").scrollTop();
|
||||
var oItem = $(".markdown-heading").find(".reference-link");
|
||||
var oName = "";
|
||||
$.each(oItem,function(){
|
||||
$.each(oItem, function () {
|
||||
var oneItem = $(this);
|
||||
var offsetTop = oneItem.offset().top;
|
||||
|
||||
if(offsetTop-scrollTop < 100){
|
||||
if (offsetTop - scrollTop < 100) {
|
||||
oName = "#" + oneItem.attr("name");
|
||||
}
|
||||
});
|
||||
$(".markdown-toc-list a").each(function () {
|
||||
if(oName === $(this).attr("href")) {
|
||||
if (oName === $(this).attr("href")) {
|
||||
$(this).parents("li").addClass("directory-item-active");
|
||||
}else{
|
||||
} else {
|
||||
$(this).parents("li").removeClass("directory-item-active");
|
||||
}
|
||||
});
|
||||
if(!$(".markdown-toc-list li").hasClass('directory-item-active')) {
|
||||
if (!$(".markdown-toc-list li").hasClass('directory-item-active')) {
|
||||
$(".markdown-toc-list li:eq(0)").addClass("directory-item-active");
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}).on("click",".markdown-toc-list a", function () {
|
||||
}).on("click", ".markdown-toc-list a", function () {
|
||||
var $this = $(this);
|
||||
setTimeout(function () {
|
||||
$(".markdown-toc-list li").removeClass("directory-item-active");
|
||||
$this.parents("li").addClass("directory-item-active");
|
||||
},10);
|
||||
}, 10);
|
||||
}).find(".markdown-toc-list li:eq(0)").addClass("directory-item-active");
|
||||
|
||||
|
||||
@@ -280,16 +290,16 @@ $(function () {
|
||||
|
||||
initHighlighting();
|
||||
window.jsTree = $("#sidebar").jstree({
|
||||
'plugins' : ["wholerow", "types"],
|
||||
'plugins': ["wholerow", "types"],
|
||||
"types": {
|
||||
"default" : {
|
||||
"icon" : false // 删除默认图标
|
||||
"default": {
|
||||
"icon": false // 删除默认图标
|
||||
}
|
||||
},
|
||||
'core' : {
|
||||
'check_callback' : true,
|
||||
"multiple" : false,
|
||||
'animation' : 0
|
||||
'core': {
|
||||
'check_callback': true,
|
||||
"multiple": false,
|
||||
'animation': 0
|
||||
}
|
||||
}).on('select_node.jstree', function (node, selected) {
|
||||
//如果是空目录则直接出发展开下一级功能
|
||||
@@ -298,7 +308,7 @@ $(function () {
|
||||
return false
|
||||
}
|
||||
$(".m-manual").removeClass('manual-mobile-show-left');
|
||||
loadDocument(selected.node.a_attr.href, selected.node.id,selected.node.a_attr['data-version']);
|
||||
loadDocument(selected.node.a_attr.href, selected.node.id, selected.node.a_attr['data-version']);
|
||||
});
|
||||
|
||||
$("#slidebar").on("click", function () {
|
||||
@@ -330,7 +340,7 @@ $(function () {
|
||||
* 项目内搜索
|
||||
*/
|
||||
$("#searchForm").ajaxForm({
|
||||
beforeSubmit : function () {
|
||||
beforeSubmit: function () {
|
||||
var keyword = $.trim($("#searchForm").find("input[name='keyword']").val());
|
||||
if (keyword === "") {
|
||||
$(".search-empty").show();
|
||||
@@ -340,10 +350,10 @@ $(function () {
|
||||
$("#btnSearch").attr("disabled", "disabled").find("i").removeClass("fa-search").addClass("loading");
|
||||
window.keyword = keyword;
|
||||
},
|
||||
success : function (res) {
|
||||
success: function (res) {
|
||||
var html = "";
|
||||
if (res.errcode === 0) {
|
||||
for(var i in res.data) {
|
||||
for (var i in res.data) {
|
||||
var item = res.data[i];
|
||||
html += '<li><a href="javascript:;" title="' + item.doc_name + '" data-id="' + item.doc_id + '"> ' + item.doc_name + ' </a></li>';
|
||||
}
|
||||
@@ -355,7 +365,7 @@ $(function () {
|
||||
}
|
||||
$("#searchList").html(html);
|
||||
},
|
||||
complete : function () {
|
||||
complete: function () {
|
||||
$("#btnSearch").removeAttr("disabled").find("i").removeClass("loading").addClass("fa-search");
|
||||
}
|
||||
});
|
||||
@@ -363,12 +373,12 @@ $(function () {
|
||||
window.onpopstate = function (e) {
|
||||
var $param = e.state;
|
||||
if (!$param) return;
|
||||
if($param.hasOwnProperty("$url")) {
|
||||
if ($param.hasOwnProperty("$url")) {
|
||||
window.jsTree.jstree().deselect_all();
|
||||
|
||||
if ($param.$id) {
|
||||
window.jsTree.jstree().select_node({ id : $param.$id });
|
||||
}else{
|
||||
window.jsTree.jstree().select_node({ id: $param.$id });
|
||||
} else {
|
||||
window.location.assign($param.$url);
|
||||
}
|
||||
// events.trigger('article.open', $param);
|
||||
@@ -379,22 +389,34 @@ $(function () {
|
||||
|
||||
// 提交评论
|
||||
$("#commentForm").ajaxForm({
|
||||
beforeSubmit : function () {
|
||||
beforeSubmit: function () {
|
||||
$("#btnSubmitComment").button("loading");
|
||||
},
|
||||
success : function (res) {
|
||||
if(res.errcode === 0){
|
||||
success: function (res) {
|
||||
if (res.errcode === 0) {
|
||||
layer.msg("保存成功");
|
||||
}else{
|
||||
} else {
|
||||
layer.msg(res.message);
|
||||
}
|
||||
$("#btnSubmitComment").button("reset");
|
||||
$("#commentContent").val("");
|
||||
pageClicked(-1, res.data.doc_id); // -1 表示请求最后一页
|
||||
},
|
||||
error : function () {
|
||||
error: function () {
|
||||
layer.msg("服务错误");
|
||||
$("#btnSubmitComment").button("reset");
|
||||
}
|
||||
});
|
||||
});
|
||||
loadCopySnippets();
|
||||
});
|
||||
|
||||
function loadCopySnippets() {
|
||||
$("pre").addClass("line-numbers language-bash");
|
||||
$("pre").attr('data-prismjs-copy', '复制');
|
||||
$("pre").attr('data-prismjs-copy-error', '按Ctrl+C复制');
|
||||
$("pre").attr('data-prismjs-copy-success', '代码已复制!');
|
||||
var snippets = document.querySelectorAll('pre code');
|
||||
[].forEach.call(snippets, function (snippet) {
|
||||
Prism.highlightElement(snippet);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user