Skip to content

Commit

Permalink
refactor(alert): move dismiss-on-timeout to an attribute
Browse files Browse the repository at this point in the history
Closes angular-ui#4405

BREAKING CHANGE: Alert's dismiss-on-timeout is now an attribute inside uib-alert.
  • Loading branch information
Foxandxss authored and jasonaden committed Sep 30, 2015
1 parent 4aee531 commit efed2a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
22 changes: 8 additions & 14 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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));
}
};
}]);
});
14 changes: 11 additions & 3 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
@@ -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(
'<div>' +
Expand Down Expand Up @@ -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('<alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</alert>')(scope);
scope.$digest();

$timeout.flush();
expect(scope.removeAlert).toHaveBeenCalled();
});
});
20 changes: 0 additions & 20 deletions src/alert/test/dismissOnTimeout.spec.js

This file was deleted.

0 comments on commit efed2a1

Please sign in to comment.