diff --git a/web/state.js b/web/state.js index f2c7f997..34ad04c4 100644 --- a/web/state.js +++ b/web/state.js @@ -158,22 +158,43 @@ function restoreState(state) { // instead of setting ninja-radio-default-version if selection is undefined or 0, // first check so the default can be controlled in the html if (state.ninjaMode !== undefined) { - document.getElementById('ninja-radio-default-version').checked = state.ninjaMode == 0; - document.getElementById('ninja-radio-system-version').checked = state.ninjaMode == 1; + const ninjaDefaultVersionRadio = document.getElementById('ninja-radio-default-version'); + if (ninjaDefaultVersionRadio) { + ninjaDefaultVersionRadio.checked = state.ninjaMode == 0; + } + const ninjaSystemVersionRadio = document.getElementById('ninja-radio-system-version'); + // not available in the DOM is system ninja is not available + if (ninjaSystemVersionRadio) { + ninjaSystemVersionRadio.checked = state.ninjaMode == 1; + } document.getElementById('ninja-radio-select-version').checked = state.ninjaMode == 2; document.getElementById('ninja-radio-path-executable').checked = state.ninjaMode == 3; } if (state.cmakeMode !== undefined) { - document.getElementById('cmake-radio-default-version').checked = state.cmakeMode == 0; - document.getElementById('cmake-radio-system-version').checked = state.cmakeMode == 1; + const cmakeDefaultVersionRadio = document.getElementById('cmake-radio-default-version'); + if (cmakeDefaultVersionRadio) { + cmakeDefaultVersionRadio.checked = state.cmakeMode == 0; + } + const cmakeSystemVersionRadio = document.getElementById('cmake-radio-system-version'); + // not available in the DOM is system cmake is not available + if (cmakeSystemVersionRadio) { + cmakeSystemVersionRadio.checked = state.cmakeMode == 1; + } document.getElementById('cmake-radio-select-version').checked = state.cmakeMode == 2; document.getElementById('cmake-radio-path-executable').checked = state.cmakeMode == 3; } - if (state.pythonMode !== undefined) { - document.getElementById('python-radio-default-version').checked = state.pythonMode == 0; - document.getElementById('python-radio-system-version').checked = state.pythonMode == 1; + if (state.pythonMode !== undefined && document.getElementById('python-radio-path-executable') !== undefined) { + const pythonDefaultVersionRadio = document.getElementById('python-radio-default-version'); + if (pythonDefaultVersionRadio) { + pythonDefaultVersionRadio.checked = state.pythonMode == 0; + } + const pythonSystemVersionRadio = document.getElementById('python-radio-system-version'); + // not available in the DOM is system python is not available + if (pythonSystemVersionRadio) { + pythonSystemVersionRadio.checked = state.pythonMode == 1; + } document.getElementById('python-radio-path-executable').checked = state.pythonMode == 2; }