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

Материал из SAMP
Нет описания правки
Нет описания правки
 
(не показано 13 промежуточных версий этого же участника)
Строка 17: Строка 17:




$(document).ready(function () {
mw.loader.using(['jquery']).then(function () {
  // Применяем только к основному контенту статьи
   $(function () {
   $('#content h2, #content h3').each(function () {
     if (window.innerWidth >= 768) return;
     const $header = $(this);


     // Не трогаем, если заголовок пустой
     $('#mw-content-text h2').each(function ()
     if ($header.text().trim() === '') return;
     {
      const $header = $(this);
      if ($header.closest('#toc').length > 0) return;


    // Получаем контент между этим заголовком и следующим h2/h3
      const $content = $header.nextUntil('h2');
    const $content = $header.nextUntil('h2, h3');


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


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


    // Создаём кнопку
      const $btn = $('<span class="arrow_hide_section">').text('');
    const toggleBtn = $('<span>')
 
      .text('[+] ')
      // Добавляем кнопку
       .css({
       $header.prepend($btn);
        cursor: 'pointer',
 
        color: '#00f',
      // Вся строка заголовка кликабельна
        'margin-right': '8px',
     
        'user-select': 'none'
     
      })
      $header.css('cursor', 'pointer').click(function () {
      .click(function () {
         const visible = $content.is(':visible');
         const isVisible = $content.is(':visible');
         $content.toggle();
         $content.toggle();
         toggleBtn.text(isVisible ? '[+] ' : '[–] ');
         if (visible) {
          $header.removeClass('vis');
        } else {
          $header.addClass('vis');
        }
       });
       });
 
     });
     // Вставляем кнопку перед заголовком
    $header.prepend(toggleBtn);
   });
   });
});

Текущая версия от 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');
        }
      });
    });
  });
});