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({
|
|
|
|
url : $url,
|
|
|
|
type : "GET",
|
2017-12-21 15:27:57 +08:00
|
|
|
beforeSend : function (xhr) {
|
2017-05-26 14:19:27 +08:00
|
|
|
var body = events.data('body_' + $id);
|
|
|
|
var title = events.data('title_' + $id);
|
|
|
|
var doc_title = events.data('doc_title_' + $id);
|
2017-12-20 18:55:17 +08:00
|
|
|
var doc_info = events.data('doc_info_' + $id);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
2017-12-21 15:27:57 +08:00
|
|
|
if (body && title && doc_title) {
|
2017-05-26 14:19:27 +08:00
|
|
|
if (typeof $callback === "function") {
|
|
|
|
body = $callback(body);
|
|
|
|
}
|
2017-12-20 18:55:17 +08:00
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
$("#page-content").html(body);
|
|
|
|
$("title").text(title);
|
|
|
|
$("#article-title").text(doc_title);
|
2017-12-20 18:55:17 +08:00
|
|
|
$("#article-info").text(doc_info);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
2018-02-06 11:27:34 +08:00
|
|
|
events.trigger('article.open', { $url : $url, $id : $id });
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NProgress.start();
|
|
|
|
},
|
|
|
|
success : function (res) {
|
2017-12-20 18:55:17 +08:00
|
|
|
if (res.errcode === 0) {
|
2017-05-26 14:19:27 +08:00
|
|
|
var body = res.data.body;
|
|
|
|
var doc_title = res.data.doc_title;
|
|
|
|
var title = res.data.title;
|
2017-12-20 16:16:41 +08:00
|
|
|
var doc_info = res.data.doc_info;
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
|
|
$body = body;
|
2017-12-20 18:55:17 +08:00
|
|
|
if (typeof $callback === "function" ) {
|
2017-05-26 14:19:27 +08:00
|
|
|
$body = $callback(body);
|
|
|
|
}
|
2017-12-20 18:55:17 +08:00
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
$("#page-content").html($body);
|
|
|
|
$("title").text(title);
|
|
|
|
$("#article-title").text(doc_title);
|
2017-12-20 16:16:41 +08:00
|
|
|
$("#article-info").text(doc_info);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
2017-12-20 18:55:17 +08:00
|
|
|
events.data('body_' + $id, body);
|
|
|
|
events.data('title_' + $id, title);
|
|
|
|
events.data('doc_title_' + $id, doc_title);
|
|
|
|
events.data('doc_info_' + $id, doc_info);
|
2017-05-26 14:19:27 +08:00
|
|
|
|
2018-02-06 11:27:34 +08:00
|
|
|
events.trigger('article.open', { $url : $url, $id : $id });
|
2017-12-21 15:27:57 +08:00
|
|
|
} else if (res.errcode === 6000) {
|
|
|
|
window.location.href = "/";
|
2017-12-20 18:55:17 +08:00
|
|
|
} else {
|
2017-05-26 14:19:27 +08:00
|
|
|
layer.msg("加载失败");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete : function () {
|
|
|
|
NProgress.done();
|
2018-06-06 20:45:24 +08:00
|
|
|
},
|
|
|
|
error : function () {
|
|
|
|
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) {
|
|
|
|
if ($(this).hasClass('prettyprinted')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
});
|
|
|
|
hljs.initLineNumbersOnLoad();
|
|
|
|
}catch (e){
|
|
|
|
console.log(e);
|
|
|
|
}
|
2017-05-26 14:19:27 +08:00
|
|
|
}
|
|
|
|
|
2018-03-01 11:28:21 +08:00
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
var events = $("body");
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$(".view-backtop").on("click", function () {
|
|
|
|
$('.manual-right').animate({ scrollTop: '0px' }, 200);
|
|
|
|
});
|
|
|
|
$(".manual-right").scroll(function () {
|
|
|
|
var top = $(".manual-right").scrollTop();
|
2017-12-20 18:55:17 +08:00
|
|
|
if (top > 100) {
|
2017-05-26 14:19:27 +08:00
|
|
|
$(".view-backtop").addClass("active");
|
2017-12-20 18:55:17 +08:00
|
|
|
} else {
|
2017-05-26 14:19:27 +08:00
|
|
|
$(".view-backtop").removeClass("active");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
window.isFullScreen = false;
|
|
|
|
|
|
|
|
initHighlighting();
|
|
|
|
window.jsTree = $("#sidebar").jstree({
|
2017-12-21 15:27:57 +08:00
|
|
|
'plugins' : ["wholerow", "types"],
|
2017-05-26 14:19:27 +08:00
|
|
|
"types": {
|
|
|
|
"default" : {
|
|
|
|
"icon" : false // 删除默认图标
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'core' : {
|
|
|
|
'check_callback' : true,
|
2017-12-20 18:55:17 +08:00
|
|
|
"multiple" : false,
|
2017-05-26 14:19:27 +08:00
|
|
|
'animation' : 0
|
|
|
|
}
|
2017-12-21 15:27:57 +08:00
|
|
|
}).on('select_node.jstree', function (node, selected, event) {
|
2017-05-26 14:19:27 +08:00
|
|
|
$(".m-manual").removeClass('manual-mobile-show-left');
|
|
|
|
var url = selected.node.a_attr.href;
|
|
|
|
|
2017-12-20 18:55:17 +08:00
|
|
|
if (url === window.location.href) {
|
2017-05-26 14:19:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-20 18:55:17 +08:00
|
|
|
loadDocument(url, selected.node.id);
|
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-20 18:55:17 +08:00
|
|
|
// 处理打开事件
|
2017-05-26 14:19:27 +08:00
|
|
|
events.on('article.open', function (event, $param) {
|
2018-02-06 11:27:34 +08:00
|
|
|
|
|
|
|
var prevState = window.history.state || {};
|
2017-05-26 14:19:27 +08:00
|
|
|
if ('pushState' in history) {
|
2018-02-06 11:27:34 +08:00
|
|
|
// if ($param.$init === false) {
|
|
|
|
// window.history.replaceState($param, $param.$id, $param.$url);
|
|
|
|
// } else {
|
|
|
|
// window.history.pushState($param, $param.$id, $param.$url);
|
|
|
|
// }
|
|
|
|
|
|
|
|
if ($param.$id) {
|
|
|
|
prevState.$id === $param.$id || window.history.pushState($param, $param.$id, $param.$url);
|
2017-05-26 14:19:27 +08:00
|
|
|
} else {
|
2017-12-20 18:55:17 +08:00
|
|
|
window.history.pushState($param, $param.$id, $param.$url);
|
2018-02-06 11:27:34 +08:00
|
|
|
window.history.replaceState($param, $param.$id, $param.$url);
|
2017-05-26 14:19:27 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window.location.hash = $param.$url;
|
|
|
|
}
|
2017-12-20 18:55:17 +08:00
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
initHighlighting();
|
2018-03-01 11:28:21 +08:00
|
|
|
|
2017-05-26 14:19:27 +08:00
|
|
|
$(".manual-right").scrollTop(0);
|
2018-01-19 20:10:54 +08:00
|
|
|
//使用layer相册功能查看图片
|
|
|
|
layer.photos({photos: "#page-content"});
|
2017-05-26 14:19:27 +08:00
|
|
|
});
|
|
|
|
|
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({
|
|
|
|
beforeSubmit : function () {
|
|
|
|
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;
|
|
|
|
},
|
2017-12-20 18:55:17 +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) {
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
complete : function () {
|
|
|
|
$("#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;
|
2017-05-26 14:19:27 +08:00
|
|
|
if($param.hasOwnProperty("$url")) {
|
|
|
|
window.jsTree.jstree().deselect_all();
|
|
|
|
|
2018-02-06 11:27:34 +08:00
|
|
|
if ($param.$id) {
|
|
|
|
window.jsTree.jstree().select_node({ id : $param.$id });
|
|
|
|
}else{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2017-06-02 16:08:14 +08:00
|
|
|
try {
|
|
|
|
var $node = window.jsTree.jstree().get_selected();
|
2018-02-06 11:27:34 +08:00
|
|
|
if ($node instanceof Array && $node.length) {
|
2017-12-21 15:27:57 +08:00
|
|
|
$node = window.jsTree.jstree().get_node({ id: $node[0] });
|
2018-02-06 11:27:34 +08:00
|
|
|
events.trigger('article.open', { $url: $node.a_attr.href, $id: $node.id });
|
2017-06-02 16:08:14 +08:00
|
|
|
}
|
2017-12-20 18:55:17 +08:00
|
|
|
} catch (e) {
|
2017-06-02 16:08:14 +08:00
|
|
|
console.log(e);
|
2017-05-26 15:51:45 +08:00
|
|
|
}
|
2017-05-26 14:19:27 +08:00
|
|
|
});
|