Made more elegant solution to tools URLs

This commit is contained in:
2023-05-26 11:57:00 +02:00
parent 6058169818
commit a8d93fc2a5

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,19 +73,23 @@ 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, updateURL = true) {
if (tools.has(tool)) { if (tools.has(tool)) {
const url = tools.get(tool); const url = tools.get(tool);
document.location.search = tool + "/"; if (updateURL) document.location.search = tool;
localStorage.setItem("lastPage", tool); localStorage.setItem("lastPage", tool);
document.getElementById("iframe").src = url; document.getElementById("iframe").src = url;
} }