fix bug: force scrollbar to the bottom while scrolling in chat when new

message pops up
new rss added : cat = news
This commit is contained in:
2014-07-13 19:01:50 +02:00
parent aa3ac66a25
commit dca32c02f1
2 changed files with 87 additions and 76 deletions

View File

@@ -82,6 +82,8 @@ databap.pageInit = function()
self.vars2('unread_msg', 'object');
self.tmp('news_period', 10*60*1000);
self.tmp('get_news', false);
self.tmp('last_message_id', '0');
self.tmp('scrolling', 'boolean');
//Main elements
$MsgInput = databap.getMainElem('#message');
@@ -93,8 +95,10 @@ databap.pageInit = function()
$MsgInput.keyup(function(event){add_message(event);});
//Loading the chat
databap.vars.last_message_id = '0';
self.initScrollBar('#chat_container', '#chat_messages_box', '#chat_messages');
$('#chat_container').find('.thumb')
.mousedown(function(){self.tmp('scrolling', true);})
.mouseup(function(){self.tmp('scrolling', false);});
//Loading Chans
setChanButton();
@@ -380,7 +384,7 @@ function switchChan(sChanKeyName)
//Show current channel messages
databap.getMainElem('#chat_messages').find('p').hide();
databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName+', p.class_'+databap.consts.all_chan_id).show();
databap.updateScrollBar('bottom');
databap.updateScrollBar(self.tmp('scrolling')?'relative':'bottom');
//Show Current channel members
databap.getMainElem('#connected_users').find('p').hide();
@@ -624,7 +628,7 @@ function refresh_chat(bReset)
{
if(bReset)
{
databap.vars.last_message_id = 0;
self.tmp('last_message_id', 0);
databap.getMainElem('#chat_messages').empty();
}
databap.getInfo
@@ -632,13 +636,13 @@ function refresh_chat(bReset)
'messages',
function(result)
{
var prevLastMsgId = databap.vars.last_message_id;
var prevLastMsgId = self.tmp('last_message_id');;
updateUsersList = false;
databap.resetIcon();
if(databap.vars.last_message_id < result.last_message_id || bReset)
if(prevLastMsgId < result.last_message_id || bReset)
{
//Update last read message id
databap.vars.last_message_id = Math.max(result.last_message_id, prevLastMsgId);
self.tmp('last_message_id', Math.max(result.last_message_id, prevLastMsgId));
//Display messages
$.each
@@ -659,16 +663,15 @@ function refresh_chat(bReset)
databap.tmp('get_news', false);
//Nicknames changes
if(updateUsersList === true || prevLastMsgId == 0)
if(updateUsersList === true || bReset)
{
databap.updateScrollBar('bottom');
refresh_users();
refresh_users(); //which execute switchChan()
updateUsersList = false;
}
else switchChan();
}
},
{message_id:databap.vars.last_message_id},
{message_id:self.tmp('last_message_id')},
'json',
function(textStatus)
{
@@ -820,40 +823,17 @@ function refresh_users()
var profileLink = databap.getInternalLink('profil', user_info.id_user);
var mission = 'Mission actuelle : '+(user_info.status || 'Aucune');
var pm = 'Cliquez pour lancer un channel privé avec '+user_info.name+' ('+user_info.company+')';
var user = $('<p>', {'class':'connected_user class_'+sChankeyName})
var $user = $('<p>', {'class':'connected_user class_'+sChankeyName})
.append($('<a>', {'class':'connected_user_logo', href:profileLink, title:mission, target:'_blank'})
.append($('<img>', {src:databap.consts.app_image_folder+user_info.logo}))
.append((user_info.afk=='1')?$('<i>', {class:'fa fa-c-afk afk'}):''))
.append($('<a>', {'class':'connected_user_name clickable '+sNickName, id:user_info.id_user, title:pm}).text(sNickName));
$user = $(user)/*.css("visibility", "hidden")*/;
$user.find('.connected_user_name').click(joinPmChan);
databap.getMainElem('#connected_users').append($user);
}
);
}
);
//Resize Nickname
/*var iMaxSize = 126 - 24 - 5; //boxSize - imageSize - marginLeftSize
$.each
(
users_list,
function(user_id, user)
{
databap.getMainElem('.'+user).each(function()
{
$nick = $(this);
while($nick.width() > iMaxSize)
{
sNickName = $nick.text();
$nick.text(sNickName.substr(0, sNickName.length - 1));
}
$nick.parent().css("visibility", "visible");
});
}
);*/
switchChan();
},
{},
@@ -900,9 +880,12 @@ function displayHelp()
});
//Close button activation
$Help.find('#close_help').click(function(){$(this).closest('.help').slideUp('fast', function()
$Help.find('#close_help').click(function()
{
databap.updateScrollBar('bottom');
});});
$(this).closest('.help').slideUp('fast', function()
{
databap.updateScrollBar('bottom');
});
});
}
</script>