mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
优化体验
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
<link href="/static/css/jstree.css" rel="stylesheet">
|
||||
{{if eq .Model.Editor "markdown"}}
|
||||
<link href="{{cdncss "/static/editor.md/css/editormd.preview.css"}}" rel="stylesheet">
|
||||
<link href="{{cdncss "/static/prettify/themes/atelier-estuary-dark.min.css"}}" rel="stylesheet">
|
||||
<link href="/static/css/markdown.preview.css" rel="stylesheet">
|
||||
{{else}}
|
||||
<link href="{{cdncss "/static/highlight/styles/zenburn.css"}}" rel="stylesheet">
|
||||
{{end}}
|
||||
@@ -226,196 +228,20 @@
|
||||
<script type="text/javascript" src="{{cdnjs "/static/nprogress/nprogress.js"}}"></script>
|
||||
<script type="text/javascript" src="{{cdnjs "/static/highlight/highlight.js"}}"></script>
|
||||
<script type="text/javascript" src="{{cdnjs "/static/highlight/highlightjs-line-numbers.min.js"}}"></script>
|
||||
<script type="text/javascript" src="/static/js/jquery.highlight.js"></script>
|
||||
<script type="text/javascript" src="/static/js/kancloud.js"></script>
|
||||
<script type="text/javascript">
|
||||
var events = $("body");
|
||||
var catalog = null;
|
||||
function initHighlighting() {
|
||||
$('pre code').each(function (i, block) {
|
||||
hljs.highlightBlock(block);
|
||||
});
|
||||
|
||||
hljs.initLineNumbersOnLoad();
|
||||
}
|
||||
function loadDocument($url,$id,$callback) {
|
||||
$.ajax({
|
||||
url : $url,
|
||||
type : "GET",
|
||||
beforeSend :function (xhr) {
|
||||
var body = events.data('body_' + $id);
|
||||
var title = events.data('title_' + $id);
|
||||
var doc_title = events.data('doc_title_' + $id);
|
||||
|
||||
if(body && title && doc_title){
|
||||
|
||||
if (typeof $callback === "function") {
|
||||
body = $callback(body);
|
||||
}
|
||||
$("#page-content").html(body);
|
||||
$("title").text(title);
|
||||
$("#article-title").text(doc_title);
|
||||
|
||||
events.trigger('article.open',$url,true);
|
||||
|
||||
return false;
|
||||
}
|
||||
NProgress.start();
|
||||
},
|
||||
success : function (res) {
|
||||
if(res.errcode === 0){
|
||||
var body = res.data.body;
|
||||
var doc_title = res.data.doc_title;
|
||||
var title = res.data.title;
|
||||
|
||||
$body = body;
|
||||
if (typeof $callback === "function" ){
|
||||
$body = $callback(body);
|
||||
}
|
||||
$("#page-content").html($body);
|
||||
$("title").text(title);
|
||||
$("#article-title").text(doc_title);
|
||||
|
||||
events.data('body_' + $id,body);
|
||||
events.data('title_' + $id,title);
|
||||
events.data('doc_title_' + $id,doc_title);
|
||||
|
||||
events.trigger('article.open',$url,false);
|
||||
|
||||
}else{
|
||||
layer.msg("加载失败");
|
||||
}
|
||||
},
|
||||
complete : function () {
|
||||
NProgress.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$(".view-backtop").on("click", function () {
|
||||
$('.manual-right').animate({ scrollTop: '0px' }, 200);
|
||||
});
|
||||
$(".manual-right").scroll(function () {
|
||||
var top = $(".manual-right").scrollTop();
|
||||
if(top > 100){
|
||||
$(".view-backtop").addClass("active");
|
||||
}else{
|
||||
$(".view-backtop").removeClass("active");
|
||||
}
|
||||
});
|
||||
window.isFullScreen = false;
|
||||
|
||||
initHighlighting();
|
||||
|
||||
$("#sidebar").jstree({
|
||||
'plugins':["wholerow","types"],
|
||||
"types": {
|
||||
"default" : {
|
||||
"icon" : false // 删除默认图标
|
||||
}
|
||||
},
|
||||
'core' : {
|
||||
'check_callback' : true,
|
||||
"multiple" : false ,
|
||||
'animation' : 0
|
||||
}
|
||||
}).on('select_node.jstree',function (node,selected,event) {
|
||||
$(".m-manual").removeClass('manual-mobile-show-left');
|
||||
var url = selected.node.a_attr.href;
|
||||
|
||||
if(url === window.location.href){
|
||||
return false;
|
||||
}
|
||||
loadDocument(url,selected.node.id);
|
||||
|
||||
});
|
||||
|
||||
$("#slidebar").on("click",function () {
|
||||
$(".m-manual").addClass('manual-mobile-show-left');
|
||||
});
|
||||
$(".manual-mask").on("click",function () {
|
||||
$(".m-manual").removeClass('manual-mobile-show-left');
|
||||
});
|
||||
|
||||
$(".manual-fullscreen-switch").on("click",function () {
|
||||
isFullScreen = !isFullScreen;
|
||||
if (isFullScreen) {
|
||||
$(".m-manual").addClass('manual-fullscreen-active');
|
||||
} else {
|
||||
$(".m-manual").removeClass('manual-fullscreen-active');
|
||||
}
|
||||
});
|
||||
events.on('article.open', function (event, url,init) {
|
||||
if ('pushState' in history) {
|
||||
|
||||
if (init == false) {
|
||||
history.replaceState({ }, '', url);
|
||||
init = true;
|
||||
} else {
|
||||
history.pushState({ }, '', url);
|
||||
}
|
||||
|
||||
} else {
|
||||
location.hash = url;
|
||||
}
|
||||
initHighlighting();
|
||||
|
||||
});
|
||||
|
||||
$(".navg-item[data-mode]").on("click",function () {
|
||||
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());
|
||||
if(keyword === ""){
|
||||
$(".search-empty").show();
|
||||
$("#searchList").html("");
|
||||
return false;
|
||||
}
|
||||
$("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading");
|
||||
window.keyword = keyword;
|
||||
},
|
||||
success :function (res) {
|
||||
var html = "";
|
||||
if(res.errcode === 0){
|
||||
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>';
|
||||
}
|
||||
}
|
||||
if(html !== ""){
|
||||
$(".search-empty").hide();
|
||||
}else{
|
||||
$(".search-empty").show();
|
||||
}
|
||||
$("#searchList").html(html);
|
||||
},
|
||||
complete : function () {
|
||||
$("#btnSearch").removeAttr("disabled").find("i").removeClass("loading").addClass("fa-search");
|
||||
}
|
||||
});
|
||||
|
||||
$("#searchList").on("click","a",function () {
|
||||
var id = $(this).attr("data-id");
|
||||
var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id;
|
||||
$(this).parent("li").siblings().find("a").removeClass("active");
|
||||
$(this).addClass("active");
|
||||
loadDocument(url,id,function (body) {
|
||||
if(body !== ""){
|
||||
console.log(window.keyword);
|
||||
|
||||
body = body.replace(new RegExp(window.keyword,"g"),'<em class="search-highlight">' + window.keyword + '</em>');
|
||||
}
|
||||
return body;
|
||||
});
|
||||
$(function () {
|
||||
$("#searchList").on("click","a",function () {
|
||||
var id = $(this).attr("data-id");
|
||||
var url = "{{urlfor "DocumentController.Read" ":key" .Model.Identify ":id" ""}}/" + id;
|
||||
$(this).parent("li").siblings().find("a").removeClass("active");
|
||||
$(this).addClass("active");
|
||||
loadDocument(url,id,function (body) {
|
||||
return $(body).highlight(window.keyword);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user