From d7baccabe82df606ca53b6fba765891f3e1c7ace Mon Sep 17 00:00:00 2001 From: Bofh Date: Mon, 28 Nov 2022 14:25:12 +0100 Subject: [PATCH] Create methods to add/remove/modify hash arguments --- js/base.php | 18 ++++++++++++++++++ views/instance.php | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/js/base.php b/js/base.php index e43c7fe..59165cc 100644 --- a/js/base.php +++ b/js/base.php @@ -131,6 +131,24 @@ function _get_func_params(func) { return params; } +function del_hash_argument(key) { + var hash = window.location.hash; + hash = hash.replace(new RegExp(';?'+key+'=[^;]+'),''); + hash = hash.replace('/;','/'); + window.location.hash = hash; +} + +function set_hash_argument(key, val) { + var hargs = get_hash_arguments(); + if (hargs[key] === undefined) { + window.location.hash += ';'+key+'='+val; + return; + } + var hash = window.location.hash; + hash = hash.replace(new RegExp(key+'=[^;]+'),`${key}=${val}`); + window.location.hash = hash; +} + function get_hash_arguments() { var args = window.location.hash.substring(1).trim().split('/'); if (args.length > 0 && args[0].trim() === '') diff --git a/views/instance.php b/views/instance.php index 4ff7c91..01c2bca 100644 --- a/views/instance.php +++ b/views/instance.php @@ -70,6 +70,8 @@ window.view.instance = { case 'settings': return window.view.instance.show_config(); default: + set_hash_argument('content', content); + E.element('#window-instance #container').innerHTML = ''; return window.view.instance .load[content.replaceAll('-','_')](); } @@ -123,6 +125,8 @@ function load__instance(args) { } return html; }); + if (hargs['content'] !== undefined) + window.view.instance.load_content(hargs['content']); }; const _main = function() {