MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 365: | Строка 365: | ||
}); | }); | ||
// Наведение на строки | |||
row.addEventListener('mouseover', function() { | |||
highlightRow(row, rowIndex, true); | |||
}); | |||
row.addEventListener('mouseout', function() { | |||
highlightRow(row, rowIndex, false); | |||
}); | |||
cell.addEventListener('mouseout', function() { | // Наведение на ячейки | ||
cells.forEach(function(cell, cellIndex) { | |||
if (cell.hasAttribute('rowspan') && parseInt(cell.getAttribute('rowspan')) > 1) { | |||
// Обработка rowspan ячейки | |||
cell.addEventListener('mouseover', function() { | |||
highlightRowspanCell(cell, rowIndex, cellIndex, true); | |||
}); | |||
cell.addEventListener('mouseout', function() { | |||
highlightRowspanCell(cell, rowIndex, cellIndex, false); | |||
}); | |||
} | |||
}); | }); | ||
// Функция подсветки для | // Функция подсветки для строк | ||
function | function highlightRow(row, rowIndex, highlight) { | ||
var | // Подсвечиваем все ячейки в строке | ||
var rowCells = Array.prototype.slice.call(row.querySelectorAll('td, th')); | |||
rowCells.forEach(function(cell, cellIndex) { | |||
var cellStyle = getComputedStyle(cell); | |||
cell.style.setProperty('background-color', highlight ? brightenColor(cellStyle.backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important'); | |||
cell.style.setProperty('color', highlight ? brightenColor(cellStyle.color) : originalStyles[cellIndex].color, 'important'); | |||
}); | }); | ||
// Если | // Если есть rowspan ячейки, подсвечиваем все строки, которые они охватывают | ||
if (cell.hasAttribute('rowspan')) { | rowCells.forEach(function(cell, cellIndex) { | ||
if (cell.hasAttribute('rowspan')) { | |||
var rowspan = parseInt(cell.getAttribute('rowspan')); | |||
for (var i = 1; i < rowspan; i++) { | |||
var targetRow = topLevelRows[rowIndex + i]; | |||
if (targetRow) { | |||
var targetCell = targetRow.querySelectorAll('td, th')[cellIndex]; | |||
targetCell.style.setProperty('background-color', highlight ? brightenColor(getComputedStyle(targetCell).backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important'); | |||
targetCell.style.setProperty('color', highlight ? brightenColor(getComputedStyle(targetCell).color) : originalStyles[cellIndex].color, 'important'); | |||
} | |||
} | } | ||
} | } | ||
} | }); | ||
} | |||
// Функция подсветки для rowspan ячейки | |||
function highlightRowspanCell(cell, rowIndex, cellIndex, highlight) { | |||
var rowspan = parseInt(cell.getAttribute('rowspan')); | |||
for (var i = 0; i < rowspan; i++) { | |||
var targetRow = topLevelRows[rowIndex + i]; | |||
if (targetRow) { | |||
var targetCell = targetRow.querySelectorAll('td, th')[cellIndex]; | |||
targetCell.style.setProperty('background-color', highlight ? brightenColor(getComputedStyle(targetCell).backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important'); | |||
targetCell.style.setProperty('color', highlight ? brightenColor(getComputedStyle(targetCell).color) : originalStyles[cellIndex].color, 'important'); | |||
} | |||
} | |||
} | } | ||
} | } | ||