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