Merged bema/ref/tools_urls to master

This commit is contained in:
2023-05-26 14:11:20 +02:00

View File

@@ -32,7 +32,7 @@ function init() {
changeActiveTools('XML'); changeActiveTools('XML');
var toolUrl = window.location.search.substring(1); var toolUrl = window.location.search.substring(1);
if (tools.has(toolUrl)) if (tools.has(toolUrl))
changeTool(toolUrl); changeTool(toolUrl, false);
else else
loadLastPage(); loadLastPage();
@@ -73,20 +73,34 @@ function changeActiveTools(activeCategoryButton) {
} }
} }
/** /**
* Function that changes active tool * This function changes active tool.
* Optional updateURL can be set to false to stop changing URL.
* This helps avoiding endless reload loop when loading page.
* *
* @function * @function
* @name changeTool * @name changeTool
* @kind function * @kind function
* @param {any} tool * @param {any} tool
* @param {boolean} updateURL?
* @returns {void} * @returns {void}
*/ */
function changeTool(tool) { function changeTool(tool) {
if (! tools.has(tool)) return;
const url = tools.get(tool); const url = tools.get(tool);
localStorage.setItem("lastPage", tool); localStorage.setItem("lastPage", tool);
function changeTool(tool, updateURL = true) {
if (! tools.has(tool)) return;
const url = tools.get(tool);
if (updateURL) document.location.search = tool;
switch (tool) { // XML category is default. switch (tool) { // XML category is default.
case "jsonform": case "jsonform":
changeActiveTools('JSON'); changeActiveTools('JSON');
@@ -94,10 +108,11 @@ function changeTool(tool) {
case "mock": case "mock":
changeActiveTools('REST'); changeActiveTools('REST');
break; break;
} }
document.location.search = tool;
localStorage.setItem("lastPage", tool);
document.getElementById("iframe").src = url; document.getElementById("iframe").src = url;
} }
/** /**