From 4694fe640ab4f4accccff1a86180c9db8b867e33 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sun, 7 Nov 2021 18:45:08 +0100 Subject: [PATCH] Store navigator and sidebar opened/closed state in cookie. --- website/o3dv/js/navigator.js | 13 +++++++++---- website/o3dv/js/panelset.js | 15 +++++++++++++++ website/o3dv/js/sidebar.js | 6 +++--- website/o3dv/js/website.js | 14 ++++++++++++-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/website/o3dv/js/navigator.js b/website/o3dv/js/navigator.js index 95346e2..c44e161 100644 --- a/website/o3dv/js/navigator.js +++ b/website/o3dv/js/navigator.js @@ -53,14 +53,16 @@ OV.Navigator = class this.panelSet.ShowPanel (this.meshesPanel); } + ShowPanels (show) + { + this.panelSet.ShowPanels (show); + } + Init (callbacks) { this.callbacks = callbacks; this.panelSet.Init ({ - onShowHidePanels : (show) => { - - }, onResize : () => { if (this.panelSet.IsPanelsVisible ()) { this.splitterDiv.show (); @@ -68,7 +70,10 @@ OV.Navigator = class this.splitterDiv.hide (); } this.callbacks.onResize (); - } + }, + onShowHidePanels : (show) => { + this.callbacks.onShowHidePanels (show); + }, }); this.filesPanel.Init ({ diff --git a/website/o3dv/js/panelset.js b/website/o3dv/js/panelset.js index c77ae59..f284a13 100644 --- a/website/o3dv/js/panelset.js +++ b/website/o3dv/js/panelset.js @@ -57,6 +57,7 @@ OV.PanelSet = class this.panels = []; this.panelButtons = []; this.panelsVisible = true; + this.requestedPanelsVisible = true; this.panelsPrevWidth = null; this.callbacks = null; } @@ -93,11 +94,17 @@ OV.PanelSet = class ShowPanels (show) { + if (!this.IsParentVisible ()) { + this.requestedPanelsVisible = show; + return; + } + if (this.panelsVisible === show) { return; } this.panelsVisible = show; + this.requestedPanelsVisible = show; if (this.panelsVisible) { this.contentDiv.show (); this.parentDiv.outerWidth (this.menuDiv.outerWidth (true) + this.panelsPrevWidth, true); @@ -158,6 +165,9 @@ OV.PanelSet = class Resize () { + if (this.requestedPanelsVisible !== this.isPanelsVisible) { + this.ShowPanels (this.requestedPanelsVisible); + } let height = this.parentDiv.height (); this.menuDiv.outerHeight (height, true); this.contentDiv.outerHeight (height, true); @@ -166,6 +176,11 @@ OV.PanelSet = class } } + IsParentVisible () + { + return this.parentDiv.is (':visible'); + } + Clear () { for (let panel of this.panels) { diff --git a/website/o3dv/js/sidebar.js b/website/o3dv/js/sidebar.js index 795ae9b..058969b 100644 --- a/website/o3dv/js/sidebar.js +++ b/website/o3dv/js/sidebar.js @@ -28,9 +28,6 @@ OV.Sidebar = class this.callbacks = callbacks; this.panelSet.Init ({ - onShowHidePanels : (show) => { - this.callbacks.onShowHidePanels (show); - }, onResize : () => { if (this.panelSet.IsPanelsVisible ()) { //this.splitterDiv.show (); @@ -38,6 +35,9 @@ OV.Sidebar = class //this.splitterDiv.hide (); } this.callbacks.onResize (); + }, + onShowHidePanels : (show) => { + this.callbacks.onShowHidePanels (show); } }); diff --git a/website/o3dv/js/website.js b/website/o3dv/js/website.js index 00aed13..39f2585 100644 --- a/website/o3dv/js/website.js +++ b/website/o3dv/js/website.js @@ -40,7 +40,9 @@ OV.Website = class this.viewer.SetClickHandler (this.OnModelClicked.bind (this)); this.viewer.SetContextMenuHandler (this.OnModelContextMenu.bind (this)); + this.Resize (); + this.SetUIState (OV.WebsiteUIState.Intro); this.hashHandler.SetEventListener (this.OnHashChange.bind (this)); this.OnHashChange (); @@ -338,7 +340,6 @@ OV.Website = class 'assets/envmaps/grayclouds/posz.jpg', 'assets/envmaps/grayclouds/negz.jpg' ]); - this.SetUIState (OV.WebsiteUIState.Intro); } InitToolbar () @@ -529,10 +530,13 @@ OV.Website = class this.Resize (); }, onShowHidePanels : (show) => { - + this.cookieHandler.SetBoolVal ('ov_show_sidebar', show); } } ); + + let showSidebar = this.cookieHandler.GetBoolVal ('ov_show_sidebar', true); + this.sidebar.ShowPanels (showSidebar); } InitNavigator () @@ -627,8 +631,14 @@ OV.Website = class }, onResize : () => { this.Resize (); + }, + onShowHidePanels : (show) => { + this.cookieHandler.SetBoolVal ('ov_show_navigator', show); } }); + + let showNavigator = this.cookieHandler.GetBoolVal ('ov_show_navigator', true); + this.navigator.ShowPanels (showNavigator); } InitCookieConsent ()