Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New maximum feature #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 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,
maximum: 1,
easing: 'ease',
positionUsing: '',
speed: 200,
Expand Down Expand Up @@ -111,6 +112,13 @@
return typeof NProgress.status === 'number';
};

/**
* Shorthand for maximum configuration. Must be greater than minimum.
*/
NProgress.max = function(maximum) {
if (typeof maximum === 'number' && maximum > Settings.minimum) Settings.maximum = maximum;
};

/**
* Shows the progress bar.
* This is the same as setting the status to 0%, except that it doesn't go backwards.
Expand Down Expand Up @@ -163,10 +171,10 @@
return NProgress.start();
} else {
if (typeof amount !== 'number') {
amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
amount = (1 - n) * clamp(Math.random() * n, 0.1, Settings.maximum - 0.05);
}

n = clamp(n + amount, 0, 0.994);
n = clamp(n + amount, 0, Settings.maximum - 0.006);
return NProgress.set(n);
}
};
Expand Down