Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- Fixed issue with destroying messages that are in preloadedDirectives
- Fixed issue with adding messages to preloadedDirective
- Updated factory.general to return the message
  • Loading branch information
flippinjoe committed Jun 17, 2015
1 parent 1941def commit a6db2cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/growlFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ angular.module("angular-growl").provider("growl", function () {
*/
function general (text, config, severity) {
severity = (severity || "error").toLowerCase();
sendMessage(text, config, severity);
return sendMessage(text, config, severity);
}

/**
Expand Down
21 changes: 15 additions & 6 deletions src/growlMessageService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', function ($sce, $timeout) {
"use strict";

var self = this;
this.directives = {};
var preloadDirectives = {};

Expand All @@ -22,6 +23,11 @@ angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', fu
return directive;
}

function directiveForRefId(referenceId) {
var refId = referenceId || 0;
return (self.directives[refId] || preloadDirectives[refId]);
}

/**
* Initialize a directive
* We look at the preloaded directive and use this else we
Expand All @@ -47,8 +53,8 @@ angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', fu
this.getAllMessages = function (referenceId) {
referenceId = referenceId || 0;
var messages;
if (this.directives[referenceId]) {
messages = this.directives[referenceId].messages;
if (directiveForRefId(referenceId)) {
messages = directiveForRefId(referenceId).messages;
} else {
messages = [];
}
Expand All @@ -60,8 +66,10 @@ angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', fu
for (var i = messages.length - 1; i >= 0; i--) {
messages[i].destroy();
}
if (this.directives[referenceId]) {
this.directives[referenceId].messages = [];

var directive = directiveForRefId(referenceId);
if (directive) {
directive.messages = [];
}
};

Expand Down Expand Up @@ -130,8 +138,9 @@ angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', fu

if (message.ttl && message.ttl !== -1) {
//adds message timeout to promises and starts messages countdown function.
var self = this;
message.promises.push($timeout(angular.bind(this, function () {
this.deleteMessage(message);
self.deleteMessage(message);
}), message.ttl));
message.promises.push($timeout(message.countdownFunction, 1000));
}
Expand All @@ -140,7 +149,7 @@ angular.module("angular-growl").service("growlMessages", ['$sce', '$timeout', fu
};

this.deleteMessage = function (message) {
var messages = this.directives[message.referenceId].messages,
var messages = this.getAllMessages(message.referenceId),
index = messages.indexOf(message);
if (index > -1) {
messages[index].close = true;
Expand Down

0 comments on commit a6db2cd

Please sign in to comment.