diff --git a/src/alert/alert.js b/src/alert/alert.js index 3bb79c4437..23d3aa592f 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -1,8 +1,13 @@ angular.module('ui.bootstrap.alert', []) -.controller('AlertController', ['$scope', '$attrs', function($scope, $attrs) { +.controller('AlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) { $scope.closeable = !!$attrs.close; - this.close = $scope.close; + + if (angular.isDefined($attrs.dismissOnTimeout)) { + $timeout(function() { + $scope.close(); + }, parseInt($attrs.dismissOnTimeout, 10)); + } }]) .directive('alert', function() { @@ -19,15 +24,4 @@ angular.module('ui.bootstrap.alert', []) close: '&' } }; -}) - -.directive('dismissOnTimeout', ['$timeout', function($timeout) { - return { - require: 'alert', - link: function(scope, element, attrs, alertCtrl) { - $timeout(function() { - alertCtrl.close(); - }, parseInt(attrs.dismissOnTimeout, 10)); - } - }; -}]); +}); diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 74514565fc..7f87de81da 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -1,14 +1,14 @@ describe('alert', function() { - var scope, $compile, $templateCache; - var element; + var element, scope, $compile, $templateCache, $timeout; beforeEach(module('ui.bootstrap.alert')); beforeEach(module('template/alert/alert.html')); - beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) { + beforeEach(inject(function($rootScope, _$compile_, _$templateCache_, _$timeout_) { scope = $rootScope; $compile = _$compile_; $templateCache = _$templateCache_; + $timeout = _$timeout_; element = angular.element( '
' + @@ -128,4 +128,12 @@ describe('alert', function() { expect(element).toHaveClass('alert-info'); }); + it('should close automatically if dismiss-on-timeout is defined on the element', function() { + scope.removeAlert = jasmine.createSpy(); + $compile('Default alert!')(scope); + scope.$digest(); + + $timeout.flush(); + expect(scope.removeAlert).toHaveBeenCalled(); + }); }); diff --git a/src/alert/test/dismissOnTimeout.spec.js b/src/alert/test/dismissOnTimeout.spec.js deleted file mode 100644 index 3d6d8796e5..0000000000 --- a/src/alert/test/dismissOnTimeout.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -describe('dismissOnTimeout', function() { - var scope, $compile, $timeout; - - beforeEach(module('ui.bootstrap.alert')); - beforeEach(module('template/alert/alert.html')); - beforeEach(inject(function($rootScope, _$compile_, _$timeout_) { - scope = $rootScope; - $compile = _$compile_; - $timeout = _$timeout_; - })); - - it('should close automatically if auto-dismiss is defined on the element', function() { - scope.removeAlert = jasmine.createSpy(); - $compile('Default alert!')(scope); - scope.$digest(); - - $timeout.flush(); - expect(scope.removeAlert).toHaveBeenCalled(); - }); -});