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

мНет описания правки
мНет описания правки
Строка 365: Строка 365:
                 });
                 });


                 cells.forEach(function(cell, index) {
                 // Наведение на строки
                     // Обработчик для обычных ячеек
                row.addEventListener('mouseover', function() {
                    cell.addEventListener('mouseover', function() {
                     highlightRow(row, rowIndex, true);
                        highlightCells(cell, rowIndex, index, originalStyles, true);
                });
                    });
                row.addEventListener('mouseout', function() {
                    highlightRow(row, rowIndex, false);
                });


                     cell.addEventListener('mouseout', function() {
                // Наведение на ячейки
                        highlightCells(cell, rowIndex, index, originalStyles, false);
                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);
                        });
                    }
                 });
                 });


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