/instantMessage/instantMessage.html |
@@ -21,7 +21,7 @@ |
tabTemplate = "<li id='#{id}'><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>", |
tabCounter = 0, |
messageIntervals = {}, |
getConversationsTimer; |
getConversationsTimeout; |
|
var tabs = $("#tabs").tabs(); |
|
@@ -65,6 +65,10 @@ |
if (!conversationExists(avatar.firstname, avatar.lastname)) |
addTab(avatar.firstname, avatar.lastname); |
}); |
getConversationsTimeout = setTimeout( |
getConversations, |
1000 |
); |
}); |
} |
|
@@ -102,11 +106,15 @@ |
function loadInstantMessage(index) { |
$.get("messages/" + $("#firstname-" + index).val() + " " + $("#lastname-" + index).val() + ".log" + "?t=" + Math.random(), function(data) { |
$("#chat-" + index).html(data); |
$("#chat-" + index).animate({ |
scrollTop: $("#chat-" + index)[0].scrollHeight - $("#chat-" + index).height() |
}, 1000); |
messageIntervals[index] = setTimeout( |
loadInstantMessage, |
1000, |
index |
); |
}); |
|
$("#chat-" + index).animate({ |
scrollTop: $("#chat-" + index)[0].scrollHeight - $("#chat-" + index).height() |
}, 1000); |
} |
|
// This function checks whether a conversation / tab already exists. |
@@ -145,7 +153,7 @@ |
tabs.find(".ui-tabs-nav").append(li); |
tabs.append("<div id='" + id + "'><p>" + " \ |
<div id='container-" + tabCounter + "'> \ |
<textarea id='chat-" + tabCounter + "' rows='12'></textarea><br/> \ |
<textarea readonly='readonly' id='chat-" + tabCounter + "' rows='12'></textarea><br/> \ |
<div id='controls-" + tabCounter + "'> \ |
Message: <input type='text' size='70' id='message-" + tabCounter + "'></input> \ |
<button type='button' id='send-" + tabCounter + "'>Send</button> \ |
@@ -179,7 +187,7 @@ |
var panelId = $(this).closest("li").remove().attr("aria-controls"); |
var selectedIndex = $(this).closest("li").remove().attr("id"); |
// Pause the conversation retrieval timer. |
clearInterval(getConversationsTimer); |
clearTimeout(getConversationsTimeout); |
$.ajax({ |
type: 'post', |
url: "deleteConversation.php", |
@@ -191,7 +199,7 @@ |
$("#" + panelId).remove(); |
tabs.tabs("refresh"); |
// Resume the conversation retrieval timer. |
getConversationsTimer = setInterval( |
getConversationsTimeout = setTimeout( |
getConversations, |
1000 |
); |
@@ -207,7 +215,7 @@ |
} |
}); |
|
messageIntervals[selectedIndex] = setInterval( |
messageIntervals[selectedIndex] = setTimeout( |
loadInstantMessage, |
1000, |
selectedIndex |
@@ -215,7 +223,7 @@ |
}); |
|
// Start a timer to load tabs of existing conversations. |
getConversationsTimer = setInterval( |
getConversationsTimeout = setTimeout( |
getConversations, |
1000 |
); |