Skip to content

Commit 3c132ba

Browse files
authored
Merge pull request #368 from dgrammatiko/patch-1
Update js scripts
2 parents fbbc891 + d68b24e commit 3c132ba

File tree

2 files changed

+26
-50
lines changed

2 files changed

+26
-50
lines changed

media/com_patchtester/joomla.asset.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
"type": "script",
1111
"uri": "com_patchtester/fetcher.js",
1212
"attributes": {
13-
"type": "module",
14-
"defer": true
13+
"type": "module"
1514
}
1615
},
1716
{
1817
"name": "com_patchtester.patchtester",
1918
"type": "script",
2019
"uri": "com_patchtester/patchtester.js",
2120
"attributes": {
22-
"type": "module",
23-
"defer": true
21+
"type": "module"
2422
}
2523
},
2624
{
Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,34 @@
11
/**
22
* Patch testing component for the Joomla! CMS
33
*
4-
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
5-
* @license GNU General Public License version 2 or later
4+
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
5+
* @license GNU General Public License version 2 or later; see LICENSE.txt
66
*/
77

88
if (typeof Joomla === 'undefined') {
99
throw new Error('PatchTester JavaScript requires the Joomla core JavaScript API')
1010
}
1111

12-
document.addEventListener("DOMContentLoaded", function (event) {
13-
const submitPatch = document.querySelectorAll(".submitPatch");
12+
Joomla.submitbutton = (task) => {
13+
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?'))) {
14+
Joomla.submitform(task);
15+
}
16+
};
1417

15-
/**
16-
* EventListener which listens on submitPatch Button,
17-
* checks if it is an apply or revert method and
18-
* processes the patch action
19-
*
20-
* @param {Event} event
21-
*/
22-
submitPatch.forEach(function (element) {
23-
element.addEventListener("click", function (event) {
24-
const currentTarget = event.currentTarget;
25-
const task = `${currentTarget.dataset.task}.${currentTarget.dataset.task}`
26-
const id = parseInt(currentTarget.dataset.id)
27-
28-
PatchTester.submitpatch(task, id);
29-
});
30-
});
31-
});
32-
33-
!function (Joomla, window, document) {
34-
'use strict';
35-
36-
window.PatchTester = {
37-
/**
38-
* Process the patch action
39-
*
40-
* @param {String} task The task to perform
41-
* @param {Number} id The item ID
42-
*/
43-
submitpatch: function (task, id) {
44-
var idField = document.getElementById('pull_id');
45-
idField.value = id;
46-
47-
Joomla.submitform(task);
48-
}
49-
};
50-
51-
Joomla.submitbutton = function (task) {
52-
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?'))) {
53-
Joomla.submitform(task);
54-
}
55-
};
56-
}(Joomla, window, document);
18+
/**
19+
* EventListener which listens on submitPatch Button,
20+
* checks if it is an apply or revert method and
21+
* processes the patch action
22+
*
23+
* @param {Event} event
24+
*/
25+
document.querySelectorAll(".submitPatch").forEach((element) => element.addEventListener("click", (event) => {
26+
const element = document.getElementById('pull_id');
27+
const target = event.currentTarget;
28+
29+
if (element) {
30+
element.value = parseInt(target.dataset.id);
31+
}
32+
33+
Joomla.submitform(`${target.dataset.task}.${target.dataset.task}`);
34+
}));

0 commit comments

Comments
 (0)