Skip to content

Commit c171626

Browse files
authored
Minor cleanup for Other JS (#42798)
1 parent 9f12c3b commit c171626

19 files changed

+139
-181
lines changed

build/media_source/system/js/core.es6.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ window.Joomla.Modal = window.Joomla.Modal || {
109109
newDestination = {};
110110
}
111111

112-
[].slice.call(Object.keys(source)).forEach((key) => {
112+
Object.keys(source).forEach((key) => {
113113
newDestination[key] = source[key];
114114
});
115115

@@ -155,10 +155,9 @@ window.Joomla.Modal = window.Joomla.Modal || {
155155
Joomla.loadOptions = (options) => {
156156
// Load form the script container
157157
if (!options) {
158-
const elements = [].slice.call(document.querySelectorAll('.joomla-script-options.new'));
159158
let counter = 0;
160159

161-
elements.forEach((element) => {
160+
document.querySelectorAll('.joomla-script-options.new').forEach((element) => {
162161
const str = element.text || element.textContent;
163162
const option = JSON.parse(str);
164163

@@ -180,7 +179,7 @@ window.Joomla.Modal = window.Joomla.Modal || {
180179
Joomla.optionsStorage = options || {};
181180
} else if (options) {
182181
// Merge with existing
183-
[].slice.call(Object.keys(options)).forEach((key) => {
182+
Object.keys(options).forEach((key) => {
184183
/**
185184
* If both existing and new options are objects, merge them with Joomla.extend().
186185
* But test for new option being null, as null is an object, but we want to allow
@@ -241,7 +240,7 @@ window.Joomla.Modal = window.Joomla.Modal || {
241240
* @returns {Joomla.Text}
242241
*/
243242
load: (object) => {
244-
[].slice.call(Object.keys(object)).forEach((key) => {
243+
Object.keys(object).forEach((key) => {
245244
Joomla.Text.strings[key.toUpperCase()] = object[key];
246245
});
247246

@@ -513,10 +512,8 @@ window.Joomla.Modal = window.Joomla.Modal || {
513512
return;
514513
}
515514

516-
const elements = [].slice.call(document.getElementsByTagName('input'));
517-
518-
elements.forEach((element) => {
519-
if (element.type === 'hidden' && element.value === '1' && element.name.length === 32) {
515+
document.querySelectorAll('input[type="hidden"]').forEach((element) => {
516+
if (element.value === '1' && element.name.length === 32) {
520517
element.name = newToken;
521518
}
522519
});
@@ -596,7 +593,7 @@ window.Joomla.Modal = window.Joomla.Modal || {
596593

597594
// Custom headers
598595
if (newOptions.headers) {
599-
[].slice.call(Object.keys(newOptions.headers)).forEach((key) => {
596+
Object.keys(newOptions.headers).forEach((key) => {
600597
// Allow request without Content-Type
601598
// eslint-disable-next-line no-empty
602599
if (key === 'Content-Type' && newOptions.headers['Content-Type'] === 'false') {

build/media_source/system/js/fields/joomla-field-permissions.w-c.es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ window.customElements.define('joomla-field-permissions', class extends HTMLEleme
3232
* Lifecycle
3333
*/
3434
connectedCallback() {
35-
this.buttons = [].slice.call(document.querySelectorAll(`[${this.buttonDataSelector}]`));
35+
this.buttons = document.querySelectorAll(`[${this.buttonDataSelector}]`);
3636
if (this.buttons) {
3737
this.buttons.forEach((button) => {
3838
button.addEventListener('change', this.onDropdownChange);

build/media_source/system/js/fields/joomla-field-simple-color.w-c.es6.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
throw new Error('Simple color field requires a select element');
216216
}
217217

218-
this.options = [].slice.call(this.select.querySelectorAll('option'));
218+
this.options = this.select.querySelectorAll('option');
219219

220220
this.select.classList.add('hidden');
221221

build/media_source/system/js/fields/passwordstrength.es6.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class PasswordStrength {
121121
};
122122

123123
document.addEventListener('DOMContentLoaded', () => {
124-
const fields = [].slice.call(document.querySelectorAll('.js-password-strength'));
124+
const fields = document.querySelectorAll('.js-password-strength');
125125

126126
// Loop through the fields
127127
fields.forEach((field, index) => {
@@ -155,9 +155,7 @@ class PasswordStrength {
155155
}
156156

157157
// Add a listener for input data change
158-
field.addEventListener('keyup', ({ target }) => {
159-
getMeter(target);
160-
});
158+
field.addEventListener('keyup', ({ target }) => getMeter(target));
161159
});
162160

163161
// Set a handler for the validation script

build/media_source/system/js/fields/select-colour.es6.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
};
2020

2121
const updateSelectboxColour = () => {
22-
const colourSelects = [].slice.call(document.querySelectorAll('.form-select-color-state'));
23-
24-
colourSelects.forEach((colourSelect) => {
22+
document.querySelectorAll('.form-select-color-state').forEach((colourSelect) => {
2523
const value = parseInt(colourSelect.value, 10);
2624

2725
// Add class on page load

build/media_source/system/js/fields/validate.es6.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class JFormValidator {
3737
});
3838

3939
// Attach all forms with a class 'form-validate'
40-
const forms = [].slice.call(document.querySelectorAll('form'));
41-
42-
forms.forEach((form) => {
40+
document.querySelectorAll('form').forEach((form) => {
4341
if (form.classList.contains('form-validate')) {
4442
this.attachToForm(form);
4543
}
@@ -74,8 +72,7 @@ class JFormValidator {
7472
}
7573
}
7674

77-
element.classList.remove('form-control-danger');
78-
element.classList.remove('invalid');
75+
element.classList.remove('form-control-danger', 'invalid');
7976
element.classList.add('form-control-success');
8077
element.parentNode.classList.remove('has-danger');
8178
element.parentNode.classList.add('has-success');
@@ -97,10 +94,8 @@ class JFormValidator {
9794
// Get a label
9895
const label = element.form.querySelector(`label[for="${element.id}"]`);
9996

100-
element.classList.remove('form-control-success');
101-
element.classList.remove('valid');
102-
element.classList.add('form-control-danger');
103-
element.classList.add('invalid');
97+
element.classList.remove('form-control-success', 'valid');
98+
element.classList.add('form-control-danger', 'invalid');
10499
element.parentNode.classList.remove('has-success');
105100
element.parentNode.classList.add('has-danger');
106101
element.setAttribute('aria-invalid', 'true');
@@ -145,18 +140,13 @@ class JFormValidator {
145140
message = label.querySelector('span.form-control-feedback');
146141
}
147142

148-
element.classList.remove('form-control-danger');
149-
element.classList.remove('form-control-success');
150-
element.classList.remove('invalid');
143+
element.classList.remove('form-control-danger', 'form-control-success', 'remove');
151144
element.classList.add('valid');
152-
element.parentNode.classList.remove('has-danger');
153-
element.parentNode.classList.remove('has-success');
145+
element.parentNode.classList.remove('has-danger', 'has-success');
154146

155147
// Remove message
156-
if (message) {
157-
if (label) {
158-
label.removeChild(message);
159-
}
148+
if (message && label) {
149+
label.removeChild(message);
160150
}
161151

162152
// Restore Label
@@ -256,7 +246,7 @@ class JFormValidator {
256246
if (form.nodeName === 'FORM') {
257247
fields = [].slice.call(form.elements);
258248
} else {
259-
fields = [].slice.call(form.querySelectorAll('input, textarea, select, button, fieldset'));
249+
fields = form.querySelectorAll('input, textarea, select, button, fieldset');
260250
}
261251
fields.forEach((field) => {
262252
if (this.validate(field) === false) {
@@ -294,7 +284,7 @@ class JFormValidator {
294284
if (form.nodeName === 'FORM') {
295285
elements = [].slice.call(form.elements);
296286
} else {
297-
elements = [].slice.call(form.querySelectorAll('input, textarea, select, button, fieldset'));
287+
elements = form.querySelectorAll('input, textarea, select, button, fieldset');
298288
}
299289

300290
// Iterate through the form object and attach the validate method to all input fields.

build/media_source/system/js/highlight.es6.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ if (Joomla.getOptions && typeof Joomla.getOptions === 'function' && Joomla.getOp
2929
const instance = new Mark(element);
3030

3131
// Loop through the terms
32-
options.highLight.forEach((term) => {
33-
instance.mark(term, options);
34-
});
32+
options.highLight.forEach((term) => instance.mark(term, options));
3533
}
3634
} else {
3735
const start = document.querySelector(`#${options.start}`);

build/media_source/system/js/inlinehelp.es6.js

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,47 @@
99
* @param {String} toggleClass The class name of the DIVs to toggle display for
1010
*/
1111
Joomla.toggleInlineHelp = (toggleClass) => {
12-
[].slice.call(document.querySelectorAll(`div.${toggleClass}`))
13-
.forEach((elDiv) => {
14-
// Toggle the visibility of the node by toggling the 'd-none' Bootstrap class.
15-
elDiv.classList.toggle('d-none');
16-
// The ID of the description whose visibility is toggled.
17-
const myId = elDiv.id;
18-
// The ID of the control described by this node (same ID, minus the '-desc' suffix).
19-
const controlId = myId ? myId.substring(0, myId.length - 5) : null;
20-
// Get the control described by this node.
21-
const elControl = controlId ? document.getElementById(controlId) : null;
22-
// Is this node hidden?
23-
const isHidden = elDiv.classList.contains('d-none');
12+
document.querySelectorAll(`div.${toggleClass}`).forEach((elDiv) => {
13+
// Toggle the visibility of the node by toggling the 'd-none' Bootstrap class.
14+
elDiv.classList.toggle('d-none');
15+
// The ID of the description whose visibility is toggled.
16+
const myId = elDiv.id;
17+
// The ID of the control described by this node (same ID, minus the '-desc' suffix).
18+
const controlId = myId ? myId.substring(0, myId.length - 5) : null;
19+
// Get the control described by this node.
20+
const elControl = controlId ? document.getElementById(controlId) : null;
21+
// Is this node hidden?
22+
const isHidden = elDiv.classList.contains('d-none');
2423

25-
// If we do not have a control we will exit early
26-
if (!controlId || !elControl) {
27-
return;
28-
}
24+
// If we do not have a control we will exit early
25+
if (!controlId || !elControl) {
26+
return;
27+
}
2928

30-
// Unset the aria-describedby attribute in the control when the description is hidden and vice–versa.
31-
if (isHidden && elControl.hasAttribute('aria-describedby')) {
32-
elControl.removeAttribute('aria-describedby');
33-
} else if (!isHidden) {
34-
elControl.setAttribute('aria-describedby', myId);
35-
}
36-
});
29+
// Unset the aria-describedby attribute in the control when the description is hidden and vice–versa.
30+
if (isHidden && elControl.hasAttribute('aria-describedby')) {
31+
elControl.removeAttribute('aria-describedby');
32+
} else if (!isHidden) {
33+
elControl.setAttribute('aria-describedby', myId);
34+
}
35+
});
3736
};
3837

3938
// Initialisation. Clicking on anything with the button-inlinehelp class will toggle the inline help.
40-
[].slice.call(document.querySelectorAll('.button-inlinehelp'))
41-
.forEach((elToggler) => {
42-
// The class of the DIVs to toggle visibility on is defined by the data-class attribute of the click target.
43-
const toggleClass = elToggler.dataset.class ?? 'hide-aware-inline-help';
44-
const collection = document.getElementsByClassName(toggleClass);
39+
document.querySelectorAll('.button-inlinehelp').forEach((elToggler) => {
40+
// The class of the DIVs to toggle visibility on is defined by the data-class attribute of the click target.
41+
const toggleClass = elToggler.dataset.class ?? 'hide-aware-inline-help';
42+
const collection = document.getElementsByClassName(toggleClass);
4543

46-
// no description => hide inlinehelp button
47-
if (collection.length === 0) {
48-
elToggler.classList.add('d-none');
49-
return;
50-
}
44+
// no description => hide inlinehelp button
45+
if (collection.length === 0) {
46+
elToggler.classList.add('d-none');
47+
return;
48+
}
5149

52-
// Add the click handler.
53-
elToggler.addEventListener('click', (event) => {
54-
event.preventDefault();
55-
Joomla.toggleInlineHelp(toggleClass);
56-
});
50+
// Add the click handler.
51+
elToggler.addEventListener('click', (event) => {
52+
event.preventDefault();
53+
Joomla.toggleInlineHelp(toggleClass);
5754
});
55+
});

build/media_source/system/js/messages.es6.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Joomla.renderMessages = (messages, selector, keepOld, timeout) => {
5353
Joomla.removeMessages(messageContainer);
5454
}
5555

56-
[].slice.call(Object.keys(messages)).forEach((type) => {
56+
Object.keys(messages).forEach((type) => {
5757
let alertClass = type;
5858

5959
// Array of messages of this type
@@ -107,12 +107,7 @@ Joomla.renderMessages = (messages, selector, keepOld, timeout) => {
107107
*/
108108
Joomla.removeMessages = (container) => {
109109
const messageContainer = getMessageContainer(container);
110-
const alerts = [].slice.call(messageContainer.querySelectorAll('joomla-alert'));
111-
if (alerts.length) {
112-
alerts.forEach((alert) => {
113-
alert.close();
114-
});
115-
}
110+
messageContainer.querySelectorAll('joomla-alert').forEach((alert) => alert.close());
116111
};
117112

118113
document.addEventListener('DOMContentLoaded', () => {

build/media_source/system/js/searchtools.es6.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Joomla = window.Joomla || {};
110110
this.clearButton = document.querySelector(this.options.clearBtnSelector);
111111

112112
// Ordering
113-
this.orderCols = Array.prototype.slice.call(document.querySelectorAll(`${this.options.formSelector} ${this.options.orderColumnSelector}`));
113+
this.orderCols = document.querySelectorAll(`${this.options.formSelector} ${this.options.orderColumnSelector}`);
114114
this.orderField = document.querySelector(`${this.options.formSelector} ${this.options.orderFieldSelector}`);
115115

116116
// Limit
@@ -375,17 +375,17 @@ Joomla = window.Joomla || {};
375375
// eslint-disable-next-line consistent-return
376376
getFilterFields() {
377377
if (this.mainContainer) {
378-
return Array.prototype.slice.call(this.mainContainer.querySelectorAll('select,input'));
378+
return this.mainContainer.querySelectorAll('select,input');
379379
}
380380
if (this.filterContainer) {
381-
return Array.prototype.slice.call(this.filterContainer.querySelectorAll('select,input'));
381+
return this.filterContainer.querySelectorAll('select,input');
382382
}
383383

384384
return [];
385385
}
386386

387387
getListFields() {
388-
return Array.prototype.slice.call(this.listContainer.querySelectorAll('select'));
388+
return this.listContainer.querySelectorAll('select');
389389
}
390390

391391
// Common container functions

0 commit comments

Comments
 (0)