From 619a0c0cc4b6d1abf3be2b8fbc7405784e867b6a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 22 Oct 2014 19:09:25 +0200 Subject: [PATCH] Fixed progress behavior when navigating too fast --- .../js/Presenters/ProgressPresenter.js | 13 ++++++++--- public_html/js/Promise.js | 22 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/public_html/js/Presenters/ProgressPresenter.js b/public_html/js/Presenters/ProgressPresenter.js index ff0b8306..d0a4cab7 100644 --- a/public_html/js/Presenters/ProgressPresenter.js +++ b/public_html/js/Presenters/ProgressPresenter.js @@ -12,10 +12,16 @@ App.Presenters.ProgressPresenter = function(nprogress) { } } - function done() { - nesting --; + function reset() { + nesting = 0; + } - if (nesting === 0) { + function done() { + if (nesting) { + nesting --; + } + + if (nesting <= 0) { nprogress.done(); } else { nprogress.inc(); @@ -25,6 +31,7 @@ App.Presenters.ProgressPresenter = function(nprogress) { return { start: start, done: done, + reset: reset, }; }; diff --git a/public_html/js/Promise.js b/public_html/js/Promise.js index e211d38f..0cdb6d53 100644 --- a/public_html/js/Promise.js +++ b/public_html/js/Promise.js @@ -10,12 +10,23 @@ App.Promise = function(_, jQuery, progress) { var promise = deferred.promise(); promise.promiseId = ++ promiseId; + progress.start(); callback(function() { - deferred.resolve.apply(deferred, arguments); - active = _.without(active, promise.promiseId); + try { + deferred.resolve.apply(deferred, arguments); + active = _.without(active, promise.promiseId); + progress.done(); + } catch (e) { + progress.reset(); + } }, function() { - deferred.reject.apply(deferred, arguments); - active = _.without(active, promise.promiseId); + try { + deferred.reject.apply(deferred, arguments); + active = _.without(active, promise.promiseId); + progress.done(); + } catch (e) { + progress.reset(); + } }); active.push(promise.promiseId); @@ -30,7 +41,6 @@ App.Promise = function(_, jQuery, progress) { } function wait() { - progress.start(); var promises = arguments; var deferred = jQuery.Deferred(); return jQuery.when.apply(jQuery, promises) @@ -38,8 +48,6 @@ App.Promise = function(_, jQuery, progress) { return deferred.resolve.apply(deferred, arguments); }).fail(function() { return deferred.reject.apply(deferred, arguments); - }).always(function() { - progress.done(); }); }