Skip to content

Commit

Permalink
Option to allow specified number of messages inside container
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosMosovsky committed Jul 17, 2014
1 parent 891ca99 commit c05208f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ app.config(['growlProvider', function(growlProvider) {
}]);
````

###Only one message [default: false]
###Limit messages count [default: undefined]

Accept only one message inside growl container. Automatically flush collection on each new message. (Message overriding) . Useful
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
message only for last request , very handy for input validation.
specified number of messages (for example 1 ) , very handy for input validation.

````html
<body>
<div growl only-one-message="true"></div>
<div growl limit-messages="1"></div>
</body>
````

Expand Down
12 changes: 7 additions & 5 deletions src/growlDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module("angular-growl").directive("growl", ["$rootScope", "$sce",
scope: {
reference: '@',
inline: '@',
onlyOneMessage : '='
limitMessages : '='
},
controller: ['$scope', '$timeout', 'growl',
function($scope, $timeout, growl) {
Expand All @@ -23,12 +23,14 @@ angular.module("angular-growl").directive("growl", ["$rootScope", "$sce",
message.text = $sce.trustAsHtml(String(message.text));


if($scope.onlyOneMessage === true )
if(angular.isDefined($scope.limitMessages))
{
//clear collection on new message
$scope.messages = [];
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 c05208f

Please # to comment.