From 48912a0b79e473880d82e38607cead0388009f05 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Mon, 19 Dec 2016 21:53:25 +0800 Subject: [PATCH] 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 09f4c90..cf8e092 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 d452583..cbeffab 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,"