Skip to content

Commit

Permalink
make auto incrementing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Quartier committed Jun 11, 2015
1 parent f112b44 commit b0d1100
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/loading-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
border: solid 2px transparent;
border-top-color: #29d;
border-left-color: #29d;
border-radius: 10px;
border-radius: 50%;

-webkit-animation: loading-bar-spinner 400ms linear infinite;
-moz-animation: loading-bar-spinner 400ms linear infinite;
Expand Down
13 changes: 9 additions & 4 deletions build/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
angular.module('cfp.loadingBar', [])
.provider('cfpLoadingBar', function() {

this.autoIncrement = true;
this.includeSpinner = true;
this.includeBar = true;
this.latencyThreshold = 100;
Expand All @@ -186,6 +187,7 @@ angular.module('cfp.loadingBar', [])
started = false,
status = 0;

var autoIncrement = this.autoIncrement;
var includeSpinner = this.includeSpinner;
var includeBar = this.includeBar;
var startSize = this.startSize;
Expand Down Expand Up @@ -236,10 +238,12 @@ angular.module('cfp.loadingBar', [])
// increment loadingbar to give the illusion that there is always
// progress but make sure to cancel the previous timeouts so we don't
// have multiple incs running at the same time.
$timeout.cancel(incTimeout);
incTimeout = $timeout(function() {
_inc();
}, 250);
if (autoIncrement) {
$timeout.cancel(incTimeout);
incTimeout = $timeout(function() {
_inc();
}, 250);
}
}

/**
Expand Down Expand Up @@ -312,6 +316,7 @@ angular.module('cfp.loadingBar', [])
status : _status,
inc : _inc,
complete : _complete,
autoIncrement : this.autoIncrement,
includeSpinner : this.includeSpinner,
latencyThreshold : this.latencyThreshold,
parentSelector : this.parentSelector,
Expand Down
2 changes: 1 addition & 1 deletion build/loading-bar.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/loading-bar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
angular.module('cfp.loadingBar', [])
.provider('cfpLoadingBar', function() {

this.autoIncrement = true;
this.includeSpinner = true;
this.includeBar = true;
this.latencyThreshold = 100;
Expand All @@ -180,6 +181,7 @@ angular.module('cfp.loadingBar', [])
started = false,
status = 0;

var autoIncrement = this.autoIncrement;
var includeSpinner = this.includeSpinner;
var includeBar = this.includeBar;
var startSize = this.startSize;
Expand Down Expand Up @@ -230,10 +232,12 @@ angular.module('cfp.loadingBar', [])
// increment loadingbar to give the illusion that there is always
// progress but make sure to cancel the previous timeouts so we don't
// have multiple incs running at the same time.
$timeout.cancel(incTimeout);
incTimeout = $timeout(function() {
_inc();
}, 250);
if (autoIncrement) {
$timeout.cancel(incTimeout);
incTimeout = $timeout(function() {
_inc();
}, 250);
}
}

/**
Expand Down Expand Up @@ -306,6 +310,7 @@ angular.module('cfp.loadingBar', [])
status : _status,
inc : _inc,
complete : _complete,
autoIncrement : this.autoIncrement,
includeSpinner : this.includeSpinner,
latencyThreshold : this.latencyThreshold,
parentSelector : this.parentSelector,
Expand Down
35 changes: 35 additions & 0 deletions test/loading-bar-interceptor-config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,38 @@ describe 'loadingBarInterceptor Service - config options', ->
cfpLoadingBar.complete()
$timeout.flush()

it 'should not auto increment loadingBar if configured', (done) ->
module 'chieffancypants.loadingBar', (cfpLoadingBarProvider) ->
cfpLoadingBarProvider.autoIncrement = false
return
inject ($timeout, cfpLoadingBar) ->
flag = false
cfpLoadingBar.start()
cfpLoadingBar.set(.5)
runs ->
setTimeout ->
flag = true
, 500

waitsFor ->
return flag
, "500ms timeout"
, 1000

runs ->
expect(cfpLoadingBar.status()).toBe .5;
cfpLoadingBar.complete()
$timeout.flush()

it 'should auto increment loadingBar if configured', ->
module 'chieffancypants.loadingBar', (cfpLoadingBarProvider) ->
cfpLoadingBarProvider.autoIncrement = true
return
inject ($timeout, cfpLoadingBar) ->
cfpLoadingBar.start()
$timeout.flush()
cfpLoadingBar.set(.5)
$timeout.flush()
expect(cfpLoadingBar.status()).toBeGreaterThan .5
cfpLoadingBar.complete()
$timeout.flush()

0 comments on commit b0d1100

Please sign in to comment.