MediaWiki:Common.js: различия между версиями
Материал из SAMP
Нет описания правки |
Нет описания правки |
||
Строка 18: | Строка 18: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
$('h2, h3').each(function () { | // Применяем только к основному контенту статьи | ||
$('#content h2, #content h3').each(function () { | |||
const $header = $(this); | const $header = $(this); | ||
// Не трогаем, если заголовок пустой | |||
if ($header.text().trim() === '') return; | |||
// Получаем контент между этим заголовком и следующим h2/h3 | |||
const $content = $header.nextUntil('h2, h3'); | const $content = $header.nextUntil('h2, h3'); | ||
if ($content.length === 0) return; | if ($content.length === 0) return; | ||
// Скрываем контент по умолчанию | |||
$content.hide(); | |||
// Создаём кнопку | |||
const toggleBtn = $('<span>') | const toggleBtn = $('<span>') | ||
.text('[ | .text('[+] ') | ||
.css({ cursor: 'pointer', color: '#00f', 'margin-right': '8px' }) | .css({ | ||
cursor: 'pointer', | |||
color: '#00f', | |||
'margin-right': '8px', | |||
'user-select': 'none' | |||
}) | |||
.click(function () { | .click(function () { | ||
const isVisible = $content.is(':visible'); | |||
$content.toggle(); | $content.toggle(); | ||
toggleBtn.text( | toggleBtn.text(isVisible ? '[+] ' : '[–] '); | ||
}); | }); | ||
// Вставляем кнопку | // Вставляем кнопку перед заголовком | ||
$header.prepend(toggleBtn); | $header.prepend(toggleBtn); | ||
}); | }); | ||
Версия от 23:49, 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; }); $(document).ready(function () { // Применяем только к основному контенту статьи $('#content h2, #content h3').each(function () { const $header = $(this); // Не трогаем, если заголовок пустой if ($header.text().trim() === '') return; // Получаем контент между этим заголовком и следующим h2/h3 const $content = $header.nextUntil('h2, h3'); if ($content.length === 0) return; // Скрываем контент по умолчанию $content.hide(); // Создаём кнопку const toggleBtn = $('<span>') .text('[+] ') .css({ cursor: 'pointer', color: '#00f', 'margin-right': '8px', 'user-select': 'none' }) .click(function () { const isVisible = $content.is(':visible'); $content.toggle(); toggleBtn.text(isVisible ? '[+] ' : '[–] '); }); // Вставляем кнопку перед заголовком $header.prepend(toggleBtn); });