MediaWiki:Common.js: различия между версиями

Материал из SAMP
Нет описания правки
Нет описания правки
Строка 19: Строка 19:
mw.loader.using(['jquery']).then(function () {
mw.loader.using(['jquery']).then(function () {
   $(function () {
   $(function () {
     // Только заголовки h2 в основном контенте
     // Условие: работаем только на мобильных (ширина экрана < 768px)
    if (window.innerWidth >= 768) return;
 
     $('#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;


      // Содержимое до следующего h2
       const $content = $header.nextUntil('h2');
       const $content = $header.nextUntil('h2');


       if ($content.length === 0) return;
       if ($content.length === 0) return;


       $content.hide(); // Скрыть по умолчанию
       $content.hide(); // скрыть всё содержимое


      // Создаём кнопку (визуально)
       const $btn = $('<span>')
       const $btn = $('<span>')
         .text('[+] ')
         .text('[+] ')
Строка 42: Строка 42:
         });
         });


       // Вставить кнопку
       // Добавляем кнопку
       $header.prepend($btn);
       $header.prepend($btn);


       // Сделать всю строку кликабельной
       // Вся строка заголовка кликабельна
       $header.css('cursor', 'pointer').click(function () {
       $header.css('cursor', 'pointer').click(function () {
         const visible = $content.is(':visible');
         const visible = $content.is(':visible');

Версия от 23:54, 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 () {
    // Условие: работаем только на мобильных (ширина экрана < 768px)
    if (window.innerWidth >= 768) return;

    $('#mw-content-text h2').each(function () {
      const $header = $(this);

      // Пропустить, если в оглавлении
      if ($header.closest('#toc').length > 0) return;

      const $content = $header.nextUntil('h2');

      if ($content.length === 0) return;

      $content.hide(); // скрыть всё содержимое

      const $btn = $('<span>')
        .text('[+] ')
        .css({
          color: '#007bff',
          'margin-right': '8px',
          'user-select': 'none'
        });

      // Добавляем кнопку
      $header.prepend($btn);

      // Вся строка заголовка кликабельна
      $header.css('cursor', 'pointer').click(function () {
        const visible = $content.is(':visible');
        $content.toggle();
        $btn.text(visible ? '[+] ' : '[–] ');
      });
    });
  });
});