MediaWiki:Common.js: различия между версиями
Материал из SAMP
Нет описания правки |
Нет описания правки |
||
| Строка 17: | Строка 17: | ||
mw.loader.using(['jquery']).then(function () { | |||
// | $(function () { | ||
// Обрабатываем только контент статьи | |||
$('#mw-content-text h2, #mw-content-text h3').each(function () { | |||
const $header = $(this); | |||
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); | |||
}); | |||
}); | }); | ||
}); | |||
Версия от 23:50, 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, #mw-content-text h3').each(function () {
const $header = $(this);
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);
});
});
});

