Make nicks clickable to bring up the userbox
authorJack Allnutt <m2ys4u@gmail.com>
Fri, 24 May 2013 22:04:35 +0000 (23:04 +0100)
committerJack Allnutt <m2ys4u@gmail.com>
Fri, 24 May 2013 22:04:35 +0000 (23:04 +0100)
Fixes #75

client/assets/src/views/channel.js

index 9136cee20665bb8ca4f505dd0c70f8405f12cf4f..8fd648a585a6b10cb19cb38fa6b1d54c5fb05fd5 100644 (file)
@@ -1,4 +1,8 @@
 _kiwi.view.Channel = _kiwi.view.Panel.extend({
+    events: {
+        'click .msg .nick': 'nickClick'
+    },
+
     initialize: function (options) {
         this.initializePanel(options);
         this.model.bind('change:topic', this.topic, this);
@@ -29,5 +33,47 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         if (_kiwi.app.panels().active === this) {
             _kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));
         }
+    },
+
+    // Click on a nickname
+    nickClick: function (event) {
+        var nick = $(event.currentTarget).text(),
+            members = this.model.get('members'),
+            member, query, userbox, menubox;
+
+        if (members) {
+            member = members.getByNick(nick);
+            if (member) {
+                $('.userbox').remove();
+                userbox = new _kiwi.view.UserBox();
+                userbox.member = member;
+                userbox.channel = this.model;
+
+                if (!member.get('is_op')) {
+                    userbox.$el.children('.if_op').remove();
+                }
+                menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User');
+                menubox.addItem('userbox', userbox.$el);
+                menubox.closeOnBlur(false);
+                menubox.show();
+                // Position the userbox + menubox
+                (function() {
+                    var t = event.pageY,
+                        m_bottom = t + menubox.$el.outerHeight(),  // Where the bottom of menu will be
+                        memberlist_bottom = this.$el.parent().offset().top + this.$el.parent().outerHeight();
+
+                    // If the bottom of the userbox is going to be too low.. raise it
+                    if (m_bottom > memberlist_bottom){
+                        t = memberlist_bottom - menubox.$el.outerHeight();
+                    }
+
+                    // Set the new positon
+                    menubox.$el.offset({
+                        left: event.clientX,
+                        top: t
+                    });
+                }).call(this);
+            }
+        }
     }
-});
\ No newline at end of file
+});