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

мНет описания правки
мНет описания правки
Строка 355: Строка 355:
             // Пропускаем первую строку, если нет <thead> и нет класса 'no-header-table'
             // Пропускаем первую строку, если нет <thead> и нет класса 'no-header-table'
             var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows;
             var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows;
            var hasInvalidRowspan = false;
            var hasTooManyRowspan = false;
            topLevelRows.forEach(function(row) {
                var cells = Array.prototype.slice.call(row.querySelectorAll('td, th')).filter(function(cell) {
                    return !cell.classList.contains('mobile');
                });
                var cellCount = cells.length;
                var rowspanCount = cells.filter(function(cell) {
                    return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1';
                }).length;
                if (rowspanCount > 2) {
                    hasTooManyRowspan = true;
                    return;
                }
                if (cellCount <= 3 && rowspanCount > 1) {
                    hasTooManyRowspan = true;
                    return;
                }
                var hasValidRowspanEdge = cells.some(function(cell, index) {
                    return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && (index === 0 || index === cells.length - 1);
                });
                if (!hasValidRowspanEdge && cells.some(function(cell, index) {
                    return cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1' && index > 0 && index < cells.length - 1;
                })) {
                    hasInvalidRowspan = true;
                }
            });
            if (hasTooManyRowspan || hasInvalidRowspan) return;


             topLevelRows.forEach(function(row, rowIndex) {
             topLevelRows.forEach(function(row, rowIndex) {
Строка 404: Строка 368:
                     // Обработчик для обычных ячеек
                     // Обработчик для обычных ячеек
                     cell.addEventListener('mouseover', function() {
                     cell.addEventListener('mouseover', function() {
                         highlightCells(cell, rowIndex, originalStyles, true);
                         highlightCells(cell, rowIndex, index, originalStyles, true);
                     });
                     });


                     cell.addEventListener('mouseout', function() {
                     cell.addEventListener('mouseout', function() {
                         highlightCells(cell, rowIndex, originalStyles, false);
                         highlightCells(cell, rowIndex, index, originalStyles, false);
                     });
                     });
                 });
                 });


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