From 464315a4d7f650d2fdebd70e55a966d189c6e325 Mon Sep 17 00:00:00 2001 From: longpshorn Date: Thu, 18 Dec 2014 18:56:10 -0600 Subject: [PATCH] Update to AngularJS-Scope.SafeApply Update to AngularJS-Scope.SafeApply to ensure that $rootScope will be safely injected when the file is minified. --- src/Scope.SafeApply.js | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/Scope.SafeApply.js b/src/Scope.SafeApply.js index 8dc2828..daf5af9 100644 --- a/src/Scope.SafeApply.js +++ b/src/Scope.SafeApply.js @@ -19,34 +19,35 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -angular.module('Scope.safeApply', []).run(function($rootScope) { - - $rootScope.$safeApply = function() { - var $scope, fn, force = false; - if(arguments.length == 1) { - var arg = arguments[0]; - if(typeof arg == 'function') { - fn = arg; +angular.module('Scope.safeApply', []).run([ + '$rootScope', + function($rootScope) { + $rootScope.$safeApply = function() { + var $scope, fn, force = false; + if(arguments.length == 1) { + var arg = arguments[0]; + if(typeof arg == 'function') { + fn = arg; + } + else { + $scope = arg; + } } else { - $scope = arg; + $scope = arguments[0]; + fn = arguments[1]; + if(arguments.length == 3) { + force = !!arguments[2]; + } } - } - else { - $scope = arguments[0]; - fn = arguments[1]; - if(arguments.length == 3) { - force = !!arguments[2]; + $scope = $scope || this; + fn = fn || function() { }; + if(force || !$scope.$$phase) { + $scope.$apply ? $scope.$apply(fn) : $scope.apply(fn); } - } - $scope = $scope || this; - fn = fn || function() { }; - if(force || !$scope.$$phase) { - $scope.$apply ? $scope.$apply(fn) : $scope.apply(fn); - } - else { - fn(); - } - }; - -}); + else { + fn(); + } + }; + } +]);