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