2018-08-15 15:33:22 +08:00
|
|
|
|
var events = function () {
|
|
|
|
|
var articleOpen = function (event, $param) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
//当打开文档时,将文档ID加入到本地缓存。
|
2018-08-17 17:39:03 +08:00
|
|
|
|
window.sessionStorage && window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, $param.$id);
|
2018-08-15 15:33:22 +08:00
|
|
|
|
var prevState = window.history.state || {};
|
|
|
|
|
if ('pushState' in history) {
|
|
|
|
|
if ($param.$id) {
|
|
|
|
|
prevState.$id === $param.$id || window.history.pushState($param, $param.$id, $param.$url);
|
|
|
|
|
} else {
|
|
|
|
|
window.history.pushState($param, $param.$id, $param.$url);
|
|
|
|
|
window.history.replaceState($param, $param.$id, $param.$url);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
window.location.hash = $param.$url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initHighlighting();
|
2018-09-13 18:19:26 +08:00
|
|
|
|
$(window).resize();
|
2018-08-15 15:33:22 +08:00
|
|
|
|
|
|
|
|
|
$(".manual-right").scrollTop(0);
|
|
|
|
|
//使用layer相册功能查看图片
|
2023-07-03 09:41:27 +08:00
|
|
|
|
layer.photos({ photos: "#page-content" });
|
2018-08-15 15:33:22 +08:00
|
|
|
|
};
|
2018-09-13 18:19:26 +08:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
data: function ($key, $value) {
|
|
|
|
|
$key = "MinDoc::Document:" + $key;
|
|
|
|
|
if (typeof $value === "undefined") {
|
|
|
|
|
return $("body").data($key);
|
|
|
|
|
} else {
|
|
|
|
|
return $('body').data($key, $value);
|
2018-08-15 15:33:22 +08:00
|
|
|
|
}
|
2018-09-13 18:19:26 +08:00
|
|
|
|
},
|
|
|
|
|
trigger: function ($e, $obj) {
|
|
|
|
|
if ($e === "article.open") {
|
|
|
|
|
articleOpen($e, $obj);
|
|
|
|
|
} else {
|
|
|
|
|
$('body').trigger('article.open', $obj);
|
2018-08-15 15:33:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 18:19:26 +08:00
|
|
|
|
|
2018-08-15 15:33:22 +08:00
|
|
|
|
}();
|
|
|
|
|
|
2021-04-03 22:44:43 +08:00
|
|
|
|
function format($d) {
|
|
|
|
|
return $d < 10 ? "0" + $d : "" + $d;
|
2021-04-03 17:40:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 22:44:43 +08:00
|
|
|
|
function timeFormat($time) {
|
|
|
|
|
var span = Date.parse($time)
|
2021-04-03 17:40:08 +08:00
|
|
|
|
var date = new Date(span)
|
|
|
|
|
var year = date.getFullYear();
|
|
|
|
|
var month = format(date.getMonth() + 1);
|
|
|
|
|
var day = format(date.getDate());
|
|
|
|
|
var hour = format(date.getHours());
|
|
|
|
|
var min = format(date.getMinutes());
|
|
|
|
|
var sec = format(date.getSeconds());
|
|
|
|
|
return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 22:44:43 +08:00
|
|
|
|
// 点击翻页
|
|
|
|
|
function pageClicked($page, $docid) {
|
2022-05-18 11:17:03 +08:00
|
|
|
|
if (!window.IS_DISPLAY_COMMENT) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-14 20:54:59 +08:00
|
|
|
|
$("#articleComment").removeClass('not-show-comment');
|
2021-04-03 17:40:08 +08:00
|
|
|
|
$.ajax({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
url: "/comment/lists?page=" + $page + "&docid=" + $docid,
|
|
|
|
|
type: "GET",
|
|
|
|
|
success: function ($res) {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
console.log($res.data);
|
|
|
|
|
loadComment($res.data.page, $res.data.doc_id);
|
2021-04-03 17:40:08 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function () {
|
2021-04-03 17:40:08 +08:00
|
|
|
|
layer.msg("加载失败");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加载评论
|
2021-04-03 22:44:43 +08:00
|
|
|
|
function loadComment($page, $docid) {
|
2021-04-03 17:40:08 +08:00
|
|
|
|
$("#commentList").empty();
|
|
|
|
|
var html = ""
|
2021-04-03 22:44:43 +08:00
|
|
|
|
var c = $page.List;
|
2021-04-03 17:40:08 +08:00
|
|
|
|
for (var i = 0; c && i < c.length; i++) {
|
|
|
|
|
html += "<div class=\"comment-item\" data-id=\"" + c[i].comment_id + "\">";
|
2023-07-03 09:41:27 +08:00
|
|
|
|
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>";
|
2021-04-03 17:40:08 +08:00
|
|
|
|
html += "</div>";
|
|
|
|
|
}
|
|
|
|
|
$("#commentList").append(html);
|
|
|
|
|
|
2021-04-03 22:44:43 +08:00
|
|
|
|
if ($page.TotalPage > 1) {
|
2021-04-03 17:40:08 +08:00
|
|
|
|
$("#page").bootstrapPaginator({
|
2021-04-03 22:44:43 +08:00
|
|
|
|
currentPage: $page.PageNo,
|
|
|
|
|
totalPages: $page.TotalPage,
|
2021-04-03 17:40:08 +08:00
|
|
|
|
bootstrapMajorVersion: 3,
|
|
|
|
|
size: "middle",
|
2023-07-03 09:41:27 +08:00
|
|
|
|
onPageClicked: function (e, originalEvent, type, page) {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
pageClicked(page, $docid);
|
2021-04-03 17:40:08 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$("#page").find("li").remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 22:44:43 +08:00
|
|
|
|
// 删除评论
|
|
|
|
|
function onDelComment($id) {
|
|
|
|
|
console.log($id);
|
|
|
|
|
$.ajax({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
url: "/comment/delete",
|
|
|
|
|
data: { "id": $id },
|
|
|
|
|
type: "POST",
|
|
|
|
|
success: function ($res) {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
if ($res.errcode == 0) {
|
|
|
|
|
layer.msg("删除成功");
|
|
|
|
|
$("div[data-id=" + $id + "]").remove();
|
|
|
|
|
} else {
|
|
|
|
|
layer.msg($res.message);
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function () {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
layer.msg("删除失败");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 17:40:08 +08:00
|
|
|
|
// 重新渲染页面
|
2021-04-03 22:44:43 +08:00
|
|
|
|
function renderPage($data) {
|
|
|
|
|
$("#page-content").html($data.body);
|
|
|
|
|
$("title").text($data.title);
|
|
|
|
|
$("#article-title").text($data.doc_title);
|
|
|
|
|
$("#article-info").text($data.doc_info);
|
|
|
|
|
$("#view_count").text("阅读次数:" + $data.view_count);
|
|
|
|
|
$("#doc_id").val($data.doc_id);
|
2022-05-14 20:54:59 +08:00
|
|
|
|
if ($data.page) {
|
|
|
|
|
loadComment($data.page, $data.doc_id);
|
2024-07-05 15:31:34 +08:00
|
|
|
|
} else {
|
2022-05-14 20:54:59 +08:00
|
|
|
|
pageClicked(-1, $data.doc_id);
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
2024-07-05 15:31:34 +08:00
|
|
|
|
checkMarkdownTocElement();
|
2021-04-03 17:40:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
|
/***
|
|
|
|
|
* 加载文档到阅读区
|
|
|
|
|
* @param $url
|
|
|
|
|
* @param $id
|
|
|
|
|
* @param $callback
|
|
|
|
|
*/
|
2017-12-21 15:27:57 +08:00
|
|
|
|
function loadDocument($url, $id, $callback) {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$.ajax({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
url: $url,
|
|
|
|
|
type: "GET",
|
|
|
|
|
beforeSend: function () {
|
2018-08-17 17:39:03 +08:00
|
|
|
|
var data = events.data($id);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (data) {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
if (typeof $callback === "function") {
|
2018-08-15 15:33:22 +08:00
|
|
|
|
data.body = $callback(data.body);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else if (data.version && data.version != $callback) {
|
2018-09-05 17:56:18 +08:00
|
|
|
|
return true;
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
2021-04-03 17:40:08 +08:00
|
|
|
|
renderPage(data);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
2023-12-19 13:19:47 +08:00
|
|
|
|
loadCopySnippets();
|
2023-07-03 09:41:27 +08:00
|
|
|
|
events.trigger('article.open', { $url: $url, $id: $id });
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
|
|
|
|
return false;
|
2018-08-15 15:33:22 +08:00
|
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
2018-08-15 15:33:22 +08:00
|
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
|
NProgress.start();
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
success: function ($res) {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
if ($res.errcode === 0) {
|
2024-01-09 19:54:31 +08:00
|
|
|
|
var data = $res.data;
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (typeof $callback === "function") {
|
2024-01-09 19:54:31 +08:00
|
|
|
|
data.body = $callback(data.body);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
2024-01-09 19:54:31 +08:00
|
|
|
|
renderPage(data);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
loadCopySnippets();
|
2024-01-09 19:54:31 +08:00
|
|
|
|
events.data($id, data);
|
2023-07-03 09:41:27 +08:00
|
|
|
|
events.trigger('article.open', { $url: $url, $id: $id });
|
2021-04-03 22:44:43 +08:00
|
|
|
|
} else if ($res.errcode === 6000) {
|
2017-12-21 15:27:57 +08:00
|
|
|
|
window.location.href = "/";
|
2017-12-20 18:55:17 +08:00
|
|
|
|
} else {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
layer.msg("加载失败");
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
complete: function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
NProgress.done();
|
2018-06-06 20:45:24 +08:00
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function () {
|
2018-06-06 20:45:24 +08:00
|
|
|
|
layer.msg("加载失败");
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 13:56:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 初始化代码高亮
|
|
|
|
|
*/
|
2017-05-26 14:19:27 +08:00
|
|
|
|
function initHighlighting() {
|
2018-06-06 22:40:12 +08:00
|
|
|
|
try {
|
|
|
|
|
$('pre,pre.ql-syntax').each(function (i, block) {
|
2024-01-05 10:42:25 +08:00
|
|
|
|
if ($(this).hasClass('prettyprinted') || $(this).hasClass('hljs')) {
|
2018-06-06 22:40:12 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
|
});
|
2018-08-07 17:19:56 +08:00
|
|
|
|
// hljs.initLineNumbersOnLoad();
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} catch (e) {
|
2018-06-06 22:40:12 +08:00
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(function () {
|
2024-07-05 15:31:34 +08:00
|
|
|
|
checkMarkdownTocElement();
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".view-backtop").on("click", function () {
|
|
|
|
|
$('.manual-right').animate({ scrollTop: '0px' }, 200);
|
|
|
|
|
});
|
|
|
|
|
$(".manual-right").scroll(function () {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
try {
|
|
|
|
|
var top = $(".manual-right").scrollTop();
|
|
|
|
|
if (top > 100) {
|
|
|
|
|
$(".view-backtop").addClass("active");
|
|
|
|
|
} else {
|
|
|
|
|
$(".view-backtop").removeClass("active");
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} catch (e) {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
2018-09-12 19:51:09 +08:00
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
try {
|
2018-09-12 19:51:09 +08:00
|
|
|
|
var scrollTop = $("body").scrollTop();
|
2018-09-12 15:08:16 +08:00
|
|
|
|
var oItem = $(".markdown-heading").find(".reference-link");
|
|
|
|
|
var oName = "";
|
2023-07-03 09:41:27 +08:00
|
|
|
|
$.each(oItem, function () {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
var oneItem = $(this);
|
|
|
|
|
var offsetTop = oneItem.offset().top;
|
2018-09-12 19:51:09 +08:00
|
|
|
|
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (offsetTop - scrollTop < 100) {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
oName = "#" + oneItem.attr("name");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$(".markdown-toc-list a").each(function () {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (oName === $(this).attr("href")) {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
$(this).parents("li").addClass("directory-item-active");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
$(this).parents("li").removeClass("directory-item-active");
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if (!$(".markdown-toc-list li").hasClass('directory-item-active')) {
|
2018-09-12 19:51:09 +08:00
|
|
|
|
$(".markdown-toc-list li:eq(0)").addClass("directory-item-active");
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} catch (e) {
|
2018-09-12 15:08:16 +08:00
|
|
|
|
console.log(e);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}).on("click", ".markdown-toc-list a", function () {
|
2018-09-13 18:19:26 +08:00
|
|
|
|
var $this = $(this);
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
$(".markdown-toc-list li").removeClass("directory-item-active");
|
|
|
|
|
$this.parents("li").addClass("directory-item-active");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}, 10);
|
2018-09-13 18:19:26 +08:00
|
|
|
|
}).find(".markdown-toc-list li:eq(0)").addClass("directory-item-active");
|
2018-09-12 19:51:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(window).resize(function (e) {
|
2024-07-05 15:31:34 +08:00
|
|
|
|
var h = $(".manual-catalog").innerHeight() - 50;
|
2018-09-12 19:51:09 +08:00
|
|
|
|
$(".markdown-toc").height(h);
|
2018-09-13 18:19:26 +08:00
|
|
|
|
}).resize();
|
2018-09-12 19:51:09 +08:00
|
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
|
window.isFullScreen = false;
|
|
|
|
|
|
|
|
|
|
initHighlighting();
|
|
|
|
|
window.jsTree = $("#sidebar").jstree({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
'plugins': ["wholerow", "types"],
|
2017-05-26 14:19:27 +08:00
|
|
|
|
"types": {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
"default": {
|
|
|
|
|
"icon": false // 删除默认图标
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
'core': {
|
|
|
|
|
'check_callback': true,
|
|
|
|
|
"multiple": false,
|
|
|
|
|
'animation': 0
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
}).on('select_node.jstree', function (node, selected) {
|
|
|
|
|
//如果是空目录则直接出发展开下一级功能
|
|
|
|
|
if (selected.node.a_attr && selected.node.a_attr.disabled) {
|
|
|
|
|
selected.instance.toggle_node(selected.node);
|
|
|
|
|
return false
|
|
|
|
|
}
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".m-manual").removeClass('manual-mobile-show-left');
|
2023-07-03 09:41:27 +08:00
|
|
|
|
loadDocument(selected.node.a_attr.href, selected.node.id, selected.node.a_attr['data-version']);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-12-20 18:55:17 +08:00
|
|
|
|
$("#slidebar").on("click", function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".m-manual").addClass('manual-mobile-show-left');
|
|
|
|
|
});
|
2017-12-20 18:55:17 +08:00
|
|
|
|
$(".manual-mask").on("click", function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".m-manual").removeClass('manual-mobile-show-left');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关闭侧边栏
|
|
|
|
|
*/
|
2017-12-21 15:27:57 +08:00
|
|
|
|
$(".manual-fullscreen-switch").on("click", function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
isFullScreen = !isFullScreen;
|
|
|
|
|
if (isFullScreen) {
|
|
|
|
|
$(".m-manual").addClass('manual-fullscreen-active');
|
|
|
|
|
} else {
|
|
|
|
|
$(".m-manual").removeClass('manual-fullscreen-active');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-21 15:27:57 +08:00
|
|
|
|
$(".navg-item[data-mode]").on("click", function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var mode = $(this).data('mode');
|
|
|
|
|
$(this).siblings().removeClass('active').end().addClass('active');
|
|
|
|
|
$(".m-manual").removeClass("manual-mode-view manual-mode-collect manual-mode-search").addClass("manual-mode-" + mode);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 项目内搜索
|
|
|
|
|
*/
|
|
|
|
|
$("#searchForm").ajaxForm({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
beforeSubmit: function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var keyword = $.trim($("#searchForm").find("input[name='keyword']").val());
|
2017-12-21 15:27:57 +08:00
|
|
|
|
if (keyword === "") {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".search-empty").show();
|
|
|
|
|
$("#searchList").html("");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-12-21 15:27:57 +08:00
|
|
|
|
$("#btnSearch").attr("disabled", "disabled").find("i").removeClass("fa-search").addClass("loading");
|
2017-05-26 14:19:27 +08:00
|
|
|
|
window.keyword = keyword;
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
success: function (res) {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var html = "";
|
2017-12-21 15:27:57 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
for (var i in res.data) {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
var item = res.data[i];
|
2017-12-20 18:55:17 +08:00
|
|
|
|
html += '<li><a href="javascript:;" title="' + item.doc_name + '" data-id="' + item.doc_id + '"> ' + item.doc_name + ' </a></li>';
|
2017-05-26 14:19:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-21 15:27:57 +08:00
|
|
|
|
if (html !== "") {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".search-empty").hide();
|
2017-12-20 18:55:17 +08:00
|
|
|
|
} else {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$(".search-empty").show();
|
|
|
|
|
}
|
|
|
|
|
$("#searchList").html(html);
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
complete: function () {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
$("#btnSearch").removeAttr("disabled").find("i").removeClass("loading").addClass("fa-search");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.onpopstate = function (e) {
|
|
|
|
|
var $param = e.state;
|
2018-02-06 11:27:34 +08:00
|
|
|
|
if (!$param) return;
|
2023-07-03 09:41:27 +08:00
|
|
|
|
if ($param.hasOwnProperty("$url")) {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
window.jsTree.jstree().deselect_all();
|
|
|
|
|
|
2018-02-06 11:27:34 +08:00
|
|
|
|
if ($param.$id) {
|
2023-07-03 09:41:27 +08:00
|
|
|
|
window.jsTree.jstree().select_node({ id: $param.$id });
|
|
|
|
|
} else {
|
2018-02-06 11:27:34 +08:00
|
|
|
|
window.location.assign($param.$url);
|
|
|
|
|
}
|
2017-12-20 18:55:17 +08:00
|
|
|
|
// events.trigger('article.open', $param);
|
|
|
|
|
} else {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
console.log($param);
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-04-03 22:44:43 +08:00
|
|
|
|
|
|
|
|
|
// 提交评论
|
|
|
|
|
$("#commentForm").ajaxForm({
|
2023-07-03 09:41:27 +08:00
|
|
|
|
beforeSubmit: function () {
|
2021-04-03 22:44:43 +08:00
|
|
|
|
$("#btnSubmitComment").button("loading");
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.errcode === 0) {
|
2021-04-04 16:44:14 +08:00
|
|
|
|
layer.msg("保存成功");
|
2023-07-03 09:41:27 +08:00
|
|
|
|
} else {
|
2022-10-28 12:33:36 +08:00
|
|
|
|
layer.msg(res.message);
|
2021-04-03 22:44:43 +08:00
|
|
|
|
}
|
|
|
|
|
$("#btnSubmitComment").button("reset");
|
|
|
|
|
$("#commentContent").val("");
|
|
|
|
|
pageClicked(-1, res.data.doc_id); // -1 表示请求最后一页
|
|
|
|
|
},
|
2023-07-03 09:41:27 +08:00
|
|
|
|
error: function () {
|
2021-04-04 16:44:14 +08:00
|
|
|
|
layer.msg("服务错误");
|
|
|
|
|
$("#btnSubmitComment").button("reset");
|
2021-04-03 22:44:43 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-03 09:41:27 +08:00
|
|
|
|
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);
|
|
|
|
|
});
|
2024-07-05 15:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkMarkdownTocElement() {
|
|
|
|
|
console.log(111)
|
|
|
|
|
let toc = $(".markdown-toc-list");
|
|
|
|
|
let articleComment = $("#articleComment");
|
|
|
|
|
if (toc.length) {
|
|
|
|
|
$(".wiki-bottom-left").css("width", "calc(100% - 260px)");
|
|
|
|
|
articleComment.css("width", "calc(100% - 260px)");
|
|
|
|
|
articleComment.css("margin", "30px 0 70px 0");
|
|
|
|
|
} else {
|
|
|
|
|
$(".wiki-bottom-left").css("width", "100%");
|
|
|
|
|
articleComment.css("width", "100%");
|
|
|
|
|
articleComment.css("margin", "30px auto 70px auto;");
|
|
|
|
|
}
|
2023-07-03 09:41:27 +08:00
|
|
|
|
}
|