MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Отмена правки 52659, сделанной Pok (обсуждение) Метка: отмена |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 341: | Строка 341: | ||
var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | ||
tables.forEach(function(table) { | |||
var tbody = table.querySelector('tbody'); | var tbody = table.querySelector('tbody'); | ||
var thead = table.querySelector('thead'); | var thead = table.querySelector('thead'); | ||
| Строка 347: | Строка 347: | ||
if (tbody) { | if (tbody) { | ||
var rows = Array. | var rows = Array.from(tbody.querySelectorAll('tr')).filter(function(row) { | ||
return row.parentElement === tbody && !row.querySelector('table'); | return row.parentElement === tbody && !row.querySelector('table'); | ||
}); | }); | ||
| Строка 357: | Строка 357: | ||
topLevelRows.forEach(function(row, rowIndex) { | topLevelRows.forEach(function(row, rowIndex) { | ||
var cells = Array. | var cells = Array.from(row.querySelectorAll('td, th')); | ||
var originalStyles = cells.map(function(cell) { | var originalStyles = cells.map(function(cell) { | ||
return { | return { | ||
| Строка 371: | Строка 371: | ||
rowspanCells.push({ cell: cell, rowIndex: rowIndex, rowspan: rowspan }); | rowspanCells.push({ cell: cell, rowIndex: rowIndex, rowspan: rowspan }); | ||
// Подсвечиваем строки, которые затрагивает ячейка с rowspan | // Подсвечиваем строки, которые затрагивает ячейка с rowspan (только один раз) | ||
var isRowspanHighlighted = false; | |||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
for (var i = 0; i < rowspan; i++) { | if (!isRowspanHighlighted) { | ||
for (var i = 0; i < rowspan; i++) { | |||
var targetRow = topLevelRows[rowIndex + i]; | |||
if (targetRow) { | |||
Array.from(targetRow.children).forEach(function(targetCell) { | |||
targetCell.style.setProperty('background-color', brightenColor(getComputedStyle(targetCell).backgroundColor), 'important'); | |||
targetCell.style.setProperty('color', brightenColor(getComputedStyle(targetCell).color), 'important'); | |||
}); | |||
} | |||
} | } | ||
isRowspanHighlighted = true; | |||
} | } | ||
}); | }); | ||
| Строка 388: | Строка 392: | ||
var targetRow = topLevelRows[rowIndex + i]; | var targetRow = topLevelRows[rowIndex + i]; | ||
if (targetRow) { | if (targetRow) { | ||
Array. | Array.from(targetRow.children).forEach(function(targetCell) { | ||
targetCell.style.setProperty('background-color', getComputedStyle(targetCell).backgroundColor, 'important'); | targetCell.style.setProperty('background-color', getComputedStyle(targetCell).backgroundColor, 'important'); | ||
targetCell.style.setProperty('color', getComputedStyle(targetCell).color, 'important'); | targetCell.style.setProperty('color', getComputedStyle(targetCell).color, 'important'); | ||
| Строка 394: | Строка 398: | ||
} | } | ||
} | } | ||
isRowspanHighlighted = false; | |||
}); | }); | ||
} | } | ||