Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for allow only one message inside growl container #21

Merged
merged 2 commits into from
Aug 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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