Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.
Open
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
39 changes: 20 additions & 19 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ angular.module('cfp.loadingBar', [])
* Inserts the loading bar element into the dom, and sets it to 2%
*/
function _start() {
if (!$animate) {
$animate = $injector.get('$animate');
}

var $parent = $document.find($parentSelector).eq(0);
$timeout.cancel(completeTimeout);

Expand All @@ -193,6 +189,7 @@ angular.module('cfp.loadingBar', [])
$rootScope.$broadcast('cfpLoadingBar:started');
started = true;

$animate = _getAnimate();
if (includeBar) {
$animate.enter(loadingBarContainer, $parent);
}
Expand All @@ -213,9 +210,11 @@ angular.module('cfp.loadingBar', [])
if (!started) {
return;
}
var pct = (n * 100) + '%';
loadingBar.css('width', pct);
status = n;
if (status < n) {
var pct = (n * 100) + '%';
loadingBar.css('width', pct);
status = n;
}

// increment loadingbar to give the illusion that there is always
// progress but make sure to cancel the previous timeouts so we don't
Expand All @@ -232,6 +231,11 @@ angular.module('cfp.loadingBar', [])
*/
function _inc() {
if (_status() >= 1) {
var promise = _getAnimate().leave(loadingBarContainer, _completeAnimation);
if (promise && promise.then) {
promise.then(_completeAnimation);
}
$rootScope.$broadcast('cfpLoadingBar:completed');
return;
}

Expand Down Expand Up @@ -271,25 +275,22 @@ angular.module('cfp.loadingBar', [])
}

function _complete() {
if (!$animate) {
$animate = $injector.get('$animate');
}

$rootScope.$broadcast('cfpLoadingBar:completed');
_set(1);

$timeout.cancel(completeTimeout);

// Attempt to aggregate any start/complete calls within 500ms:
completeTimeout = $timeout(function() {
var promise = $animate.leave(loadingBarContainer, _completeAnimation);
if (promise && promise.then) {
promise.then(_completeAnimation);
}
$animate.leave(spinner);
_set(1);
_getAnimate().leave(spinner);
}, 500);
}

function _getAnimate() {
if (!$animate) {
$animate = $injector.get('$animate');
}
return $animate;
}

return {
start : _start,
set : _set,
Expand Down