From c2645f4a6129d68fb965d401e9de2f55ffd43c14 Mon Sep 17 00:00:00 2001 From: Joe Vanderstelt Date: Thu, 28 Mar 2013 17:59:05 -0400 Subject: [PATCH] fix(alert): don't show close button if no close callback specified --- src/alert/alert.js | 11 +++++++---- src/alert/docs/demo.html | 2 +- src/alert/docs/readme.md | 4 +++- src/alert/test/alert.spec.js | 31 ++++++++++++++++++++----------- template/alert/alert.html | 4 ++-- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/alert/alert.js b/src/alert/alert.js index bec5a2904b..07f68dde5b 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -4,9 +4,12 @@ angular.module("ui.bootstrap.alert", []).directive('alert', function () { templateUrl:'template/alert/alert.html', transclude:true, replace:true, - scope:{ - type:'=', - close:'&' + scope: { + type: '=', + close: '&' + }, + link: function(scope, iElement, iAttrs, controller) { + scope.closeable = "close" in iAttrs; } }; -}); \ No newline at end of file +}); diff --git a/src/alert/docs/demo.html b/src/alert/docs/demo.html index d91517526e..a750374f37 100644 --- a/src/alert/docs/demo.html +++ b/src/alert/docs/demo.html @@ -1,4 +1,4 @@
{{alert.msg}} -
\ No newline at end of file + diff --git a/src/alert/docs/readme.md b/src/alert/docs/readme.md index 1fafb54af4..fb8029a5a3 100644 --- a/src/alert/docs/readme.md +++ b/src/alert/docs/readme.md @@ -1,3 +1,5 @@ Alert is an AngularJS-version of bootstrap's alert. -This directive can be used to generate alerts from the dynamic model data (using the ng-repeat directive); \ No newline at end of file +This directive can be used to generate alerts from the dynamic model data (using the ng-repeat directive); + +The presence of the "close" attribute determines if a close button is displayed diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 5fa21daeb5..0ffbc241a7 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -1,4 +1,5 @@ describe("alert", function () { + var scope, ctrl, model, $compile; var element; @@ -11,14 +12,16 @@ describe("alert", function () { $compile = _$compile_; element = angular.element( - "
{{alert.msg}}" + - "
"); + "
" + + "{{alert.msg}}" + + "" + + "
"); scope.alerts = [ { msg:'foo', type:'success'}, { msg:'bar', type:'error'}, - { msg:'baz' } + { msg:'baz'} ]; })); @@ -48,13 +51,6 @@ describe("alert", function () { expect(alerts.eq(2)).not.toHaveClass('alert-block'); }); - it('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 fire callback when closed", function () { var alerts = createAlerts(); @@ -67,4 +63,17 @@ describe("alert", function () { expect(scope.removeAlert).toHaveBeenCalledWith(1); }); + it('should not show close buttons if no close callback specified', function () { + var element = $compile('No close')(scope); + scope.$digest(); + expect(findCloseButton(0).length).toEqual(0); + }); + + it('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'); + }); + }); diff --git a/template/alert/alert.html b/template/alert/alert.html index d060a1779c..26f65b3c75 100644 --- a/template/alert/alert.html +++ b/template/alert/alert.html @@ -1,4 +1,4 @@
- +
-
\ No newline at end of file +