Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 953ecc0

Browse files
committed
hiding chat settings menu on click outside of it
1 parent 0717983 commit 953ecc0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

js/templates/chatConversation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</div>
1212
</div>
1313

14-
<div class="chatConversationMenu hide">
14+
<div class="chatConversationMenu js-chatSettingsMenu hide">
1515
<div>
1616
<a class="js-clearConvo"><%= polyglot.t('ClearConvo') %></a>
1717
</div>

js/views/chatConversationVw.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ module.exports = baseVw.extend({
8282
this.scrollHandler = __.bind(
8383
__.throttle(this.onScroll, 100), this
8484
);
85+
86+
87+
$(document).on('click', this.onDocumentClick.bind(this));
88+
},
89+
90+
onDocumentClick: function(e) {
91+
if (
92+
e.target !== this.$settingsMenu[0] &&
93+
!$(e.target).parents('.js-chatSettingsMenu').length
94+
) {
95+
this.closeConvoSettings();
96+
}
8597
},
8698

8799
onScroll: function(e) {
@@ -148,11 +160,13 @@ module.exports = baseVw.extend({
148160
},
149161

150162
closeConvoSettings: function() {
151-
this.$('.chatConversationMenu').addClass('hide');
163+
this.$settingsMenu.addClass('hide');
152164
},
153165

154166
toggleConvoSettings: function() {
155-
this.$('.chatConversationMenu').toggleClass('hide');
167+
this.$settingsMenu.toggleClass('hide');
168+
169+
return false;
156170
},
157171

158172
onBlockClick: function() {
@@ -232,6 +246,7 @@ module.exports = baseVw.extend({
232246
this.$loadingSpinner = this.$messagesScrollContainer.find('.js-loadingSpinner');
233247
this.$messagesContainer = this.$messagesScrollContainer.find('.js-messagesContainer');
234248
this.$msgTextArea = this.$('textarea');
249+
this.$settingsMenu = this.$('.js-chatSettingsMenu');
235250

236251
if (this.collection.length) {
237252
this.collection.forEach((md) => {
@@ -252,6 +267,7 @@ module.exports = baseVw.extend({
252267

253268
remove: function() {
254269
this.$scrollContainer && this.$scrollContainer.off('scroll', this.scrollHandler);
270+
$(document).off('click', this.onDocumentClick);
255271

256272
baseVw.prototype.remove.apply(this, arguments);
257273
}

js/views/chatVw.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,11 @@ module.exports = baseVw.extend({
428428
},
429429

430430
closeConversation: function() {
431+
console.log('close convo yo');
431432
this.$('.chatConversationHeads').removeClass('chatConversationHeadsCompressed textOpacity50');
432433
this.$('.chatSearch').removeClass('textOpacity50');
433434
this.$convoContainer.addClass('chatConversationContainerHide');
435+
434436
if (this.chatConversationVw) {
435437
this.chatConversationVw.closeConvoSettings();
436438
}

0 commit comments

Comments
 (0)