nicklist:select renamed nick:select; inline nicks using same plugins hooks as nicklis...
authorDarren <darren@darrenwhitlen.com>
Fri, 28 Nov 2014 17:51:33 +0000 (17:51 +0000)
committerDarren <darren@darrenwhitlen.com>
Fri, 28 Nov 2014 17:51:33 +0000 (17:51 +0000)
client/src/views/channel.js
client/src/views/memberlist.js

index af132165dd4510687d4c1e1e93a1e257d74d63d8..8e0e5b5cda25421f3d3450dd7ed1bcadc5bd92ba 100644 (file)
@@ -376,51 +376,71 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
 
     // Click on a nickname
     nickClick: function (event) {
-        var nick,
+        var $target = $(event.currentTarget),
+            nick,
             members = this.model.get('members'),
-            are_we_an_op = !!members.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op'),
-            member, query, userbox, menubox;
+            member;
 
         event.stopPropagation();
 
         // Check this current element for a nick before resorting to the main message
         // (eg. inline nicks has the nick on its own element within the message)
-        nick = $(event.currentTarget).data('nick');
+        nick = $target.data('nick');
         if (!nick) {
-            nick = $(event.currentTarget).parent('.msg').data('message').nick;
+            nick = $target.parent('.msg').data('message').nick;
         }
 
-        if (members) {
-            member = members.getByNick(nick);
-            if (member) {
-                userbox = new _kiwi.view.UserBox();
-                userbox.setTargets(member, this.model);
-                userbox.displayOpItems(are_we_an_op);
-
-                menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User');
-                menubox.addItem('userbox', userbox.$el);
-                menubox.showFooter(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);
-            }
+        // Make sure this nick is still in the channel
+        member = members ? members.getByNick(nick) : null;
+        if (!member) {
+            return;
         }
+
+        _kiwi.global.events.emit('nick:select', {target: $target, member: member, source: 'message'})
+        .then(_.bind(this.openUserMenuForNick, this, $target, member));
+    },
+
+
+    openUserMenuForNick: function ($target, member) {
+        var members = this.model.get('members'),
+            are_we_an_op = !!members.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op'),
+            userbox, menubox;
+
+        userbox = new _kiwi.view.UserBox();
+        userbox.setTargets(member, this.model);
+        userbox.displayOpItems(are_we_an_op);
+
+        menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User');
+        menubox.addItem('userbox', userbox.$el);
+        menubox.showFooter(false);
+
+        _kiwi.global.events.emit('usermenu:created', {menu: menu, userbox: userbox})
+        .then(_.bind(function() {
+            menubox.show();
+
+            // Position the userbox + menubox
+            var target_offset = $target.offset(),
+                t = target_offset.top,
+                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: target_offset.left,
+                top: t
+            });
+        }, this))
+        .catch(_.bind(function() {
+            userbox = null;
+
+            menu.dispose();
+            menu = null;
+        }, this));
     },
 
 
index 817d84bd88517a5a4529d57f431514676bf12bc9..742446721d46a2acb6da05b257b6a17dd28dc8ff 100644 (file)
@@ -41,7 +41,7 @@ _kiwi.view.MemberList = Backbone.View.extend({
         var $target = $(event.currentTarget).parent('li'),
             member = $target.data('member');
 
-        _kiwi.global.events.emit('nicklist:select', {target: $target, member: member})
+        _kiwi.global.events.emit('nick:select', {target: $target, member: member, source: 'nicklist'})
         .then(_.bind(this.openUserMenuForItem, this, $target));
     },