From dae2e14aac05b54bc65cc15a5e90f0340ea44323 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 8 Jul 2014 21:53:18 -0400 Subject: [PATCH] epic hax to make the chat message list resize #1788 --- public/src/forum/chats.js | 22 ++++++++++++++++++++++ src/socket.io/modules.js | 1 + 2 files changed, 23 insertions(+) diff --git a/public/src/forum/chats.js b/public/src/forum/chats.js index 6a9d998ca5..c9b438bae9 100644 --- a/public/src/forum/chats.js +++ b/public/src/forum/chats.js @@ -12,9 +12,11 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) { if (!Chats.initialised) { Chats.addSocketListeners(); + Chats.addGlobalEventListeners(); } Chats.addEventListeners(); + Chats.resizeMainWindow(); Chats.scrollToBottom(containerEl); Chats.setActive(); @@ -62,6 +64,10 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) { }); }; + Chats.addGlobalEventListeners = function() { + $(window).on('resize', Chats.resizeMainWindow); + }; + Chats.addSocketListeners = function() { socket.on('event:chats.receive', function(data) { var typingNotifEl = $('.user-typing'), @@ -102,6 +108,22 @@ define('forum/chats', ['string', 'sounds'], function(S, sounds) { }); }; + Chats.resizeMainWindow = function() { + var messagesList = $('.expanded-chat ul'); + + if (messagesList.length) { + var inputEl = $('.chat-input'), + viewportHeight = $(window).height(), + margin = $('.expanded-chat ul').outerHeight() - $('.expanded-chat ul').height(), + inputHeight = inputEl.outerHeight(), + fromTop = messagesList.offset().top; + + messagesList.height(viewportHeight-(fromTop+inputHeight+(margin*4))); + } + + return; + }; + Chats.notifyTyping = function(toUid, typing) { socket.emit('modules.chats.user' + (typing ? 'Start' : 'Stop') + 'Typing', { touid: toUid, diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index b6cd649264..31b0926b73 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -15,6 +15,7 @@ var posts = require('../posts'), winston = require('winston'), _ = require('underscore'), server = require('./'), + nconf = require('nconf'), SocketModules = { composer: {