From aed665f36196b9cebe9f4e608a72ac189082850c Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 13 Jan 2013 22:21:44 +0100 Subject: [PATCH] notifications only when not focused --- lib/nsui.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/nsui.js b/lib/nsui.js index cf3bc32..62da932 100644 --- a/lib/nsui.js +++ b/lib/nsui.js @@ -16,6 +16,7 @@ var Nsui = function() { this.tab_lst = []; + this.focus = false; }; Nsui.prototype.setReconnect = function(func) { @@ -99,14 +100,17 @@ Nsui.prototype.addContentToTab = function(tab_name, content) { tab = this.addNewTab(tab_name); 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) { var notif = webkitNotifications.createNotification( url, content.login, content.message.substr(0, 24) ); - console.log(notif); + notif.onclick = function() { + window.focus(); + this.cancel(); + }; notif.show(); setTimeout(function() { notif.cancel(); @@ -167,6 +171,17 @@ Nsui.prototype.switchContent = function(part_id, part_id_to) { } 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) { return function() { elem.switchContent("config-pannel", "chat-pannel");