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

мНет описания правки
мНет описания правки
Строка 449: Строка 449:
$toc.empty();
$toc.empty();
var $headings = $content.find('h1, h2, h3, h4, h5, h6, .custom-heading');
var $headings = $content.find('h1, h2, h3, h4, h5, h6, .custom-heading');
var tocCounters = [0];  
var tocCounters = [];  
var lastLevel = 1;  
var lastLevel = 1;  
var $currentList = $toc;  
var $currentList = $toc;  


function updateCounters(level) {
function updateCounters(level) {
if (level > lastLevel) {
if (level > tocCounters.length) {
tocCounters.push(0);  
tocCounters.push(0);  
} else if (level < lastLevel) {
} else if (level < tocCounters.length) {
tocCounters = tocCounters.slice(0, level);  
tocCounters = tocCounters.slice(0, level);  
}
}
Строка 509: Строка 509:
if (headingText.length > 0) {
if (headingText.length > 0) {
if (level > 1) {
if (level > 1) {
// Проверяем, нужно ли создавать новый вложенный список
while (tocCounters.length > level) {
while (tocCounters.length > level) {
$currentList = $currentList.parent();
$currentList = $currentList.parent();
}
}
if ($currentList.children('ul').length === 0) {
 
$currentList = createNestedList($currentList);
// Проверяем, существует ли вложенный список
var $nestedList = $currentList.children('ul').last();
if ($nestedList.length === 0) {
$nestedList = createNestedList($currentList);
}
}
$currentList = $nestedList; // Переходим в новый вложенный список
} else {
} else {
$currentList = $toc;
$currentList = $toc;
Строка 526: Строка 532:
)
)
);
);
$currentList.append(tocItem);
$currentList.append(tocItem);
}
}