MediaWiki:Common.js
Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.
- Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
- Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
function safeNormalize(text) {
text = String(text || '').toLowerCase().trim();
try {
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
} catch (e) {
return text;
}
}
function hasMark(cellText) {
cellText = String(cellText || '').replace(/\s+/g, '').trim();
return (
cellText !== '' &&
(
cellText.indexOf('✔') !== -1 ||
cellText.indexOf('✅') !== -1 ||
cellText.indexOf('☑') !== -1
)
);
}
function filterMatrix(tableId, selectId, inputId) {
var table = document.getElementById(tableId);
var select = document.getElementById(selectId);
var input = document.getElementById(inputId);
if (!table || !select || !input || !table.tBodies.length) return;
var selectColIndex = select.value;
var inputText = safeNormalize(input.value);
var rows = table.tBodies[0].getElementsByTagName('tr');
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var tds = row.getElementsByTagName('td');
var matchCategory = true;
var matchText = true;
if (selectColIndex !== '') {
var colIdx = parseInt(selectColIndex, 10);
var categoryCell = tds[colIdx];
if (!categoryCell || !hasMark(categoryCell.textContent || categoryCell.innerText)) {
matchCategory = false;
}
}
if (inputText !== '') {
var rowContent = '';
if (tableId === 'tableSlot1') {
rowContent += (tds[0] ? (tds[0].textContent || tds[0].innerText) : '') + ' ';
rowContent += (tds[1] ? (tds[1].textContent || tds[1].innerText) : '');
} else {
rowContent += (tds[0] ? (tds[0].textContent || tds[0].innerText) : '') + ' ';
rowContent += (tds[1] ? (tds[1].textContent || tds[1].innerText) : '') + ' ';
rowContent += (tds[2] ? (tds[2].textContent || tds[2].innerText) : '');
}
rowContent = safeNormalize(rowContent);
if (rowContent.indexOf(inputText) === -1) {
matchText = false;
}
}
row.style.display = (matchCategory && matchText) ? '' : 'none';
}
}
function bindFilter(tableId, selectId, inputId) {
var table = document.getElementById(tableId);
var select = document.getElementById(selectId);
var input = document.getElementById(inputId);
if (!table || !select || !input) return;
select.addEventListener('change', function () {
filterMatrix(tableId, selectId, inputId);
});
input.addEventListener('input', function () {
filterMatrix(tableId, selectId, inputId);
});
}
function initOrozaDropFilters() {
bindFilter('tableSlot1', 'catSlot1', 'textSlot1');
bindFilter('tableSlot2', 'catSlot2', 'textSlot2');
}
document.addEventListener('DOMContentLoaded', initOrozaDropFilters);