From eabdd98c2c8747954049812eeb4b453fdfbbeb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Tue, 22 Jan 2019 09:36:59 +0100 Subject: [PATCH] Provide delay configuration option --- nprogress.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nprogress.js b/nprogress.js index beb9d2c..9f22848 100644 --- a/nprogress.js +++ b/nprogress.js @@ -180,6 +180,30 @@ return NProgress.inc(); }; + // delay extension, see https://github.com/rstacruz/nprogress/issues/169#issuecomment-456312510 + + NProgress.doStart = NProgress.start; + NProgress.doDone = NProgress.done; + + NProgress.clearDelay = function () { + if (this.startDelay) { + clearTimeout(this.startDelay); + this.startDelay = undefined; + } + } + + NProgress.start = function () { + this.clearDelay(); + this.startDelay = setTimeout(function () { + NProgress.doStart(); + }, this.settings.delay || 0); + }; + + NProgress.done = function () { + this.clearDelay(); + this.doDone(); + }; + /** * Waits for all supplied jQuery promises and * increases the progress as the promises resolve.