MediaWiki:Common.js: различия между версиями
Материал из SAMP
Нет описания правки |
Нет описания правки |
||
| Строка 19: | Строка 19: | ||
mw.loader.using(['jquery']).then(function () { | mw.loader.using(['jquery']).then(function () { | ||
$(function () { | $(function () { | ||
// Применяем только к | // Применяем только к h2 в контенте статьи | ||
$('#mw-content-text h2').each(function () { | $('#mw-content-text h2').each(function () { | ||
const $header = $(this); | const $header = $(this); | ||
// Защита: не | // Защита: не обрабатывать заголовки в оглавлении (TOC) | ||
if ($header.closest('#toc').length > 0) return; | if ($header.closest('#toc').length > 0) return; | ||
const $ | // Скрываем всё до следующего h2 — включая h3, p, div, ul и т.д. | ||
const $content = $header.nextUntil('h2'); | |||
if ($ | if ($content.length === 0) return; | ||
// Скрыть | // Скрыть по умолчанию | ||
$ | $content.hide(); | ||
// | // Кнопка | ||
const $btn = $('<span>') | const $btn = $('<span>') | ||
.text('[+] ') | .text('[+] ') | ||
| Строка 43: | Строка 44: | ||
}) | }) | ||
.click(function () { | .click(function () { | ||
const visible = $ | const visible = $content.is(':visible'); | ||
$ | $content.toggle(); | ||
$btn.text(visible ? '[+] ' : '[–] '); | $btn.text(visible ? '[+] ' : '[–] '); | ||
}); | }); | ||
// | // Вставляем кнопку перед заголовком | ||
$header.prepend($btn); | $header.prepend($btn); | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
Версия от 23:52, 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 () {
// Применяем только к h2 в контенте статьи
$('#mw-content-text h2').each(function () {
const $header = $(this);
// Защита: не обрабатывать заголовки в оглавлении (TOC)
if ($header.closest('#toc').length > 0) return;
// Скрываем всё до следующего h2 — включая h3, p, div, ul и т.д.
const $content = $header.nextUntil('h2');
if ($content.length === 0) return;
// Скрыть по умолчанию
$content.hide();
// Кнопка
const $btn = $('<span>')
.text('[+] ')
.css({
cursor: 'pointer',
color: '#007bff',
'margin-right': '8px',
'user-select': 'none'
})
.click(function () {
const visible = $content.is(':visible');
$content.toggle();
$btn.text(visible ? '[+] ' : '[–] ');
});
// Вставляем кнопку перед заголовком
$header.prepend($btn);
});
});
});

