Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.
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
28 changes: 25 additions & 3 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,37 @@ angular.module('chieffancypants.loadingBar', [])
*/
var latencyThreshold = cfpLoadingBar.latencyThreshold;

/**
* The amount of time spent before actually stopping the bar
*/
var stopThreshold = cfpLoadingBar.stopThreshold;

/**
* $timeout handle for latencyThreshold
*/
var startTimeout;

/**
* $timeout handle for the stop timeout.
*/
var stopTimeout;


/**
* calls cfpLoadingBar.complete() which removes the
* loading bar from the DOM.
*/
function setComplete() {
$timeout.cancel(startTimeout);
cfpLoadingBar.complete();
reqsCompleted = 0;
reqsTotal = 0;

// Don't stop the bar immediately because if we get
// a request immediately after stopping it, it looks like
// it goes back, and the effect is not really good.
stopTimeout = $timeout(function () {
cfpLoadingBar.complete();
reqsCompleted = 0;
reqsTotal = 0;
}, stopThreshold);
}

/**
Expand Down Expand Up @@ -99,6 +115,10 @@ angular.module('chieffancypants.loadingBar', [])
// the requester didn't explicitly ask us to ignore this request:
if (!config.ignoreLoadingBar && !isCached(config)) {
$rootScope.$broadcast('cfpLoadingBar:loading', {url: config.url});

// Cancel the stop timeout because we just got another request.
$timeout.cancel(stopTimeout);

if (reqsTotal === 0) {
startTimeout = $timeout(function() {
cfpLoadingBar.start();
Expand Down Expand Up @@ -156,6 +176,7 @@ angular.module('chieffancypants.loadingBar', [])
this.includeSpinner = true;
this.includeBar = true;
this.latencyThreshold = 100;
this.stopThreshold = 0;
this.parentSelector = 'body';

this.$get = ['$document', '$timeout', '$animate', '$rootScope', function ($document, $timeout, $animate, $rootScope) {
Expand Down Expand Up @@ -282,6 +303,7 @@ angular.module('chieffancypants.loadingBar', [])
complete : _complete,
includeSpinner : this.includeSpinner,
latencyThreshold : this.latencyThreshold,
stopThreshold : this.stopThreshold,
parentSelector : this.parentSelector
};

Expand Down