From 1e20dcb415722ad2cc1aa6efc805e3a0842ff52c Mon Sep 17 00:00:00 2001 From: TevinLi <6317595@qq.com> Date: Fri, 8 Apr 2016 22:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0javascript=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=AE=B5=E9=9A=90=E8=97=8F=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/amWiki.css | 9 +++++++++ files/amWiki.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/files/amWiki.css b/files/amWiki.css index b578a7c..5ec5aec 100644 --- a/files/amWiki.css +++ b/files/amWiki.css @@ -3,6 +3,8 @@ /* ---------- custom markdown ---------- */ .markdown-body{font-size:14px;} +.markdown-body h1{border-bottom:1px solid #ddd;} +.markdown-body pre{position:relative;} .markdown-body code{padding-top:0.15em;padding-bottom:0.15em;margin:0 1px;font-size:90%;color:#000;background-color:rgba(0,0,0,0.05);} .markdown-body code.hljs{color:#333;word-wrap:break-word;white-space:pre-wrap;} .markdown-body .hljs-string{color:#183691;} @@ -12,6 +14,13 @@ .markdown-body .anchor{padding-top:10px;margin-top:-10px;} .markdown-body .anchor img{visibility:hidden;} .markdown-body h1:hover .anchor img,.markdown-body h2:hover .anchor img,.markdown-body h3:hover .anchor img{visibility:visible;} +.markdown-body :not(.anchor)>img:hover{outline:rgba(0,0,0,.05) 1px solid;box-shadow:1px 1px 1px rgba(0,0,0,.1);} +.markdown-body .lang-off-js-comment{position:absolute;top:0;right:0;width:27px;height:27px;color:#ccc;text-align:center;line-height:27px;background:#f0f0f0;cursor:pointer} +.markdown-body .lang-off-js-comment i{position:absolute;top:0;left:0;width:27px;height:27px;font-size:22px;color:#ddd;text-align:center;line-height:27px;} +.markdown-body .lang-off-js-comment:hover{color:#999;background:#ddd;} +.markdown-body .lang-off-js-comment:hover i{color:#999;} +.markdown-body .lang-off-js-comment.on{color:#333;background:#ccc;} +.markdown-body .lang-off-js-comment.on i{color:#f00;} /* ---------- base ---------- */ body{background:#e7e8eb !important;min-width:720px;} diff --git a/files/amWiki.js b/files/amWiki.js index d765ea5..7068634 100644 --- a/files/amWiki.js +++ b/files/amWiki.js @@ -187,6 +187,22 @@ $(function () { } }); + //设置js注释隐藏 + var setJSCommentDisable = function($elm) { + var $disBtn = $('
/
'); + $disBtn.on('click',function(){ + var $this = $(this); + if ($this.hasClass('on')) { + $this.removeClass('on'); + $elm.find('.hljs-comment').show(); + } else { + $this.addClass('on'); + $elm.find('.hljs-comment').hide(); + } + }); + $elm.prepend($disBtn); + }; + //加载页面 var url; if (localStorage.urlEcode == 'encode') { @@ -196,10 +212,14 @@ $(function () { } $.get(url, function (data) { $view.html(marked(data)).find('pre code').each(function (i, block) { - var className = $(block).attr('class') || ''; + var $elm = $(block); + var className = $elm.attr('class') || ''; if (className.indexOf('lang') >= 0) { hljs.highlightBlock(block); } + if (className.indexOf('javascript') >= 0) { + setJSCommentDisable($elm); + } }); setTitleAnchor(); }, 'text').fail(function () { @@ -211,10 +231,14 @@ $(function () { $.get(url, function (data) { localStorage.urlEcode = 'decode'; $view.html(marked(data)).find('pre code').each(function (i, block) { - var className = $(block).attr('class') || ''; + var $elm = $(block); + var className = $elm.attr('class') || ''; if (className.indexOf('lang') >= 0) { hljs.highlightBlock(block); } + if (className.indexOf('javascript') >= 0) { + setJSCommentDisable($elm); + } }); setTitleAnchor(); }, 'text').fail(function () {