Skip to content

Commit

Permalink
added aria live support
Browse files Browse the repository at this point in the history
To change text announced, use `growlProvider.closeButtonText(@string);`

Closes marcorinckGH-22
  • Loading branch information
jonespen committed Mar 6, 2014
1 parent 9eb745a commit 546b2d0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Finally, you have to include the directive somewhere in your HTML like this:

````html
<body>
<div growl></div>
<div growl aria-live="polite"></div>
</body>
````

Expand Down Expand Up @@ -189,6 +189,21 @@ app.controller("demoCtrl", ['$scope', 'growl', function($scope, growl) {
}
}]);
````
````
###Close text for assisitive technology (AT)
* Default: 'Close'
Label for close button. If angular-translate is present, provide a key for the translate text
````javascript
var app = angular.module('myApp', ['angular-growl']);
app.config(['growlProvider', function(growlProvider) {
growlProvider.closeButtonText('Lukk');
}]);
````

###Animations

Expand Down
2 changes: 1 addition & 1 deletion demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div ng-controller="demoCtrl">
<div class="text-center container"><h1>angular-growl Demo site</h1></div>

<div growl></div>
<div growl aria-live="polite"></div>
<div class="container">
<div class="well row">
<label>
Expand Down
13 changes: 8 additions & 5 deletions src/growlDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ angular.module("angular-growl").directive("growl", ["$rootScope", function ($roo
restrict: 'A',
template: '<div class="growl">' +
' <div class="growl-item alert" ng-repeat="message in messages" ng-class="computeClasses(message)">' +
' <button type="button" class="close" ng-click="deleteMessage(message)">&times;</button>' +
' <div ng-switch="message.enableHtml">' +
' <div ng-switch-when="true" ng-bind-html="message.text"></div>' +
' <div ng-switch-default ng-bind="message.text"></div>' +
' </div>' +
' <button type="button" class="close" ng-click="deleteMessage(message)">' +
' <span aria-hidden="true">&times;</span>' +
' <span class="sr-only hide-text" ng-bind="message.closeButtonText"></span>' +
' </button>' +
' <div ng-switch="message.enableHtml">' +
' <div ng-switch-when="true" ng-bind-html="message.text"></div>' +
' <div ng-switch-default ng-bind="message.text"></div>' +
' </div>' +
' </div>' +
'</div>',
replace: false,
Expand Down
16 changes: 14 additions & 2 deletions src/growlFactory.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
angular.module("angular-growl").provider("growl", function() {
"use strict";

var _ttl = null,
_enableHtml = false,
var _closeButtonText = 'close',
_ttl = null,
_enableHtml = false,
_messagesKey = 'messages',
_messageTextKey = 'text',
_messageSeverityKey = 'severity',
_onlyUniqueMessages = true;

/**
* set the text used for the close button for screen readers
*
* @param {string} closeButtonText default: close
*/
this.closeButtonText = function(closeButtonText) {
_closeButtonText = closeButtonText;
};

/**
* set a global timeout (time to live) after which messages will be automatically closed
*
Expand Down Expand Up @@ -97,6 +107,7 @@ angular.module("angular-growl").provider("growl", function() {
function broadcastMessage(message) {
if (translate) {
message.text = translate(message.text);
message.closeButtonText = translate(message.closeButtonText);
}
$rootScope.$broadcast("growlMessage", message);
}
Expand All @@ -105,6 +116,7 @@ angular.module("angular-growl").provider("growl", function() {
var _config = config || {}, message;

message = {
closeButtonText: _config.closeButtonText || _closeButtonText,
text: text,
severity: severity,
ttl: _config.ttl || _ttl,
Expand Down

0 comments on commit 546b2d0

Please sign in to comment.