Skip to content

Commit

Permalink
issue #46: new module created just for the service API
Browse files Browse the repository at this point in the history
  • Loading branch information
chieffancypants committed May 10, 2014
1 parent 8176aff commit 6c2b0e5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build/loading-bar.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* angular-loading-bar v0.4.0
* angular-loading-bar v0.4.1
* https://chieffancypants.github.io/angular-loading-bar
* Copyright (c) 2014 Wes Cruver
* License: MIT
Expand Down
35 changes: 18 additions & 17 deletions build/loading-bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* angular-loading-bar v0.4.0
* angular-loading-bar v0.4.1
* https://chieffancypants.github.io/angular-loading-bar
* Copyright (c) 2014 Wes Cruver
* License: MIT
Expand All @@ -19,17 +19,17 @@

'use strict';

// Alias the loading bar so it can be included using a simpler
// (and maybe more professional) module name:
angular.module('angular-loading-bar', ['chieffancypants.loadingBar']);
// Alias the loading bar for various backwards compatibilities since the project has matured:
angular.module('angular-loading-bar', ['cfp.loadingBarInterceptor']);
angular.module('chieffancypants.loadingBar', ['cfp.loadingBarInterceptor']);


/**
* loadingBarInterceptor service
*
* Registers itself as an Angular interceptor and listens for XHR requests.
*/
angular.module('chieffancypants.loadingBar', [])
angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
.config(['$httpProvider', function ($httpProvider) {

var interceptor = ['$q', '$cacheFactory', '$timeout', '$rootScope', 'cfpLoadingBar', function ($q, $cacheFactory, $timeout, $rootScope, cfpLoadingBar) {
Expand Down Expand Up @@ -145,18 +145,19 @@ angular.module('chieffancypants.loadingBar', [])
}];

$httpProvider.interceptors.push(interceptor);
}])


/**
* Loading Bar
*
* This service handles adding and removing the actual element in the DOM.
* Generally, best practices for DOM manipulation is to take place in a
* directive, but because the element itself is injected in the DOM only upon
* XHR requests, and it's likely needed on every view, the best option is to
* use a service.
*/
}]);


/**
* Loading Bar
*
* This service handles adding and removing the actual element in the DOM.
* Generally, best practices for DOM manipulation is to take place in a
* directive, but because the element itself is injected in the DOM only upon
* XHR requests, and it's likely needed on every view, the best option is to
* use a service.
*/
angular.module('cfp.loadingBar', [])
.provider('cfpLoadingBar', function() {

this.includeSpinner = true;
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.

4 changes: 2 additions & 2 deletions build/loading-bar.min.js

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

33 changes: 17 additions & 16 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

'use strict';

// Alias the loading bar so it can be included using a simpler
// (and maybe more professional) module name:
angular.module('angular-loading-bar', ['chieffancypants.loadingBar']);
// Alias the loading bar for various backwards compatibilities since the project has matured:
angular.module('angular-loading-bar', ['cfp.loadingBarInterceptor']);
angular.module('chieffancypants.loadingBar', ['cfp.loadingBarInterceptor']);


/**
* loadingBarInterceptor service
*
* Registers itself as an Angular interceptor and listens for XHR requests.
*/
angular.module('chieffancypants.loadingBar', [])
angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
.config(['$httpProvider', function ($httpProvider) {

var interceptor = ['$q', '$cacheFactory', '$timeout', '$rootScope', 'cfpLoadingBar', function ($q, $cacheFactory, $timeout, $rootScope, cfpLoadingBar) {
Expand Down Expand Up @@ -139,18 +139,19 @@ angular.module('chieffancypants.loadingBar', [])
}];

$httpProvider.interceptors.push(interceptor);
}])


/**
* Loading Bar
*
* This service handles adding and removing the actual element in the DOM.
* Generally, best practices for DOM manipulation is to take place in a
* directive, but because the element itself is injected in the DOM only upon
* XHR requests, and it's likely needed on every view, the best option is to
* use a service.
*/
}]);


/**
* Loading Bar
*
* This service handles adding and removing the actual element in the DOM.
* Generally, best practices for DOM manipulation is to take place in a
* directive, but because the element itself is injected in the DOM only upon
* XHR requests, and it's likely needed on every view, the best option is to
* use a service.
*/
angular.module('cfp.loadingBar', [])
.provider('cfpLoadingBar', function() {

this.includeSpinner = true;
Expand Down
33 changes: 33 additions & 0 deletions test/loading-bar-interceptor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,36 @@ describe 'loadingBarInterceptor Service', ->

$timeout.flush()


describe 'LoadingBar only', ->
cfpLoadingBar = $document = $timeout = null

beforeEach ->
module 'cfp.loadingBar'

inject (_$http_, _$httpBackend_, _$document_, _$timeout_, _cfpLoadingBar_) ->
$timeout = _$timeout_
$document = _$document_
cfpLoadingBar = _cfpLoadingBar_

it 'should be capable of being used alone', ->
# just a simple quick test to make sure:
cfpLoadingBar.start()
$timeout.flush()

# test setting progress
cfpLoadingBar.set(0.4)
expect(cfpLoadingBar.status()).toBe 0.4

# make sure it was injected into the DOM:
expect(isLoadingBarInjected($document.find(cfpLoadingBar.parentSelector))).toBe true

cfpLoadingBar.set(0.9)
expect(cfpLoadingBar.status()).toBe 0.9

# test the complete call, which should remove it from the DOM
cfpLoadingBar.complete()
$timeout.flush()
expect(isLoadingBarInjected($document.find(cfpLoadingBar.parentSelector))).toBe false


0 comments on commit 6c2b0e5

Please sign in to comment.