From b7a6fae4d901f4ff6ae6c9519447b2e98d2c8407 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Wed, 1 Feb 2017 14:14:49 +0100 Subject: [PATCH] BUG FIX: Menu loading Menu's now load slower but update when needed. Also frozen users now catch the forbidden error --- website/public/js/header.js | 7 ++-- website/public/js/main.js | 12 +------ website/public/js/menu.js | 68 +++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/website/public/js/header.js b/website/public/js/header.js index 4feea40..e4408cc 100644 --- a/website/public/js/header.js +++ b/website/public/js/header.js @@ -11,7 +11,8 @@ $(document).ready(function() { // Add cookie so the menu stays open on other pages 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=/"; } else { document.cookie = "menu=closed; path=/"; @@ -22,7 +23,8 @@ $(document).ready(function() { $("#notification-center").css("display", "none"); 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 { // Make the menu invisible and move the content to the right. $("#contact-menu").css("display", "none"); @@ -43,6 +45,7 @@ $(document).ready(function() { // Add cookie so the menu stays open on other pages if (window.innerWidth > 1080) { + $("#chat-history").css("margin-right", "266px"); $("#chat-history").width("calc(100% - 587px)"); document.cookie = "menu=open; path=/"; } else { diff --git a/website/public/js/main.js b/website/public/js/main.js index a5f17de..7741406 100644 --- a/website/public/js/main.js +++ b/website/public/js/main.js @@ -94,14 +94,4 @@ function showGroups(groups, list) { } else { 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(""); - } - }); -}); \ No newline at end of file +} \ No newline at end of file diff --git a/website/public/js/menu.js b/website/public/js/menu.js index 5ca9c97..c575ecd 100644 --- a/website/public/js/menu.js +++ b/website/public/js/menu.js @@ -6,11 +6,7 @@ var updatingMenus = 0; // On document load, load menus and loops loading menus every 10 seconds. $(document).ready(function() { - updatingMenus = 4; - loadMenuFriends(5); - loadNotificationFriends(); - loadUnreadMessages(); - loadMenuGroups(); + updateMenus(); setInterval(updateMenus, 10000); }); @@ -18,7 +14,6 @@ $(document).ready(function() { // Update the menu and notification items. function updateMenus() { if (updatingMenus <= 0) { - updatingMenus = 4; loadMenuFriends(5); loadNotificationFriends(); 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) { + updatingMenus ++; $.post( "API/loadFriends.php", { limit: 5 } ).done(function(data) { + if (data == "" || data == "[]") { + $("#friends-menu-section").hide(); + } else { + $("#friends-menu-section").show(); + } if (menuFriendsData != data) { menuFriendsData = data; - if (showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) { - $("#friends-menu-section").show(); - } else { + if (!showFriends(data, "#menu-friends-list", 5, "profile.php", "GET", limit)) { $("#friends-menu-section").hide(); } } + }).fail(function() { + $("#friends-menu-section").hide(); + }).always(function() { updatingMenus --; }); } -// Get, every 3 seconds, the groups and insert them in the menu. +// Get the groups and insert them in the menu. function loadMenuGroups() { + updatingMenus ++; $.post( "API/loadGroups.php", { limit: 5 } ).done(function(data) { + + if (data == "" || data == "[]") { + $("#groups-menu-section").hide(); + } else { + $("#groups-menu-section").show(); + } if (menuGroupsData != data) { menuGroupsData = data; - if (showGroups(data, "#menu-groups-list")) { - $("#groups-menu-section").show(); - } else { + if (!showGroups(data, "#menu-groups-list")) { $("#groups-menu-section").hide(); } } + }).fail(function() { + $("#groups-menu-section").hide(); + }).always(function() { 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() { + updatingMenus ++; $.post( "API/loadFriendRequest.php" ).done(function(data) { + if (data == "" || data == "[]") { + $("#friend-request-section").hide(); + } else { + $("#friend-request-section").show(); + } if (notificationRequestsData != data) { notificationRequestsData = data; - if (showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) { - $("#friend-request-section").show(); - } else { + if (!showFriendsPlus(data, "#friend-requests-list", 5, "profile.php", "GET")) { $("#friend-request-section").hide(); } } + }).fail(function() { + $("#friend-request-section").hide(); + }).always(function() { 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() { + updatingMenus ++; $.post( "API/loadChatNotifications.php" ).done(function(data) { + if (data == "" || data == "[]") { + $("#unread-messages-section").hide(); + } else { + $("#unread-messages-section").show(); + } if (notificationMessagesData != data) { notificationMessagesData = data; - if (showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) { - $("#unread-messages-section").show(); - } else { + if (!showFriendsPlus(data, "#unread-chat-list", 5, "chat.php", "GET")) { $("#unread-messages-section").hide(); } } + }).fail(function() { + $("#unread-messages-section").hide(); + }).always(function() { updatingMenus --; }); } \ No newline at end of file