notifications fix

This commit is contained in:
Rodolphe Breard 2013-01-26 21:21:29 +01:00
parent 048d8cb394
commit 077a7d054a

View file

@ -107,6 +107,30 @@ Nsui.prototype.addNewTab = function(tab_name) {
return tab; 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) { Nsui.prototype.addContentToTab = function(tab_name, content) {
var tab = null; var tab = null;
@ -115,21 +139,11 @@ Nsui.prototype.addContentToTab = function(tab_name, content) {
tab.appendMessage(content); tab.appendMessage(content);
if (!this.focus && typeof content.login !== "undefined" && content.login !== null && $cs.opts.get("enable_notif")) { if (!this.focus && typeof content.login !== "undefined" && content.login !== null && $cs.opts.get("enable_notif")) {
$cs.avatars.get(content.login, function(url) { $cs.avatars.get(content.login, (function(elem) {
var notif = webkitNotifications.createNotification( return function(url) {
url, elem.sendNotification(url, content.login, content.message);
content.login,
content.message.substr(0, 24)
);
notif.onclick = function() {
window.focus();
this.cancel();
}; };
notif.show(); })(this));
setTimeout(function() {
notif.cancel();
}, 5000);
});
} }
} }
}; };