- '+N(e.children)+"
diff --git a/CHANGELOG.md b/CHANGELOG.md index e445d16c..a6b0cf5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ +3.0.5 / 2017-02-21 +================== + + * feat(pwa): add sw.js + * fix(layout.css): loading style + * fix(event): highlight sidebar when clicked, fixed #86 + * fix(gen-tree): cache toc list, fixed #88 + 3.0.4 / 2017-02-20 ================== diff --git a/lib/docsify.js b/lib/docsify.js index c75429e4..9597d929 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -407,14 +407,12 @@ function btn (el) { el = getNode(el); on(el, 'click', toggle); - if (isMobile) { - var sidebar = getNode('.sidebar'); + var sidebar = getNode('.sidebar'); - on(sidebar, 'click', function () { - toggle(); - setTimeout(function () { return getAndActive(sidebar, true, true); }, 0); - }); - } + on(sidebar, 'click', function () { + isMobile && toggle(); + setTimeout(function () { return getAndActive(sidebar, true, true); }, 0); + }); } function sticky () { @@ -598,7 +596,6 @@ var progressbar = function (ref) { }; var cache = {}; -var RUN_VERSION = Date.now(); /** * Simple ajax get @@ -614,8 +611,6 @@ function get (url, hasBar) { xhr.addEventListener.apply(xhr, arguments); }; - url += (/\?(\w+)=/g.test(url) ? '&' : '?') + "v=" + RUN_VERSION; - if (cache[url]) { return { then: function (cb) { return cb(cache[url]); }, abort: noop } } @@ -2893,8 +2888,7 @@ function genTree (toc, maxLevel) { if (level > maxLevel) { return } if (last[len]) { - last[len].children = last[len].children || []; - last[len].children.push(headline); + last[len].children = (last[len].children || []).concat(headline); } else { headlines.push(headline); } @@ -2943,7 +2937,7 @@ var markdownCompiler = marked; var contentBase = ''; var currentPath = ''; var renderer = new marked.Renderer(); -var TOC = {}; +var cacheTree = {}; var toc = []; /** @@ -3056,11 +3050,9 @@ function sidebar (text, level) { function subSidebar (el, level) { if (el) { toc[0] && toc[0].level === 1 && toc.shift(); - var tree$$1 = genTree(TOC[currentPath] || toc, level); + var tree$$1 = cacheTree[currentPath] || genTree(toc, level); el.parentNode.innerHTML += tree(tree$$1, '
'+t.slice(5).trim()+"
"}function I(e){return""}function H(e,t){return t={exports:{}},e(t,t.exports),t.exports}function z(e,t){var n=[],r={};return e.forEach(function(e){var i=e.level||1,a=i-1;i>t||(r[a]?(r[a].children=r[a].children||[],r[a].children.push(e)):n.push(e),r[i]=e)}),n}function R(e){if("string"!=typeof e)return"";var t=e.toLowerCase().trim().replace(/<[^>\d]+>/g,"").replace(De,"").replace(/\s/g,"-").replace(/-+/g,"-").replace(/^(\d)/,"_$1"),n=Be[t];return n=Be.hasOwnProperty(t)?n+1:0,Be[t]=n,n&&(t=t+"-"+n),t}function W(){Be={}}function B(e){return e.replace(/<(pre|template)[^>]*?>([\s\S]+)<\/(pre|template)>/g,function(e){return e.replace(/:/g,"__colon__")}).replace(/:(\w+?):/gi,'"+a(e.message+"",!0)+"";throw e}}var p={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:l,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:l,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:l,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};p.bullet=/(?:[*+-]|\d+\.)/,p.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,p.item=s(p.item,"gm")(/bull/g,p.bullet)(),p.list=s(p.list)(/bull/g,p.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+p.def.source+")")(),p.blockquote=s(p.blockquote)("def",p.def)(),p._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",p.html=s(p.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/
'+(n?e:a(e,!0))+"\n\n":""+(n?e:a(e,!0))+"\n"},r.prototype.blockquote=function(e){return"\n"+e+"\n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n){return"
"+e+"
\n"},r.prototype.table=function(e,t){return""+e+""},r.prototype.br=function(){return this.options.xhtml?""+a(e.message+"",!0)+"";throw e}}var p={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:l,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:l,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:l,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};p.bullet=/(?:[*+-]|\d+\.)/,p.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,p.item=s(p.item,"gm")(/bull/g,p.bullet)(),p.list=s(p.list)(/bull/g,p.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+p.def.source+")")(),p.blockquote=s(p.blockquote)("def",p.def)(),p._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",p.html=s(p.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/
'+(n?e:a(e,!0))+"\n\n":""+(n?e:a(e,!0))+"\n"},r.prototype.blockquote=function(e){return"\n"+e+"\n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n){return"
"+e+"
\n"},r.prototype.table=function(e,t){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"