MediaWiki:Common.js: различия между версиями

Нет описания правки
Метка: ручная отмена
мНет описания правки
Строка 392: Строка 392:
             if (hasTooManyRowspan || hasInvalidRowspan) return;
             if (hasTooManyRowspan || hasInvalidRowspan) return;


             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'));
                 var originalStyles = cells.map(function(cell) {
                 var originalStyles = cells.map(function(cell) {
Строка 402: Строка 402:


                 cells.forEach(function(cell, index) {
                 cells.forEach(function(cell, index) {
                     if (cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1') return;
                     // Обработчик для обычных ячеек
                     cell.addEventListener('mouseover', function() {
                     cell.addEventListener('mouseover', function() {
                         cells.forEach(function(innerCell, innerIndex) {
                         highlightCells(cell, rowIndex, originalStyles, true);
                            if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') {
                                innerCell.style.setProperty('background-color', brightenColor(originalStyles[innerIndex].backgroundColor), 'important');
                                innerCell.style.setProperty('color', brightenColor(originalStyles[innerIndex].color), 'important');
                            }
                        });
                     });
                     });
                     cell.addEventListener('mouseout', function() {
                     cell.addEventListener('mouseout', function() {
                         cells.forEach(function(innerCell, innerIndex) {
                         highlightCells(cell, rowIndex, originalStyles, false);
                            if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') {
                    });
                                 innerCell.style.setProperty('background-color', originalStyles[innerIndex].backgroundColor, 'important');
                });
                                 innerCell.style.setProperty('color', originalStyles[innerIndex].color, 'important');
 
                // Функция подсветки для обычных ячеек и rowspan ячеек
                function highlightCells(cell, rowIndex, originalStyles, highlight) {
                    var allRows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) {
                        return row.parentElement === tbody && !row.querySelector('table');
                    });
 
                    // Если у ячейки есть rowspan, подсветить все строки, которые она охватывает
                    if (cell.hasAttribute('rowspan')) {
                        var rowspan = parseInt(cell.getAttribute('rowspan'));
                        for (var i = 0; i < rowspan; i++) {
                            var targetRow = allRows[rowIndex + i];
                            var targetCell = targetRow ? targetRow.querySelectorAll('td, th')[index] : null;
                            if (targetCell) {
                                 targetCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[index].backgroundColor) : originalStyles[index].backgroundColor, 'important');
                                 targetCell.style.setProperty('color', highlight ? brightenColor(originalStyles[index].color) : originalStyles[index].color, 'important');
                             }
                             }
                        }
                    } else {
                        // Подсвечиваем rowspan ячейки в текущем ряду
                        allRows.forEach(function(row) {
                            var rowCells = Array.prototype.slice.call(row.querySelectorAll('td, th'));
                            rowCells.forEach(function(rowCell, cellIndex) {
                                if (rowCell.hasAttribute('rowspan')) {
                                    var rowspan = parseInt(rowCell.getAttribute('rowspan'));
                                    var cellRowIndex = allRows.indexOf(row);
                                    if (rowIndex >= cellRowIndex && rowIndex < cellRowIndex + rowspan) {
                                        rowCell.style.setProperty('background-color', highlight ? brightenColor(originalStyles[cellIndex].backgroundColor) : originalStyles[cellIndex].backgroundColor, 'important');
                                        rowCell.style.setProperty('color', highlight ? brightenColor(originalStyles[cellIndex].color) : originalStyles[cellIndex].color, 'important');
                                    }
                                }
                            });
                         });
                         });
                     });
                     }
                 });
                 }
             });
             });
         }
         }