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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/* ReferenceTooltip 스크립트 로드 */
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-referenceTooltips.js&action=raw&ctype=text/javascript');
// jQuery를 사용하여 접기/펼치기 기능 추가
$(document).ready(function() {
$(document).ready(function() {
     // 기존의 .custom-toggle 클릭 이벤트 핸들러
     // 기존의 .custom-toggle 클릭 이벤트 핸들러
53번째 줄: 47번째 줄:
             $this.text('접기');
             $this.text('접기');
         }
         }
    });
   
     // <nolinkstyle> 태그를 .nolinkstyle 클래스로 변환
     // <nolinkstyle> 태그를 .nolinkstyle 클래스로 변환
     $('nolinkstyle').each(function() {
     $('nolinkstyle').each(function() {
58번째 줄: 54번째 줄:
         var content = $this.html();
         var content = $this.html();
         $this.replaceWith('<span class="nolinkstyle">' + content + '</span>');
         $this.replaceWith('<span class="nolinkstyle">' + content + '</span>');
    });
     });
     });
});
});

2024년 9월 27일 (금) 09:35 판

$(document).ready(function() {
    // 기존의 .custom-toggle 클릭 이벤트 핸들러
    $('.custom-toggle').click(function() {
        $(this).next('.custom-content').slideToggle(); 
    });

    // 새로 추가할 .toggle-collapse 클릭 이벤트 핸들러
    $('.toggle-collapse').click(function() {
        var $this = $(this);
        var rowsToToggle = parseInt($this.data('rows')) || 1;
        var isCollapsed = $this.data('collapsed') === true;
        var $row = $this.closest('tr');

        // 지정된 행 수만큼 다음 행을 숨기거나 표시
        for (var i = 0; i < rowsToToggle; i++) {
            $row = $row.next();
            if ($row.length) { // 다음 행이 존재하는지 확인
                if (isCollapsed) {
                    $row.show();
                } else {
                    $row.hide();
                }
            }
        }

        // 상태 토글
        $this.data('collapsed', !isCollapsed);
        $this.text($this.data('collapsed') ? '펼치기' : '접기');
    });

    // 페이지 로드 시 기본 상태 설정
    $('.toggle-collapse').each(function() {
        var $this = $(this);
        var rowsToToggle = parseInt($this.data('rows')) || 1;
        var isCollapsed = $this.data('collapsed') === true;

        if (isCollapsed) {
            var $row = $this.closest('tr');
            for (var i = 0; i < rowsToToggle; i++) {
                $row = $row.next();
                if ($row.length) { // 다음 행이 존재하는지 확인
                    $row.hide();
                }
            }
            $this.text('펼치기');
        } else {
            $this.text('접기');
        }
    });
    
    // <nolinkstyle> 태그를 .nolinkstyle 클래스로 변환
    $('nolinkstyle').each(function() {
        var $this = $(this);
        var content = $this.html();
        $this.replaceWith('<span class="nolinkstyle">' + content + '</span>');
    });
});