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

Материал из SAMP
Нет описания правки
Нет описания правки
 
(не показано 12 промежуточных версий этого же участника)
Строка 19: Строка 19:
mw.loader.using(['jquery']).then(function () {
mw.loader.using(['jquery']).then(function () {
   $(function () {
   $(function () {
     // Обрабатываем только контент статьи
     if (window.innerWidth >= 768) return;
     $('#mw-content-text h2, #mw-content-text h3').each(function () {
 
     $('#mw-content-text h2').each(function ()  
    {
       const $header = $(this);
       const $header = $(this);
       const $next = $header.nextUntil('h2, h3');
       if ($header.closest('#toc').length > 0) return;


       if ($next.length === 0) return;
       const $content = $header.nextUntil('h2');


       // Скрыть содержимое по умолчанию
       if ($content.length === 0) return;
      $next.hide();


       // Создать кнопку
       $content.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 ? '[+] ' : '[–] ');
        });


       // Вставить кнопку перед заголовком
      const $btn = $('<span class="arrow_hide_section">').text('');
 
       // Добавляем кнопку
       $header.prepend($btn);
       $header.prepend($btn);
      // Вся строка заголовка кликабельна
     
     
      $header.css('cursor', 'pointer').click(function () {
        const visible = $content.is(':visible');
        $content.toggle();
        if (visible) {
          $header.removeClass('vis');
        } else {
          $header.addClass('vis');
        }
      });
     });
     });
   });
   });
});
});

Текущая версия от 00:06, 2 августа 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 () {
    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 class="arrow_hide_section">').text('');

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

      // Вся строка заголовка кликабельна
      
      
      $header.css('cursor', 'pointer').click(function () {
        const visible = $content.is(':visible');
        $content.toggle();
        if (visible) {
          $header.removeClass('vis');
        } else {
          $header.addClass('vis');
        }
      });
    });
  });
});