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

Added counter counting how many times NProgress has been started #132

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 26 additions & 17 deletions nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@

NProgress.status = null;

/**
* How many times it's been started
*/

NProgress.count = 0;

/**
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
*
Expand Down Expand Up @@ -83,16 +89,16 @@

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

setTimeout(function() {
css(progress, {
transition: 'all ' + speed + 'ms linear',
opacity: 0
css(progress, {
transition: 'all ' + speed + 'ms linear',
opacity: 0
});
setTimeout(function() {
NProgress.remove();
Expand All @@ -108,7 +114,7 @@
};

NProgress.isStarted = function() {
return typeof NProgress.status === 'number';
return NProgress.count > 0;
};

/**
Expand All @@ -121,6 +127,8 @@
NProgress.start = function() {
if (!NProgress.status) NProgress.set(0);

NProgress.count++;

var work = function() {
setTimeout(function() {
if (!NProgress.status) return;
Expand All @@ -147,6 +155,8 @@
*/

NProgress.done = function(force) {
NProgress.count = 0;

if (!force && !NProgress.status) return this;

return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
Expand Down Expand Up @@ -220,7 +230,7 @@
if (NProgress.isRendered()) return document.getElementById('nprogress');

addClass(document.documentElement, 'nprogress-busy');

var progress = document.createElement('div');
progress.id = 'nprogress';
progress.innerHTML = Settings.template;
Expand All @@ -229,7 +239,7 @@
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
parent = document.querySelector(Settings.parent),
spinner;

css(bar, {
transition: 'all 0 linear',
transform: 'translate3d(' + perc + '%,0,0)'
Expand Down Expand Up @@ -340,7 +350,7 @@

var queue = (function() {
var pending = [];

function next() {
var fn = pending.shift();
if (fn) {
Expand All @@ -355,10 +365,10 @@
})();

/**
* (Internal) Applies css properties to an element, similar to the jQuery
* (Internal) Applies css properties to an element, similar to the jQuery
* css method.
*
* While this helper does assist with vendor prefixed property names, it
* While this helper does assist with vendor prefixed property names, it
* does not perform any manipulation of values prior to setting styles.
*/

Expand Down Expand Up @@ -399,7 +409,7 @@

return function(element, properties) {
var args = arguments,
prop,
prop,
value;

if (args.length == 2) {
Expand Down Expand Up @@ -430,7 +440,7 @@
var oldList = classList(element),
newList = oldList + name;

if (hasClass(oldList, name)) return;
if (hasClass(oldList, name)) return;

// Trim the opening space.
element.className = newList.substring(1);
Expand All @@ -454,8 +464,8 @@
}

/**
* (Internal) Gets a space separated list of the class names on the element.
* The list is wrapped with a single space on each end to facilitate finding
* (Internal) Gets a space separated list of the class names on the element.
* The list is wrapped with a single space on each end to facilitate finding
* matches within the list.
*/

Expand All @@ -473,4 +483,3 @@

return NProgress;
});