Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 5e3a87a

Browse files
committed
feat(alert): use uib- prefix
Closes #4406
1 parent a04b4ff commit 5e3a87a

File tree

4 files changed

+79
-19
lines changed

4 files changed

+79
-19
lines changed

Diff for: src/alert/alert.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
angular.module('ui.bootstrap.alert', [])
22

3-
.controller('AlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) {
3+
.controller('UibAlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) {
44
$scope.closeable = !!$attrs.close;
55

66
if (angular.isDefined($attrs.dismissOnTimeout)) {
@@ -10,9 +10,9 @@ angular.module('ui.bootstrap.alert', [])
1010
}
1111
}])
1212

13-
.directive('alert', function() {
13+
.directive('uibAlert', function() {
1414
return {
15-
controller: 'AlertController',
15+
controller: 'UibAlertController',
1616
controllerAs: 'alert',
1717
templateUrl: function(element, attrs) {
1818
return attrs.templateUrl || 'template/alert/alert.html';
@@ -25,3 +25,30 @@ angular.module('ui.bootstrap.alert', [])
2525
}
2626
};
2727
});
28+
29+
/* Deprecated alert below */
30+
31+
angular.module('ui.bootstrap.alert')
32+
33+
.value('$alertSuppressWarning', false)
34+
35+
.directive('alert', ['$log', '$alertSuppressWarning', function($log, $alertSuppressWarning) {
36+
return {
37+
controller: 'UibAlertController',
38+
controllerAs: 'alert',
39+
templateUrl: function(element, attrs) {
40+
return attrs.templateUrl || 'template/alert/alert.html';
41+
},
42+
transclude: true,
43+
replace: true,
44+
scope: {
45+
type: '@',
46+
close: '&'
47+
},
48+
link: function() {
49+
if (!$alertSuppressWarning) {
50+
$log.warn('alert is now deprecated. Use uib-alert instead.');
51+
}
52+
}
53+
};
54+
}]);

Diff for: src/alert/docs/demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</div>
66
</script>
77

8-
<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</alert>
9-
<alert template-url="alert.html">A happy alert!</alert>
8+
<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>
9+
<uib-alert template-url="alert.html">A happy alert!</uib-alert>
1010
<button type="button" class='btn btn-default' ng-click="addAlert()">Add Alert</button>
1111
</div>

Diff for: src/alert/docs/readme.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
This directive can be used both to generate alerts from static and dynamic model data (using the `ng-repeat` directive).
22

3-
### Alert settings
3+
### uib-alert settings
44

5-
* `close` (Defaults: none):
5+
* `close` _(Default: `none`)_ -
66
A callback function that gets fired when an `alert` is closed. If the attribute exists, a close button is displayed as well.
7-
* `dismiss-on-timeout` (Defaults: none)(Optional):
7+
* `dismiss-on-timeout` _(Default: `none`)(Optional)_ -
88
Takes the number of milliseconds that specify the timeout duration, after which the alert will be closed. This attribute requires the presence of the `close` attribute.
9-
* `template-url` (Defaults: `template/alert/alert.html`):
9+
* `template-url` _(Default: `template/alert/alert.html`)_ -
1010
Add the ability to override the template used in the component.
11-
* `type` (Defaults: `warning`):
11+
* `type` _(Default: `warning`)_ -
1212
Defines the type of the alert. Go to [bootstrap page](http://getbootstrap.com/components/#alerts) to see the type of alerts available.

Diff for: src/alert/test/alert.spec.js

+42-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('alert', function() {
1+
describe('uib-alert', function() {
22
var element, scope, $compile, $templateCache, $timeout;
33

44
beforeEach(module('ui.bootstrap.alert'));
@@ -12,9 +12,9 @@ describe('alert', function() {
1212

1313
element = angular.element(
1414
'<div>' +
15-
'<alert ng-repeat="alert in alerts" type="{{alert.type}}"' +
15+
'<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}"' +
1616
'close="removeAlert($index)">{{alert.msg}}' +
17-
'</alert>' +
17+
'</uib-alert>' +
1818
'</div>');
1919

2020
scope.alerts = [
@@ -41,10 +41,10 @@ describe('alert', function() {
4141
it('should expose the controller to the view', function() {
4242
$templateCache.put('template/alert/alert.html', '<div>{{alert.text}}</div>');
4343

44-
element = $compile('<alert></alert>')(scope);
44+
element = $compile('<uib-alert></uib-alert>')(scope);
4545
scope.$digest();
4646

47-
var ctrl = element.controller('alert');
47+
var ctrl = element.controller('uib-alert');
4848
expect(ctrl).toBeDefined();
4949

5050
ctrl.text = 'foo';
@@ -56,7 +56,7 @@ describe('alert', function() {
5656
it('should support custom templates', function() {
5757
$templateCache.put('foo/bar.html', '<div>baz</div>');
5858

59-
element = $compile('<alert template-url="foo/bar.html"></alert>')(scope);
59+
element = $compile('<uib-alert template-url="foo/bar.html"></uib-alert>')(scope);
6060
scope.$digest();
6161

6262
expect(element.html()).toBe('baz');
@@ -115,25 +115,58 @@ describe('alert', function() {
115115
});
116116

117117
it('should not show close button and have the dismissible class if no close callback specified', function() {
118-
element = $compile('<alert>No close</alert>')(scope);
118+
element = $compile('<uib-alert>No close</uib-alert>')(scope);
119119
scope.$digest();
120120
expect(findCloseButton(0)).toBeHidden();
121121
expect(element).not.toHaveClass('alert-dismissible');
122122
});
123123

124124
it('should be possible to add additional classes for alert', function() {
125-
var element = $compile('<alert class="alert-block" type="info">Default alert!</alert>')(scope);
125+
var element = $compile('<uib-alert class="alert-block" type="info">Default alert!</uib-alert>')(scope);
126126
scope.$digest();
127127
expect(element).toHaveClass('alert-block');
128128
expect(element).toHaveClass('alert-info');
129129
});
130130

131131
it('should close automatically if dismiss-on-timeout is defined on the element', function() {
132132
scope.removeAlert = jasmine.createSpy();
133-
$compile('<alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</alert>')(scope);
133+
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</uib-alert>')(scope);
134134
scope.$digest();
135135

136136
$timeout.flush();
137137
expect(scope.removeAlert).toHaveBeenCalled();
138138
});
139139
});
140+
141+
/* Deprecation tests below */
142+
143+
describe('alert deprecation', function() {
144+
beforeEach(module('ui.bootstrap.alert'));
145+
beforeEach(module('template/alert/alert.html'));
146+
147+
it('should suppress warning', function() {
148+
module(function($provide) {
149+
$provide.value('$alertSuppressWarning', true);
150+
});
151+
152+
inject(function($compile, $log, $rootScope) {
153+
spyOn($log, 'warn');
154+
155+
var element = '<alert></alert>';
156+
element = $compile(element)($rootScope);
157+
$rootScope.$digest();
158+
expect($log.warn.calls.count()).toBe(0);
159+
});
160+
});
161+
162+
it('should give warning by default', inject(function($compile, $log, $rootScope) {
163+
spyOn($log, 'warn');
164+
165+
var element = '<alert></alert>';
166+
element = $compile(element)($rootScope);
167+
$rootScope.$digest();
168+
169+
expect($log.warn.calls.count()).toBe(1);
170+
expect($log.warn.calls.argsFor(0)).toEqual(['alert is now deprecated. Use uib-alert instead.']);
171+
}));
172+
});

0 commit comments

Comments
 (0)