From d343ff5b21adab16419652a6a984e1f177ad21e9 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Sun, 18 Dec 2016 19:43:58 +0800 Subject: [PATCH 1/5] Update badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3397acb4..22c63cece 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@

- Travis Status - npm + Travis Status + npm npm

From 30b6644f218c5f1b30e1a9452898a54cc74a26fa Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Mon, 19 Dec 2016 20:38:35 +0800 Subject: [PATCH 2/5] fix typo --- README.md | 2 +- docs/README.md | 2 +- docs/zh-cn.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 22c63cece..6dde20298 100644 --- a/README.md +++ b/README.md @@ -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) ## 快速上手 From 73a193d602556af90ec24e88a737fc0e0c9784dc Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Mon, 19 Dec 2016 21:52:33 +0800 Subject: [PATCH 3/5] Optimize progress bar --- CHANGELOG.md | 4 ++++ src/render.js | 14 ++++++++++---- src/util.js | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) 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/src/render.js b/src/render.js index fe9989434..61740d883 100644 --- a/src/render.js +++ b/src/render.js @@ -114,8 +114,8 @@ export function renderSidebar (content) { * render loading bar * @return {[type]} [description] */ -export function renderLoading ({ loaded, total }) { - const num = Math.floor(loaded / total * 100) +export function renderLoading ({ loaded, total, step }) { + let num if (!CACHE.loading) { const div = document.createElement('div') @@ -124,13 +124,19 @@ export function renderLoading ({ loaded, total }) { 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(_ => { + clearTimeout(renderLoading.cacheTimeout) + renderLoading.cacheTimeout = setTimeout(_ => { CACHE.loading.style.opacity = 0 CACHE.loading.style.width = '0%' }, 200) diff --git a/src/util.js b/src/util.js index c93b5888d..94521dde1 100644 --- a/src/util.js +++ b/src/util.js @@ -14,8 +14,14 @@ export function load (url, method = 'GET', loading) { return { then: function (success, error = function () {}) { if (loading) { + const id = setInterval(_ => + loading({ step: Math.floor(Math.random() * 5 + 1) }), + 500) xhr.addEventListener('progress', loading) - xhr.addEventListener('loaded', loading) + xhr.addEventListener('loadend', evt => { + loading(evt) + clearInterval(id) + }) } xhr.addEventListener('error', error) xhr.addEventListener('load', ({ target }) => { From 48912a0b79e473880d82e38607cead0388009f05 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Mon, 19 Dec 2016 21:53:25 +0800 Subject: [PATCH 4/5] bump 1.1.7 --- lib/docsify.js | 20 ++++++++++++++++---- lib/docsify.min.js | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) 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;e10){var o=n[a.id];if(!o||o===i)return;return i&&i.setAttribute("class",""),o.setAttribute("class","active"),void(i=o)}}}if(!a()){for(var t=document.querySelectorAll(".anchor"),n={},r=document.querySelectorAll(".sidebar li"),i=null,s=0,o=r.length;s\n \n '):""}function g(){return'
\n \n
\n
\n
\n
'}function d(e){return e?'':""}function f(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='
  • '+e.title+"
  • ",e.children&&(t+='
    • '+f(e.children)+"
    ")}),t):""}function m(e,t){var n=document.querySelector("nav")||document.createElement("nav");e[t?"outerHTML":"innerHTML"]=d($.sidebarToggle)+h($.repo)+g(),document.body.insertBefore(n,document.body.children[0]),u("button.sidebar-toggle")}function b(e){q("article",e?C(e):"not found"),k.rendered||k(null,$),y.rendered||y(null,$),k.rendered=!1,y.rendered=!1,$.auto2top&&c()}function y(e){E.navbar&&E.navbar===e||(E.navbar=e,y.rendered=!0,e&&q("nav",C(e)),l("nav"))}function k(e){var n=!1;e?e=C(e):$.sidebar?e=f($.sidebar,"