Merge pull request #2235 from thelounge/xpaw/store-sidebar-visibility

Store visibility status of sidebar menus
This commit is contained in:
Jérémie Astori 2018-03-16 23:57:24 -04:00 committed by GitHub
commit c395e74e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}); });
@ -364,8 +375,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

@ -8,6 +8,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,