summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xstatic/js/pichat.js53
1 files changed, 41 insertions, 12 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 48e1e50..0a2743d 100755
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -56,12 +56,7 @@ function buildGrowlDataAndPopDatShit(msg) {
}
function growl(user, msg) {
- $.gritter.add({
- // (string | mandatory) the heading of the notification
- title: user,
- // (string | mandatory) the text inside the notification
- text: msg
- });
+ $.gritter.add({title: user, text: msg});
}
function handleMsgError(resp) {
@@ -111,6 +106,7 @@ function ifEnter(fn) {
};
}
+/*
function isScrolledToBottom(div) {
return Math.abs(div.scrollTop - (div.scrollHeight - div.offsetHeight)) <= 3;
}
@@ -124,20 +120,18 @@ function scrollToBottom(div) {
function delayedScrollToBottom(delay) {
setTimeout(scrollToBottom, delay, $('#messageList')[0]);
}
+*/
function addNewMessages(msgs) {
- var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]);
+ //var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]);
var msgStr = $.map(msgs, buildMessageDiv).join('');
$('#messageList').append(msgStr);
-
- if (wasScrolledToBottom) { delayedScrollToBottom(500); }
}
function addNewMessage(msg, isLoading) {
- var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]);
+ //var wasScrolledToBottom = isScrolledToBottom($('#messageList')[0]);
var msgStr = buildMessageDiv(msg, isLoading);
var div = $(msgStr).appendTo('#messageList');
- if (wasScrolledToBottom) { delayedScrollToBottom(500); }
return div;
}
@@ -216,10 +210,15 @@ function initChat() {
$('#msgInput').keyup(ifEnter(submitMessage));
$('#msgSubmit').click(submitMessage);
- delayedScrollToBottom(500);
+ messageList = $("#messageList")[0]
+
+ scrollToEnd()
+ scrollWatcher()
+
setTimeout(refresh, 1000);
}
+
function initProfile() {
$('.logged-dump .content').each(function() {
var t = $(this);
@@ -280,4 +279,34 @@ function setupUpload(elementId, roomKey) {
name: 'image',
data: { room: roomKey }
});
+}
+
+// scrolling stuff
+// this code keeps the div scrolled to the bottom, but will also let the user scroll up, without jumping down
+
+function isScrolledToBottom(){
+ var threshold = 15;
+
+ var containerHeight = messageList.style.pixelHeight || messageList.offsetHeight
+ var currentHeight = (messageList.scrollHeight > 0) ? messageList.scrollHeight : 0
+
+ var result = (currentHeight - messageList.scrollTop - containerHeight < threshold);
+
+ return result;
+}
+
+function scrollIfPossible(){
+ if (lastScriptedScrolledPosition == messageList.scrollTop || isScrolledToBottom())
+ scrollToEnd()
+}
+
+var lastScriptedScrolledPosition = 0
+function scrollToEnd(){
+ messageList.scrollTop = messageList.scrollHeight
+ lastScriptedScrolledPosition = messageList.scrollTop
+}
+
+function scrollWatcher(){
+ scrollIfPossible()
+ setTimeout(scrollWatcher, 500)
} \ No newline at end of file