From e6f60ab93a03da39425b1d09cd62958c92398dce Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Sat, 7 Oct 2023 00:12:23 +0300 Subject: [PATCH 1/6] Update patchtester.js --- media/com_patchtester/js/patchtester.js | 77 +++++++++++-------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index a0409140..dce34933 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -9,48 +9,41 @@ if (typeof Joomla === 'undefined') { throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API') } -document.addEventListener("DOMContentLoaded", function (event) { - const submitPatch = document.querySelectorAll(".submitPatch"); +Joomla.submitbutton = (task) => { + if (task !== 'reset' || confirm(Joomla.JText._('COM_PATCHTESTER_CONFIRM_RESET', 'Resetting will attempt to revert all applied patches and removes all backed up files. This may result in a corrupted environment. Are you sure you want to continue?'))) { + Joomla.submitform(task); + } +}; + +const PatchTester = { + /** + * Process the patch action + * + * @param {String} task The task to perform + * @param {Number} id The item ID + */ + submitpatch: function (task, id) { + var idField = document.getElementById('pull_id'); + idField.value = id; + + Joomla.submitform(task); + } +}; - /** - * EventListener which listens on submitPatch Button, - * checks if it is an apply or revert method and - * processes the patch action - * - * @param {Event} event - */ - submitPatch.forEach(function (element) { - element.addEventListener("click", function (event) { - const currentTarget = event.currentTarget; - const task = `${currentTarget.dataset.task}.${currentTarget.dataset.task}` - const id = parseInt(currentTarget.dataset.id) - - PatchTester.submitpatch(task, id); - }); - }); -}); - -!function (Joomla, window, document) { - 'use strict'; - - window.PatchTester = { - /** - * Process the patch action - * - * @param {String} task The task to perform - * @param {Number} id The item ID - */ - submitpatch: function (task, id) { - var idField = document.getElementById('pull_id'); - idField.value = id; +/** + * EventListener which listens on submitPatch Button, + * checks if it is an apply or revert method and + * processes the patch action + * + * @param {Event} event + */ +function patchSubmit(event) { + const currentTarget = event.currentTarget; + const task = `${currentTarget.dataset.task}.${currentTarget.dataset.task}` + const id = parseInt(currentTarget.dataset.id) + + PatchTester.submitpatch(task, id); +} - Joomla.submitform(task); - } - }; - Joomla.submitbutton = function (task) { - if (task !== 'reset' || confirm(Joomla.JText._('COM_PATCHTESTER_CONFIRM_RESET', 'Resetting will attempt to revert all applied patches and removes all backed up files. This may result in a corrupted environment. Are you sure you want to continue?'))) { - Joomla.submitform(task); - } - }; -}(Joomla, window, document); +document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", patchSubmit)); From 012d39a3161efaccb2c2103a676cbb4445b1fd99 Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Sat, 7 Oct 2023 00:13:52 +0300 Subject: [PATCH 2/6] Type module scripts are always deferred (unless async) --- media/com_patchtester/joomla.asset.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/media/com_patchtester/joomla.asset.json b/media/com_patchtester/joomla.asset.json index 522b6a06..cfc04f95 100644 --- a/media/com_patchtester/joomla.asset.json +++ b/media/com_patchtester/joomla.asset.json @@ -10,8 +10,7 @@ "type": "script", "uri": "com_patchtester/fetcher.js", "attributes": { - "type": "module", - "defer": true + "type": "module" } }, { @@ -19,8 +18,7 @@ "type": "script", "uri": "com_patchtester/patchtester.js", "attributes": { - "type": "module", - "defer": true + "type": "module" } }, { From 24346681628e235375eeea23cc335ac141bbb95b Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Sat, 7 Oct 2023 00:18:25 +0300 Subject: [PATCH 3/6] Update patchtester.js --- media/com_patchtester/js/patchtester.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index dce34933..113dcd52 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -22,9 +22,8 @@ const PatchTester = { * @param {String} task The task to perform * @param {Number} id The item ID */ - submitpatch: function (task, id) { - var idField = document.getElementById('pull_id'); - idField.value = id; + submitpatch: (task, id) => { + document.getElementById('pull_id')?.value = id; Joomla.submitform(task); } @@ -37,13 +36,7 @@ const PatchTester = { * * @param {Event} event */ -function patchSubmit(event) { - const currentTarget = event.currentTarget; - const task = `${currentTarget.dataset.task}.${currentTarget.dataset.task}` - const id = parseInt(currentTarget.dataset.id) - - PatchTester.submitpatch(task, id); -} +const patchSubmit = (event) => PatchTester.submitpatch(`${event.currentTarget.dataset.task}.${currentTarget.dataset.task}`, parseInt(event.currentTarget.dataset.id)); document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", patchSubmit)); From 28871503bf168aed8e5f21c07bf5bfe3f5cb7d30 Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Tue, 10 Oct 2023 10:34:02 +0300 Subject: [PATCH 4/6] Update patchtester.js --- media/com_patchtester/js/patchtester.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index 113dcd52..65ed7e67 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -23,7 +23,11 @@ const PatchTester = { * @param {Number} id The item ID */ submitpatch: (task, id) => { - document.getElementById('pull_id')?.value = id; + const value = document.getElementById('pull_id')?.value; + + if (value) { + value = id; + } Joomla.submitform(task); } From c87730187c014692ad5c63a43bd282203b457511 Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Tue, 10 Oct 2023 12:50:26 +0300 Subject: [PATCH 5/6] more simplifications --- media/com_patchtester/js/patchtester.js | 33 ++++++++----------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index 65ed7e67..73c3663e 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -1,8 +1,8 @@ /** * Patch testing component for the Joomla! CMS * - * @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved. - * @license GNU General Public License version 2 or later + * @copyright (C) 2023 Open Source Matters, Inc. + * @license GNU General Public License version 2 or later; see LICENSE.txt */ if (typeof Joomla === 'undefined') { @@ -15,24 +15,6 @@ Joomla.submitbutton = (task) => { } }; -const PatchTester = { - /** - * Process the patch action - * - * @param {String} task The task to perform - * @param {Number} id The item ID - */ - submitpatch: (task, id) => { - const value = document.getElementById('pull_id')?.value; - - if (value) { - value = id; - } - - Joomla.submitform(task); - } -}; - /** * EventListener which listens on submitPatch Button, * checks if it is an apply or revert method and @@ -40,7 +22,12 @@ const PatchTester = { * * @param {Event} event */ -const patchSubmit = (event) => PatchTester.submitpatch(`${event.currentTarget.dataset.task}.${currentTarget.dataset.task}`, parseInt(event.currentTarget.dataset.id)); - +document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", (event) => { + const value = document.getElementById('pull_id')?.value; + + if (value) { + value = parseInt(event.currentTarget.dataset.id); + } -document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", patchSubmit)); + Joomla.submitform(`${event.currentTarget.dataset.task}.${currentTarget.dataset.task}`); +})); From d68b24ed7f0d7fe6983e6f92f9210ca5cae403b1 Mon Sep 17 00:00:00 2001 From: Dimitris Grammatikogiannis Date: Tue, 10 Oct 2023 13:00:31 +0300 Subject: [PATCH 6/6] Safer --- media/com_patchtester/js/patchtester.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/media/com_patchtester/js/patchtester.js b/media/com_patchtester/js/patchtester.js index 73c3663e..f8604338 100644 --- a/media/com_patchtester/js/patchtester.js +++ b/media/com_patchtester/js/patchtester.js @@ -23,11 +23,12 @@ Joomla.submitbutton = (task) => { * @param {Event} event */ document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", (event) => { - const value = document.getElementById('pull_id')?.value; + const element = document.getElementById('pull_id'); + const target = event.currentTarget; - if (value) { - value = parseInt(event.currentTarget.dataset.id); + if (element) { + element.value = parseInt(target.dataset.id); } - Joomla.submitform(`${event.currentTarget.dataset.task}.${currentTarget.dataset.task}`); + Joomla.submitform(`${target.dataset.task}.${target.dataset.task}`); }));