notifications fix
This commit is contained in:
parent
048d8cb394
commit
077a7d054a
1 changed files with 28 additions and 14 deletions
42
lib/nsui.js
42
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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Reference in a new issue