MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 362: | Строка 362: | ||
// Пропускаем первую строку, если нет thead и нет класса 'no-header' | // Пропускаем первую строку, если нет thead и нет класса 'no-header' | ||
var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | ||
// Проходим по каждой строке для добавления событий подсветки | // Проходим по каждой строке для добавления событий подсветки | ||
| Строка 411: | Строка 374: | ||
cells.forEach(function(cell, cellIndex) { | cells.forEach(function(cell, cellIndex) { | ||
var rowspan = cell.hasAttribute('rowspan') ? parseInt(cell.getAttribute('rowspan'), 10) : 1; | |||
// Наведение на ячейку | |||
cell.addEventListener('mouseover', function() { | |||
highlightRow(rowIndex, rowspan); | |||
}); | |||
// Убираем подсветку при выходе мыши | |||
cell.addEventListener('mouseout', function() { | |||
resetHighlight(rowIndex, rowspan); | |||
}); | |||
// Функция для подсветки строки и ячеек с rowspan | |||
function highlightRow(startRowIndex, rowspan) { | |||
for (var i = startRowIndex; i < startRowIndex + rowspan; i++) { | |||
var targetRow = rows[i]; | |||
if (!targetRow) continue; | |||
var targetCells = Array.prototype.slice.call(targetRow.querySelectorAll('td, th')); | |||
targetCells.forEach(function(targetCell) { | |||
targetCell.style.backgroundColor = brightenColor(getComputedStyle(targetCell).backgroundColor); | |||
targetCell.style.color = brightenColor(getComputedStyle(targetCell).color); | |||
}); | |||
} | |||
// Подсветить все ячейки в текущем ряду | |||
cells.forEach(function(targetCell) { | |||
targetCell.style.backgroundColor = brightenColor(getComputedStyle(targetCell).backgroundColor); | |||
targetCell.style.color = brightenColor(getComputedStyle(targetCell).color); | |||
}); | }); | ||
} | |||
// Функция для сброса подсветки | |||
for (var i = | function resetHighlight(startRowIndex, rowspan) { | ||
for (var i = startRowIndex; i < startRowIndex + rowspan; i++) { | |||
var | var targetRow = rows[i]; | ||
if (!targetRow) continue; | |||
var targetCells = Array.prototype.slice.call(targetRow.querySelectorAll('td, th')); | |||
targetCells.forEach(function(targetCell, targetIndex) { | |||
targetCell.style.backgroundColor = originalStyles[targetIndex].backgroundColor; | |||
targetCell.style.color = originalStyles[targetIndex].color; | |||
}); | }); | ||
} | } | ||
// Сбросить подсветку всех ячеек в текущем ряду | |||
cells.forEach(function(targetCell, targetIndex) { | |||
targetCell.style.backgroundColor = originalStyles[targetIndex].backgroundColor; | |||
targetCell.style.color = originalStyles[targetIndex].color; | |||
}); | |||
} | } | ||
}); | }); | ||