added time to chat messages
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
var previousDate = new Date("1970-01-01 00:00:00");
|
var previousDate = new Date("1970-01-01 00:00:00");
|
||||||
|
var previousTime = "00:00";
|
||||||
var gettingMessages = false;
|
var gettingMessages = false;
|
||||||
|
var previousType = "robot";
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
setInterval(loadMessages, 1000);
|
setInterval(loadMessages, 1000);
|
||||||
@@ -39,34 +40,51 @@ function sendMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addMessages(messages) {
|
function addMessages(messages) {
|
||||||
|
var messagesText = "";
|
||||||
for(var i in messages) {
|
for(var i in messages) {
|
||||||
thisDate = new Date(messages[i].creationdate);
|
// Initialize message variables
|
||||||
|
var thisDate = new Date(messages[i].creationdate);
|
||||||
|
var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes();
|
||||||
|
var type;
|
||||||
thisDate.setHours(0,0,0,0);
|
thisDate.setHours(0,0,0,0);
|
||||||
|
|
||||||
if (messages[i].destination == $(".destinationID").val()) {
|
if (messages[i].destination == $(".destinationID").val()) {
|
||||||
type = "chat-message-self";
|
type = "chat-message-self";
|
||||||
} else {
|
} else {
|
||||||
type = "chat-message-other";
|
type = "chat-message-other";
|
||||||
}
|
}
|
||||||
if (thisDate > previousDate) {
|
if (i == 0) {
|
||||||
|
messagesText += '<div class="chat-message"><div class="' + type + '">';
|
||||||
|
} else if (type != previousType || thisTime != previousTime || thisDate > previousDate) {
|
||||||
|
messagesText += '<div class="chat-time">\
|
||||||
|
' + thisTime + '\
|
||||||
|
</div></div></div>';
|
||||||
|
|
||||||
previousDate = thisDate;
|
previousDate = thisDate;
|
||||||
$("#chat-history").append('\
|
previousTime = thisTime;
|
||||||
|
previousType = type;
|
||||||
|
if (thisDate > previousDate) {
|
||||||
|
messagesText += '\
|
||||||
<div class="day-message"> \
|
<div class="day-message"> \
|
||||||
<div class="day-message-content">\
|
<div class="day-message-content">\
|
||||||
' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\
|
' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\
|
||||||
</div> \
|
</div> \
|
||||||
</div>\
|
</div>';
|
||||||
');
|
|
||||||
}
|
|
||||||
$("#chat-history").append('\
|
|
||||||
<div class="chat-message"> \
|
|
||||||
<div class="' + type + '">\
|
|
||||||
' + fancyText(messages[i].content) + '\
|
|
||||||
</div> \
|
|
||||||
</div>\
|
|
||||||
');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#chat-history").scrollTop($("#chat-history")[0].scrollHeight);
|
messagesText += '<div class="chat-message"><div class="' + type + '">';
|
||||||
|
}
|
||||||
|
messagesText += fancyText(messages[i].content) + "<br />";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the last message
|
||||||
|
messagesText += '<div class="chat-time">\
|
||||||
|
' + thisTime + '\
|
||||||
|
</div></div></div>';
|
||||||
|
|
||||||
|
$("#chat-history").append(messagesText);
|
||||||
|
|
||||||
|
$("#chat-history").scrollTop($("#chat-history")[0].scrollHeight - $('#chat-history')[0].clientHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchUser(userID) {
|
function switchUser(userID) {
|
||||||
@@ -80,5 +98,5 @@ function switchUser(userID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sayEmpty() {
|
function sayEmpty() {
|
||||||
$("#chat-history").html("Begin nu met chatten!");
|
$("#chat-history").html("Probeer ook eens foto's en video's te sturen");
|
||||||
}
|
}
|
||||||
@@ -135,3 +135,13 @@ body {
|
|||||||
.chat-message a {
|
.chat-message a {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chat-time {
|
||||||
|
color: #666666;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-bottom: -3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chat-message-other .chat-time {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user