Merge branch 'master' into hendrik-post

This commit is contained in:
Hendrik
2017-02-02 13:43:31 +01:00
29 changed files with 206 additions and 62 deletions

View File

@@ -9,13 +9,17 @@ $(document).ready(function() {
$(".chat-field").hide();
});
// This function loads the new messages and runs the addMessages function to show them.
function loadMessages() {
// If the function is not running elsewhere, run it here.
if (!gettingMessages) {
gettingMessages = true;
// Get the messages.
$.post(
"API/loadMessages.php",
$("#lastIDForm").serialize()
).done(function (data) {
// Post the messages in the chat.
if (data && data != "[]") {
messages = JSON.parse(data);
addMessages(messages);
@@ -28,7 +32,7 @@ function loadMessages() {
}
}
// Send a message to a friend of the user.
function sendMessage() {
$.post(
"API/sendMessage.php",
@@ -37,42 +41,54 @@ function sendMessage() {
if (response == "frozen") {
alert("Je account is bevroren, dus je kan niet chat berichten versturen. Contacteer een admin als je denkt dat dit onjuist is.");
}
// Load messages if the message has been send, so it shows in the chat.
loadMessages();
});
$("#newContent").val("");
loadMessages();
}
// Add messages to the chat.
function addMessages(messages) {
var messagesText = "";
// Loop over all the messages.
for(var i in messages) {
// Initialize message variables
// Initialize message variables.
var thisDate = new Date(messages[i].creationdate.replace(/ /,"T"));
var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes();
var type;
thisDate.setHours(0,0,0,0);
// See where the message has been send from, so it shows on the right side.
if (messages[i].destination == $(".destinationID").val()) {
type = "chat-message-self";
} else {
type = "chat-message-other";
}
// If it is the first message, open the message box and maybe add a year.
if (i == 0) {
if (thisDate.getTime() > previousDate.getTime()) {
messagesText += '\
<div class="day-message"> \
<div class="day-message-content">\
' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\
</div> \
</div>';
}
previousDate = thisDate;
messagesText += '\
<div class="day-message"> \
<div class="day-message-content">\
' + days[thisDate.getDay()] + " " + thisDate.getDate() + " " + months[thisDate.getMonth()] + " " + thisDate.getFullYear() + '\
</div> \
</div>';
messagesText += '<div class="chat-message"><div class="' + type + '">';
// If it is not the first message, and has a different date/time/type then the previous message,
} else if (type != previousType || thisTime != previousTime || thisDate.getTime() > previousDate.getTime()) {
// Close the previous message.
messagesText += '<div class="chat-time">\
' + thisTime + '\
</div></div></div>';
previousTime = thisTime;
previousType = type;
// If the date is different, add a new date.
if (thisDate > previousDate) {
previousDate = thisDate;
messagesText += '\
@@ -83,8 +99,11 @@ function addMessages(messages) {
</div>';
}
// Open the new message.
messagesText += '<div class="chat-message"><div class="' + type + '">';
}
// Add the content of the message in the new box.
messagesText += fancyText(messages[i].content) + "<br />";
}
@@ -93,11 +112,14 @@ function addMessages(messages) {
' + thisTime + '\
</div></div></div>';
// Add all the new created messaged to the chat.
$("#chat-history").append(messagesText);
// Scroll down, so the user can see the new messages.
$("#chat-history").scrollTop($("#chat-history")[0].scrollHeight - $('#chat-history')[0].clientHeight);
}
// Switch to a different user.
function switchUser(userID) {
previousDate = new Date("1970-01-01 00:00:00");
$(".chat-field").show();
@@ -108,6 +130,7 @@ function switchUser(userID) {
$("#friend-item-" + userID).addClass("active-friend-chat");
}
// Insert a message in the chat, this is used when it is empty.
function sayEmpty() {
$("#chat-history").html("Probeer ook eens foto's en video's te sturen");
}

View File

@@ -14,14 +14,14 @@ function fancyText(text) {
return "<video width='100%'>" +
"<source src='"+ link +"' type='video/mp4'>" +
"<b>Je browser ondersteund geen video</b>" +
"</video><button class='gray' onclick='$(this).prev().get(0).play();'>Speel af</button>";
"</video><button class='gray' onclick='$(this).prev().get(0).play();'><i class='fa fa-play'></i></button>";
}
// Add ogg video's
else if (link.match(/(https?:\/\/.[^ ]*\.(?:ogg))/ig)) {
return "<video width='100%'>" +
"<source src='"+ link +"' type='video/ogg'>" +
"<b>Je browser ondersteund geen video</b>" +
"</video><button onclick='$(this).prev().get(0).play();'>Speel af</button>";
"</video><button class='gray' onclick='$(this).prev().get(0).play();'><i class='fa fa-play'></i></button>";
}
// Add youtube video's
else if (link.match(/(https?:\/\/.(www.)?youtube|youtu.be)*watch/ig)) {
@@ -38,6 +38,8 @@ function fancyText(text) {
return text;
}
// This function gets the value of a cookie when given a key.
// If didn´t find any compatible cookie, it returns false.
function getCookie(key) {
cookies = document.cookie.split("; ");
for (var i in cookies) {
@@ -49,6 +51,7 @@ function getCookie(key) {
return false;
}
// Edit the friendship status of two users.
function editFriendship(userID, value) {
$.post("API/editFriendship.php", { usr: userID, action: value })
.done(function() {
@@ -57,6 +60,8 @@ function editFriendship(userID, value) {
});
}
// Show the given friends in the given list.
// The friends are giving in JSON, and the list is giving with a hashtag.
function showFriends(friends, list) {
if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", {
@@ -69,6 +74,8 @@ function showFriends(friends, list) {
}
}
// Show the given friends in the given list.
// This function supports more options given as parameters. This adds extra functionality.
function showFriendsPlus(friends, list, limit, action, actionType) {
if(friends && friends != "[]") {
$(list).load("bits/friend-item.php", {
@@ -84,6 +91,7 @@ function showFriendsPlus(friends, list, limit, action, actionType) {
}
}
// Show the given groups in the given list.
function showGroups(groups, list) {
if(groups && groups != "[]") {
$(list).load("bits/group-item.php", {

View File

@@ -134,7 +134,7 @@ function masonry(mode) {
$form.append($("<input class=\"newpost\" name=\"title\" placeholder=\"Titel\" type=\"text\">"));
$form.append($("<textarea class=\"newpost\" name=\"content\" placeholder=\"Schrijf een berichtje...\" maxlength='1000'></textarea><span></span>"));
$form.append($("<input value=\"Plaats!\" type=\"submit\">"));
$form.append($("<button type=\"submit\"><i class='fa fa-sticky-note-o'></i> Plaats!</button>"));
columns[0][1].append($postInput);
columns[0][0] = $postInput.height() + margin;

View File

@@ -36,6 +36,4 @@ function deletePost(postID) {
postAmount = 0;
closeModal();
masonry(masonryMode);
}

View File

@@ -2,6 +2,7 @@ $(window).on('load', function () {
pageNumber();
});
// Search for the users and put them in the user list.
function searchUsers() {
$.post(
"API/searchUsers.php",
@@ -13,6 +14,7 @@ function searchUsers() {
});
}
// Search for the groups and put them in the group list.
function searchGroups() {
$.post(
"API/searchGroups.php",
@@ -24,6 +26,7 @@ function searchGroups() {
});
}
// Get the page numbers and return them in the select.
function pageNumber() {
var input = input2 = $('#search-form').serialize();
$.post(