From 3499d6258426b0f11e1db400066eac16e0a3b124 Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 4 Sep 2013 19:34:44 +0100 Subject: [PATCH] Channel/query specific events moved out of panel view --- client/assets/src/views/channel.js | 73 ++++++++++++++++++++++++++++-- client/assets/src/views/panel.js | 61 ------------------------- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/client/assets/src/views/channel.js b/client/assets/src/views/channel.js index 846a3e2..2e3e8fd 100644 --- a/client/assets/src/views/channel.js +++ b/client/assets/src/views/channel.js @@ -1,12 +1,16 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ events: function(){ var parent_events = _kiwi.view.Panel.prototype.events; - + if(_.isFunction(parent_events)){ parent_events = parent_events(); } return _.extend({}, parent_events, { - 'click .msg .nick' : 'nickClick' + 'click .msg .nick' : 'nickClick', + "click .chan": "chanClick", + 'click .media .open': 'mediaClick', + 'mouseenter .msg .nick': 'msgEnter', + 'mouseleave .msg .nick': 'msgLeave' }); }, @@ -89,5 +93,68 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ }).call(this); } } - } + }, + + + chanClick: function (event) { + if (event.target) { + _kiwi.gateway.join(null, $(event.target).data('channel')); + } else { + // IE... + _kiwi.gateway.join(null, $(event.srcElement).data('channel')); + } + }, + + + mediaClick: function (event) { + var $media = $(event.target).parents('.media'); + var media_message; + + if ($media.data('media')) { + media_message = $media.data('media'); + } else { + media_message = new _kiwi.view.MediaMessage({el: $media[0]}); + + // Cache this MediaMessage instance for when it's opened again + $media.data('media', media_message); + } + + media_message.toggle(); + }, + + + // Cursor hovers over a message + msgEnter: function (event) { + var nick_class; + + // Find a valid class that this element has + _.each($(event.currentTarget).parent('.msg').attr('class').split(' '), function (css_class) { + if (css_class.match(/^nick_[a-z0-9]+/i)) { + nick_class = css_class; + } + }); + + // If no class was found.. + if (!nick_class) return; + + $('.'+nick_class).addClass('global_nick_highlight'); + }, + + + // Cursor leaves message + msgLeave: function (event) { + var nick_class; + + // Find a valid class that this element has + _.each($(event.currentTarget).parent('.msg').attr('class').split(' '), function (css_class) { + if (css_class.match(/^nick_[a-z0-9]+/i)) { + nick_class = css_class; + } + }); + + // If no class was found.. + if (!nick_class) return; + + $('.'+nick_class).removeClass('global_nick_highlight'); + }, }); diff --git a/client/assets/src/views/panel.js b/client/assets/src/views/panel.js index fefde49..5cb4879 100644 --- a/client/assets/src/views/panel.js +++ b/client/assets/src/views/panel.js @@ -3,10 +3,6 @@ _kiwi.view.Panel = Backbone.View.extend({ className: "panel messages", events: { - "click .chan": "chanClick", - 'click .media .open': 'mediaClick', - 'mouseenter .msg .nick': 'msgEnter', - 'mouseleave .msg .nick': 'msgLeave' }, initialize: function (options) { @@ -177,64 +173,7 @@ _kiwi.view.Panel = Backbone.View.extend({ this.msg_count--; } }, - chanClick: function (event) { - if (event.target) { - _kiwi.gateway.join(null, $(event.target).data('channel')); - } else { - // IE... - _kiwi.gateway.join(null, $(event.srcElement).data('channel')); - } - }, - - mediaClick: function (event) { - var $media = $(event.target).parents('.media'); - var media_message; - - if ($media.data('media')) { - media_message = $media.data('media'); - } else { - media_message = new _kiwi.view.MediaMessage({el: $media[0]}); - // Cache this MediaMessage instance for when it's opened again - $media.data('media', media_message); - } - - media_message.toggle(); - }, - - // Cursor hovers over a message - msgEnter: function (event) { - var nick_class; - - // Find a valid class that this element has - _.each($(event.currentTarget).parent('.msg').attr('class').split(' '), function (css_class) { - if (css_class.match(/^nick_[a-z0-9]+/i)) { - nick_class = css_class; - } - }); - - // If no class was found.. - if (!nick_class) return; - - $('.'+nick_class).addClass('global_nick_highlight'); - }, - - // Cursor leaves message - msgLeave: function (event) { - var nick_class; - - // Find a valid class that this element has - _.each($(event.currentTarget).parent('.msg').attr('class').split(' '), function (css_class) { - if (css_class.match(/^nick_[a-z0-9]+/i)) { - nick_class = css_class; - } - }); - - // If no class was found.. - if (!nick_class) return; - - $('.'+nick_class).removeClass('global_nick_highlight'); - }, show: function () { var $this = this.$el; -- 2.25.1