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

add 'NProgress.queueWorker' #111

Open
wants to merge 2 commits 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
47 changes: 33 additions & 14 deletions nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
*/

NProgress.status = null;

/**
* Queue worker
*/
NProgress.queueWorker = 0;

/**
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
Expand Down Expand Up @@ -81,23 +86,37 @@
// Add transition
css(bar, barPositionCSS(n, speed, ease));

// Fade in
css(progress, {
transition: 'none',
opacity: 1
});

if (n === 1) {
// Fade out
css(progress, {
transition: 'none',
opacity: 1
});
progress.offsetWidth; /* Repaint */

NProgress.queueWorker += 2;

setTimeout(function() {
css(progress, {
transition: 'all ' + speed + 'ms linear',
opacity: 0
});
setTimeout(function() {
NProgress.remove();
next();
}, speed);
if (NProgress.queueWorker == 2 && ! NProgress.isStarted()) {
NProgress.queueWorker -= 1;

// Fade out
css(progress, {
transition: 'all ' + speed + 'ms linear',
opacity: 0
});

setTimeout(function() {
NProgress.queueWorker -= 1;

if (NProgress.queueWorker == 0 && ! NProgress.isStarted()) {
NProgress.remove();
next();
}
}, speed);
} else {
NProgress.queueWorker -= 2;
}
}, speed);
} else {
setTimeout(next, speed);
Expand Down