diff --git a/lib/nsui.js b/lib/nsui.js index a9bed56..bdc35ae 100644 --- a/lib/nsui.js +++ b/lib/nsui.js @@ -107,6 +107,30 @@ Nsui.prototype.addNewTab = function(tab_name) { return tab; }; +Nsui.prototype.sendNotification = function(image, title, message) { + var notif; + + if (message.lenght > 32) { + message = message.substr(0, 32) + "…"; + } + + notif = webkitNotifications.createNotification( + image, + title, + message + ); + + notif.onclick = function() { + window.focus(); + this.cancel(); + }; + + notif.show(); + setTimeout(function() { + notif.cancel(); + }, 5000); +} + Nsui.prototype.addContentToTab = function(tab_name, content) { var tab = null; @@ -115,21 +139,11 @@ Nsui.prototype.addContentToTab = function(tab_name, content) { tab.appendMessage(content); if (!this.focus && typeof content.login !== "undefined" && content.login !== null && $cs.opts.get("enable_notif")) { - $cs.avatars.get(content.login, function(url) { - var notif = webkitNotifications.createNotification( - url, - content.login, - content.message.substr(0, 24) - ); - notif.onclick = function() { - window.focus(); - this.cancel(); + $cs.avatars.get(content.login, (function(elem) { + return function(url) { + elem.sendNotification(url, content.login, content.message); }; - notif.show(); - setTimeout(function() { - notif.cancel(); - }, 5000); - }); + })(this)); } } };