MediaWiki:Common.js: различия между версиями
Материал из SAMP
Нет описания правки |
Нет описания правки |
||
Строка 20: | Строка 20: | ||
$(function () { | $(function () { | ||
// Применяем только к заголовкам в основном контенте | // Применяем только к заголовкам в основном контенте | ||
$('#mw-content-text h2 | $('#mw-content-text h2').each(function () { | ||
const $header = $(this); | const $header = $(this); | ||
Версия от 23:51, 1 августа 2025
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */ $(document).on('click','.index_elem', function(event) { var target = event["target"]["parentElement"]["className"]; if (target != "index_subelems") { if ($(this).hasClass('active')) { $(this).removeClass('active'); } else { $(this).addClass('active'); } } }); $(document).on('click','.index_subelem', function() { var link = $(this).html(); document.location.href = 'https://wiki.samp.world/index.php/'+link; }); mw.loader.using(['jquery']).then(function () { $(function () { // Применяем только к заголовкам в основном контенте $('#mw-content-text h2').each(function () { const $header = $(this); // Защита: не трогаем, если заголовок находится в оглавлении (TOC) if ($header.closest('#toc').length > 0) return; const $next = $header.nextUntil('h2, h3'); if ($next.length === 0) return; // Скрыть содержимое по умолчанию $next.hide(); // Создать кнопку const $btn = $('<span>') .text('[+] ') .css({ cursor: 'pointer', color: '#007bff', 'margin-right': '8px', 'user-select': 'none' }) .click(function () { const visible = $next.is(':visible'); $next.toggle(); $btn.text(visible ? '[+] ' : '[–] '); }); // Вставить кнопку перед текстом заголовка $header.prepend($btn); }); }); });