Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Provide delay option
Browse files Browse the repository at this point in the history
  • Loading branch information
fracz authored Jan 22, 2019
1 parent eabdd98 commit 5682902
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

var Settings = NProgress.settings = {
minimum: 0.08,
delay: 50,
easing: 'linear',
positionUsing: '',
speed: 200,
Expand Down Expand Up @@ -111,13 +112,21 @@
};

/**
* Shows the progress bar.
* Shows the progress bar after the delay.
* This is the same as setting the status to 0%, except that it doesn't go backwards.
*
* NProgress.start();
*
*/
NProgress.start = function() {
NProgress.start = function () {
this.clearDelay();
this.startDelay = setTimeout(function () {
NProgress.doStart();
}, Settings.delay || 0);
};


NProgress.doStart = function() {
if (!NProgress.status) NProgress.set(0);

var work = function() {
Expand Down Expand Up @@ -146,6 +155,7 @@
*/

NProgress.done = function(force) {
this.clearDelay();
if (!force && !NProgress.status) return this;

return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
Expand Down Expand Up @@ -180,28 +190,11 @@
return NProgress.inc();
};

// delay extension, see https://github.com/rstacruz/nprogress/issues/169#issuecomment-456312510

NProgress.doStart = NProgress.start;
NProgress.doDone = NProgress.done;

NProgress.clearDelay = function () {
if (this.startDelay) {
clearTimeout(this.startDelay);
this.startDelay = undefined;
}
}

NProgress.start = function () {
this.clearDelay();
this.startDelay = setTimeout(function () {
NProgress.doStart();
}, this.settings.delay || 0);
};

NProgress.done = function () {
this.clearDelay();
this.doDone();
};

/**
Expand Down

0 comments on commit 5682902

Please sign in to comment.