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

Отмена правки 52659, сделанной Pok (обсуждение)
Метка: отмена
Нет описания правки
Строка 341: Строка 341:
     var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)');
     var tables = document.querySelectorAll('.wikitable:not(.no-highlight-table)');


     Array.prototype.forEach.call(tables, function(table) {
     tables.forEach(function(table) {
         var tbody = table.querySelector('tbody');
         var tbody = table.querySelector('tbody');
         var thead = table.querySelector('thead');
         var thead = table.querySelector('thead');
Строка 347: Строка 347:


         if (tbody) {
         if (tbody) {
             var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) {
             var rows = Array.from(tbody.querySelectorAll('tr')).filter(function(row) {
                 return row.parentElement === tbody && !row.querySelector('table');
                 return row.parentElement === tbody && !row.querySelector('table');
             });
             });
Строка 357: Строка 357:


             topLevelRows.forEach(function(row, rowIndex) {
             topLevelRows.forEach(function(row, rowIndex) {
                 var cells = Array.prototype.slice.call(row.querySelectorAll('td, th'));
                 var cells = Array.from(row.querySelectorAll('td, th'));
                 var originalStyles = cells.map(function(cell) {
                 var originalStyles = cells.map(function(cell) {
                     return {
                     return {
Строка 371: Строка 371:
                         rowspanCells.push({ cell: cell, rowIndex: rowIndex, rowspan: rowspan });
                         rowspanCells.push({ cell: cell, rowIndex: rowIndex, rowspan: rowspan });


                         // Подсвечиваем строки, которые затрагивает ячейка с rowspan
                         // Подсвечиваем строки, которые затрагивает ячейка с rowspan (только один раз)
                        var isRowspanHighlighted = false;
                         cell.addEventListener('mouseover', function() {
                         cell.addEventListener('mouseover', function() {
                             for (var i = 0; i < rowspan; i++) {
                             if (!isRowspanHighlighted) {
                                var targetRow = topLevelRows[rowIndex + i];
                                for (var i = 0; i < rowspan; i++) {
                                if (targetRow) {
                                    var targetRow = topLevelRows[rowIndex + i];
                                    Array.prototype.forEach.call(targetRow.children, function(targetCell) {
                                    if (targetRow) {
                                        targetCell.style.setProperty('background-color', brightenColor(getComputedStyle(targetCell).backgroundColor), 'important');
                                        Array.from(targetRow.children).forEach(function(targetCell) {
                                        targetCell.style.setProperty('color', brightenColor(getComputedStyle(targetCell).color), 'important');
                                            targetCell.style.setProperty('background-color', brightenColor(getComputedStyle(targetCell).backgroundColor), 'important');
                                    });
                                            targetCell.style.setProperty('color', brightenColor(getComputedStyle(targetCell).color), 'important');
                                        });
                                    }
                                 }
                                 }
                                isRowspanHighlighted = true;
                             }
                             }
                         });
                         });
Строка 388: Строка 392:
                                 var targetRow = topLevelRows[rowIndex + i];
                                 var targetRow = topLevelRows[rowIndex + i];
                                 if (targetRow) {
                                 if (targetRow) {
                                     Array.prototype.forEach.call(targetRow.children, function(targetCell) {
                                     Array.from(targetRow.children).forEach(function(targetCell) {
                                         targetCell.style.setProperty('background-color', getComputedStyle(targetCell).backgroundColor, 'important');
                                         targetCell.style.setProperty('background-color', getComputedStyle(targetCell).backgroundColor, 'important');
                                         targetCell.style.setProperty('color', getComputedStyle(targetCell).color, 'important');
                                         targetCell.style.setProperty('color', getComputedStyle(targetCell).color, 'important');
Строка 394: Строка 398:
                                 }
                                 }
                             }
                             }
                            isRowspanHighlighted = false;
                         });
                         });
                     }
                     }