diff --git a/converse.js b/converse.js index e5d580381..de4ab6c5d 100644 --- a/converse.js +++ b/converse.js @@ -1269,8 +1269,9 @@ ) ) ); + this.$content = this.$el.find('.chat-content'); this.renderToolbar().renderAvatar(); - this.$el.find('.chat-content').on('scroll', _.debounce(this.onScroll.bind(this), 100)); + this.$content.on('scroll', _.debounce(this.onScroll.bind(this), 100)); converse.emit('chatBoxOpened', this); setTimeout(converse.refreshWebkit, 50); return this.showStatusMessage(); @@ -1281,7 +1282,7 @@ if ($(ev.target).scrollTop() === 0) { oldest = this.model.messages.where({'time': this.model.messages.pluck('time').sort()[0]}); if (oldest) { - this.$el.find('.chat-content').prepend(''); + this.$content.prepend(''); this.fetchArchivedMessages({ 'before': oldest[0].get('archive_id'), 'with': this.model.get('jid'), @@ -1368,11 +1369,10 @@ }, showStatusNotification: function (message, keep_old) { - var $chat_content = this.$el.find('.chat-content'); if (!keep_old) { - $chat_content.find('div.chat-event').remove(); + this.$content.find('div.chat-event').remove(); } - $chat_content.append($('
').text(message)); + this.$content.append($('').text(message)); this.scrollDown(); }, @@ -1380,27 +1380,25 @@ if (typeof ev !== "undefined") { ev.stopPropagation(); } var result = confirm(__("Are you sure you want to clear the messages from this room?")); if (result === true) { - this.$el.find('.chat-content').empty(); + this.$content.empty(); } return this; }, clearSpinner: function () { - var $content = this.$el.find('.chat-content'); - if ($content.children(':first').is('span.spinner')) { - $content.children(':first').first().remove(); + if (this.$content.children(':first').is('span.spinner')) { + this.$content.children(':first').first().remove(); } }, showMessage: function (msg_dict) { - var $content = this.$el.find('.chat-content'), - msg_time = moment(msg_dict.time) || moment, + var msg_time = moment(msg_dict.time) || moment, text = msg_dict.message, match = text.match(/^\/(.*?)(?: (.*))?$/), fullname = this.model.get('fullname') || msg_dict.fullname, extra_classes = msg_dict.delayed && 'delayed' || '', num_messages = this.model.messages.length, - has_scrollbar = $content.get(0).scrollHeight > $content[0].clientHeight, + has_scrollbar = this.$content.get(0).scrollHeight > this.$content[0].clientHeight, template, username, insertMessage; // FIXME: A better approach here is probably to look at what is @@ -1412,12 +1410,12 @@ insertMessage = _.compose( this.scrollDownMessageHeight.bind(this), function ($el) { - $content.prepend($el); + this.$content.prepend($el); return $el; - } + }.bind(this) ); } else { - insertMessage = _.compose(_.debounce(this.scrollDown.bind(this), 50), $content.append.bind($content)); + insertMessage = _.compose(_.debounce(this.scrollDown.bind(this), 50), this.$content.append.bind(this.$content)); } if ((match) && (match[1] === 'me')) { text = text.replace(/^\/me/, ''); @@ -1427,7 +1425,7 @@ template = converse.templates.message; username = msg_dict.sender === 'me' && __('me') || fullname; } - $content.find('div.chat-event').remove(); + this.$content.find('div.chat-event').remove(); if (this.is_chatroom && msg_dict.sender == 'them' && (new RegExp("\\b"+this.model.get('nick')+"\\b")).test(text)) { // Add special class to mark groupchat messages in which we @@ -1450,15 +1448,14 @@ }, showHelpMessages: function (msgs, type, spinner) { - var $chat_content = this.$el.find('.chat-content'), i, - msgs_length = msgs.length; + var i, msgs_length = msgs.length; for (i=0; i