mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2024-11-30 08:44:02 +00:00
Update script.js
This commit is contained in:
parent
9d12ef26e1
commit
8769bcc066
@ -1,98 +1,104 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const jsonDataElement = document.getElementById('jed-rules-json');
|
const jsonDataElement = document.getElementById('jed-rules-json');
|
||||||
if (!jsonDataElement) {
|
if (!jsonDataElement) {
|
||||||
thrown new Error('Initialization data is missing');
|
throw new Error('Initialization data is missing');
|
||||||
}
|
}
|
||||||
let jedOptions;
|
let jedOptions;
|
||||||
try {
|
try {
|
||||||
jedOptions = JSON.parse(jsonDataElement.innerHTML);
|
jedOptions = JSON.parse(jsonDataElement.innerHTML);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
thrown new Error('Initialization data is missing');
|
throw new Error('Initialization data is missing');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jedOptions) thrown new Error('Initialization data is missing');
|
if (!jedOptions) throw new Error('Initialization data is missing');
|
||||||
|
|
||||||
const add_validation = () => {
|
add_validation = () => {
|
||||||
// Loop over them and prevent submission
|
// Loop over them and prevent submission
|
||||||
[...document.querySelectorAll('.needs-validation')].forEach((form) => {
|
[...document.querySelectorAll('.needs-validation')].forEach((form) => {
|
||||||
form.addEventListener('submit', (event) => {
|
form.addEventListener('submit', (event) => {
|
||||||
const form = event.target;
|
const form = event.target;
|
||||||
if (form.checkValidity() === false) {
|
if (form.checkValidity() === false) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
form.classList.add('was-validated');
|
form.classList.add('was-validated');
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function check(url, rule) {
|
function check(url, rule) {
|
||||||
fetch(`${url}index.php?option=com_jedchecker&task=police.check&format=raw&rule=${rule}`)
|
fetch(`${url}index.php?option=com_jedchecker&task=police.check&format=raw&rule=${rule}`)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const sidebar = document.querySelector(`#jed-${rule}`);
|
const sidebar = document.querySelector(`#jed-${rule}`);
|
||||||
const target = document.querySelector(`#police-check-result-${rule}`);
|
const target = document.querySelector(`#police-check-result-${rule}`);
|
||||||
|
|
||||||
target.innerHTML = data;
|
target.innerHTML = data;
|
||||||
|
|
||||||
const error = [...target.querySelectorAll('.alert-danger')].length;
|
const error = [...target.querySelectorAll('.alert-danger')].length;
|
||||||
[...sidebar.querySelectorAll('.badge.bg-danger')].map(el => el.textContent = error || '');
|
[...sidebar.querySelectorAll('.badge.bg-danger')].map(el => el.textContent = error || '');
|
||||||
|
|
||||||
const warning = [...target.querySelectorAll('.alert-warning')].length;
|
const warning = [...target.querySelectorAll('.alert-warning')].length;
|
||||||
[...sidebar.querySelectorAll('.badge.bg-warning')].map(el => el.textContent = warning || '');
|
[...sidebar.querySelectorAll('.badge.bg-warning')].map(el => el.textContent = warning || '');
|
||||||
|
|
||||||
const compat = [...target.querySelectorAll('.alert-secondary')].length;
|
const compat = [...target.querySelectorAll('.alert-secondary')].length;
|
||||||
[...sidebar.querySelectorAll('.badge.bg-secondary')].map(el => el.textContent = compat || '');
|
[...sidebar.querySelectorAll('.badge.bg-secondary')].map(el => el.textContent = compat || '');
|
||||||
|
|
||||||
var info = [...target.querySelectorAll('.alert-info')].length;
|
var info = [...target.querySelectorAll('.alert-info')].length;
|
||||||
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.textContent = info || '');
|
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.textContent = info || '');
|
||||||
|
|
||||||
var success = [...target.querySelectorAll('.alert-success')].length;
|
var success = [...target.querySelectorAll('.alert-success')].length;
|
||||||
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.classList.toggle('hidden', !success));
|
[...sidebar.querySelectorAll('.badge.bg-info')].map(el => el.classList.toggle('hidden', !success));
|
||||||
|
|
||||||
[...sidebar.querySelectorAll('.badge.bg-border')].map(el => el.classList.add('hidden'));
|
[...sidebar.querySelectorAll('.badge.bg-border')].map(el => el.classList.add('hidden'));
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
const sidebar = document.querySelector(`#jed-${rule}`);
|
const sidebar = document.querySelector(`#jed-${rule}`);
|
||||||
const target = document.querySelector(`#police-check-result-${rule}`);
|
const target = document.querySelector(`#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.status}:</b> ${xhr.status} ${xhr.statusText}</span>`;
|
||||||
|
|
||||||
[...sidebar.querySelectorAll('.badge.bg-danger')].map(el => el.textContent = '?');
|
[...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, .badge.bg-secondary, .badge.bg-info')].map(el => el.textContent = '');
|
||||||
[...sidebar.querySelectorAll('.badge.bg-success, .spinner-border')].map(el => el.addClass('hidden'));
|
[...sidebar.querySelectorAll('.badge.bg-success, .spinner-border')].map(el => el.addClass('hidden'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let jed_collapse_init = false;
|
let jed_collapse_init = false;
|
||||||
Joomla.submitbutton = function (task) {
|
window.Joomla.submitbutton = function (task) {
|
||||||
if (task == 'check') {
|
if (task == 'check') {
|
||||||
[...document.querySelectorAll(".jedchecker-results")].map((el) => el.removeClass("hidden"));
|
[...document.querySelectorAll(".jedchecker-results")].map((el) => el.removeClass("hidden"));
|
||||||
[...document.querySelectorAll('.jedchecker-results .badge:not(.bg-success)')].map((el) => el.innerHTML = '');
|
[...document.querySelectorAll('.jedchecker-results .badge:not(.bg-success)')].map((el) => el.innerHTML = '');
|
||||||
[...document.querySelectorAll('.jedchecker-results .badge.bg-success')].map((el) => el.addClass('hidden'));
|
[...document.querySelectorAll('.jedchecker-results .badge.bg-success')].map((el) => el.addClass('hidden'));
|
||||||
[...document.querySelectorAll('.jedchecker-results .spinner-border')].map((el) => el.removeClass('hidden'));
|
[...document.querySelectorAll('.jedchecker-results .spinner-border')].map((el) => el.removeClass('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')].map((el) => el.innerHTML = '<div class="text-center text-info"><span class="spinner-border"></span></div>');
|
||||||
|
|
||||||
if (!jed_collapse_init) {
|
if (!jed_collapse_init) {
|
||||||
[...document.querySelectorAll(".card-header[data-bs-toggle]")].forEach((el) => {
|
[...document.querySelectorAll(".card-header[data-bs-toggle]")].forEach((el) => {
|
||||||
el.addClass("accordion-button collapsed");
|
el.addClass("accordion-button collapsed");
|
||||||
el.setAttribute('href', el.dataset.href);
|
el.setAttribute('href', el.dataset.href);
|
||||||
});
|
});
|
||||||
|
|
||||||
new bootstrap.Collapse(document.getElementById('jedchecker-welcome'));
|
new bootstrap.Collapse(document.getElementById('jedchecker-welcome'));
|
||||||
new bootstrap.Collapse(document.getElementById('jedchecker-contributors'));
|
new bootstrap.Collapse(document.getElementById('jedchecker-contributors'));
|
||||||
|
|
||||||
jed_collapse_init = true;
|
jed_collapse_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
jedOptions["rules"].forEach((rule) => {
|
jedOptions["rules"].forEach((rule) => {
|
||||||
check(jedOptions["url"], rule);
|
check(jedOptions["url"], rule);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Joomla.submitform(task);
|
Joomla.submitform(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new bootstrap.Tooltip(document.getElementById('jedchecker'), {container: 'body', selector: '[data-bs-toggle=tooltip]'});
|
document.getElementById('extension-upload').addEventListener('click', (event) => {
|
||||||
|
add_validation();
|
||||||
|
document.getElementById('jed_uploading_spinner').classList.remove('hidden');
|
||||||
|
Joomla.submitbutton('uploads.upload')
|
||||||
|
});
|
||||||
|
|
||||||
|
new bootstrap.Tooltip(document.getElementById('jedchecker'), {container: 'body', selector: '[data-bs-toggle=tooltip]'});
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user