Skip to content

Commit

Permalink
[5.2] Minor cleanup for plugins JS (#42797)
Browse files Browse the repository at this point in the history
* Minor cleanup for plugins JS
* Update build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js
* Fix
  • Loading branch information
C-Lodder authored May 21, 2024
1 parent 8ecc131 commit 9f12c3b
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 106 deletions.
3 changes: 1 addition & 2 deletions build/media_source/plg_captcha_recaptcha/js/recaptcha.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]()));
}));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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) => {
Expand Down
23 changes: 7 additions & 16 deletions build/media_source/plg_media-action_rotate/js/rotate.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

/**
Expand Down Expand Up @@ -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));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
};

/**
Expand Down Expand Up @@ -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));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -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);
7 changes: 2 additions & 5 deletions build/media_source/plg_system_debug/js/debug.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@
* 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));
});
});
};

document.addEventListener('DOMContentLoaded', () => {
registerEvents();
});
document.addEventListener('DOMContentLoaded', registerEvents);
})(document);
10 changes: 5 additions & 5 deletions build/media_source/plg_system_guidedtours/js/guidedtours.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ const initScheduler = () => {
};

((document) => {
document.addEventListener('DOMContentLoaded', () => {
initScheduler();
});
document.addEventListener('DOMContentLoaded', initScheduler);
})(document);
11 changes: 3 additions & 8 deletions build/media_source/plg_system_webauthn/js/login.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 2 additions & 13 deletions build/media_source/plg_system_webauthn/js/management.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9f12c3b

Please sign in to comment.