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

Commit

Permalink
fix(alert): don't show close button if no close callback specified
Browse files Browse the repository at this point in the history
  • Loading branch information
thisboyiscrazy authored and pkozlowski-opensource committed Apr 2, 2013
1 parent 556a37e commit c2645f4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
});
});
2 changes: 1 addition & 1 deletion src/alert/docs/demo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-controller="AlertDemoCtrl">
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
<button class='btn' ng-click="addAlert()">Add Alert</button>
</div>
</div>
4 changes: 3 additions & 1 deletion src/alert/docs/readme.md
Original file line number Diff line number Diff line change
@@ -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);
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
31 changes: 20 additions & 11 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe("alert", function () {

var scope, ctrl, model, $compile;
var element;

Expand All @@ -11,14 +12,16 @@ describe("alert", function () {
$compile = _$compile_;

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

scope.alerts = [
{ msg:'foo', type:'success'},
{ msg:'bar', type:'error'},
{ msg:'baz' }
{ msg:'baz'}
];
}));

Expand Down Expand Up @@ -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('<alert class="alert-block" type="\'info\'">Default alert!</alert>')(scope);
scope.$digest();
expect(element).toHaveClass('alert-block');
expect(element).toHaveClass('alert-info');
});

it("should fire callback when closed", function () {

var alerts = createAlerts();
Expand All @@ -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('<alert>No close</alert>')(scope);
scope.$digest();
expect(findCloseButton(0).length).toEqual(0);
});

it('it should be possible to add additional classes for alert', function () {
var element = $compile('<alert class="alert-block" type="\'info\'">Default alert!</alert>')(scope);
scope.$digest();
expect(element).toHaveClass('alert-block');
expect(element).toHaveClass('alert-info');
});

});
4 changes: 2 additions & 2 deletions template/alert/alert.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class='alert' ng-class='type && "alert-" + type'>
<button type='button' class='close' ng-click='close()'>&times;</button>
<button ng-show='closeable' type='button' class='close' ng-click='close()'>&times;</button>
<div ng-transclude></div>
</div>
</div>

0 comments on commit c2645f4

Please sign in to comment.