From fbfeca9fb5670a59e15c0cadaa2241d9bca7483e Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 8 Aug 2017 12:45:20 +0200 Subject: [PATCH] Load first messages when clicking to the "chat online" button See BT#12617 --- main/inc/lib/javascript/chat/js/chat.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main/inc/lib/javascript/chat/js/chat.js b/main/inc/lib/javascript/chat/js/chat.js index 88d747a1d6..8257fa94b1 100755 --- a/main/inc/lib/javascript/chat/js/chat.js +++ b/main/inc/lib/javascript/chat/js/chat.js @@ -356,6 +356,7 @@ function chatWith(user_id, user_name, status, userImage) { createChatBox(user_id, user_name, 0, status, userImage); $("#chatbox_"+user_id+" .chatboxtextarea").focus(); + getMoreItems(user_id, 'last'); } /** @@ -524,8 +525,9 @@ function createChatBox(user_id, chatboxtitle, minimizeChatBox, online, userImage /** * @param int userId + * @param string scrollType */ -function getMoreItems(userId) +function getMoreItems(userId, scrollType) { var visibleMessages = $("#chatbox_"+userId+" .chatboxcontent").find('div').length; $.ajax({ @@ -541,12 +543,22 @@ function getMoreItems(userId) } var chatBubble = createChatBubble(userId, item); $("#chatbox_"+userId+" .chatboxcontent").prepend(chatBubble); - $("#chatbox_"+userId+" .chatboxcontent").scrollTop( - 10 - ); + if ($('#chatbox_'+userId+' .chatboxcontent').css('display') == 'none') { $('#chatbox_'+userId+' .chatboxhead').toggleClass('chatboxblink'); } + + // When using scroll set the scroll window to the first + var scrollValue = 10; + if (scrollType === 'last') { + // When loading for the first time show the last msg + scrollValue = $("#chatbox_"+userId+" .chatboxcontent").height(); + } + + $("#chatbox_"+userId+" .chatboxcontent").scrollTop( + scrollValue + ); + } }); }