Diferencia entre revisiones de «MediaWiki:Common.js»
Ir a la navegación
Ir a la búsqueda
Página blanqueada Etiqueta: Vaciado |
Sin resumen de edición |
||
| Línea 1: | Línea 1: | ||
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); | |||
Revisión del 21:51 3 abr 2026
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);