From 99138b171a71bcab3cbd0e957e43e70cf314f045 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Tue, 17 Apr 2018 10:30:34 -0700 Subject: [PATCH] Fix: trigger group card on a post's primary group click --- .../discourse/components/user-card-contents.js.es6 | 9 ++++++++- .../javascripts/discourse/widgets/poster-name.js.es6 | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/user-card-contents.js.es6 b/app/assets/javascripts/discourse/components/user-card-contents.js.es6 index da9f8dfdda1..61d34e36a6e 100644 --- a/app/assets/javascripts/discourse/components/user-card-contents.js.es6 +++ b/app/assets/javascripts/discourse/components/user-card-contents.js.es6 @@ -11,6 +11,7 @@ const clickOutsideEventName = "mousedown.outside-user-card"; const clickDataExpand = "click.discourse-user-card"; const clickMention = "click.discourse-user-mention"; const groupClickMention = "click.discourse-group-mention"; +const groupClickDataExpand = "click.discourse-group-card" const maxMembersToDisplay = 10; @@ -162,6 +163,12 @@ export default Ember.Component.extend(CleansUp, { return this._show($target.text().replace(/^@/, ''), $target, 'user'); }); + $('#main-outlet').on(groupClickDataExpand, '[data-group-card]', (e) => { + if (wantsNewWindow(e)) { return; } + const $target = $(e.currentTarget); + return this._show($target.data('group-card'), $target, 'group'); + }); + $('#main-outlet').on(groupClickMention, 'a.mention-group', (e) => { if (wantsNewWindow(e)) { return; } const $target = $(e.target); @@ -247,7 +254,7 @@ export default Ember.Component.extend(CleansUp, { willDestroyElement() { this._super(); $('html').off(clickOutsideEventName); - $('#main').off(clickDataExpand).off(clickMention).off(groupClickMention); + $('#main').off(clickDataExpand).off(clickMention).off(groupClickMention).off(groupClickDataExpand); }, actions: { diff --git a/app/assets/javascripts/discourse/widgets/poster-name.js.es6 b/app/assets/javascripts/discourse/widgets/poster-name.js.es6 index 5a93ab9fd1e..3fc5c0ee2af 100644 --- a/app/assets/javascripts/discourse/widgets/poster-name.js.es6 +++ b/app/assets/javascripts/discourse/widgets/poster-name.js.es6 @@ -14,7 +14,7 @@ createWidget('poster-name-title', { let titleContents = attrs.title; if (attrs.primaryGroupName) { const href = Discourse.getURL(`/groups/${attrs.primaryGroupName}`); - titleContents = h('a.user-group', { className: attrs.extraClasses, attributes: { href } }, attrs.title); + titleContents = h('a.user-group', { className: attrs.extraClasses, attributes: { href, 'data-group-card': attrs.primaryGroupName } }, attrs.title); } return titleContents; }