From d8e63b2a7cb49f10f960a9685cd358f0c26191b5 Mon Sep 17 00:00:00 2001 From: Frank Knoll Date: Sun, 14 Jul 2024 01:33:27 +0200 Subject: [PATCH] refactoring --- docs/SymptomsCausedByDrugs/index.html | 5 ++--- docs/UIUtils.js | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/SymptomsCausedByDrugs/index.html b/docs/SymptomsCausedByDrugs/index.html index 30ef302ac64..0b45a9c37d4 100644 --- a/docs/SymptomsCausedByDrugs/index.html +++ b/docs/SymptomsCausedByDrugs/index.html @@ -40,13 +40,12 @@ document.addEventListener( "DOMContentLoaded", event => { - const urlSearchParams = new URLSearchParams(window.location.search); const name = 'Drug'; PageInitializer.initializePage( { symptom: { symptomSelectElement: $('#symptomSelect'), - selectSymptom: UIUtils.getSearchParam(urlSearchParams, 'symptom', null), + selectSymptom: UIUtils.getSearchParamOfCurrentUrl('symptom'), onSymptomSelected: symptom => UIUtils.setSearchParamOfCurrentUrl('symptom', symptom), prrByVaccineTableElement: $('#prrByVaccineTable'), downloadPrrByVaccineTableButton: document.querySelector("#downloadPrrByVaccineTable"), @@ -54,7 +53,7 @@ }, vaccine: { vaccineSelectElement: $('#vaccineSelect'), - selectVaccine: UIUtils.getSearchParam(urlSearchParams, 'vaccine', null), + selectVaccine: UIUtils.getSearchParamOfCurrentUrl('vaccine'), onVaccineSelected: vaccine => UIUtils.setSearchParamOfCurrentUrl('vaccine', vaccine), prrBySymptomTableElement: $('#prrBySymptomTable'), downloadPrrBySymptomTableButton: document.querySelector("#downloadPrrBySymptomTable"), diff --git a/docs/UIUtils.js b/docs/UIUtils.js index 530604b8159..d5b113f62a0 100644 --- a/docs/UIUtils.js +++ b/docs/UIUtils.js @@ -38,6 +38,11 @@ class UIUtils { return UIUtils.getSearchParam(urlParams, searchParam, 'NO').toUpperCase() == 'YES'; } + static getSearchParamOfCurrentUrl(searchParam) { + const urlSearchParams = new URLSearchParams(window.location.search); + return UIUtils.getSearchParam(urlSearchParams, searchParam, null) + } + static setSearchParamOfCurrentUrl(nameOfSearchParam, valueOfSearchParam) { const url = new URL(window.location.href); url.searchParams.set(nameOfSearchParam, valueOfSearchParam);