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

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,15 +12,17 @@ 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 });
@ -39,6 +41,7 @@ function loadDocument($url,$id,$callback) {
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);
@ -47,6 +50,7 @@ function loadDocument($url,$id,$callback) {
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 });
@ -105,8 +109,8 @@ $(function () {
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 () {
@ -130,17 +134,16 @@ $(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);
}); });
@ -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")) {