-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
6 lines (6 loc) · 4.34 KB
/
index.js
1
2
3
4
5
6
/**
* @Acknowledegment
* NProgressE version 0.2.5
* Repository: https://github.com/AkatQuas/nprogresse.git
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).NProgressE=e()}(this,function(){"use strict";function n(t,e,n){return t<e?e:n<t?n:t}function l(t){return 100*(-1+t)}var e,r,s=(e=[],r=function(){var t=e.shift();t&&t(r)},function(t){e.push(t),1===e.length&&r()});function i(t){return(" "+(t&&t.className||"")+" ").replace(/\s+/gi," ")}function o(t,e){return 0<=("string"==typeof t?t:i(t)).indexOf(" "+e+" ")}function a(t,e){var n=i(t),r=n+e;o(n,e)||(t.className=r.substring(1))}function u(t,e){var n=i(t);o(t,e)&&(e=n.replace(" "+e+" "," "),t.className=e.substring(1,e.length-1))}function c(t){t&&t.parentNode&&t.parentNode.removeChild(t)}var p,f,d=(p=["Webkit","O","Moz","ms"],f={},function(t,e){var n=arguments;if(2==n.length)for(var r in e){var s=e[r];void 0!==s&&e.hasOwnProperty(r)&&m(t,r,s)}else m(t,n[1],n[2])});function h(t){return t=t.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,function(t,e){return e.toUpperCase()}),f[t]||(f[t]=function(t){var e=document.body.style;if(t in e)return t;for(var n,r=p.length,s=t.charAt(0).toUpperCase()+t.slice(1);r--;)if((n=p[r]+s)in e)return n;return t}(t))}function m(t,e,n){e=h(e),t.style[e]=n}function t(){this.settings={minimum:.08,easing:"linear",positionUsing:"",speed:200,trickle:!0,trickleSpeed:200,showSpinner:!1,barSelector:'[role="bar"]',spinnerSelector:'[role="spinner"]',parent:"body",template:'<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'},this.status=null,this.el=null}return new(t.prototype.configure=function(t){for(var e in t){var n=t[e];void 0!==n&&t.hasOwnProperty(e)&&(this.settings[e]=n)}return this},t.prototype.isStarted=function(){return"number"==typeof this.status},t.prototype.isRendered=function(){var t=document.querySelector(this.settings.parent);return!!t&&!!t.querySelector("#nprogresse")},t.prototype.render=function(t){if(this.isRendered())return this.el;var e=this.settings;a(document.documentElement,"nprogresse-busy");var n=document.createElement("div");n.id="nprogresse",n.innerHTML=e.template;var r=n.querySelector(e.barSelector),s=t?-100:l(this.status||0),t=document.querySelector(e.parent);return d(r,{transition:"all 0 linear",transform:"translate3d("+s+"%,0,0)"}),e.showSpinner||(e=n.querySelector(e.spinnerSelector))&&c(e),t!=document.body&&a(t,"nprogresse-custom-parent"),t.appendChild(n),this.el=n},t.prototype.remove=function(){var t=this.settings;u(document.documentElement,"nprogresse-busy"),u(document.querySelector(t.parent),"nprogresse-custom-parent");t=this.el;t&&c(t),this.status=null,this.el=null},t.prototype.set=function(o){var a=this,t=this.isStarted(),u=this.settings;o=n(o,u.minimum,1),this.status=o;var c=this.render(!t);return c.offsetWidth,s(function(t){var e=u.speed,n=u.easing,r=u.barSelector,s=u.positionUsing,i=c.querySelector(r);""===s&&(a.settings.positionUsing=(r=document.body.style,(s="WebkitTransform"in r?"Webkit":"MozTransform"in r?"Moz":"msTransform"in r?"ms":"OTransform"in r?"O":"")+"Perspective"in r?"translate3d":s+"Transform"in r?"translate":"margin")),d(i,function(t,e,n,r){var s={transition:"all "+n+"ms "+r};switch(t){case"translate3d":s.transform="translate3d("+l(e)+"%,0,0)";break;case"translate":s.transform="translate("+l(e)+"%,0)";break;default:s["margin-left"]=l(e)+"%"}return s}(a.settings.positionUsing,o,e,n)),1===o?(d(c,{transition:"none",opacity:1}),c.offsetWidth,setTimeout(function(){d(c,{transition:"all "+e+"ms linear",opacity:0}),setTimeout(function(){a.remove(),t()},e)},e)):setTimeout(t,e)}),this},t.prototype.start=function(){var t=this;this.status||this.set(0);var e=this.settings,n=function(){setTimeout(function(){t.status&&(t.inc(),n())},e.trickleSpeed)};return e.trickle&&n(),this},t.prototype.done=function(t){return t||this.status?(this.inc(.3+.5*Math.random()),u(this.el,"error"),this.set(1)):this},t.prototype.error=function(t){return t||this.status?(this.inc(.3+.5*Math.random()),a(this.el,"error"),this.set(1)):this},t.prototype.inc=function(t){var e=this.status;return e?1<e?this:(e=n(e+(t="number"!=typeof t?0<=e&&e<.2?.1:.2<=e&&e<.5?.04:.5<=e&&e<.8?.02:.8<=e&&e<.99?.005:0:t),0,.994),this.set(e)):this.start()},t.version="0.2.2",t)});