MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 392: | Строка 392: | ||
if (hasTooManyRowspan || hasInvalidRowspan) return; | if (hasTooManyRowspan || hasInvalidRowspan) return; | ||
topLevelRows.forEach(function(row) { | topLevelRows.forEach(function(row, rowIndex) { | ||
var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | ||
var originalStyles = cells.map(function(cell) { | var originalStyles = cells.map(function(cell) { | ||
| Строка 402: | Строка 402: | ||
cells.forEach(function(cell, index) { | cells.forEach(function(cell, index) { | ||
// Обработчик для обычных ячеек | |||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
highlightCells(cell, rowIndex, originalStyles, true); | |||
}); | }); | ||
cell.addEventListener('mouseout', function() { | cell.addEventListener('mouseout', function() { | ||
highlightCells(cell, rowIndex, originalStyles, false); | |||
}); | |||
}); | |||
// Функция подсветки для обычных ячеек и rowspan ячеек | |||
function highlightCells(cell, rowIndex, originalStyles, highlight) { | |||
var allRows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | |||
return row.parentElement === tbody && !row.querySelector('table'); | |||
}); | |||
// Если у ячейки есть rowspan, подсветить все строки, которые она охватывает | |||
if (cell.hasAttribute('rowspan')) { | |||
var rowspan = parseInt(cell.getAttribute('rowspan')); | |||
for (var i = 0; i < rowspan; i++) { | |||
var targetRow = allRows[rowIndex + i]; | |||
var targetCell = targetRow ? targetRow.querySelectorAll('td, th')[index] : null; | |||
if (targetCell) { | |||
targetCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[index].backgroundColor) : originalStyles[index].backgroundColor, 'important'); | |||
targetCell.style.setProperty('color', highlight ? brightenColor(originalStyles[index].color) : originalStyles[index].color, 'important'); | |||
} | } | ||
} | |||
} else { | |||
// Подсвечиваем rowspan ячейки в текущем ряду | |||
allRows.forEach(function(row) { | |||
var rowCells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | |||
rowCells.forEach(function(rowCell, cellIndex) { | |||
if (rowCell.hasAttribute('rowspan')) { | |||
var rowspan = parseInt(rowCell.getAttribute('rowspan')); | |||
var cellRowIndex = allRows.indexOf(row); | |||
if (rowIndex >= cellRowIndex && rowIndex < cellRowIndex + rowspan) { | |||
rowCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[cellIndex].backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important'); | |||
rowCell.style.setProperty('color', highlight ? brightenColor(originalStyles[cellIndex].color) : originalStyles[cellIndex].color, 'important'); | |||
} | |||
} | |||
}); | |||
}); | }); | ||
} | } | ||
} | } | ||
}); | }); | ||
} | } | ||