BUG FIX: Menu loading

Menu's now load slower but update when needed.
Also frozen users now catch the forbidden error
This commit is contained in:
Lars van Hijfte
2017-02-01 14:14:49 +01:00
parent 2b98480587
commit b7a6fae4d9
3 changed files with 52 additions and 35 deletions

View File

@@ -11,7 +11,8 @@ $(document).ready(function() {
// Add cookie so the menu stays open on other pages // Add cookie so the menu stays open on other pages
if (window.innerWidth > 1080) { if (window.innerWidth > 1080) {
$("#chat-history").width("calc(100% - 587px)"); $("#chat-history").css("margin-right", "266px");
$("#chat-history").css("width", "calc(100% - 512px - 75px)");
document.cookie = "menu=open; path=/"; document.cookie = "menu=open; path=/";
} else { } else {
document.cookie = "menu=closed; path=/"; document.cookie = "menu=closed; path=/";
@@ -22,7 +23,8 @@ $(document).ready(function() {
$("#notification-center").css("display", "none"); $("#notification-center").css("display", "none");
if (window.innerWidth > 1080) { if (window.innerWidth > 1080) {
$("#chat-history").width("calc(100% - 331px)"); $("#chat-history").css("margin-right", "10px");
$("#chat-history").css("width", "calc(100% - 256px - 85px)");
} else { } else {
// Make the menu invisible and move the content to the right. // Make the menu invisible and move the content to the right.
$("#contact-menu").css("display", "none"); $("#contact-menu").css("display", "none");
@@ -43,6 +45,7 @@ $(document).ready(function() {
// Add cookie so the menu stays open on other pages // Add cookie so the menu stays open on other pages
if (window.innerWidth > 1080) { if (window.innerWidth > 1080) {
$("#chat-history").css("margin-right", "266px");
$("#chat-history").width("calc(100% - 587px)"); $("#chat-history").width("calc(100% - 587px)");
document.cookie = "menu=open; path=/"; document.cookie = "menu=open; path=/";
} else { } else {

View File

@@ -94,14 +94,4 @@ function showGroups(groups, list) {
} else { } else {
return false; return false;
} }
} }
$(document).ready(function() {
$("body").delegate("textarea[maxlength]", "keydown", function() {
if ($(this).val().length / .9 >= $(this).attr("maxlength")) {
$(this).next().text($(this).val().length + "/" + $(this).attr("maxlength"));
} else {
$(this).next().text("");
}
});
});

View File

@@ -6,11 +6,7 @@ var updatingMenus = 0;
// On document load, load menus and loops loading menus every 10 seconds. // On document load, load menus and loops loading menus every 10 seconds.
$(document).ready(function() { $(document).ready(function() {
updatingMenus = 4; updateMenus();
loadMenuFriends(5);
loadNotificationFriends();
loadUnreadMessages();
loadMenuGroups();
setInterval(updateMenus, 10000); setInterval(updateMenus, 10000);
}); });
@@ -18,7 +14,6 @@ $(document).ready(function() {
// Update the menu and notification items. // Update the menu and notification items.
function updateMenus() { function updateMenus() {
if (updatingMenus <= 0) { if (updatingMenus <= 0) {
updatingMenus = 4;
loadMenuFriends(5); loadMenuFriends(5);
loadNotificationFriends(); loadNotificationFriends();
loadUnreadMessages(); loadUnreadMessages();
@@ -27,76 +22,105 @@ function updateMenus() {
} }
// Get, every 3 seconds, the friends and insert them in the menu. // Get the friends and insert them in the menu.
function loadMenuFriends(limit) { function loadMenuFriends(limit) {
updatingMenus ++;
$.post( $.post(
"API/loadFriends.php", "API/loadFriends.php",
{ {
limit: 5 limit: 5
} }
).done(function(data) { ).done(function(data) {
if (data == "" || data == "[]") {
$("#friends-menu-section").hide();
} else {
$("#friends-menu-section").show();
}
if (menuFriendsData != data) { if (menuFriendsData != data) {
menuFriendsData = data; menuFriendsData = data;
if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) { if (!showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) {
$("#friends-menu-section").show();
} else {
$("#friends-menu-section").hide(); $("#friends-menu-section").hide();
} }
} }
}).fail(function() {
$("#friends-menu-section").hide();
}).always(function() {
updatingMenus --; updatingMenus --;
}); });
} }
// Get, every 3 seconds, the groups and insert them in the menu. // Get the groups and insert them in the menu.
function loadMenuGroups() { function loadMenuGroups() {
updatingMenus ++;
$.post( $.post(
"API/loadGroups.php", "API/loadGroups.php",
{ {
limit: 5 limit: 5
} }
).done(function(data) { ).done(function(data) {
if (data == "" || data == "[]") {
$("#groups-menu-section").hide();
} else {
$("#groups-menu-section").show();
}
if (menuGroupsData != data) { if (menuGroupsData != data) {
menuGroupsData = data; menuGroupsData = data;
if (showGroups(data, "#menu-groups-list")) { if (!showGroups(data, "#menu-groups-list")) {
$("#groups-menu-section").show();
} else {
$("#groups-menu-section").hide(); $("#groups-menu-section").hide();
} }
} }
}).fail(function() {
$("#groups-menu-section").hide();
}).always(function() {
updatingMenus --; updatingMenus --;
}); });
} }
// Get, every 3 seconds, the friends requests and insert them in the notification center. // Get the friends requests and insert them in the notification center.
function loadNotificationFriends() { function loadNotificationFriends() {
updatingMenus ++;
$.post( $.post(
"API/loadFriendRequest.php" "API/loadFriendRequest.php"
).done(function(data) { ).done(function(data) {
if (data == "" || data == "[]") {
$("#friend-request-section").hide();
} else {
$("#friend-request-section").show();
}
if (notificationRequestsData != data) { if (notificationRequestsData != data) {
notificationRequestsData = data; notificationRequestsData = data;
if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) { if (!showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) {
$("#friend-request-section").show();
} else {
$("#friend-request-section").hide(); $("#friend-request-section").hide();
} }
} }
}).fail(function() {
$("#friend-request-section").hide();
}).always(function() {
updatingMenus --; updatingMenus --;
}); });
} }
// Get, every 3 seconds, the unread messages and insert them in the notification center. // Get the unread messages and insert them in the notification center.
function loadUnreadMessages() { function loadUnreadMessages() {
updatingMenus ++;
$.post( $.post(
"API/loadChatNotifications.php" "API/loadChatNotifications.php"
).done(function(data) { ).done(function(data) {
if (data == "" || data == "[]") {
$("#unread-messages-section").hide();
} else {
$("#unread-messages-section").show();
}
if (notificationMessagesData != data) { if (notificationMessagesData != data) {
notificationMessagesData = data; notificationMessagesData = data;
if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) { if (!showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) {
$("#unread-messages-section").show();
} else {
$("#unread-messages-section").hide(); $("#unread-messages-section").hide();
} }
} }
}).fail(function() {
$("#unread-messages-section").hide();
}).always(function() {
updatingMenus --; updatingMenus --;
}); });
} }