修订在文档件切换时有时文档信息不更新的问题。

pull/178/head
Dandy Cheung 2017-12-20 18:55:17 +08:00
parent 292cf049e2
commit 9e2fbccc92
1 changed files with 33 additions and 31 deletions

View File

@ -12,45 +12,49 @@ function loadDocument($url,$id,$callback) {
var body = events.data('body_' + $id); var body = events.data('body_' + $id);
var title = events.data('title_' + $id); var title = events.data('title_' + $id);
var doc_title = events.data('doc_title_' + $id); var doc_title = events.data('doc_title_' + $id);
var doc_info = events.data('doc_info_' + $id);
if(body && title && doc_title){ if(body && title && doc_title) {
if (typeof $callback === "function") { if (typeof $callback === "function") {
body = $callback(body); body = $callback(body);
} }
$("#page-content").html(body); $("#page-content").html(body);
$("title").text(title); $("title").text(title);
$("#article-title").text(doc_title); $("#article-title").text(doc_title);
$("#article-info").text(doc_info);
events.trigger('article.open',{ $url : $url, $init : false , $id : $id }); events.trigger('article.open', { $url : $url, $init : false , $id : $id });
return false; return false;
} }
NProgress.start(); NProgress.start();
}, },
success : function (res) { success : function (res) {
if(res.errcode === 0){ if (res.errcode === 0) {
var body = res.data.body; var body = res.data.body;
var doc_title = res.data.doc_title; var doc_title = res.data.doc_title;
var title = res.data.title; var title = res.data.title;
var doc_info = res.data.doc_info; var doc_info = res.data.doc_info;
$body = body; $body = body;
if (typeof $callback === "function" ){ if (typeof $callback === "function" ) {
$body = $callback(body); $body = $callback(body);
} }
$("#page-content").html($body); $("#page-content").html($body);
$("title").text(title); $("title").text(title);
$("#article-title").text(doc_title); $("#article-title").text(doc_title);
$("#article-info").text(doc_info); $("#article-info").text(doc_info);
events.data('body_' + $id,body); events.data('body_' + $id, body);
events.data('title_' + $id,title); events.data('title_' + $id, title);
events.data('doc_title_' + $id,doc_title); events.data('doc_title_' + $id, doc_title);
events.data('doc_info_' + $id, doc_info);
events.trigger('article.open',{ $url : $url, $init : true, $id : $id }); events.trigger('article.open', { $url : $url, $init : true, $id : $id });
}else{ } else {
layer.msg("加载失败"); layer.msg("加载失败");
} }
}, },
@ -76,9 +80,9 @@ $(function () {
}); });
$(".manual-right").scroll(function () { $(".manual-right").scroll(function () {
var top = $(".manual-right").scrollTop(); var top = $(".manual-right").scrollTop();
if(top > 100){ if (top > 100) {
$(".view-backtop").addClass("active"); $(".view-backtop").addClass("active");
}else{ } else {
$(".view-backtop").removeClass("active"); $(".view-backtop").removeClass("active");
} }
}); });
@ -87,7 +91,7 @@ $(function () {
initHighlighting(); initHighlighting();
window.jsTree = $("#sidebar").jstree({ window.jsTree = $("#sidebar").jstree({
'plugins':["wholerow","types"], 'plugins':["wholerow", "types"],
"types": { "types": {
"default" : { "default" : {
"icon" : false // 删除默认图标 "icon" : false // 删除默认图标
@ -95,24 +99,24 @@ $(function () {
}, },
'core' : { 'core' : {
'check_callback' : true, 'check_callback' : true,
"multiple" : false , "multiple" : false,
'animation' : 0 'animation' : 0
} }
}).on('select_node.jstree',function (node,selected,event) { }).on('select_node.jstree',function (node,selected,event) {
$(".m-manual").removeClass('manual-mobile-show-left'); $(".m-manual").removeClass('manual-mobile-show-left');
var url = selected.node.a_attr.href; var url = selected.node.a_attr.href;
if(url === window.location.href){ if (url === window.location.href) {
return false; return false;
} }
loadDocument(url,selected.node.id);
loadDocument(url, selected.node.id);
}); });
$("#slidebar").on("click",function () { $("#slidebar").on("click", function () {
$(".m-manual").addClass('manual-mobile-show-left'); $(".m-manual").addClass('manual-mobile-show-left');
}); });
$(".manual-mask").on("click",function () { $(".manual-mask").on("click", function () {
$(".m-manual").removeClass('manual-mobile-show-left'); $(".m-manual").removeClass('manual-mobile-show-left');
}); });
@ -128,19 +132,18 @@ $(function () {
} }
}); });
//处理打开事件 // 处理打开事件
events.on('article.open', function (event, $param) { events.on('article.open', function (event, $param) {
if ('pushState' in history) { if ('pushState' in history) {
if ($param.$init === false) { if ($param.$init === false) {
window.history.replaceState($param , $param.$id , $param.$url); window.history.replaceState($param, $param.$id, $param.$url);
} else { } else {
window.history.pushState($param, $param.$id , $param.$url); window.history.pushState($param, $param.$id, $param.$url);
} }
} else { } else {
window.location.hash = $param.$url; window.location.hash = $param.$url;
} }
initHighlighting(); initHighlighting();
$(".manual-right").scrollTop(0); $(".manual-right").scrollTop(0);
}); });
@ -165,17 +168,17 @@ $(function () {
$("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading"); $("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading");
window.keyword = keyword; window.keyword = keyword;
}, },
success :function (res) { success : function (res) {
var html = ""; var html = "";
if(res.errcode === 0){ if(res.errcode === 0){
for(var i in res.data){ for(var i in res.data){
var item = res.data[i]; var item = res.data[i];
html += '<li><a href="javascript:;" title="'+ item.doc_name +'" data-id="'+ item.doc_id+'"> '+ item.doc_name +' </a></li>'; html += '<li><a href="javascript:;" title="' + item.doc_name + '" data-id="' + item.doc_id + '"> ' + item.doc_name + ' </a></li>';
} }
} }
if(html !== ""){ if(html !== "") {
$(".search-empty").hide(); $(".search-empty").hide();
}else{ } else {
$(".search-empty").show(); $(".search-empty").show();
} }
$("#searchList").html(html); $("#searchList").html(html);
@ -186,7 +189,6 @@ $(function () {
}); });
window.onpopstate = function (e) { window.onpopstate = function (e) {
var $param = e.state; var $param = e.state;
console.log($param); console.log($param);
if($param.hasOwnProperty("$url")) { if($param.hasOwnProperty("$url")) {
@ -194,8 +196,8 @@ $(function () {
window.jsTree.jstree().select_node({ id : $param.$id }); window.jsTree.jstree().select_node({ id : $param.$id });
$param.$init = false; $param.$init = false;
//events.trigger('article.open', $param ); // events.trigger('article.open', $param);
}else{ } else {
console.log($param); console.log($param);
} }
}; };
@ -205,7 +207,7 @@ $(function () {
$node = window.jsTree.jstree().get_node({id: $node[0]}); $node = window.jsTree.jstree().get_node({id: $node[0]});
events.trigger('article.open', {$url: $node.a_attr.href, $init: true, $id: $node.a_attr.id}); events.trigger('article.open', {$url: $node.a_attr.href, $init: true, $id: $node.a_attr.id});
} }
}catch (e){ } catch (e) {
console.log(e); console.log(e);
} }
}); });