MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 355: | Строка 355: | ||
// Пропускаем первую строку, если нет <thead> и нет класса 'no-header-table' | // Пропускаем первую строку, если нет <thead> и нет класса 'no-header-table' | ||
var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | ||
topLevelRows.forEach(function(row, rowIndex) { | topLevelRows.forEach(function(row, rowIndex) { | ||
| Строка 404: | Строка 368: | ||
// Обработчик для обычных ячеек | // Обработчик для обычных ячеек | ||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
highlightCells(cell, rowIndex, originalStyles, true); | highlightCells(cell, rowIndex, index, originalStyles, true); | ||
}); | }); | ||
cell.addEventListener('mouseout', function() { | cell.addEventListener('mouseout', function() { | ||
highlightCells(cell, rowIndex, originalStyles, false); | highlightCells(cell, rowIndex, index, originalStyles, false); | ||
}); | }); | ||
}); | }); | ||
// Функция подсветки для обычных ячеек и rowspan ячеек | // Функция подсветки для обычных ячеек и rowspan ячеек | ||
function highlightCells(cell, rowIndex, originalStyles, highlight) { | function highlightCells(cell, rowIndex, cellIndex, originalStyles, highlight) { | ||
var allRows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | var allRows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | ||
return row.parentElement === tbody && !row.querySelector('table'); | return row.parentElement === tbody && !row.querySelector('table'); | ||
| Строка 422: | Строка 386: | ||
var rowspan = parseInt(cell.getAttribute('rowspan')); | var rowspan = parseInt(cell.getAttribute('rowspan')); | ||
for (var i = 0; i < rowspan; i++) { | for (var i = 0; i < rowspan; i++) { | ||
var targetRow = allRows[rowIndex + i]; | var targetRow = allRows[rowIndex + i]; // Получаем нужную строку | ||
var targetCell = targetRow ? targetRow.querySelectorAll('td, th')[ | var targetCell = targetRow ? targetRow.querySelectorAll('td, th')[cellIndex] : null; // Получаем нужную ячейку в строке | ||
if (targetCell) { | if (targetCell) { | ||
targetCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[ | targetCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[cellIndex].backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important'); | ||
targetCell.style.setProperty('color', highlight ? brightenColor(originalStyles[ | targetCell.style.setProperty('color', highlight ? brightenColor(originalStyles[cellIndex].color) : originalStyles[cellIndex].color, 'important'); | ||
} | } | ||
} | } | ||
| Строка 433: | Строка 397: | ||
allRows.forEach(function(row) { | allRows.forEach(function(row) { | ||
var rowCells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | var rowCells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | ||
rowCells.forEach(function(rowCell, | rowCells.forEach(function(rowCell, rowCellIndex) { | ||
if (rowCell.hasAttribute('rowspan')) { | if (rowCell.hasAttribute('rowspan')) { | ||
var rowspan = parseInt(rowCell.getAttribute('rowspan')); | var rowspan = parseInt(rowCell.getAttribute('rowspan')); | ||
var | var startRow = allRows.indexOf(row); // Индекс строки, где начинается rowspan | ||
if (rowIndex >= | if (rowIndex >= startRow && rowIndex < startRow + rowspan) { | ||
rowCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[ | rowCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[rowCellIndex].backgroundColor) : originalStyles[rowCellIndex].backgroundColor, 'important'); | ||
rowCell.style.setProperty('color', highlight ? brightenColor(originalStyles[ | rowCell.style.setProperty('color', highlight ? brightenColor(originalStyles[rowCellIndex].color) : originalStyles[rowCellIndex].color, 'important'); | ||
} | } | ||
} | } | ||