From 8c26b0e82f2be28738938e52c74e6353e3e5af9c Mon Sep 17 00:00:00 2001 From: Wesley Milan Date: Tue, 30 Jun 2015 23:46:11 -0300 Subject: [PATCH 1/6] Compatibility with Angular-Translate --- .idea/.name | 1 + .idea/misc.xml | 14 ++ .idea/modules.xml | 8 ++ .idea/ng-busy.iml | 8 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 180 +++++++++++++++++++++++++ src/angular-busy.js | 317 ++++++++++++++++++++++++-------------------- 7 files changed, 390 insertions(+), 144 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/ng-busy.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..07bc849 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ng-busy \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..19f74da --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f54c641 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/ng-busy.iml b/.idea/ng-busy.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/ng-busy.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..f2520e9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1435718625410 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/angular-busy.js b/src/angular-busy.js index 8eb9080..477d072 100644 --- a/src/angular-busy.js +++ b/src/angular-busy.js @@ -1,151 +1,180 @@ (function (window, angular, undefined) { - 'use strict'; - - angular.module('ngBusy.interceptor', []) - .provider('busyInterceptor', function() { - - this.$get = ['$rootScope', '$q', function($rootScope, $q) { - var _total = 0, _completed = 0; - - function complete() { - _total = _completed = 0; - } - - function handleResponse(r) { - if (r.config.notBusy) return; - - $rootScope.$broadcast('busy.end', {url: r.config.url, name: r.config.name, remaining: _total - ++_completed}); - if (_completed >= _total) complete(); - } - - return { - outstanding: function() { - return _total - _completed; - }, - 'request': function(config) { - if (!config.notBusy) { - $rootScope.$broadcast('busy.begin', {url: config.url, name: config.name}); - _total++; - } - return config || $q.when(config); - }, - 'response': function(response) { - handleResponse(response); - return response; - }, - 'responseError': function(rejection) { - handleResponse(rejection); - return $q.reject(rejection); - } - }; - }]; - }) - .config(['$httpProvider', function($httpProvider) { - $httpProvider.interceptors.push('busyInterceptor'); - }]); + 'use strict'; + + angular.module('ngBusy.interceptor', []) + .provider('busyInterceptor', function() { + + this.$get = ['$rootScope', '$q', function($rootScope, $q) { + var _total = 0, _completed = 0; + + function complete() { + _total = _completed = 0; + } + + function handleResponse(r) { + if (r.config.notBusy) return; + + $rootScope.$broadcast('busy.end', {url: r.config.url, name: r.config.name, remaining: _total - ++_completed}); + if (_completed >= _total) complete(); + } + + return { + outstanding: function() { + return _total - _completed; + }, + 'request': function(config) { + if (!config.notBusy) { + $rootScope.$broadcast('busy.begin', {url: config.url, name: config.name}); + _total++; + } + return config || $q.when(config); + }, + 'response': function(response) { + handleResponse(response); + return response; + }, + 'responseError': function(rejection) { + handleResponse(rejection); + return $q.reject(rejection); + } + }; + }]; + }) + .config(['$httpProvider', function($httpProvider) { + $httpProvider.interceptors.push('busyInterceptor'); + }]); // minimal: