diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f1abbbb..3d7e4a7e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.7 +### Bug fixes +- Optimize progress bar + ## 1.1.6 ### Features - Add logo 😂 diff --git a/README.md b/README.md index f3397acb4..6dde20298 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@
@@ -19,7 +19,7 @@ - [CLI](https://github.com/QingWei-Li/docsify-cli) ## Features -- Easy and lightweight (~12kB gzipped) +- Easy and lightweight (~12kb gzipped) - Custom themes - No build diff --git a/docs/README.md b/docs/README.md index 0dfd45b07..791885beb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ ## Features -- Easy and lightweight (~12kB gzipped) +- Easy and lightweight (~12kb gzipped) - Custom themes - No build diff --git a/docs/zh-cn.md b/docs/zh-cn.md index a320e1af4..2e76fb7ef 100644 --- a/docs/zh-cn.md +++ b/docs/zh-cn.md @@ -9,7 +9,7 @@ ## 特性 - 无需构建,写完 markdown 直接发布 - 支持自定义主题 -- 容易使用并且轻量 (~12kB gzipped) +- 容易使用并且轻量 (~12kb gzipped) ## 快速上手 diff --git a/lib/docsify.js b/lib/docsify.js index 09f4c90cb..cf8e092f7 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -21,8 +21,13 @@ function load (url, method, loading) { if ( error === void 0 ) error = function () {}; if (loading) { + var id = setInterval(function (_) { return loading({ step: Math.floor(Math.random() * 5 + 1) }); }, + 500); xhr.addEventListener('progress', loading); - xhr.addEventListener('loaded', loading); + xhr.addEventListener('loadend', function (evt) { + loading(evt); + clearInterval(id); + }); } xhr.addEventListener('error', error); xhr.addEventListener('load', function (ref) { @@ -2466,8 +2471,9 @@ function renderSidebar (content) { function renderLoading (ref) { var loaded = ref.loaded; var total = ref.total; + var step = ref.step; - var num = Math.floor(loaded / total * 100); + var num; if (!CACHE.loading) { var div = document.createElement('div'); @@ -2476,13 +2482,19 @@ function renderLoading (ref) { document.body.appendChild(div); CACHE.loading = div; } + if (step) { + num = parseInt(CACHE.loading.style.width, 10) + step; + num = num > 80 ? 80 : num; + } else { + num = Math.floor(loaded / total * 100); + } CACHE.loading.style.opacity = 1; CACHE.loading.style.width = num >= 95 ? '100%' : num + '%'; if (num >= 95) { - clearTimeout(renderLoading.cacheTImeout); - renderLoading.cacheTImeout = setTimeout(function (_) { + clearTimeout(renderLoading.cacheTimeout); + renderLoading.cacheTimeout = setTimeout(function (_) { CACHE.loading.style.opacity = 0; CACHE.loading.style.width = '0%'; }, 200); diff --git a/lib/docsify.min.js b/lib/docsify.min.js index d452583a1..cbeffab61 100644 --- a/lib/docsify.min.js +++ b/lib/docsify.min.js @@ -1,2 +1,2 @@ -var Docsify=function(){"use strict";function e(e,t,n){void 0===t&&(t="GET");var r=new XMLHttpRequest;return r.open(t,e),r.send(),{then:function(e,t){void 0===t&&(t=function(){}),n&&(r.addEventListener("progress",n),r.addEventListener("loaded",n)),r.addEventListener("error",t),r.addEventListener("load",function(n){var r=n.target;r.status>=400?t(r):e(r.response)})},abort:function(){return 4!==r.readyState&&r.abort()}}}function t(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 n(e){return e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()})}function r(e){return null===e||void 0===e}function i(){var e=window.location;if(_===e.hash&&!r(S))return S;var t=e.hash.match(/^#\/([^#]+)/);return t=t&&2===t.length?t[1]:/^#\//.test(e.hash)?"":e.pathname,S=t,_=e.hash,t}function a(){return document.body.clientWidth<=600}function s(){function e(){for(var e=0,r=t.length;e"+s(e.message+"",!0)+"";throw e}}var h={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:u,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:u,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:u,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};h.bullet=/(?:[*+-]|\d+\.)/,h.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,h.item=l(h.item,"gm")(/bull/g,h.bullet)(),h.list=l(h.list)(/bull/g,h.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+h.def.source+")")(),h.blockquote=l(h.blockquote)("def",h.def)(),h._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",h.html=l(h.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/
1&&o.length>1||(e=a.slice(c+1).join("\n")+e,c=p-1)),i=r||/\n\n(?!\s*$)/.test(l),c!==p-1&&(r="\n"===l.charAt(l.length-1),i||(i=r)),g.tokens.push({type:i?"loose_item_start":"list_item_start"}),g.token(l,!1,n),g.tokens.push({type:"list_item_end"});g.tokens.push({type:"list_end"})}else if(a=g.rules.html.exec(e))e=e.substring(a[0].length),g.tokens.push({type:g.options.sanitize?"paragraph":"html",pre:!g.options.sanitizer&&("pre"===a[1]||"script"===a[1]||"style"===a[1]),text:a[0]});else if(!n&&t&&(a=g.rules.def.exec(e)))e=e.substring(a[0].length),g.tokens.links[a[1].toLowerCase()]={href:a[2],title:a[3]};else if(t&&(a=g.rules.table.exec(e))){for(e=e.substring(a[0].length),l={type:"table",header:a[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:a[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:a[3].replace(/(?: *\| *)?\n$/,"").split("\n")},c=0;c "+e+"
\n":"'+(n?e:s(e,!0))+"\n
"},i.prototype.blockquote=function(e){return""+(n?e:s(e,!0))+"\n
\n"+e+"
\n"},i.prototype.html=function(e){return e},i.prototype.heading=function(e,t,n){return"
\n":"
\n"},i.prototype.list=function(e,t){var n=t?"ol":"ul";return"<"+n+">\n"+e+""+n+">\n"},i.prototype.listitem=function(e){return"\n\n"+e+"\n\n"+t+"\n
\n"},i.prototype.tablerow=function(e){return"\n"+e+" \n"},i.prototype.tablecell=function(e,t){var n=t.header?"th":"td",r=t.align?"<"+n+' style="text-align:'+t.align+'">':"<"+n+">";return r+e+""+n+">\n"},i.prototype.strong=function(e){return""+e+""},i.prototype.em=function(e){return""+e+""},i.prototype.codespan=function(e){return""+e+"
"},i.prototype.br=function(){return this.options.xhtml?"
":"
"},i.prototype.del=function(e){return""+e+""},i.prototype.link=function(e,t,n){if(this.options.sanitize){try{var r=decodeURIComponent(o(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(0===r.indexOf("javascript:")||0===r.indexOf("vbscript:"))return""}var i='"+n+""},i.prototype.image=function(e,t,n){var r='":">"},i.prototype.text=function(e){return e},a.parse=function(e,t,n){var r=new a(t,n);return r.parse(e)},a.prototype.parse=function(e){var t=this;this.inline=new r(e.links,this.options,this.renderer),this.tokens=e.reverse();for(var n="";this.next();)n+=t.tok();return n},a.prototype.next=function(){return this.token=this.tokens.pop()},a.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},a.prototype.parseText=function(){for(var e=this,t=this.token.text;"text"===this.peek().type;)t+="\n"+e.next().text;return this.inline.output(t)},a.prototype.tok=function(){var e=this;switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,this.token.text);case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var t,n,r,i,a,s="",o="";for(r="",t=0;t