From 47e9e963fd7efb4be000a7fef624b5aba154290b Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 17 Sep 2014 22:04:47 +0200 Subject: [PATCH] Remember state of chat room sidebar. --- converse.js | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/converse.js b/converse.js index 6dbc54271..19fa498be 100644 --- a/converse.js +++ b/converse.js @@ -1060,26 +1060,6 @@ this.scrollDown(); }, - toggleParticipants: function (ev) { - if (ev) { - ev.preventDefault(); - ev.stopPropagation(); - } - var $el = $(ev.target); - if ($el.hasClass("icon-hide-users")) { - $el.removeClass('icon-hide-users').addClass('icon-show-users'); - this.$('div.participants').animate({width: 0}).hide(); - this.$('.chat-area').animate({width: '100%'}); - this.$('form.sendXMPPMessage').animate({width: '100%'}); - } else { - $el.removeClass('icon-show-users').addClass('icon-hide-users'); - this.$('.chat-area').animate({width: '200px'}, $.proxy(function () { - this.$('div.participants').css({width: '100px'}).show(); - }, this)); - this.$('form.sendXMPPMessage').animate({width: '200px'}); - } - }, - clearChatRoomMessages: function (ev) { ev.stopPropagation(); var result = confirm(__("Are you sure you want to clear the messages from this room?")); @@ -2180,7 +2160,7 @@ 'click .toggle-smiley': 'toggleEmoticonMenu', 'click .toggle-smiley ul li': 'insertEmoticon', 'click .toggle-clear': 'clearChatRoomMessages', - 'click .toggle-participants a': 'toggleParticipants', + 'click .toggle-participants a': 'toggleOccupants', 'keypress textarea.chat-textarea': 'keyPressed', 'mousedown .dragresize-tm': 'onDragResizeStart' }, @@ -2245,9 +2225,36 @@ .append(this.occupantsview.render().$el); this.renderToolbar(); } + // XXX: This is a bit of a hack, to make sure that the + // sidebar's state is remembered. + this.model.set({hidden_occupants: !this.model.get('hidden_occupants')}); + this.toggleOccupants(); return this; }, + toggleOccupants: function (ev) { + if (ev) { + ev.preventDefault(); + ev.stopPropagation(); + } + var $el = this.$('.icon-hide-users'); + if (!this.model.get('hidden_occupants')) { + this.model.save({hidden_occupants: true}); + $el.removeClass('icon-hide-users').addClass('icon-show-users'); + this.$('div.participants').animate({width: 0}).hide(); + this.$('.chat-area').animate({width: '100%'}); + this.$('form.sendXMPPMessage').animate({width: '100%'}); + } else { + this.model.save({hidden_occupants: false}); + $el.removeClass('icon-show-users').addClass('icon-hide-users'); + this.$('.chat-area').animate({width: '200px'}, $.proxy(function () { + this.$('div.participants').css({width: '100px'}).show(); + }, this)); + this.$('form.sendXMPPMessage').animate({width: '200px'}); + } + }, + + onCommandError: function (stanza) { this.showStatusNotification(__("Error: could not execute the command"), true); },