Skip to content

Commit

Permalink
Release v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rinck committed Nov 19, 2013
1 parent f1da03a commit 9eb745a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Marco Rinck",
"name": "angular-growl",
"description": "growl like notifications for angularJS projects, using bootstrap alert classes",
"version": "0.3.0",
"version": "0.4.0",
"homepage": "https://github.com/marcorinck/angular-growl",
"repository": {
"type": "git",
Expand Down
73 changes: 49 additions & 24 deletions build/angular-growl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-growl - v0.3.1 - 2013-10-01
* angular-growl - v0.4.0 - 2013-11-19
* https://github.com/marcorinck/angular-growl
* Copyright (c) 2013 Marco Rinck; Licensed MIT
*/
Expand All @@ -10,21 +10,38 @@ angular.module('angular-growl').directive('growl', [
'use strict';
return {
restrict: 'A',
template: '<div class="growl">' + '\t<div class="growl-item alert" ng-repeat="message in messages" ng-class="computeClasses(message)">' + '\t\t<button type="button" class="close" ng-click="deleteMessage(message)">&times;</button>' + ' {{ message.text}}' + '\t</div>' + '</div>',
template: '<div class="growl">' + '\t<div class="growl-item alert" ng-repeat="message in messages" ng-class="computeClasses(message)">' + '\t\t<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>' + '\t</div>' + '</div>',
replace: false,
scope: true,
controller: [
'$scope',
'$timeout',
function ($scope, $timeout) {
'growl',
function ($scope, $timeout, growl) {
var onlyUnique = growl.onlyUnique();
$scope.messages = [];
$rootScope.$on('growlMessage', function (event, message) {
function addMessage(message) {
$scope.messages.push(message);
if (message.ttl && message.ttl !== -1) {
$timeout(function () {
$scope.deleteMessage(message);
}, message.ttl);
}
}
$rootScope.$on('growlMessage', function (event, message) {
var found;
if (onlyUnique) {
angular.forEach($scope.messages, function (msg) {
if (message.text === msg.text && message.severity === msg.severity) {
found = true;
}
});
if (!found) {
addMessage(message);
}
} else {
addMessage(message);
}
});
$scope.deleteMessage = function (message) {
var index = $scope.messages.indexOf(message);
Expand All @@ -34,11 +51,11 @@ angular.module('angular-growl').directive('growl', [
};
$scope.computeClasses = function (message) {
return {
'alert-success': message.isSuccess,
'alert-error': message.isError,
'alert-danger': message.isError,
'alert-info': message.isInfo,
'alert-warning': message.isWarn
'alert-success': message.severity === 'success',
'alert-error': message.severity === 'error',
'alert-danger': message.severity === 'error',
'alert-info': message.severity === 'info',
'alert-warning': message.severity === 'warn'
};
};
}
Expand All @@ -48,10 +65,13 @@ angular.module('angular-growl').directive('growl', [
]);
angular.module('angular-growl').provider('growl', function () {
'use strict';
var _ttl = null, _messagesKey = 'messages', _messageTextKey = 'text', _messageSeverityKey = 'severity';
var _ttl = null, _enableHtml = false, _messagesKey = 'messages', _messageTextKey = 'text', _messageSeverityKey = 'severity', _onlyUniqueMessages = true;
this.globalTimeToLive = function (ttl) {
_ttl = ttl;
};
this.globalEnableHtml = function (enableHtml) {
_enableHtml = enableHtml;
};
this.messagesKey = function (messagesKey) {
_messagesKey = messagesKey;
};
Expand All @@ -61,6 +81,9 @@ angular.module('angular-growl').provider('growl', function () {
this.messageSeverityKey = function (messageSeverityKey) {
_messageSeverityKey = messageSeverityKey;
};
this.onlyUniqueMessages = function (onlyUniqueMessages) {
_onlyUniqueMessages = onlyUniqueMessages;
};
this.serverMessagesInterceptor = [
'$q',
'growl',
Expand Down Expand Up @@ -102,25 +125,23 @@ angular.module('angular-growl').provider('growl', function () {
var _config = config || {}, message;
message = {
text: text,
isWarn: severity.isWarn,
isError: severity.isError,
isInfo: severity.isInfo,
isSuccess: severity.isSuccess,
ttl: _config.ttl || _ttl
severity: severity,
ttl: _config.ttl || _ttl,
enableHtml: _config.enableHtml || _enableHtml
};
broadcastMessage(message);
}
function addWarnMessage(text, config) {
sendMessage(text, config, { isWarn: true });
sendMessage(text, config, 'warn');
}
function addErrorMessage(text, config) {
sendMessage(text, config, { isError: true });
sendMessage(text, config, 'error');
}
function addInfoMessage(text, config) {
sendMessage(text, config, { isInfo: true });
sendMessage(text, config, 'info');
}
function addSuccessMessage(text, config) {
sendMessage(text, config, { isSuccess: true });
sendMessage(text, config, 'success');
}
function addServerMessages(messages) {
var i, message, severity, length;
Expand All @@ -130,28 +151,32 @@ angular.module('angular-growl').provider('growl', function () {
if (message[_messageTextKey] && message[_messageSeverityKey]) {
switch (message[_messageSeverityKey]) {
case 'warn':
severity = { isWarn: true };
severity = 'warn';
break;
case 'success':
severity = { isSuccess: true };
severity = 'success';
break;
case 'info':
severity = { isInfo: true };
severity = 'info';
break;
case 'error':
severity = { isError: true };
severity = 'error';
break;
}
sendMessage(message[_messageTextKey], undefined, severity);
}
}
}
function onlyUnique() {
return _onlyUniqueMessages;
}
return {
addWarnMessage: addWarnMessage,
addErrorMessage: addErrorMessage,
addInfoMessage: addInfoMessage,
addSuccessMessage: addSuccessMessage,
addServerMessages: addServerMessages
addServerMessages: addServerMessages,
onlyUnique: onlyUnique
};
}
];
Expand Down
2 changes: 1 addition & 1 deletion build/angular-growl.min.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-growl - v0.3.1 - 2013-10-01
* angular-growl - v0.4.0 - 2013-11-19
* https://github.com/marcorinck/angular-growl
* Copyright (c) 2013 Marco Rinck; Licensed MIT
*/
Expand Down
4 changes: 2 additions & 2 deletions build/angular-growl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-growl",
"version": "0.3.1",
"version": "0.4.0",
"description": "growl like notifications for angularJS projects, using bootstrap alert classes",
"repository": {
"type": "git",
Expand Down

0 comments on commit 9eb745a

Please sign in to comment.