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

Нет описания правки
Метка: ручная отмена
мНет описания правки
Строка 366: Строка 366:
             var hasTooManyRowspan = false;
             var hasTooManyRowspan = false;


// Проходим по строкам первого уровня
            // Проходим по строкам первого уровня
             topLevelRows.forEach(function(row) {
             topLevelRows.forEach(function(row) {
                // Получаем все ячейки строки, исключая те, что имеют класс 'mobile'
                 var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')).filter(function(cell) {
                 var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')).filter(function(cell) {
                return !cell.classList.contains('mobile');
                    return !cell.classList.contains('mobile');
                 });
                 });
                 var cellCount = cells.length;
                 var cellCount = cells.length;
Строка 406: Строка 405:
             // Если есть некорректные строки с rowspan или слишком много rowspan, выходим
             // Если есть некорректные строки с rowspan или слишком много rowspan, выходим
             if (hasTooManyRowspan || hasInvalidRowspan) return;
             if (hasTooManyRowspan || hasInvalidRowspan) return;
            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'));
                 var originalStyles = cells.map(function(cell) {
 
                     // Сохраняем оригинальные стили каждой ячейки
                // Сохраняем исходные стили каждой ячейки
                     return {
                 cells.forEach(function(cell, index) {
                     if (!originalStyles[rowIndex]) originalStyles[rowIndex] = [];
                     originalStyles[rowIndex][index] = {
                         backgroundColor: getComputedStyle(cell).backgroundColor,
                         backgroundColor: getComputedStyle(cell).backgroundColor,
                         color: getComputedStyle(cell).color
                         color: getComputedStyle(cell).color
Строка 418: Строка 421:
                 });
                 });


                // Добавляем события 'mouseover' и 'mouseout' для подсветки
                 cells.forEach(function(cell, index) {
                 cells.forEach(function(cell, index) {
                     if (cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1') return;
                     var rowspan = parseInt(cell.getAttribute('rowspan'), 10) || 1;


                     // Добавляем обработчик события при наведении мыши
                     // Добавляем обработчик события при наведении мыши
                     cell.addEventListener('mouseover', function() {
                     cell.addEventListener('mouseover', function() {
                        // Подсвечиваем все строки, охватываемые rowspan
                        if (rowspan > 1) {
                            for (var i = 0; i < rowspan; i++) {
                                var targetRow = topLevelRows[rowIndex + i];
                                if (targetRow) {
                                    var targetCells = targetRow.querySelectorAll('td, th');
                                    Array.prototype.forEach.call(targetCells, function(innerCell, innerIndex) {
                                        innerCell.style.backgroundColor = brightenColor(getComputedStyle(innerCell).backgroundColor);
                                        innerCell.style.color = brightenColor(getComputedStyle(innerCell).color);
                                    });
                                }
                            }
                        }
                        // Подсвечиваем ячейки в текущем ряду
                         cells.forEach(function(innerCell, innerIndex) {
                         cells.forEach(function(innerCell, innerIndex) {
                             if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') {
                             innerCell.style.backgroundColor = brightenColor(getComputedStyle(innerCell).backgroundColor);
                                // Увеличиваем яркость фона и текста ячейки при наведении
                            innerCell.style.color = brightenColor(getComputedStyle(innerCell).color);
                                innerCell.style.backgroundColor = brightenColor(originalStyles[innerIndex].backgroundColor);
                        });
                                innerCell.style.color = brightenColor(originalStyles[innerIndex].color);
 
                        // Подсвечиваем ячейки, прилегающие к rowspan
                        if (rowspan > 1) {
                            var nextRow = topLevelRows[rowIndex + rowspan];
                            if (nextRow) {
                                var nextRowCells = Array.prototype.slice.call(nextRow.querySelectorAll('td, th'));
                                nextRowCells.forEach(function(nextCell) {
                                    if (nextCell.cellIndex >= cell.cellIndex && nextCell.cellIndex < cell.cellIndex + rowspan) {
                                        nextCell.style.backgroundColor = brightenColor(getComputedStyle(nextCell).backgroundColor);
                                        nextCell.style.color = brightenColor(getComputedStyle(nextCell).color);
                                    }
                                });
                             }
                             }
                         });
                         }
                     });
                     });


                     // Добавляем обработчик события, когда мышь уходит с ячейки
                     // Добавляем обработчик события, когда мышь уходит с ячейки
                     cell.addEventListener('mouseout', function() {
                     cell.addEventListener('mouseout', function() {
                        // Восстанавливаем стили для всех строк, затронутых rowspan
                        if (rowspan > 1) {
                            for (var i = 0; i < rowspan; i++) {
                                var targetRow = topLevelRows[rowIndex + i];
                                if (targetRow) {
                                    var targetCells = targetRow.querySelectorAll('td, th');
                                    Array.prototype.forEach.call(targetCells, function(innerCell, innerIndex) {
                                        innerCell.style.backgroundColor = originalStyles[rowIndex + i][innerIndex].backgroundColor;
                                        innerCell.style.color = originalStyles[rowIndex + i][innerIndex].color;
                                    });
                                }
                            }
                        }
                        // Восстанавливаем стили в текущем ряду
                         cells.forEach(function(innerCell, innerIndex) {
                         cells.forEach(function(innerCell, innerIndex) {
                             if (!innerCell.hasAttribute('rowspan') || innerCell.getAttribute('rowspan') === '1') {
                             innerCell.style.backgroundColor = originalStyles[rowIndex][innerIndex].backgroundColor;
                                // Восстанавливаем оригинальные стили после наведения
                            innerCell.style.color = originalStyles[rowIndex][innerIndex].color;
                                innerCell.style.backgroundColor = originalStyles[innerIndex].backgroundColor;
                                innerCell.style.color = originalStyles[innerIndex].color;
                            }
                         });
                         });
                     });
                     });