From 65394e049b188e7d21481d5ab9f7c5663f995211 Mon Sep 17 00:00:00 2001 From: Franciska Perisa Date: Thu, 18 Aug 2022 17:43:15 +0200 Subject: [PATCH] Always check updateCheck before using it --- .../com_joomlaupdate/js/default.es6.js | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/build/media_source/com_joomlaupdate/js/default.es6.js b/build/media_source/com_joomlaupdate/js/default.es6.js index f8b54dfa634dd..144c29675647f 100644 --- a/build/media_source/com_joomlaupdate/js/default.es6.js +++ b/build/media_source/com_joomlaupdate/js/default.es6.js @@ -10,13 +10,14 @@ Joomla = window.Joomla || {}; Joomla.submitbuttonUpload = () => { const form = document.getElementById('uploadForm'); + const confirmBackup = document.getElementById('joomlaupdate-confirm-backup'); // do field validation if (form.install_package.value === '') { alert(Joomla.Text._('COM_INSTALLER_MSG_INSTALL_PLEASE_SELECT_A_PACKAGE'), true); } else if (form.install_package.files[0].size > form.max_upload_size.value) { alert(Joomla.Text._('COM_INSTALLER_MSG_WARNINGS_UPLOADFILETOOBIG'), true); - } else if (document.getElementById('joomlaupdate-confirm-backup').checked) { + } else if (confirmBackup && confirmBackup.checked) { form.submit(); } }; @@ -53,13 +54,15 @@ Joomla = window.Joomla || {}; const form = installButton ? installButton.closest('form') : null; const task = form ? form.querySelector('[name=task]', form) : null; if (uploadButton) { - uploadButton.disabled = !updateCheck.checked; uploadButton.addEventListener('click', Joomla.submitbuttonUpload); - updateCheck.addEventListener('change', () => { - uploadButton.disabled = !updateCheck.checked; - }); + uploadButton.disabled = updateCheck && !updateCheck.checked; + if (updateCheck) { + updateCheck.addEventListener('change', () => { + uploadButton.disabled = !updateCheck.checked; + }); + } } - if (confirmButton && !updateCheck.checked) { + if (confirmButton && updateCheck && !updateCheck.checked) { confirmButton.classList.add('disabled'); } if (confirmButton && updateCheck) { @@ -73,22 +76,24 @@ Joomla = window.Joomla || {}; } if (uploadField) { uploadField.addEventListener('change', Joomla.installpackageChange); - uploadField.addEventListener('change', () => { - const fileSize = uploadForm.install_package.files[0].size; - const allowedSize = uploadForm.max_upload_size.value; - if (fileSize <= allowedSize && updateCheck.disabled) { - updateCheck.disabled = !updateCheck.disabled; - } else if (fileSize <= allowedSize && !updateCheck.disabled && !updateCheck.checked) { - updateCheck.disabled = false; - } else if (fileSize <= allowedSize && updateCheck.checked) { - updateCheck.checked = updateCheck.classList.contains('d-none'); - uploadButton.disabled = true; - } else if (fileSize > allowedSize && !updateCheck.disabled) { - updateCheck.disabled = !updateCheck.disabled; - updateCheck.checked = updateCheck.classList.contains('d-none'); - uploadButton.disabled = true; - } - }); + if (updateCheck) { + uploadField.addEventListener('change', () => { + const fileSize = uploadForm.install_package.files[0].size; + const allowedSize = uploadForm.max_upload_size.value; + if (fileSize <= allowedSize && updateCheck.disabled) { + updateCheck.disabled = !updateCheck.disabled; + } else if (fileSize <= allowedSize && !updateCheck.disabled && !updateCheck.checked) { + updateCheck.disabled = false; + } else if (fileSize <= allowedSize && updateCheck.checked) { + updateCheck.checked = updateCheck.classList.contains('d-none'); + uploadButton.disabled = true; + } else if (fileSize > allowedSize && !updateCheck.disabled) { + updateCheck.disabled = !updateCheck.disabled; + updateCheck.checked = updateCheck.classList.contains('d-none'); + uploadButton.disabled = true; + } + }); + } } // Trigger (re-) install (including checkbox confirm if we update) if (installButton && installButton.getAttribute('href') === '#' && task) {