Skip to content

Commit

Permalink
Merge pull request #21 from MilosMosovsky/master
Browse files Browse the repository at this point in the history
Option for allow only one message inside growl container
  • Loading branch information
Jan Stevens committed Aug 10, 2014
2 parents f793744 + c05208f commit 48afd81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ app.config(['growlProvider', function(growlProvider) {
}]);
````

###Limit messages count [default: undefined]

Accept only one X messages inside growl container. Automatically flush collection to limited count on each new message. (Message overriding) . Useful
when growl is handling messages corresponding to specified element (for example input box inside form) , and you need to show
specified number of messages (for example 1 ) , very handy for input validation.

````html
<body>
<div growl limit-messages="1"></div>
</body>
````

###Automatic closing of notifications (timeout, ttl) [default: none]

However, you can configure a global timeout (TTL) after which notifications should be automatically closed. To do this, you have to configure this during config phase of angular bootstrap like this:
Expand Down
12 changes: 11 additions & 1 deletion src/growlDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ angular.module("angular-growl").directive("growl", ["$rootScope", "$sce",
replace: false,
scope: {
reference: '@',
inline: '@'
inline: '@',
limitMessages : '='
},
controller: ['$scope', '$timeout', 'growl',
function($scope, $timeout, growl) {
Expand All @@ -21,6 +22,15 @@ angular.module("angular-growl").directive("growl", ["$rootScope", "$sce",
$timeout(function() {
message.text = $sce.trustAsHtml(String(message.text));


if(angular.isDefined($scope.limitMessages))
{
var diff = $scope.messages.length - ($scope.limitMessages-1);
if(diff > 0)
{
$scope.messages.splice($scope.limitMessages-1,diff)
}
}
/** abillity to reverse order (newest first ) **/
if(growl.reverseOrder())
{
Expand Down

0 comments on commit 48afd81

Please # to comment.