From cb35194651faf802b6779244d5f1d3be06dd1f02 Mon Sep 17 00:00:00 2001 From: Petra Gulicher Date: Thu, 23 Feb 2017 15:22:02 +1100 Subject: [PATCH] Add a configuration option for maximum percentage --- Readme.md | 7 +++++++ nprogress.js | 3 ++- test/test.js | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index dc9b15c..588bfc0 100644 --- a/Readme.md +++ b/Readme.md @@ -121,6 +121,13 @@ Changes the minimum percentage used upon starting. (default: `0.08`) NProgress.configure({ minimum: 0.1 }); ~~~ +#### `maximum` +Changes the maximum percentage the bar will increment to. (default: `0.994`) + +~~~ js +NProgress.configure({ minimum: 0.1 }); +~~~ + #### `template` You can change the markup using `template`. To keep the progress bar working, keep an element with `role='bar'` in there. See the [default template] diff --git a/nprogress.js b/nprogress.js index beb9d2c..9ce3a48 100644 --- a/nprogress.js +++ b/nprogress.js @@ -18,6 +18,7 @@ var Settings = NProgress.settings = { minimum: 0.08, + maximum: 0.994, easing: 'linear', positionUsing: '', speed: 200, @@ -171,7 +172,7 @@ else { amount = 0; } } - n = clamp(n + amount, 0, 0.994); + n = clamp(n + amount, 0, Settings.maximum); return NProgress.set(n); } }; diff --git a/test/test.js b/test/test.js index a381b09..c432d7c 100644 --- a/test/test.js +++ b/test/test.js @@ -135,6 +135,12 @@ assert.operator(NProgress.status, '>', start); }); + it('should respect maximum', function() { + NProgress.configure({ maximum: 0.8 }); + for (var i=0; i<100; ++i) { NProgress.inc(); } + assert.equal(NProgress.status, NProgress.settings.maximum); + }); + it('should never reach 1.0', function() { for (var i=0; i<100; ++i) { NProgress.inc(); } assert.operator(NProgress.status, '<', 1.0);