From 7bc8b3cc63ae138e925b3609efbe66bd9cd0baab Mon Sep 17 00:00:00 2001 From: Jerome Brunel Date: Mon, 16 Nov 2015 23:53:15 +0100 Subject: [PATCH] Added counter counting how many times it has been started --- nprogress.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/nprogress.js b/nprogress.js index b23b300..51b1ced 100644 --- a/nprogress.js +++ b/nprogress.js @@ -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`. * @@ -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(); @@ -108,7 +114,7 @@ }; NProgress.isStarted = function() { - return typeof NProgress.status === 'number'; + return NProgress.count > 0; }; /** @@ -121,6 +127,8 @@ NProgress.start = function() { if (!NProgress.status) NProgress.set(0); + NProgress.count++; + var work = function() { setTimeout(function() { if (!NProgress.status) return; @@ -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); @@ -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; @@ -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)' @@ -340,7 +350,7 @@ var queue = (function() { var pending = []; - + function next() { var fn = pending.shift(); if (fn) { @@ -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. */ @@ -399,7 +409,7 @@ return function(element, properties) { var args = arguments, - prop, + prop, value; if (args.length == 2) { @@ -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); @@ -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. */ @@ -473,4 +483,3 @@ return NProgress; }); -