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

Материал из SAMP
Нет описания правки
Нет описания правки
Строка 17: Строка 17:




$(document).ready(function () {
mw.loader.using(['jquery']).then(function () {
   // Применяем только к основному контенту статьи
   $(function () {
  $('#content h2, #content h3').each(function () {
    // Обрабатываем только контент статьи
    const $header = $(this);
    $('#mw-content-text h2, #mw-content-text h3').each(function () {
      const $header = $(this);
      const $next = $header.nextUntil('h2, h3');


    // Не трогаем, если заголовок пустой
      if ($next.length === 0) return;
    if ($header.text().trim() === '') return;


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


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


    // Скрываем контент по умолчанию
      // Вставить кнопку перед заголовком
    $content.hide();
       $header.prepend($btn);
 
    });
    // Создаём кнопку
    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);
   });
   });
});

Версия от 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);
    });
  });
});