Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make auto incrementing optional #209

Merged
merged 1 commit into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
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
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()