MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 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 = [ | var tocCounters = []; | ||
var lastLevel = 1; | var lastLevel = 1; | ||
var $currentList = $toc; | var $currentList = $toc; | ||
function updateCounters(level) { | function updateCounters(level) { | ||
if (level > | if (level > tocCounters.length) { | ||
tocCounters.push(0); | tocCounters.push(0); | ||
} else if (level < | } 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(); | ||
} | } | ||
$ | // Проверяем, существует ли вложенный список | ||
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); | ||
} | } | ||