MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 333: | Строка 333: | ||
} | } | ||
// Функция для | // Функция для увеличения яркости цвета | ||
function applyHighlighting() { | function applyHighlighting() { | ||
if (/Mobi|Android/i.test(navigator.userAgent)) { | if (/Mobi|Android/i.test(navigator.userAgent)) { | ||
return; | return; // Отключаем подсветку на мобильных устройствах | ||
} | } | ||
| Строка 347: | Строка 347: | ||
if (tbody) { | if (tbody) { | ||
// Получаем | // Получаем строки <tr> из первого уровня <tbody> и исключаем строки с вложенными таблицами | ||
var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | var rows = Array.prototype.slice.call(tbody.querySelectorAll('tr')).filter(function(row) { | ||
return row.parentElement === tbody && !row.querySelector('table'); | return row.parentElement === tbody && !row.querySelector('table'); | ||
}); | }); | ||
| Строка 356: | Строка 355: | ||
var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | var topLevelRows = (!thead && !noHeader) ? rows.slice(1) : rows; | ||
// Логика проверки для ограничения количества rowspan в строках | |||
var hasInvalidRowspan = false; | var hasInvalidRowspan = false; | ||
var hasTooManyRowspan = false; | var hasTooManyRowspan = false; | ||
| Строка 361: | Строка 361: | ||
topLevelRows.forEach(function(row) { | topLevelRows.forEach(function(row) { | ||
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'); // Исключаем ячейки с классом mobile | ||
}); | }); | ||
var rowspanCount = cells.filter(function(cell) { | var rowspanCount = cells.filter(function(cell) { | ||
| Строка 401: | Строка 400: | ||
}); | }); | ||
// Добавляем обработчики событий для подсветки ячеек | |||
cells.forEach(function(cell, index) { | cells.forEach(function(cell, index) { | ||
if (cell.hasAttribute('rowspan') && cell.getAttribute('rowspan') !== '1') return; // Пропускаем ячейки с rowspan | |||
cell.addEventListener('mouseover', function() { | cell.addEventListener('mouseover', function() { | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
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'); | |||
} | |||
}); | }); | ||
}); | }); | ||
| Строка 417: | Строка 415: | ||
cell.addEventListener('mouseout', function() { | cell.addEventListener('mouseout', function() { | ||
cells.forEach(function(innerCell, innerIndex) { | cells.forEach(function(innerCell, innerIndex) { | ||
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'); | |||
} | |||
}); | }); | ||
}); | }); | ||