From 9e2fbccc92ced93e489454f3f16b62bd803568af Mon Sep 17 00:00:00 2001 From: Dandy Cheung Date: Wed, 20 Dec 2017 18:55:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=AE=A2=E5=9C=A8=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=BB=B6=E5=88=87=E6=8D=A2=E6=97=B6=E6=9C=89=E6=97=B6=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=BF=A1=E6=81=AF=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/kancloud.js | 64 ++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/static/js/kancloud.js b/static/js/kancloud.js index 2d5e9a2e..03d74ec8 100644 --- a/static/js/kancloud.js +++ b/static/js/kancloud.js @@ -12,45 +12,49 @@ function loadDocument($url,$id,$callback) { var body = events.data('body_' + $id); var title = events.data('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") { body = $callback(body); } + $("#page-content").html(body); $("title").text(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; } NProgress.start(); }, success : function (res) { - if(res.errcode === 0){ + if (res.errcode === 0) { var body = res.data.body; var doc_title = res.data.doc_title; var title = res.data.title; var doc_info = res.data.doc_info; $body = body; - if (typeof $callback === "function" ){ + if (typeof $callback === "function" ) { $body = $callback(body); } + $("#page-content").html($body); $("title").text(title); $("#article-title").text(doc_title); $("#article-info").text(doc_info); - events.data('body_' + $id,body); - events.data('title_' + $id,title); - events.data('doc_title_' + $id,doc_title); + events.data('body_' + $id, body); + events.data('title_' + $id, 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("加载失败"); } }, @@ -76,9 +80,9 @@ $(function () { }); $(".manual-right").scroll(function () { var top = $(".manual-right").scrollTop(); - if(top > 100){ + if (top > 100) { $(".view-backtop").addClass("active"); - }else{ + } else { $(".view-backtop").removeClass("active"); } }); @@ -87,7 +91,7 @@ $(function () { initHighlighting(); window.jsTree = $("#sidebar").jstree({ - 'plugins':["wholerow","types"], + 'plugins':["wholerow", "types"], "types": { "default" : { "icon" : false // 删除默认图标 @@ -95,24 +99,24 @@ $(function () { }, 'core' : { 'check_callback' : true, - "multiple" : false , + "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){ + if (url === window.location.href) { 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'); }); - $(".manual-mask").on("click",function () { + $(".manual-mask").on("click", function () { $(".m-manual").removeClass('manual-mobile-show-left'); }); @@ -128,19 +132,18 @@ $(function () { } }); - //处理打开事件 + // 处理打开事件 events.on('article.open', function (event, $param) { - if ('pushState' in history) { if ($param.$init === false) { - window.history.replaceState($param , $param.$id , $param.$url); + window.history.replaceState($param, $param.$id, $param.$url); } else { - window.history.pushState($param, $param.$id , $param.$url); + window.history.pushState($param, $param.$id, $param.$url); } - } else { window.location.hash = $param.$url; } + initHighlighting(); $(".manual-right").scrollTop(0); }); @@ -165,17 +168,17 @@ $(function () { $("#btnSearch").attr("disabled","disabled").find("i").removeClass("fa-search").addClass("loading"); window.keyword = keyword; }, - success :function (res) { + success : function (res) { var html = ""; if(res.errcode === 0){ for(var i in res.data){ var item = res.data[i]; - html += '
  • '+ item.doc_name +'
  • '; + html += '
  • ' + item.doc_name + '
  • '; } } - if(html !== ""){ + if(html !== "") { $(".search-empty").hide(); - }else{ + } else { $(".search-empty").show(); } $("#searchList").html(html); @@ -186,7 +189,6 @@ $(function () { }); window.onpopstate = function (e) { - var $param = e.state; console.log($param); if($param.hasOwnProperty("$url")) { @@ -194,8 +196,8 @@ $(function () { window.jsTree.jstree().select_node({ id : $param.$id }); $param.$init = false; - //events.trigger('article.open', $param ); - }else{ + // events.trigger('article.open', $param); + } else { console.log($param); } }; @@ -205,7 +207,7 @@ $(function () { $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}); } - }catch (e){ + } catch (e) { console.log(e); } }); \ No newline at end of file