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

편집 요약 없음
태그: 수동 되돌리기
편집 요약 없음
6번째 줄: 6번째 줄:
// jQuery를 사용하여 접기/펼치기 기능 추가
// jQuery를 사용하여 접기/펼치기 기능 추가
$(document).ready(function() {
$(document).ready(function() {
     // .custom-toggle를 클릭하면 다음 형제 요소(.custom-content)가 접히고 펼쳐짐
     // 기존의 .custom-toggle 클릭 이벤트 핸들러
     $('.custom-toggle').click(function() {
     $('.custom-toggle').click(function() {
         $(this).next('.custom-content').slideToggle();  
         $(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('접기');
        }
     });
     });
});
});

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

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

/* ReferenceTooltip 스크립트 로드 */
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-referenceTooltips.js&action=raw&ctype=text/javascript');

// jQuery를 사용하여 접기/펼치기 기능 추가
$(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('접기');
        }
    });
});