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

Commit

Permalink
feat(alert): use uib- prefix
Browse files Browse the repository at this point in the history
Closes #4406
  • Loading branch information
Foxandxss committed Sep 11, 2015
1 parent a04b4ff commit 5e3a87a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
33 changes: 30 additions & 3 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('ui.bootstrap.alert', [])

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

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

.directive('alert', function() {
.directive('uibAlert', function() {
return {
controller: 'AlertController',
controller: 'UibAlertController',
controllerAs: 'alert',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/alert/alert.html';
Expand All @@ -25,3 +25,30 @@ angular.module('ui.bootstrap.alert', [])
}
};
});

/* Deprecated alert below */

angular.module('ui.bootstrap.alert')

.value('$alertSuppressWarning', false)

.directive('alert', ['$log', '$alertSuppressWarning', function($log, $alertSuppressWarning) {
return {
controller: 'UibAlertController',
controllerAs: 'alert',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/alert/alert.html';
},
transclude: true,
replace: true,
scope: {
type: '@',
close: '&'
},
link: function() {
if (!$alertSuppressWarning) {
$log.warn('alert is now deprecated. Use uib-alert instead.');
}
}
};
}]);
4 changes: 2 additions & 2 deletions src/alert/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>
</script>

<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</alert>
<alert template-url="alert.html">A happy alert!</alert>
<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>
<uib-alert template-url="alert.html">A happy alert!</uib-alert>
<button type="button" class='btn btn-default' ng-click="addAlert()">Add Alert</button>
</div>
10 changes: 5 additions & 5 deletions src/alert/docs/readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
This directive can be used both to generate alerts from static and dynamic model data (using the `ng-repeat` directive).

### Alert settings
### uib-alert settings

* `close` (Defaults: none):
* `close` _(Default: `none`)_ -
A callback function that gets fired when an `alert` is closed. If the attribute exists, a close button is displayed as well.
* `dismiss-on-timeout` (Defaults: none)(Optional):
* `dismiss-on-timeout` _(Default: `none`)(Optional)_ -
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.
* `template-url` (Defaults: `template/alert/alert.html`):
* `template-url` _(Default: `template/alert/alert.html`)_ -
Add the ability to override the template used in the component.
* `type` (Defaults: `warning`):
* `type` _(Default: `warning`)_ -
Defines the type of the alert. Go to [bootstrap page](http://getbootstrap.com/components/#alerts) to see the type of alerts available.
51 changes: 42 additions & 9 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('alert', function() {
describe('uib-alert', function() {
var element, scope, $compile, $templateCache, $timeout;

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

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

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

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

var ctrl = element.controller('alert');
var ctrl = element.controller('uib-alert');
expect(ctrl).toBeDefined();

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

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

expect(element.html()).toBe('baz');
Expand Down Expand Up @@ -115,25 +115,58 @@ describe('alert', function() {
});

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

it('should be possible to add additional classes for alert', function() {
var element = $compile('<alert class="alert-block" type="info">Default alert!</alert>')(scope);
var element = $compile('<uib-alert class="alert-block" type="info">Default alert!</uib-alert>')(scope);
scope.$digest();
expect(element).toHaveClass('alert-block');
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);
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</uib-alert>')(scope);
scope.$digest();

$timeout.flush();
expect(scope.removeAlert).toHaveBeenCalled();
});
});

/* Deprecation tests below */

describe('alert deprecation', function() {
beforeEach(module('ui.bootstrap.alert'));
beforeEach(module('template/alert/alert.html'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$alertSuppressWarning', true);
});

inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = '<alert></alert>';
element = $compile(element)($rootScope);
$rootScope.$digest();
expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = '<alert></alert>';
element = $compile(element)($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(1);
expect($log.warn.calls.argsFor(0)).toEqual(['alert is now deprecated. Use uib-alert instead.']);
}));
});

0 comments on commit 5e3a87a

Please sign in to comment.