From 9f12c3ba2c2c229ae71660b7ddaaae6e274872d1 Mon Sep 17 00:00:00 2001 From: Lodder Date: Tue, 21 May 2024 12:27:59 +0100 Subject: [PATCH] [5.2] Minor cleanup for plugins JS (#42797) * Minor cleanup for plugins JS * Update build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js * Fix --- .../plg_captcha_recaptcha/js/recaptcha.es6.js | 3 +-- .../js/recaptcha.es6.js | 3 +-- .../js/codemirror.es6.js | 4 +--- .../js/joomla-editor-codemirror.w-c.es6.js | 8 ++----- .../js/tinymce-builder.es6.js | 6 +---- .../js/packageinstaller.es6.js | 4 +--- .../js/client.es6.js | 4 ++-- .../plg_media-action_rotate/js/rotate.es6.js | 23 ++++++------------- .../js/webauthn.es6.js | 4 +--- .../js/extensionupdatecheck.es6.js | 13 ++++------- .../js/jupdatecheck.es6.js | 13 ++++------- .../js/overridecheck.es6.js | 13 ++++------- .../js/privacycheck.es6.js | 4 +--- .../plg_system_debug/js/debug.es6.js | 7 ++---- .../js/guidedtours.es6.js | 10 ++++---- .../js/run-schedule.es6.js | 4 +--- .../plg_system_webauthn/js/login.es6.js | 11 +++------ .../plg_system_webauthn/js/management.es6.js | 15 ++---------- 18 files changed, 43 insertions(+), 106 deletions(-) diff --git a/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js b/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js index 938274ad7570d..9b5b2cd18747f 100644 --- a/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js +++ b/build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js @@ -8,10 +8,9 @@ 'use strict'; window.JoomlainitReCaptcha2 = () => { - const elements = [].slice.call(document.getElementsByClassName('g-recaptcha')); const optionKeys = ['sitekey', 'theme', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback']; - elements.forEach((element) => { + document.querySelectorAll('.g-recaptcha').forEach((element) => { let options = {}; if (element.dataset) { diff --git a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js index 83e828df72861..a66792e323779 100644 --- a/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js +++ b/build/media_source/plg_captcha_recaptcha_invisible/js/recaptcha.es6.js @@ -8,10 +8,9 @@ 'use strict'; window.JoomlainitReCaptchaInvisible = () => { - const elements = [].slice.call(document.getElementsByClassName('g-recaptcha')); const optionKeys = ['sitekey', 'badge', 'size', 'tabindex', 'callback', 'expired-callback', 'error-callback']; - elements.forEach((element) => { + document.getElementsByClassName('g-recaptcha').forEach((element) => { let options = {}; if (element.dataset) { diff --git a/build/media_source/plg_editors_codemirror/js/codemirror.es6.js b/build/media_source/plg_editors_codemirror/js/codemirror.es6.js index 2fb8b5a8f4c26..ef896352d6f20 100644 --- a/build/media_source/plg_editors_codemirror/js/codemirror.es6.js +++ b/build/media_source/plg_editors_codemirror/js/codemirror.es6.js @@ -125,9 +125,7 @@ const optionsToExtensions = async (options) => { const [module, methods] = extInfo; q.push(import(module).then((modObject) => { // Call each method - methods.forEach((method) => { - extensions.push(modObject[method]()); - }); + methods.forEach((method) => extensions.push(modObject[method]())); })); }); } diff --git a/build/media_source/plg_editors_codemirror/js/joomla-editor-codemirror.w-c.es6.js b/build/media_source/plg_editors_codemirror/js/joomla-editor-codemirror.w-c.es6.js index 6d0cc79db52c4..c09bc4f288955 100644 --- a/build/media_source/plg_editors_codemirror/js/joomla-editor-codemirror.w-c.es6.js +++ b/build/media_source/plg_editors_codemirror/js/joomla-editor-codemirror.w-c.es6.js @@ -103,9 +103,7 @@ class CodemirrorEditor extends HTMLElement { // Relocate BS modals, to resolve z-index issue in full screen this.bsModals = this.querySelectorAll('.joomla-modal.modal'); - this.bsModals.forEach((modal) => { - document.body.appendChild(modal); - }); + this.bsModals.forEach((modal) => document.body.appendChild(modal)); } // Create and register the Editor @@ -129,9 +127,7 @@ class CodemirrorEditor extends HTMLElement { // Restore modals if (this.bsModals && this.bsModals.length) { - this.bsModals.forEach((modal) => { - this.appendChild(modal); - }); + this.bsModals.forEach((modal) => this.appendChild(modal)); } } } diff --git a/build/media_source/plg_editors_tinymce/js/tinymce-builder.es6.js b/build/media_source/plg_editors_tinymce/js/tinymce-builder.es6.js index 7345066947363..7b68d7d2574a5 100644 --- a/build/media_source/plg_editors_tinymce/js/tinymce-builder.es6.js +++ b/build/media_source/plg_editors_tinymce/js/tinymce-builder.es6.js @@ -464,8 +464,4 @@ const toggleAvailableOption = () => { window.addEventListener('load', () => toggleAvailableOption()); // Allow to select the group only once per the set -selects.forEach((select) => { - select.addEventListener('change', () => { - toggleAvailableOption(); - }); -}); +selects.forEach((select) => select.addEventListener('change', () => toggleAvailableOption())); diff --git a/build/media_source/plg_installer_packageinstaller/js/packageinstaller.es6.js b/build/media_source/plg_installer_packageinstaller/js/packageinstaller.es6.js index 178be5dc981de..64c5fec32cafc 100644 --- a/build/media_source/plg_installer_packageinstaller/js/packageinstaller.es6.js +++ b/build/media_source/plg_installer_packageinstaller/js/packageinstaller.es6.js @@ -63,9 +63,7 @@ Joomla = window.Joomla || {}; uploadUrl += `&return=${returnUrl}`; } - button.addEventListener('click', () => { - fileInput.click(); - }); + button.addEventListener('click', () => fileInput.click()); fileInput.addEventListener('change', () => { if (uploading) { diff --git a/build/media_source/plg_installer_webinstaller/js/client.es6.js b/build/media_source/plg_installer_webinstaller/js/client.es6.js index 17f30b55db7c0..4f4b8e23cc9b2 100644 --- a/build/media_source/plg_installer_webinstaller/js/client.es6.js +++ b/build/media_source/plg_installer_webinstaller/js/client.es6.js @@ -184,7 +184,7 @@ class WebInstaller { WebInstaller.clicker(); if (webInstallerOptions.view !== 'extension') { - [].slice.call(document.querySelectorAll('div.load-extension')).forEach((element) => { + document.querySelectorAll('div.load-extension').forEach((element) => { element.addEventListener('click', (event) => { event.preventDefault(); this.processLinkClick(element.getAttribute('data-url')); @@ -237,7 +237,7 @@ class WebInstaller { } clickforlinks() { - [].slice.call(document.querySelectorAll('a.transcode')).forEach((element) => { + document.querySelectorAll('a.transcode').forEach((element) => { const ajaxurl = element.getAttribute('href'); element.addEventListener('click', (event) => { diff --git a/build/media_source/plg_media-action_rotate/js/rotate.es6.js b/build/media_source/plg_media-action_rotate/js/rotate.es6.js index 0a054c38264ec..f5a2871c69c63 100644 --- a/build/media_source/plg_media-action_rotate/js/rotate.es6.js +++ b/build/media_source/plg_media-action_rotate/js/rotate.es6.js @@ -62,27 +62,18 @@ const initRotate = (image) => { target.value = 0; // Deselect all buttons - [].slice.call(document.querySelectorAll('#jform_rotate_distinct label')) - .forEach((element) => { - element.classList.remove('active'); - element.classList.remove('focus'); - }); + document.querySelectorAll('#jform_rotate_distinct label').forEach((element) => element.classList.remove('active', 'focus')); }); // The 90 degree rotate buttons listeners - [].slice.call(document.querySelectorAll('#jform_rotate_distinct [type=radio]')) - .forEach((element) => { - element.addEventListener('click', ({ target }) => { - rotate(parseInt(target.value, 10), image); + document.querySelectorAll('#jform_rotate_distinct [type=radio]').forEach((element) => { + element.addEventListener('click', ({ target }) => { + rotate(parseInt(target.value, 10), image); - // Deselect all buttons - [].slice.call(document.querySelectorAll('#jform_rotate_distinct label')) - .forEach((el) => { - el.classList.remove('active'); - el.classList.remove('focus'); - }); - }); + // Deselect all buttons + document.querySelectorAll('#jform_rotate_distinct label').forEach((el) => el.classList.remove('active', 'focus')); }); + }); activated = true; } diff --git a/build/media_source/plg_multifactorauth_webauthn/js/webauthn.es6.js b/build/media_source/plg_multifactorauth_webauthn/js/webauthn.es6.js index fb13fac24c7f5..3e5c8050c7636 100644 --- a/build/media_source/plg_multifactorauth_webauthn/js/webauthn.es6.js +++ b/build/media_source/plg_multifactorauth_webauthn/js/webauthn.es6.js @@ -188,9 +188,7 @@ document.getElementById('users-mfa-captive-button-submit') .addEventListener('click', onValidateClick); } else { - document.querySelectorAll('.multifactorauth_webauthn_setup').forEach((btn) => { - btn.addEventListener('click', setUp); - }); + document.querySelectorAll('.multifactorauth_webauthn_setup').forEach((btn) => btn.addEventListener('click', setUp)); } }); })(Joomla, document); diff --git a/build/media_source/plg_quickicon_extensionupdate/js/extensionupdatecheck.es6.js b/build/media_source/plg_quickicon_extensionupdate/js/extensionupdatecheck.es6.js index 813688ded259a..c7dc64c1a4d79 100644 --- a/build/media_source/plg_quickicon_extensionupdate/js/extensionupdatecheck.es6.js +++ b/build/media_source/plg_quickicon_extensionupdate/js/extensionupdatecheck.es6.js @@ -13,16 +13,13 @@ const update = (type, text) => { const link = document.getElementById('plg_quickicon_extensionupdate'); - const linkSpans = [].slice.call(link.querySelectorAll('span.j-links-link')); if (link) { link.classList.add(type); } - if (linkSpans.length) { - linkSpans.forEach((span) => { - span.innerHTML = Joomla.sanitizeHtml(text); - }); - } + link.querySelectorAll('span.j-links-link').forEach((span) => { + span.innerHTML = Joomla.sanitizeHtml(text); + }); }; /** @@ -57,7 +54,5 @@ }; // Give some times to the layout and other scripts to settle their stuff - window.addEventListener('load', () => { - setTimeout(fetchUpdate, 330); - }); + window.addEventListener('load', () => setTimeout(fetchUpdate, 330)); })(); diff --git a/build/media_source/plg_quickicon_joomlaupdate/js/jupdatecheck.es6.js b/build/media_source/plg_quickicon_joomlaupdate/js/jupdatecheck.es6.js index eb27ea84aea54..27d2fd12985f1 100644 --- a/build/media_source/plg_quickicon_joomlaupdate/js/jupdatecheck.es6.js +++ b/build/media_source/plg_quickicon_joomlaupdate/js/jupdatecheck.es6.js @@ -6,16 +6,13 @@ if (Joomla && Joomla.getOptions('js-extensions-update')) { const update = (type, text) => { const link = document.getElementById('plg_quickicon_joomlaupdate'); - const linkSpans = [].slice.call(link.querySelectorAll('span.j-links-link')); if (link) { link.classList.add(type); } - if (linkSpans.length) { - linkSpans.forEach((span) => { - span.innerHTML = Joomla.sanitizeHtml(text); - }); - } + link.querySelectorAll('span.j-links-link').forEach((span) => { + span.innerHTML = Joomla.sanitizeHtml(text); + }); }; const fetchUpdate = () => { @@ -58,7 +55,5 @@ if (Joomla && Joomla.getOptions('js-extensions-update')) { }; // Give some times to the layout and other scripts to settle their stuff - window.addEventListener('load', () => { - setTimeout(fetchUpdate, 300); - }); + window.addEventListener('load', () => setTimeout(fetchUpdate, 300)); } diff --git a/build/media_source/plg_quickicon_overridecheck/js/overridecheck.es6.js b/build/media_source/plg_quickicon_overridecheck/js/overridecheck.es6.js index ca587dbe617e1..faed2462eb013 100644 --- a/build/media_source/plg_quickicon_overridecheck/js/overridecheck.es6.js +++ b/build/media_source/plg_quickicon_overridecheck/js/overridecheck.es6.js @@ -12,7 +12,6 @@ const options = Joomla.getOptions('js-override-check'); const update = (type, text, linkHref) => { const link = document.getElementById('plg_quickicon_overridecheck'); - const linkSpans = link.querySelectorAll('span.j-links-link'); if (link) { link.classList.add(type); @@ -21,11 +20,9 @@ } } - if (linkSpans.length) { - linkSpans.forEach((span) => { - span.innerHTML = Joomla.sanitizeHtml(text); - }); - } + link.querySelectorAll('span.j-links-link').forEach((span) => { + span.innerHTML = Joomla.sanitizeHtml(text); + }); }; /** @@ -66,7 +63,5 @@ }; // Give some times to the layout and other scripts to settle their stuff - window.addEventListener('load', () => { - setTimeout(checkOverride, 390); - }); + window.addEventListener('load', () => setTimeout(checkOverride, 390)); })(); diff --git a/build/media_source/plg_quickicon_privacycheck/js/privacycheck.es6.js b/build/media_source/plg_quickicon_privacycheck/js/privacycheck.es6.js index 20879fe4a7c13..a6de7485027cc 100644 --- a/build/media_source/plg_quickicon_privacycheck/js/privacycheck.es6.js +++ b/build/media_source/plg_quickicon_privacycheck/js/privacycheck.es6.js @@ -68,7 +68,5 @@ }; // Give some times to the layout and other scripts to settle their stuff - window.addEventListener('load', () => { - setTimeout(checkPrivacy, 360); - }); + window.addEventListener('load', () => setTimeout(checkPrivacy, 360)); })(document); diff --git a/build/media_source/plg_system_debug/js/debug.es6.js b/build/media_source/plg_system_debug/js/debug.es6.js index 2b690177f6c85..fa5570402b30d 100644 --- a/build/media_source/plg_system_debug/js/debug.es6.js +++ b/build/media_source/plg_system_debug/js/debug.es6.js @@ -22,8 +22,7 @@ * Register events */ const registerEvents = () => { - const sectionTogglers = [].slice.call(document.querySelectorAll(debugSectionTogglerSelector)); - sectionTogglers.forEach((toggler) => { + document.querySelectorAll(debugSectionTogglerSelector).forEach((toggler) => { toggler.addEventListener('click', (event) => { event.preventDefault(); toggle(toggler.getAttribute(toggleTargetAttribute)); @@ -31,7 +30,5 @@ }); }; - document.addEventListener('DOMContentLoaded', () => { - registerEvents(); - }); + document.addEventListener('DOMContentLoaded', registerEvents); })(document); diff --git a/build/media_source/plg_system_guidedtours/js/guidedtours.es6.js b/build/media_source/plg_system_guidedtours/js/guidedtours.es6.js index 18d9d38a8896a..5b24ff27bfa93 100644 --- a/build/media_source/plg_system_guidedtours/js/guidedtours.es6.js +++ b/build/media_source/plg_system_guidedtours/js/guidedtours.es6.js @@ -577,23 +577,23 @@ function loadTour(tourId) { } // Opt-in Start buttons -document.querySelector('body').addEventListener('click', (event) => { +document.querySelector('body').addEventListener('click', ({ target }) => { // Click somewhere else - if (!event.target || !event.target.classList.contains('button-start-guidedtour')) { + if (!target || !target.classList.contains('button-start-guidedtour')) { return; } // Click button but missing data-id if ( - (!event.target.hasAttribute('data-id') || event.target.getAttribute('data-id') <= 0) - && (!event.target.hasAttribute('data-gt-uid') || event.target.getAttribute('data-gt-uid') === '') + (!target.hasAttribute('data-id') || target.getAttribute('data-id') <= 0) + && (!target.hasAttribute('data-gt-uid') || target.getAttribute('data-gt-uid') === '') ) { Joomla.renderMessages({ error: [Joomla.Text._('PLG_SYSTEM_GUIDEDTOURS_COULD_NOT_LOAD_THE_TOUR')] }); return; } sessionStorage.setItem('tourToken', String(Joomla.getOptions('com_guidedtours.token'))); - loadTour(event.target.getAttribute('data-id') || event.target.getAttribute('data-gt-uid')); + loadTour(target.getAttribute('data-id') || target.getAttribute('data-gt-uid')); }); // Start a given tour diff --git a/build/media_source/plg_system_schedulerunner/js/run-schedule.es6.js b/build/media_source/plg_system_schedulerunner/js/run-schedule.es6.js index 1932cd064dcef..a2d943b62798e 100644 --- a/build/media_source/plg_system_schedulerunner/js/run-schedule.es6.js +++ b/build/media_source/plg_system_schedulerunner/js/run-schedule.es6.js @@ -30,7 +30,5 @@ const initScheduler = () => { }; ((document) => { - document.addEventListener('DOMContentLoaded', () => { - initScheduler(); - }); + document.addEventListener('DOMContentLoaded', initScheduler); })(document); diff --git a/build/media_source/plg_system_webauthn/js/login.es6.js b/build/media_source/plg_system_webauthn/js/login.es6.js index ee98feee2409c..6110a3e820ffc 100644 --- a/build/media_source/plg_system_webauthn/js/login.es6.js +++ b/build/media_source/plg_system_webauthn/js/login.es6.js @@ -256,12 +256,7 @@ window.Joomla = window.Joomla || {}; }; // Initialization. Runs on DOM content loaded since this script is always loaded deferred. - const loginButtons = [].slice.call(document.querySelectorAll('.plg_system_webauthn_login_button')); - if (loginButtons.length) { - loginButtons.forEach((button) => { - button.addEventListener('click', ({ currentTarget }) => { - Joomla.plgSystemWebauthnLogin(currentTarget.getAttribute('data-webauthn-form')); - }); - }); - } + document.querySelectorAll('.plg_system_webauthn_login_button').forEach((button) => { + button.addEventListener('click', ({ currentTarget }) => Joomla.plgSystemWebauthnLogin(currentTarget.getAttribute('data-webauthn-form'))); + }); })(Joomla, document); diff --git a/build/media_source/plg_system_webauthn/js/management.es6.js b/build/media_source/plg_system_webauthn/js/management.es6.js index d4abb618bcdea..afeac297b702d 100644 --- a/build/media_source/plg_system_webauthn/js/management.es6.js +++ b/build/media_source/plg_system_webauthn/js/management.es6.js @@ -469,19 +469,8 @@ window.Joomla = window.Joomla || {}; addButton.addEventListener('click', Joomla.plgSystemWebauthnAddOnClick); } - const editLabelButtons = [].slice.call(document.querySelectorAll('.plg_system_webauthn-manage-edit')); - if (editLabelButtons.length) { - editLabelButtons.forEach((button) => { - button.addEventListener('click', Joomla.plgSystemWebauthnEditOnClick); - }); - } - - const deleteButtons = [].slice.call(document.querySelectorAll('.plg_system_webauthn-manage-delete')); - if (deleteButtons.length) { - deleteButtons.forEach((button) => { - button.addEventListener('click', Joomla.plgSystemWebauthnDeleteOnClick); - }); - } + document.querySelectorAll('.plg_system_webauthn-manage-edit').forEach((button) => button.addEventListener('click', Joomla.plgSystemWebauthnEditOnClick)); + document.querySelectorAll('.plg_system_webauthn-manage-delete').forEach((button) => button.addEventListener('click', Joomla.plgSystemWebauthnDeleteOnClick)); }; // Initialization. Runs on DOM content loaded since this script is always loaded deferred.