Store visibility status of sidebar menus

Fixes #51
Closes #1606
This commit is contained in:
Pavel Djundik 2018-03-15 15:11:15 +02:00
parent 640d8df487
commit 103c3395dd
3 changed files with 29 additions and 6 deletions

View File

@ -32,18 +32,29 @@ $(function() {
const contextMenuContainer = $("#context-menu-container"); const contextMenuContainer = $("#context-menu-container");
const contextMenu = $("#context-menu"); const contextMenu = $("#context-menu");
function storeSidebarVisibility(name, state) {
if ($(window).outerWidth() < utils.mobileViewportPixels) {
return;
}
storage.set(name, state);
}
$("#windows").on("click", function(e) { $("#windows").on("click", function(e) {
const isOpen = slideoutMenu.isOpen(); const isOpen = slideoutMenu.isOpen();
if (isOpen || $(e.target).is(".lt")) { if ((isOpen && $(window).outerWidth() < utils.mobileViewportPixels) || $(e.target).is(".lt")) {
slideoutMenu.toggle(!isOpen); slideoutMenu.toggle(!isOpen);
storeSidebarVisibility("thelounge.state.sidebar", !isOpen);
} }
}); });
viewport.on("click", ".rt", function() { viewport.on("click", ".rt", function() {
const self = $(this); const isOpen = !viewport.hasClass("rt");
viewport.toggleClass(self.prop("class"));
viewport.toggleClass("rt", isOpen);
chat.find(".chan.active .chat").trigger("keepToBottom"); chat.find(".chan.active .chat").trigger("keepToBottom");
storeSidebarVisibility("thelounge.state.userlist", isOpen);
return false; return false;
}); });
@ -374,8 +385,11 @@ $(function() {
} }
utils.scrollIntoViewNicely(self[0]); utils.scrollIntoViewNicely(self[0]);
if ($(window).outerWidth() < utils.mobileViewportPixels) {
slideoutMenu.toggle(false); slideoutMenu.toggle(false);
} }
}
const lastActive = $("#windows > .active"); const lastActive = $("#windows > .active");

View File

@ -42,12 +42,19 @@ socket.on("init", function(data) {
webpush.configurePushNotifications(data.pushSubscription, data.applicationServerKey); webpush.configurePushNotifications(data.pushSubscription, data.applicationServerKey);
slideoutMenu.enable();
const viewport = $("#viewport");
if ($(window).outerWidth() >= utils.mobileViewportPixels) {
slideoutMenu.toggle(storage.get("thelounge.state.sidebar") === "true");
viewport.toggleClass("rt", storage.get("thelounge.state.userlist") === "true");
}
$(document.body).removeClass("signed-out"); $(document.body).removeClass("signed-out");
$("#loading").remove(); $("#loading").remove();
$("#sign-in").remove(); $("#sign-in").remove();
slideoutMenu.enable();
if (window.g_LoungeErrorHandler) { if (window.g_LoungeErrorHandler) {
window.removeEventListener("error", window.g_LoungeErrorHandler); window.removeEventListener("error", window.g_LoungeErrorHandler);
window.g_LoungeErrorHandler = null; window.g_LoungeErrorHandler = null;

View File

@ -9,6 +9,8 @@ var serverHash = -1; // eslint-disable-line no-var
var lastMessageId = -1; // eslint-disable-line no-var var lastMessageId = -1; // eslint-disable-line no-var
module.exports = { module.exports = {
// Same value as media query in CSS that forces sidebars to become overlays
mobileViewportPixels: 768,
inputCommands: {collapse, expand, join}, inputCommands: {collapse, expand, join},
findCurrentNetworkChan, findCurrentNetworkChan,
serverHash, serverHash,