diff --git a/src/alert/alert.js b/src/alert/alert.js index 0ad230be7f..73387e55a5 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -1,7 +1,12 @@ angular.module('ui.bootstrap.alert', []) -.controller('UibAlertController', ['$scope', '$attrs', '$interpolate', '$timeout', function($scope, $attrs, $interpolate, $timeout) { +.controller('UibAlertController', ['$scope', '$element', '$attrs', '$interpolate', '$timeout', function($scope, $element, $attrs, $interpolate, $timeout) { $scope.closeable = !!$attrs.close; + $element.addClass('alert'); + $attrs.$set('role', 'alert'); + if ($scope.closeable) { + $element.addClass('alert-dismissible'); + } var dismissOnTimeout = angular.isDefined($attrs.dismissOnTimeout) ? $interpolate($attrs.dismissOnTimeout)($scope.$parent) : null; @@ -17,13 +22,12 @@ angular.module('ui.bootstrap.alert', []) return { controller: 'UibAlertController', controllerAs: 'alert', + restrict: 'A', templateUrl: function(element, attrs) { return attrs.templateUrl || 'uib/template/alert/alert.html'; }, transclude: true, - replace: true, scope: { - type: '@', close: '&' } }; diff --git a/src/alert/docs/demo.html b/src/alert/docs/demo.html index e2ce4b3870..b599f48091 100644 --- a/src/alert/docs/demo.html +++ b/src/alert/docs/demo.html @@ -1,11 +1,9 @@
- {{alert.msg}} - A happy alert! +
{{alert.msg}}
+
A happy alert!
diff --git a/src/alert/docs/readme.md b/src/alert/docs/readme.md index 3361f6418e..cf0bcad1ab 100644 --- a/src/alert/docs/readme.md +++ b/src/alert/docs/readme.md @@ -5,15 +5,11 @@ This directive can be used both to generate alerts from static and dynamic model * `close()` $ - 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` _(Default: `none`)_ - 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` _(Default: `uib/template/alert/alert.html`)_ - Add the ability to override the template used in the component. - -* `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. diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 752127ae51..d38b4fab60 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -12,9 +12,10 @@ describe('uib-alert', function() { element = angular.element( '
' + - '{{alert.msg}}' + - '' + + '
' + ''); scope.alerts = [ @@ -41,7 +42,7 @@ describe('uib-alert', function() { it('should expose the controller to the view', function() { $templateCache.put('uib/template/alert/alert.html', '
{{alert.text}}
'); - element = $compile('')(scope); + element = $compile('
')(scope); scope.$digest(); var ctrl = element.controller('uib-alert'); @@ -50,16 +51,16 @@ describe('uib-alert', function() { ctrl.text = 'foo'; scope.$digest(); - expect(element.html()).toBe('foo'); + expect(element.html()).toBe('
foo
'); }); it('should support custom templates', function() { $templateCache.put('foo/bar.html', '
baz
'); - element = $compile('')(scope); + element = $compile('
')(scope); scope.$digest(); - expect(element.html()).toBe('baz'); + expect(element.html()).toBe('
baz
'); }); it('should generate alerts using ng-repeat', function() { @@ -67,23 +68,6 @@ describe('uib-alert', function() { expect(alerts.length).toEqual(3); }); - it('should use correct classes for different alert types', function() { - var alerts = createAlerts(); - expect(alerts.eq(0)).toHaveClass('alert-success'); - expect(alerts.eq(1)).toHaveClass('alert-error'); - expect(alerts.eq(2)).toHaveClass('alert-warning'); - }); - - it('should respect alert type binding', function() { - var alerts = createAlerts(); - expect(alerts.eq(0)).toHaveClass('alert-success'); - - scope.alerts[0].type = 'error'; - scope.$digest(); - - expect(alerts.eq(0)).toHaveClass('alert-error'); - }); - it('should show the alert content', function() { var alerts = createAlerts(); @@ -115,22 +99,15 @@ describe('uib-alert', function() { }); it('should not show close button and have the dismissible class if no close callback specified', function() { - element = $compile('No close')(scope); + element = $compile('
No close
')(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('Default 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('Default alert!')(scope); + $compile('
Default alert!
')(scope); scope.$digest(); $timeout.flush(); @@ -140,7 +117,7 @@ describe('uib-alert', function() { it('should not close immediately with a dynamic dismiss-on-timeout', function() { scope.removeAlert = jasmine.createSpy(); scope.dismissTime = 500; - $compile('Default alert!')(scope); + $compile('
Default alert!
')(scope); scope.$digest(); $timeout.flush(100); diff --git a/template/alert/alert.html b/template/alert/alert.html index 0885587d98..b5bade4b0d 100644 --- a/template/alert/alert.html +++ b/template/alert/alert.html @@ -1,7 +1,5 @@ - + +