Use local storage for saving menu items

Fixes a bug when visiting with browser: www.wykop.pl, and then navigating back to myaac (browser freeze)
This commit is contained in:
slawkens 2021-01-07 22:43:15 +01:00
parent 98bd51436b
commit bca098e074

View File

@ -23,6 +23,7 @@ if(isset($config['boxes']))
<?php endif; ?> <?php endif; ?>
<script type="text/javascript"> <script type="text/javascript">
var menus = '';
var loginStatus="<?php echo ($logged ? 'true' : 'false'); ?>"; var loginStatus="<?php echo ($logged ? 'true' : 'false'); ?>";
<?php <?php
if(PAGE !== 'news') { if(PAGE !== 'news') {
@ -112,8 +113,8 @@ if(isset($config['boxes']))
} }
} }
var menu = new Array(); var menu = [];
menu[0] = new Object(); menu[0] = {};
var unloadhelper = false; var unloadhelper = false;
// load the menu and set the active submenu item by using the variable 'activeSubmenuItem' // load the menu and set the active submenu item by using the variable 'activeSubmenuItem'
@ -121,8 +122,9 @@ if(isset($config['boxes']))
{ {
document.getElementById("submenu_"+activeSubmenuItem).style.color = "white"; document.getElementById("submenu_"+activeSubmenuItem).style.color = "white";
document.getElementById("ActiveSubmenuItemIcon_"+activeSubmenuItem).style.visibility = "visible"; document.getElementById("ActiveSubmenuItemIcon_"+activeSubmenuItem).style.visibility = "visible";
if(self.name.lastIndexOf("&") == -1) { menus = localStorage.getItem('menus');
self.name = "news=1&account=0&community=0&library=0&forum=0<?php if($config['gifts_system']) echo '&shops=0'; ?>&"; if(menus.lastIndexOf("&") === -1) {
menus = "news=1&account=0&community=0&library=0&forum=0<?php if($config['gifts_system']) echo '&shops=0'; ?>&";
} }
FillMenuArray(); FillMenuArray();
InitializeMenu(); InitializeMenu();
@ -139,13 +141,13 @@ if(isset($config['boxes']))
// store the values of the variable 'self.name' in the array menu // store the values of the variable 'self.name' in the array menu
function FillMenuArray() function FillMenuArray()
{ {
while(self.name.length > 0 ){ while(menus.length > 0 ){
var mark1 = self.name.indexOf("="); var mark1 = menus.indexOf("=");
var mark2 = self.name.indexOf("&"); var mark2 = menus.indexOf("&");
var menuItemName = self.name.substr(0, mark1); var menuItemName = menus.substr(0, mark1);
menu[0][menuItemName] = self.name.substring(mark1 + 1, mark2); menu[0][menuItemName] = menus.substring(mark1 + 1, mark2);
self.name = self.name.substr(mark2 + 1, self.name.length); menus = menus.substr(mark2 + 1, menus.length);
} }
} }
// hide or show the corresponding submenus // hide or show the corresponding submenus
@ -167,16 +169,17 @@ if(isset($config['boxes']))
} }
} }
// reconstruct the variable "self.name" out of the array menu
function SaveMenuArray() function SaveMenuArray()
{ {
var stringSlices = ""; var stringSlices = "";
var temp = ""; var temp = "";
for(menuItemName in menu[0]) {
stringSlices = menuItemName + "=" + menu[0][menuItemName] + "&"; for(menuItemName in menu[0]) {
temp = temp + stringSlices; stringSlices = menuItemName + "=" + menu[0][menuItemName] + "&";
} temp = temp + stringSlices;
self.name = temp; }
localStorage.setItem('menus', temp);
} }
// onClick open or close submenus // onClick open or close submenus