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

편집 요약 없음
태그: 되돌려진 기여
편집 요약 없음
태그: 되돌려진 기여
3번째 줄: 3번째 줄:
     $('.custom-toggle').click(function() {
     $('.custom-toggle').click(function() {
         var $content = $(this).next('.custom-content');
         var $content = $(this).next('.custom-content');
         if ($content.hasClass('custom-expanded')) {
         if ($content.is(':visible')) {
            // 접기 애니메이션
             $content.stop(true, true).slideUp(300); // 접기 애니메이션
             $content.removeClass('custom-expanded').css('max-height', 0);
         } else {
         } else {
            // 펼치기 애니메이션
             $content.stop(true, true).slideDown(300); // 펼치기 애니메이션
             $content.addClass('custom-expanded');
         }
         }
    });
    // .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');
        // 사용자 정의 텍스트 확인
        var expandText = $this.data('expand-text') || '펼치기';
        var collapseText = $this.data('collapse-text') || expandText;
        // 지정된 행 수만큼 다음 행을 슬라이드 애니메이션으로 표시/숨김
        $row.nextAll().each(function(index) {
            if (index < rowsToToggle) {
                var $currentRow = $(this).find('.custom-content');
                if (isCollapsed) {
                    // 접기 애니메이션
                    $currentRow.removeClass('custom-expanded').css('max-height', 0);
                } else {
                    // 펼치기 애니메이션
                    $currentRow.addClass('custom-expanded');
                }
            }
        });
        // 상태 토글
        $this.data('collapsed', !isCollapsed);
        $this.text($this.data('collapsed') ? expandText : collapseText);
     });
     });


     // 페이지 로드 시 기본 상태 설정
     // 페이지 로드 시 기본 상태 설정
     $('.toggle-collapse').each(function() {
     $('.custom-content').each(function() {
         var $this = $(this);
         $(this).hide(); // 페이지 로드 시 모든 컨텐츠 숨김
        var rowsToToggle = parseInt($this.data('rows')) || 1;
        var isCollapsed = $this.data('collapsed') === true;
 
        // 사용자 정의 텍스트 확인
        var expandText = $this.data('expand-text') || '펼치기';
        var collapseText = $this.data('collapse-text') || expandText;
 
        if (isCollapsed) {
            var $row = $this.closest('tr');
            $row.nextAll().each(function(index) {
                if (index < rowsToToggle) {
                    $(this).find('.custom-content').css({
                        display: 'none',
                        maxHeight: 0,
                        overflow: 'hidden'
                    });
                }
            });
            $this.text(expandText);
        } else {
            $this.text(collapseText);
        }
     });
     });



2024년 11월 29일 (금) 12:14 판

$(document).ready(function() {
    // 기존의 .custom-toggle 클릭 이벤트 핸들러
    $('.custom-toggle').click(function() {
        var $content = $(this).next('.custom-content');
        if ($content.is(':visible')) {
            $content.stop(true, true).slideUp(300); // 접기 애니메이션
        } else {
            $content.stop(true, true).slideDown(300); // 펼치기 애니메이션
        }
    });

    // 페이지 로드 시 기본 상태 설정
    $('.custom-content').each(function() {
        $(this).hide(); // 페이지 로드 시 모든 컨텐츠 숨김
    });

    // <nolinkstyle> 태그를 .nolinkstyle 클래스로 변환
    $('nolinkstyle').each(function() {
        var $this = $(this);
        var content = $this.html();
        $this.replaceWith('<span class="nolinkstyle">' + content + '</span>');
    });
});