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;
};
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));
}
}
};