Document title changes on activity
authorDarren <darren@darrenwhitlen.com>
Sun, 7 Oct 2012 18:41:24 +0000 (19:41 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 7 Oct 2012 18:41:24 +0000 (19:41 +0100)
client_backbone/dev/model_panel.js
client_backbone/dev/view.js

index a14724b2149737e08e76e0ae478b6c7cba8195ce..1b05f89c0206a987b800ac320c0093132c81663d 100755 (executable)
@@ -98,5 +98,9 @@ kiwi.model.Panel = Backbone.Model.extend({
 \r
     isServer: function () {\r
         return this.server ? true : false;\r
+    },\r
+\r
+    isActive: function () {\r
+        return (kiwi.app.panels.active === this);\r
     }\r
 });
\ No newline at end of file
index f8106d5b1c82e75b4e88ae3a15e59eafbd6b89c9..8307ff799c17e5262e5ccb11953842a5fda87fad 100755 (executable)
@@ -317,11 +317,17 @@ kiwi.view.Panel = Backbone.View.extend({
         line_msg = '<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';\r
         $this.append(_.template(line_msg, msg));\r
 \r
+        // Activity/alerts based on the type of new message\r
         if (msg.type.match(/^action /)) {\r
             this.alert('action');\r
         } else if (msg.msg.indexOf(kiwi.gateway.get('nick')) > -1) {\r
+            kiwi.app.view.alertWindow('* People are talking!');\r
             this.alert('highlight');\r
         } else {\r
+            // If this is the active panel, send an alert out\r
+            if (this.model.isActive()) {\r
+                kiwi.app.view.alertWindow('* People are talking!');\r
+            }\r
             this.alert('activity');\r
         }\r
 \r
@@ -908,6 +914,77 @@ kiwi.view.Application = Backbone.View.extend({
     },\r
 \r
 \r
+    alertWindow: function (title) {\r
+        if (!this.alertWindowTimer) {\r
+            this.alertWindowTimer = new (function () {\r
+                var that = this;\r
+                var tmr;\r
+                var has_focus = true;\r
+                var state = 0;\r
+                var default_title = 'Kiwi IRC';\r
+                var title = 'Kiwi IRC';\r
+\r
+                this.setTitle = function (new_title) {\r
+                    new_title = new_title || default_title;\r
+                    window.document.title = new_title;\r
+                    return new_title;\r
+                };\r
+\r
+                this.start = function (new_title) {\r
+                    // Don't alert if we already have focus\r
+                    if (has_focus) return;\r
+\r
+                    title = new_title;\r
+                    if (tmr) return;\r
+                    tmr = setInterval(this.update, 1000);\r
+                };\r
+\r
+                this.stop = function () {\r
+                    // Stop the timer and clear the title\r
+                    if (tmr) clearInterval(tmr);\r
+                    tmr = null;\r
+                    this.setTitle();\r
+\r
+                    // Some browsers don't always update the last title correctly\r
+                    // Wait a few seconds and then reset\r
+                    setTimeout(this.reset, 2000);\r
+                };\r
+\r
+                this.reset = function () {\r
+                    if (tmr) return;\r
+                    that.setTitle();\r
+                };\r
+\r
+\r
+                this.update = function () {\r
+                    if (state === 0) {\r
+                        that.setTitle(title);\r
+                        state = 1;\r
+                    } else {\r
+                        that.setTitle();\r
+                        state = 0;\r
+                    }\r
+                };\r
+\r
+                $(window).focus(function (event) {\r
+                    has_focus = true;\r
+                    that.stop();\r
+\r
+                    // Some browsers don't always update the last title correctly\r
+                    // Wait a few seconds and then reset\r
+                    setTimeout(this.reset, 2000);\r
+                });\r
+\r
+                $(window).blur(function (event) {\r
+                    has_focus = false;\r
+                });\r
+            })();\r
+        }\r
+\r
+        this.alertWindowTimer.start(title);\r
+    },\r
+\r
+\r
     barsHide: function (instant) {\r
         var that = this;\r
 \r