From 2b984805877c7519fac54db8e645aabb16e4cc19 Mon Sep 17 00:00:00 2001 From: Lars van Hijfte Date: Wed, 1 Feb 2017 13:07:06 +0100 Subject: [PATCH] BUG FIX: Menu now saves the cookie again --- website/public/js/admin.js | 3 -- website/public/js/chat.js | 1 - website/public/js/groupButtons.js | 1 + website/public/js/header.js | 68 ++++++++++++++++++------------- website/public/js/main.js | 1 + website/public/js/menu.js | 21 +++++++--- 6 files changed, 57 insertions(+), 38 deletions(-) diff --git a/website/public/js/admin.js b/website/public/js/admin.js index 2b78e0b..e0dc9f7 100644 --- a/website/public/js/admin.js +++ b/website/public/js/admin.js @@ -17,12 +17,10 @@ $(window).on("load", function () { because serialize doesn't take submit values. */ $('#admin-batchform > button').click(function () { $('#batchinput').prop('value', $(this).prop('value')); - console.log($('#batchinput').prop('value')); }); $('#admin-groupbatchform > button').click(function () { $('#groupbatchinput').prop('value', $(this).prop('value')); - console.log($('#batchinput').prop('value')); }); }); @@ -67,7 +65,6 @@ function searchFromOne() { } function adminSearch() { - console.log($("#admin-searchform").serialize()); $.post( "API/adminSearchUsers.php", $("#admin-searchform").serialize() diff --git a/website/public/js/chat.js b/website/public/js/chat.js index e332324..6a027c8 100644 --- a/website/public/js/chat.js +++ b/website/public/js/chat.js @@ -49,7 +49,6 @@ function addMessages(messages) { // Initialize message variables var thisDate = new Date(messages[i].creationdate.replace(/ /,"T")); var thisTime = thisDate.getHours() + ":" + thisDate.getMinutes(); - console.log(thisDate); var type; thisDate.setHours(0,0,0,0); diff --git a/website/public/js/groupButtons.js b/website/public/js/groupButtons.js index 0f1b6bf..e6ada67 100644 --- a/website/public/js/groupButtons.js +++ b/website/public/js/groupButtons.js @@ -25,6 +25,7 @@ function placeGroupButtons() { .done(function() { $buttonContainer.children().remove(); placeGroupButtons(); + updateMenus(); }).fail(function() { }); }); diff --git a/website/public/js/header.js b/website/public/js/header.js index 13e3e12..4feea40 100644 --- a/website/public/js/header.js +++ b/website/public/js/header.js @@ -1,40 +1,52 @@ $(document).ready(function() { // Toggle menu $("#own-profile-picture, #open-notifications").click(function() { - if ($("#notification-center").css('display') == "none") { - // Make the menu visible and move the content to the left. - $(".modal").width("calc(100% - 512px)"); - $(".content").css("margin-right", "256px"); - $("#notification-center").css("right", "0px"); - $("#notification-center").css("display", "block"); - $("#contact-menu").css("display", "block"); + if ($("#notification-center").css('display') == "none") { + // Make the menu visible and move the content to the left. + $(".modal").width("calc(100% - 512px)"); + $(".content").css("margin-right", "256px"); + $("#notification-center").css("right", "0px"); + $("#notification-center").css("display", "block"); + $("#contact-menu").css("display", "block"); - // Add cookie so the menu stays open on other pages - if (window.innerWidth > 1080) { - $("#chat-history").width("calc(100% - 587px)"); - document.cookie = "menu=open; path=/"; - } else { - document.cookie = "menu=closed; path=/"; - } + // Add cookie so the menu stays open on other pages + if (window.innerWidth > 1080) { + $("#chat-history").width("calc(100% - 587px)"); + document.cookie = "menu=open; path=/"; } else { - $(".modal").width("calc(100% - 256px)"); - $(".content").css("margin-right", "0px"); - $("#notification-center").css("display", "none"); - - if (window.innerWidth > 1080) { - $("#chat-history").width("calc(100% - 331px)"); - } else { - // Make the menu invisible and move the content to the right. - $("#contact-menu").css("display", "none"); - } - - // Change menu cookie to close document.cookie = "menu=closed; path=/"; - } + } else { + $(".modal").width("calc(100% - 256px)"); + $(".content").css("margin-right", "0px"); + $("#notification-center").css("display", "none"); + + if (window.innerWidth > 1080) { + $("#chat-history").width("calc(100% - 331px)"); + } else { + // Make the menu invisible and move the content to the right. + $("#contact-menu").css("display", "none"); + } + + // Change menu cookie to close + document.cookie = "menu=closed; path=/"; + } }); if (getCookie("menu") == "open") { - $("#own-profile-picture").click(); + // Make the menu visible and move the content to the left. + $(".modal").width("calc(100% - 512px)"); + $(".content").css("margin-right", "256px"); + $("#notification-center").css("right", "0px"); + $("#notification-center").css("display", "block"); + $("#contact-menu").css("display", "block"); + + // Add cookie so the menu stays open on other pages + if (window.innerWidth > 1080) { + $("#chat-history").width("calc(100% - 587px)"); + document.cookie = "menu=open; path=/"; + } else { + document.cookie = "menu=closed; path=/"; + } } }); diff --git a/website/public/js/main.js b/website/public/js/main.js index 2983fdb..a5f17de 100644 --- a/website/public/js/main.js +++ b/website/public/js/main.js @@ -53,6 +53,7 @@ function editFriendship(userID, value) { $.post("API/editFriendship.php", { usr: userID, action: value }) .done(function() { placeFriendButtons(); + updateMenus(); }); } diff --git a/website/public/js/menu.js b/website/public/js/menu.js index d15d678..5ca9c97 100644 --- a/website/public/js/menu.js +++ b/website/public/js/menu.js @@ -2,23 +2,28 @@ var menuFriendsData; var menuGroupsData; var notificationMessagesData; var notificationRequestsData; +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(); - setInterval(updateMenus, 3000); + setInterval(updateMenus, 10000); }); // Update the menu and notification items. function updateMenus() { - loadMenuFriends(5); - loadNotificationFriends(); - loadUnreadMessages(); - loadMenuGroups(); + if (updatingMenus <= 0) { + updatingMenus = 4; + loadMenuFriends(5); + loadNotificationFriends(); + loadUnreadMessages(); + loadMenuGroups(); + } } @@ -38,6 +43,7 @@ function loadMenuFriends(limit) { $("#friends-menu-section").hide(); } } + updatingMenus --; }); } @@ -57,6 +63,7 @@ function loadMenuGroups() { $("#groups-menu-section").hide(); } } + updatingMenus --; }); } @@ -73,6 +80,7 @@ function loadNotificationFriends() { $("#friend-request-section").hide(); } } + updatingMenus --; }); } @@ -89,5 +97,6 @@ function loadUnreadMessages() { $("#unread-messages-section").hide(); } } + updatingMenus --; }); } \ No newline at end of file