MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 339: | Строка 339: | ||
// Функция для подсветки ячеек в таблице при наведении | // Функция для подсветки ячеек в таблице при наведении | ||
function applyHighlighting() { | function applyHighlighting() { | ||
if (/Mobi|Android/i.test(navigator.userAgent)) { | if (/Mobi|Android/i.test(navigator.userAgent)) { | ||
return; | return; | ||
} | } | ||
var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)'); | ||
| Строка 353: | Строка 351: | ||
if (tbody) { | if (tbody) { | ||
var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | ||
return !row.querySelector('table'); | return !row.querySelector('table'); | ||
}); | }); | ||
var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | ||
var | var originalStyles = {}; | ||
// | // Обрабатываем каждую строку таблицы | ||
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')); | ||
cells.forEach(function(cell, index) { | |||
var rowspan = parseInt(cell.getAttribute('rowspan'), 10) || 1; | |||
// Сохраняем исходные стили каждой ячейки | |||
if (!originalStyles[rowIndex]) originalStyles[rowIndex] = []; | |||
originalStyles[rowIndex][index] = { | |||
backgroundColor: getComputedStyle(cell).backgroundColor, | backgroundColor: getComputedStyle(cell).backgroundColor, | ||
color: getComputedStyle(cell).color | color: getComputedStyle(cell).color | ||
}; | }; | ||
// Обработчик при наведении на ячейку | // Обработчик при наведении на ячейку | ||
| Строка 421: | Строка 378: | ||
if (rowspan > 1) { | if (rowspan > 1) { | ||
for (var i = 0; i < rowspan; i++) { | for (var i = 0; i < rowspan; i++) { | ||
var targetRow = topLevelRows[ | var targetRow = topLevelRows[rowIndex + i]; | ||
if (targetRow) { | if (targetRow) { | ||
var targetCells = targetRow.querySelectorAll('td, th'); | var targetCells = targetRow.querySelectorAll('td, th'); | ||
Array.prototype.forEach.call(targetCells, function(innerCell) { | Array.prototype.forEach.call(targetCells, function(innerCell, innerIndex) { | ||
innerCell.style.backgroundColor = brightenColor(getComputedStyle(innerCell).backgroundColor); | innerCell.style.backgroundColor = brightenColor(getComputedStyle(innerCell).backgroundColor); | ||
innerCell.style.color = brightenColor(getComputedStyle(innerCell).color); | innerCell.style.color = brightenColor(getComputedStyle(innerCell).color); | ||
| Строка 434: | Строка 391: | ||
// Подсвечиваем ячейки в текущем ряду | // Подсвечиваем ячейки в текущем ряду | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
innerCell.style.backgroundColor = brightenColor(originalStyles[innerIndex].backgroundColor); | innerCell.style.backgroundColor = brightenColor(originalStyles[rowIndex][innerIndex].backgroundColor); | ||
innerCell.style.color = brightenColor(originalStyles[innerIndex].color); | innerCell.style.color = brightenColor(originalStyles[rowIndex][innerIndex].color); | ||
}); | }); | ||
}); | }); | ||
| Строка 444: | Строка 401: | ||
if (rowspan > 1) { | if (rowspan > 1) { | ||
for (var i = 0; i < rowspan; i++) { | for (var i = 0; i < rowspan; i++) { | ||
var targetRow = topLevelRows[ | var targetRow = topLevelRows[rowIndex + i]; | ||
if (targetRow) { | if (targetRow) { | ||
var targetCells = targetRow.querySelectorAll('td, th'); | var targetCells = targetRow.querySelectorAll('td, th'); | ||
Array.prototype.forEach.call(targetCells, function(innerCell) { | Array.prototype.forEach.call(targetCells, function(innerCell, innerIndex) { | ||
innerCell.style.backgroundColor = | innerCell.style.backgroundColor = originalStyles[rowIndex + i][innerIndex].backgroundColor; | ||
innerCell.style.color = | innerCell.style.color = originalStyles[rowIndex + i][innerIndex].color; | ||
}); | }); | ||
} | } | ||
| Строка 457: | Строка 414: | ||
// Восстанавливаем стили в текущем ряду | // Восстанавливаем стили в текущем ряду | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
innerCell.style.backgroundColor = originalStyles[innerIndex].backgroundColor; | innerCell.style.backgroundColor = originalStyles[rowIndex][innerIndex].backgroundColor; | ||
innerCell.style.color = originalStyles[innerIndex].color; | innerCell.style.color = originalStyles[rowIndex][innerIndex].color; | ||
}); | }); | ||
}); | }); | ||