diff --git a/build/loading-bar.css b/build/loading-bar.css index 84a0517..60c24ce 100644 --- a/build/loading-bar.css +++ b/build/loading-bar.css @@ -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 diff --git a/build/loading-bar.js b/build/loading-bar.js index cccb15a..1135e5f 100644 --- a/build/loading-bar.js +++ b/build/loading-bar.js @@ -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 @@ -19,9 +19,9 @@ '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']); /** @@ -29,7 +29,7 @@ angular.module('angular-loading-bar', ['chieffancypants.loadingBar']); * * 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) { @@ -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; diff --git a/build/loading-bar.min.css b/build/loading-bar.min.css index fd27805..ece60ac 100644 --- a/build/loading-bar.min.css +++ b/build/loading-bar.min.css @@ -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 diff --git a/build/loading-bar.min.js b/build/loading-bar.min.js index 58ca248..4f7dcd8 100644 --- a/build/loading-bar.min.js +++ b/build/loading-bar.min.js @@ -1,7 +1,7 @@ /*! - * 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 */ -!function(){"use strict";angular.module("angular-loading-bar",["chieffancypants.loadingBar"]),angular.module("chieffancypants.loadingBar",[]).config(["$httpProvider",function(a){var b=["$q","$cacheFactory","$timeout","$rootScope","cfpLoadingBar",function(b,c,d,e,f){function g(){d.cancel(i),f.complete(),k=0,j=0}function h(b){var d,e=a.defaults;if("GET"!==b.method||b.cache===!1)return b.cached=!1,!1;d=b.cache===!0&&void 0===e.cache?c.get("$http"):void 0!==e.cache?e.cache:b.cache;var f=void 0!==d?void 0!==d.get(b.url):!1;return void 0!==b.cached&&f!==b.cached?b.cached:(b.cached=f,f)}var i,j=0,k=0,l=f.latencyThreshold;return{request:function(a){return a.ignoreLoadingBar||h(a)||(e.$broadcast("cfpLoadingBar:loading",{url:a.url}),0===j&&(i=d(function(){f.start()},l)),j++,f.set(k/j)),a},response:function(a){return h(a.config)||(k++,e.$broadcast("cfpLoadingBar:loaded",{url:a.config.url}),k>=j?g():f.set(k/j)),a},responseError:function(a){return h(a.config)||(k++,e.$broadcast("cfpLoadingBar:loaded",{url:a.config.url}),k>=j?g():f.set(k/j)),b.reject(a)}}}];a.interceptors.push(b)}]).provider("cfpLoadingBar",function(){this.includeSpinner=!0,this.includeBar=!0,this.latencyThreshold=100,this.startSize=.02,this.parentSelector="body",this.$get=["$document","$timeout","$animate","$rootScope",function(a,b,c,d){function e(){var e=a.find(l);b.cancel(k),p||(d.$broadcast("cfpLoadingBar:started"),p=!0,s&&c.enter(m,e),r&&c.enter(o,e),f(t))}function f(a){if(p){var c=100*a+"%";n.css("width",c),q=a,b.cancel(j),j=b(function(){g()},250)}}function g(){if(!(h()>=1)){var a=0,b=h();a=b>=0&&.25>b?(3*Math.random()+3)/100:b>=.25&&.65>b?3*Math.random()/100:b>=.65&&.9>b?2*Math.random()/100:b>=.9&&.99>b?.005:0;var c=h()+a;f(c)}}function h(){return q}function i(){d.$broadcast("cfpLoadingBar:completed"),f(1),k=b(function(){c.leave(m,function(){q=0,p=!1}),c.leave(o)},500)}var j,k,l=this.parentSelector,m=angular.element('
'),n=m.find("div").eq(0),o=angular.element('
'),p=!1,q=0,r=this.includeSpinner,s=this.includeBar,t=this.startSize;return{start:e,set:f,status:h,inc:g,complete:i,includeSpinner:this.includeSpinner,latencyThreshold:this.latencyThreshold,parentSelector:this.parentSelector,startSize:this.startSize}}]})}(); \ No newline at end of file +!function(){"use strict";angular.module("angular-loading-bar",["cfp.loadingBarInterceptor"]),angular.module("chieffancypants.loadingBar",["cfp.loadingBarInterceptor"]),angular.module("cfp.loadingBarInterceptor",["cfp.loadingBar"]).config(["$httpProvider",function(a){var b=["$q","$cacheFactory","$timeout","$rootScope","cfpLoadingBar",function(b,c,d,e,f){function g(){d.cancel(i),f.complete(),k=0,j=0}function h(b){var d,e=a.defaults;if("GET"!==b.method||b.cache===!1)return b.cached=!1,!1;d=b.cache===!0&&void 0===e.cache?c.get("$http"):void 0!==e.cache?e.cache:b.cache;var f=void 0!==d?void 0!==d.get(b.url):!1;return void 0!==b.cached&&f!==b.cached?b.cached:(b.cached=f,f)}var i,j=0,k=0,l=f.latencyThreshold;return{request:function(a){return a.ignoreLoadingBar||h(a)||(e.$broadcast("cfpLoadingBar:loading",{url:a.url}),0===j&&(i=d(function(){f.start()},l)),j++,f.set(k/j)),a},response:function(a){return h(a.config)||(k++,e.$broadcast("cfpLoadingBar:loaded",{url:a.config.url}),k>=j?g():f.set(k/j)),a},responseError:function(a){return h(a.config)||(k++,e.$broadcast("cfpLoadingBar:loaded",{url:a.config.url}),k>=j?g():f.set(k/j)),b.reject(a)}}}];a.interceptors.push(b)}]),angular.module("cfp.loadingBar",[]).provider("cfpLoadingBar",function(){this.includeSpinner=!0,this.includeBar=!0,this.latencyThreshold=100,this.startSize=.02,this.parentSelector="body",this.$get=["$document","$timeout","$animate","$rootScope",function(a,b,c,d){function e(){var e=a.find(l);b.cancel(k),p||(d.$broadcast("cfpLoadingBar:started"),p=!0,s&&c.enter(m,e),r&&c.enter(o,e),f(t))}function f(a){if(p){var c=100*a+"%";n.css("width",c),q=a,b.cancel(j),j=b(function(){g()},250)}}function g(){if(!(h()>=1)){var a=0,b=h();a=b>=0&&.25>b?(3*Math.random()+3)/100:b>=.25&&.65>b?3*Math.random()/100:b>=.65&&.9>b?2*Math.random()/100:b>=.9&&.99>b?.005:0;var c=h()+a;f(c)}}function h(){return q}function i(){d.$broadcast("cfpLoadingBar:completed"),f(1),k=b(function(){c.leave(m,function(){q=0,p=!1}),c.leave(o)},500)}var j,k,l=this.parentSelector,m=angular.element('
'),n=m.find("div").eq(0),o=angular.element('
'),p=!1,q=0,r=this.includeSpinner,s=this.includeBar,t=this.startSize;return{start:e,set:f,status:h,inc:g,complete:i,includeSpinner:this.includeSpinner,latencyThreshold:this.latencyThreshold,parentSelector:this.parentSelector,startSize:this.startSize}}]})}(); \ No newline at end of file diff --git a/src/loading-bar.js b/src/loading-bar.js index 507acb0..7911135 100644 --- a/src/loading-bar.js +++ b/src/loading-bar.js @@ -13,9 +13,9 @@ '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']); /** @@ -23,7 +23,7 @@ angular.module('angular-loading-bar', ['chieffancypants.loadingBar']); * * 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) { @@ -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; diff --git a/test/loading-bar-interceptor.coffee b/test/loading-bar-interceptor.coffee index e27efb0..e0659f4 100644 --- a/test/loading-bar-interceptor.coffee +++ b/test/loading-bar-interceptor.coffee @@ -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 + +