diff --git a/lib/docsify.js b/lib/docsify.js index 63a6069..2dbcdf1 100644 --- a/lib/docsify.js +++ b/lib/docsify.js @@ -105,12 +105,16 @@ function getRoute () { return route } +function isMobile () { + return /mobile/i.test(navigator.userAgent) +} + /** * Active sidebar when scroll * @link https://buble.surge.sh/ */ function scrollActiveSidebar () { - if (/mobile/i.test(navigator.userAgent)) { return } + if (isMobile()) { return } var anchors = document.querySelectorAll('.anchor'); var nav = {}; @@ -198,8 +202,11 @@ function bindToggle (dom) { } var cacheContentDOM; -function scroll2Top (dom) { - cacheContentDOM = cacheContentDOM || document.querySelector(dom); +function scroll2Top () { + if (!cacheContentDOM) { + var dom = isMobile() ? 'body' : 'section.content'; + cacheContentDOM = document.querySelector(dom); + } cacheContentDOM.scrollTop = 0; } @@ -2412,7 +2419,7 @@ function renderArticle (content) { renderSidebar.rendered = false; renderNavbar.rendered = false; - if (OPTIONS$1.auto2top) { scroll2Top('section.content'); } + if (OPTIONS$1.auto2top) { scroll2Top(); } } /** @@ -2468,14 +2475,16 @@ function renderLoading (ref) { CACHE['loading'] = div; } - CACHE['loading'].style.opacity = 1; - CACHE['loading'].style.width = num + '%'; if (num >= 95) { clearTimeout(renderLoading.cacheTImeout); + CACHE['loading'].style.width = '100%'; renderLoading.cacheTImeout = setTimeout(function (_) { CACHE['loading'].style.opacity = 0; CACHE['loading'].style.width = '0%'; }, 200); + } else { + CACHE['loading'].style.opacity = 1; + CACHE['loading'].style.width = num + '%'; } } diff --git a/lib/docsify.min.js b/lib/docsify.min.js index e8a267f..147e529 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(S===e.hash&&!r(w))return w;var t=e.hash.match(/^#\/([^#]+)/);return t=t&&2===t.length?t[1]:/^#\//.test(e.hash)?"":e.pathname,w=t,S=e.hash,t}function a(){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(!/mobile/i.test(navigator.userAgent)){for(var t=document.querySelectorAll(".anchor"),n={},r=document.querySelectorAll(".sidebar li"),i=null,a=0,s=r.length;a\n \n '):""}function g(){return'
\n \n
\n
\n
\n
'}function h(e){return e?'':""}function d(e,t){return void 0===t&&(t=""),e&&e.length?(e.forEach(function(e){t+='
  • '+e.title+"
  • ",e.children&&(t+='
    • '+d(e.children)+"
    ")}),t):""}function f(e,t){var n=document.querySelector("nav")||document.createElement("nav");e[t?"outerHTML":"innerHTML"]=h(A.sidebarToggle)+p(A.repo)+g(),document.body.insertBefore(n,document.body.children[0]),l("button.sidebar-toggle")}function m(e){E("article",e?L(e):"not found"),y.rendered||y(null,A),b.rendered||b(null,A),y.rendered=!1,b.rendered=!1,A.auto2top&&u("section.content")}function b(e){$.navbar&&$.navbar===e||($.navbar=e,b.rendered=!0,e&&E("nav",L(e)),o("nav"))}function y(e){var n=!1;e?e=L(e):A.sidebar?e=d(A.sidebar,"