MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 335: | Строка 335: | ||
// Функция для подсветки ячеек в таблице при наведении | // Функция для подсветки ячеек в таблице при наведении | ||
function applyHighlighting() { | function applyHighlighting() { | ||
if (/Mobi|Android/i.test(navigator.userAgent)) | if (/Mobi|Android/i.test(navigator.userAgent)) return; | ||
var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | ||
| Строка 343: | Строка 341: | ||
tables.forEach(function(table) { | tables.forEach(function(table) { | ||
var tbody = table.querySelector('tbody'); | var tbody = table.querySelector('tbody'); | ||
if (!tbody) return; | |||
var rows = Array.from(tbody.querySelectorAll('tr')).filter(row => !row.querySelector('table')); | |||
var rowspanCells = []; | |||
var | rows.forEach(function(row, rowIndex) { | ||
var cells = Array.from(row.querySelectorAll('td, th')); | |||
cells.forEach(function(cell) { | |||
var rowspan = parseInt(cell.getAttribute('rowspan'), 10); | |||
// Если у ячейки есть rowspan | |||
if (!isNaN(rowspan) && rowspan > 1) { | |||
rowspanCells.push({ cell: cell, rowIndex: rowIndex, rowspan: rowspan }); | |||
// | // Подсветка для ячейки с rowspan | ||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
for (var i = 0; i < rowspan; i++) { | |||
if (rows[rowIndex + i]) { | |||
highlightRow(rows[rowIndex + i]); | |||
if ( | |||
} | } | ||
} | } | ||
}); | }); | ||
cell.addEventListener('mouseout', function() { | cell.addEventListener('mouseout', function() { | ||
for (var i = 0; i < rowspan; i++) { | |||
if (rows[rowIndex + i]) { | |||
resetRow(rows[rowIndex + i]); | |||
if ( | |||
} | } | ||
} | } | ||
}); | }); | ||
} | |||
// Подсветка для строки | |||
row.addEventListener('mouseover', function() { | |||
highlightRow(row); | |||
}); | }); | ||
row.addEventListener('mouseout', function() { | |||
resetRow(row); | |||
}); | |||
}); | |||
}); | |||
function highlightRow(row) { | |||
row.querySelectorAll('td, th').forEach(function(cell) { | |||
cell.style.backgroundColor = brightenColor(getComputedStyle(cell).backgroundColor); | |||
cell.style.color = brightenColor(getComputedStyle(cell).color); | |||
}); | |||
} | |||
function resetRow(row) { | |||
row.querySelectorAll('td, th').forEach(function(cell) { | |||
cell.style.backgroundColor = ''; // сбросить на стандартный фон | |||
cell.style.color = ''; // сбросить цвет текста | |||
}); | }); | ||
} | } | ||