From 145389ffe8200aa4d77e168c209104e946caa01d Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 7 Oct 2012 19:41:24 +0100 Subject: [PATCH] Document title changes on activity --- client_backbone/dev/model_panel.js | 4 ++ client_backbone/dev/view.js | 77 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/client_backbone/dev/model_panel.js b/client_backbone/dev/model_panel.js index a14724b..1b05f89 100755 --- a/client_backbone/dev/model_panel.js +++ b/client_backbone/dev/model_panel.js @@ -98,5 +98,9 @@ kiwi.model.Panel = Backbone.Model.extend({ isServer: function () { return this.server ? true : false; + }, + + isActive: function () { + return (kiwi.app.panels.active === this); } }); \ No newline at end of file diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index f8106d5..8307ff7 100755 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -317,11 +317,17 @@ kiwi.view.Panel = Backbone.View.extend({ line_msg = '
<%- time %>
<%- nick %>
<%= msg %>
'; $this.append(_.template(line_msg, msg)); + // Activity/alerts based on the type of new message if (msg.type.match(/^action /)) { this.alert('action'); } else if (msg.msg.indexOf(kiwi.gateway.get('nick')) > -1) { + kiwi.app.view.alertWindow('* People are talking!'); this.alert('highlight'); } else { + // If this is the active panel, send an alert out + if (this.model.isActive()) { + kiwi.app.view.alertWindow('* People are talking!'); + } this.alert('activity'); } @@ -908,6 +914,77 @@ kiwi.view.Application = Backbone.View.extend({ }, + alertWindow: function (title) { + if (!this.alertWindowTimer) { + this.alertWindowTimer = new (function () { + var that = this; + var tmr; + var has_focus = true; + var state = 0; + var default_title = 'Kiwi IRC'; + var title = 'Kiwi IRC'; + + this.setTitle = function (new_title) { + new_title = new_title || default_title; + window.document.title = new_title; + return new_title; + }; + + this.start = function (new_title) { + // Don't alert if we already have focus + if (has_focus) return; + + title = new_title; + if (tmr) return; + tmr = setInterval(this.update, 1000); + }; + + this.stop = function () { + // Stop the timer and clear the title + if (tmr) clearInterval(tmr); + tmr = null; + this.setTitle(); + + // Some browsers don't always update the last title correctly + // Wait a few seconds and then reset + setTimeout(this.reset, 2000); + }; + + this.reset = function () { + if (tmr) return; + that.setTitle(); + }; + + + this.update = function () { + if (state === 0) { + that.setTitle(title); + state = 1; + } else { + that.setTitle(); + state = 0; + } + }; + + $(window).focus(function (event) { + has_focus = true; + that.stop(); + + // Some browsers don't always update the last title correctly + // Wait a few seconds and then reset + setTimeout(this.reset, 2000); + }); + + $(window).blur(function (event) { + has_focus = false; + }); + })(); + } + + this.alertWindowTimer.start(title); + }, + + barsHide: function (instant) { var that = this; -- 2.25.1