notifications only when not focused

This commit is contained in:
Rodolphe Breard 2013-01-13 22:21:44 +01:00
parent 6b898144c5
commit aed665f361

View file

@ -16,6 +16,7 @@
var Nsui = function() { var Nsui = function() {
this.tab_lst = []; this.tab_lst = [];
this.focus = false;
}; };
Nsui.prototype.setReconnect = function(func) { Nsui.prototype.setReconnect = function(func) {
@ -99,14 +100,17 @@ Nsui.prototype.addContentToTab = function(tab_name, content) {
tab = this.addNewTab(tab_name); tab = this.addNewTab(tab_name);
tab.appendMessage(content); tab.appendMessage(content);
if (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(url) {
var notif = webkitNotifications.createNotification( var notif = webkitNotifications.createNotification(
url, url,
content.login, content.login,
content.message.substr(0, 24) content.message.substr(0, 24)
); );
console.log(notif); notif.onclick = function() {
window.focus();
this.cancel();
};
notif.show(); notif.show();
setTimeout(function() { setTimeout(function() {
notif.cancel(); notif.cancel();
@ -167,6 +171,17 @@ Nsui.prototype.switchContent = function(part_id, part_id_to) {
} }
Nsui.prototype.init = function() { Nsui.prototype.init = function() {
window.onfocus = (function(elem) {
return function() {
elem.focus = true;
};
})(this);
window.onblur = (function(elem) {
return function() {
elem.focus = false;
};
})(this);
document.getElementById("settings-btn").addEventListener("click", (function(elem) { document.getElementById("settings-btn").addEventListener("click", (function(elem) {
return function() { return function() {
elem.switchContent("config-pannel", "chat-pannel"); elem.switchContent("config-pannel", "chat-pannel");