mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2025-01-02 14:21:52 +00:00
CS etc
This commit is contained in:
parent
269e042321
commit
07bd714cf1
@ -1,18 +1,16 @@
|
||||
(() => {
|
||||
const jsonDataElement = document.getElementById('jed-rules-json');
|
||||
if (!jsonDataElement) {
|
||||
throw new Error('Initialization data is missing');
|
||||
}
|
||||
'use strict';
|
||||
|
||||
let jedOptions;
|
||||
try {
|
||||
jedOptions = JSON.parse(jsonDataElement.innerHTML);
|
||||
jedOptions = JSON.parse(document.getElementById('jed-rules-json').innerHTML);
|
||||
} catch (e) {
|
||||
throw new Error('Initialization data is missing');
|
||||
}
|
||||
|
||||
if (!jedOptions) throw new Error('Initialization data is missing');
|
||||
|
||||
add_validation = () => {
|
||||
const add_validation = () => {
|
||||
// Loop over them and prevent submission
|
||||
[...document.querySelectorAll('.needs-validation')].forEach((form) => {
|
||||
form.addEventListener('submit', (event) => {
|
||||
@ -28,56 +26,61 @@
|
||||
|
||||
function check(url, rule) {
|
||||
fetch(`${url}index.php?option=com_jedchecker&task=police.check&format=raw&rule=${rule}`)
|
||||
.then(response => response.text())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} ${response.statusCode}`);
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
const sidebar = document.querySelector(`#jed-${rule}`);
|
||||
const target = document.querySelector(`#police-check-result-${rule}`);
|
||||
const sidebar = document.getElementById(`jed-${rule}`);
|
||||
const target = document.getElementById(`police-check-result-${rule}`);
|
||||
|
||||
target.innerHTML = data;
|
||||
|
||||
const error = [...target.querySelectorAll('.alert-danger')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-danger')].map(el => el.textContent = error || '');
|
||||
[...sidebar.querySelectorAll('.badge.bg-danger')].forEach(el => el.textContent = error || '');
|
||||
|
||||
const warning = [...target.querySelectorAll('.alert-warning')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-warning')].map(el => el.textContent = warning || '');
|
||||
[...sidebar.querySelectorAll('.badge.bg-warning')].forEach(el => el.textContent = warning || '');
|
||||
|
||||
const compat = [...target.querySelectorAll('.alert-secondary')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-secondary')].map(el => el.textContent = compat || '');
|
||||
[...sidebar.querySelectorAll('.badge.bg-secondary')].forEach(el => el.textContent = compat || '');
|
||||
|
||||
var info = [...target.querySelectorAll('.alert-info')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.textContent = info || '');
|
||||
const info = [...target.querySelectorAll('.alert-info')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-info')].forEach(el => el.textContent = info || '');
|
||||
|
||||
var success = [...target.querySelectorAll('.alert-success')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.classList.toggle('hidden', !success));
|
||||
const success = [...target.querySelectorAll('.alert-success')].length;
|
||||
[...sidebar.querySelectorAll('.badge.bg-info')].forEach(el => el.classList.toggle('hidden', !success));
|
||||
|
||||
[...sidebar.querySelectorAll('.spinner-border')].map(el => el.classList.add('hidden'));
|
||||
[...sidebar.querySelectorAll('.spinner-border')].forEach(el => el.classList.add('hidden'));
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
const sidebar = document.querySelector(`#jed-${rule}`);
|
||||
const target = document.querySelector(`#police-check-result-${rule}`);
|
||||
console.error(error);
|
||||
const sidebar = document.getElementById(`jed-${rule}`);
|
||||
const target = document.getElementById(`police-check-result-${rule}`);
|
||||
|
||||
target.innerHTML = `<span class="text-danger"><b>${error.status}:</b> ${xhr.status} ${xhr.statusText}</span>`;
|
||||
target.innerHTML = `<span class="text-danger"><b>${error.name}:</b> ${error.message}</span>`;
|
||||
|
||||
[...sidebar.querySelectorAll('.badge.bg-danger')].map(el => el.textContent = '?');
|
||||
[...sidebar.querySelectorAll('.badge.bg-danger, .badge.bg-secondary, .badge.bg-info')].map(el => el.textContent = '');
|
||||
[...sidebar.querySelectorAll('.badge.bg-danger')].forEach(el => el.textContent = '?');
|
||||
[...sidebar.querySelectorAll('.badge.bg-warning, .badge.bg-secondary, .badge.bg-info')].map(el => el.textContent = '');
|
||||
[...sidebar.querySelectorAll('.badge.bg-success, .spinner-border')].map(el => el.classList.add('hidden'));
|
||||
});
|
||||
}
|
||||
|
||||
let jed_collapse_init = false;
|
||||
window.Joomla.submitbutton = function (task) {
|
||||
if (task == 'check') {
|
||||
[...document.querySelectorAll(".jedchecker-results")].map((el) => el.classList.remove("hidden"));
|
||||
if (task === 'check') {
|
||||
[...document.querySelectorAll('.jedchecker-results')].forEach(el => el.classList.remove('hidden'));
|
||||
[...document.querySelectorAll('.jedchecker-results .badge:not(.bg-success)')].map((el) => el.innerHTML = '');
|
||||
[...document.querySelectorAll('.jedchecker-results .badge.bg-success')].map((el) => el.classList.add('hidden'));
|
||||
[...document.querySelectorAll('.jedchecker-results .spinner-border')].map((el) => el.classList.remove('hidden'));
|
||||
[...document.querySelectorAll('.police-check-result')].map((el) => el.innerHTML = '<div class="text-center text-info"><span class="spinner-border"></span></div>');
|
||||
[...document.querySelectorAll('.police-check-result')].forEach(el => el.innerHTML = '<div class='text-center text-info'><span class='spinner-border'></span></div>');
|
||||
|
||||
if (!jed_collapse_init) {
|
||||
[...document.querySelectorAll(".card-header[data-bs-toggle]")].forEach((el) => {
|
||||
el.classList.add("accordion-button");
|
||||
el.classList.add("collapsed");
|
||||
[...document.querySelectorAll('.card-header[data-bs-toggle]')].forEach(el => {
|
||||
el.classList.add('accordion-button');
|
||||
el.classList.add('collapsed');
|
||||
el.setAttribute('href', el.dataset.href);
|
||||
});
|
||||
|
||||
@ -87,15 +90,13 @@
|
||||
jed_collapse_init = true;
|
||||
}
|
||||
|
||||
jedOptions["rules"].forEach((rule) => {
|
||||
check(jedOptions["url"], rule);
|
||||
});
|
||||
jedOptions["rules"].forEach(rule => check(jedOptions["url"], rule));
|
||||
} else {
|
||||
Joomla.submitform(task);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('extension-upload').addEventListener('click', (event) => {
|
||||
document.getElementById('extension-upload').addEventListener('click', () => {
|
||||
add_validation();
|
||||
document.getElementById('jed_uploading_spinner').classList.remove('hidden');
|
||||
Joomla.submitbutton('uploads.upload')
|
||||
|
Loading…
Reference in New Issue
Block a user