From: Darren Date: Mon, 17 Sep 2012 20:51:40 +0000 (+0100) Subject: Highlights/activity alerts X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0fc0605dcb437048daced6ba230b6258d82a9b25;p=KiwiIRC.git Highlights/activity alerts --- diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 4e0be2a..620149a 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -154,6 +154,9 @@ kiwi.view.Panel = Backbone.View.extend({ "click .chan": "chanClick" }, + // none=0, action=1, activity=2, highlight=3 + alert_level: 0, + // The container this panel is within $container: null, @@ -238,6 +241,14 @@ kiwi.view.Panel = Backbone.View.extend({ line_msg = '
<%- time %>
<%- nick %>
<%= msg %>
'; $this.append(_.template(line_msg, msg)); + if (msg.type === 'action') { + this.alert('action'); + } else if (msg.msg.indexOf(kiwi.gateway.get('nick')) > -1) { + this.alert('highlight'); + } else { + this.alert('activity'); + } + this.scrollToBottom(); // Make sure our DOM isn't getting too large (Acts as scrollback) @@ -270,12 +281,50 @@ kiwi.view.Panel = Backbone.View.extend({ } this.scrollToBottom(); + this.alert('none'); this.trigger('active', this.model); kiwi.app.panels.trigger('active', this.model); }, + alert: function (level) { + // No need to highlight if this si the active panel + if (this.model == kiwi.app.panels.active) return; + + var types, type_idx; + var types = ['none', 'action', 'activity', 'highlight']; + + // Default alert level + level = level || 'none'; + + // If this alert level does not exist, assume clearing current level + type_idx = _.indexOf(types, level); + if (!type_idx) { + level = 'none'; + type_idx = 0; + } + + // Only 'upgrade' the alert. Never down (unless clearing) + console.log(type_idx, this.alert_level); + if (type_idx !== 0 && type_idx <= this.alert_level) { + return; + } + + // Clear any existing levels + this.model.tab.removeClass(function (i, css) { + return (css.match (/\balert_\S+/g) || []).join(' '); + }); + + // Add the new level if there is one + if (level !== 'none') { + this.model.tab.addClass('alert_' + level); + } + + this.alert_level = type_idx; + }, + + // Scroll to the bottom of the panel scrollToBottom: function () { // TODO: Don't scroll down if we're scrolled up the panel a little diff --git a/client_backbone/style.css b/client_backbone/style.css index c99e091..4274484 100644 --- a/client_backbone/style.css +++ b/client_backbone/style.css @@ -62,11 +62,11 @@ a { color:#36C; text-decoration:none; cursor:pointer; } ); } #toolbar .panellist .active { padding-right:23px; } -#toolbar .panellist .highlight { +#toolbar .panellist .alert_highlight { background: #990000; font-weight: bold; } -#toolbar .panellist .activity { font-weight: bold; background: #009900; } +#toolbar .panellist .alert_activity { font-weight: bold; background: #009900; } #toolbar .panellist li img { width:1em; height:1em; top:7px; right:5px; position:absolute; } #toolbar .panellist li img.icon { left:5px; top:2px; height:auto; width:auto; }