미디어위키:Common.js: 두 판 사이의 차이

인테리어 위키
둘러보기로 이동 검색으로 이동
잔글 "미디어위키:Common.js" 문서를 보호했습니다 ([편집=관리자만 허용] (무기한) [이동=관리자만 허용] (무기한)) [연쇄적]
편집 요약 없음
태그: 되돌려진 기여
3번째 줄: 3번째 줄:
mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {


   $content.find('h3, h4').each(function () {
   $content.find('h4').each(function () {
     const $heading = $(this);
     const $heading = $(this);


20번째 줄: 20번째 줄:


     while (
     while (
      $next.length &&
  $next.length &&
      !$next.is('h2') &&
  !$next.is('h1, h2, h3, h4')
      !($next.is('h3') && level === 'h3') &&
) {
      !($next.is('h4') && level === 'h4')
    ) {
       let $current = $next;
       let $current = $next;
       $next = $next.next();
       $next = $next.next();

2026년 1월 15일 (목) 06:21 판

/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */

mw.hook('wikipage.content').add(function ($content) {

  $content.find('h4').each(function () {
    const $heading = $(this);

    if ($heading.data('fold-ready')) return;
    $heading.data('fold-ready', true);

    const level = this.tagName.toLowerCase();

    // 아이콘 생성
    const $icon = $('<span class="mw-fold-icon">▾</span>');
    $heading.prepend($icon);

    // 본문 wrapper
    let $wrapper = $('<div class="mw-fold-content"></div>');
    let $next = $heading.next();

    while (
  $next.length &&
  !$next.is('h1, h2, h3, h4')
) {
      let $current = $next;
      $next = $next.next();
      $wrapper.append($current);
    }

    if ($wrapper.children().length === 0) return;

    $heading.after($wrapper);

    // 기본 상태 (펼침)
    let collapsed = false;

    // 클릭 이벤트 (아이콘 + 제목)
    $heading.on('click', function () {
      collapsed = !collapsed;

      if (collapsed) {
        $icon.text('▸');
        $wrapper.slideUp(150);
        $heading.addClass('mw-fold-collapsed');
      } else {
        $icon.text('▾');
        $wrapper.slideDown(150);
        $heading.removeClass('mw-fold-collapsed');
      }
    });
  });
});