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

편집 요약 없음
편집 요약 없음
 
(같은 사용자의 중간 판 113개는 보이지 않습니다)
1번째 줄: 1번째 줄:
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
$(document).ready(function() {
$(document).ready(function() {
     // jQuery를 사용하여 접기/펼치기 기능 추가
     // .custom-toggle 클릭 이벤트 핸들러
     $('.custom-toggle').click(function() {
     $('.custom-toggle').click(function() {
         $(this).next('.custom-content').slideToggle();
         $(this).next('.custom-content').slideToggle();
     });
     });


     // 각주 팝업 기능 추가
     // 페이지 로드 시 기본 상태 설정
     $('.reference').hover(function() {
     $('.custom-toggle').each(function() {
         var refId = $(this).attr('href').substring(1); // 각주의 id 가져오기
         var $this = $(this);
         var tooltip = $('#' + refId).clone().find('.mw-cite-backlink').remove().end().html(); // 각주 내용에서 backlink 제거 후 가져오기
        var isCollapsed = $this.data('collapsed') === true;
         if (!tooltip) {
 
            tooltip = $(this).attr('title') || '내용을 찾을 수 없습니다.'; // 만약 각주 내용을 찾지 못할 경우 기본 메시지 사용
        if (isCollapsed) {
            $this.next('.custom-content').hide();
        } else {
            $this.next('.custom-content').show();
        }
    });
 
    // 접기 상태를 확인하고 초기화하는 코드
    $('.custom-toggle').each(function() {
        var $this = $(this);
         var collapsedState = $this.data('collapsed');
 
        // '유형'에 맞는 접기 상태 설정
        if (collapsedState !== undefined) {
            if (collapsedState === true) {
                $this.next('.custom-content').hide();
            } else {
                $this.next('.custom-content').show();
            }
        }
    });
 
    // .toggle-collapse 클릭 이벤트 핸들러
    $('.toggle-collapse').click(function() {
        var $this = $(this);
        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;
 
        // 지정된 행 수만큼 다음 행을 즉시 표시/숨김
        var $row = $this.closest('tr');
        for (var i = 0; i < rowsToToggle; i++) {
            $row = $row.next();
            if ($row.length) {
                $row.toggle(); // 슬라이드 없이 즉시 토글
            }
        }
 
        // 상태 토글
        $this.data('collapsed', !isCollapsed);
        $this.text($this.data('collapsed') ? expandText : collapseText);
    });
 
    // .toggle-collapse 클릭 이벤트 핸들러
    $('.toggle-collapse').click(function() {
        var $this = $(this);
        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;
 
        // 지정된 행 수만큼 다음 행을 즉시 표시/숨김
        var $row = $this.closest('tr');
        for (var i = 0; i < rowsToToggle; i++) {
            $row = $row.next();
            if ($row.length) {
                $row.toggle(); // 슬라이드 없이 즉시 토글
            }
         }
         }
         $('<div id="ref-tooltip"></div>')
 
            .css({
         // 상태 토글
                position: 'absolute',
        $this.data('collapsed', !isCollapsed);
                background: '#f9f9f9',
        $this.text($this.data('collapsed') ? expandText : collapseText);
                border: '1px solid #aaa',
     });
                padding: '5px',
 
                'z-index': 100,
    // <nolinkstyle> 태그를 .nolinkstyle 클래스로 변환
                display: 'none',
    $('nolinkstyle').each(function() {
                'max-width': '300px',
         var $this = $(this);
                'box-shadow': '0 0 5px rgba(0,0,0,0.2)'
        var content = $this.html();
            })
        $this.replaceWith('<span class="nolinkstyle">' + content + '</span>');
            .appendTo('body')
            .html(tooltip)
            .fadeIn('fast');
     }, function() {
        $('#ref-tooltip').remove();
    }).mousemove(function(e) {
         $('#ref-tooltip')
            .css({
                top: e.pageY + 10 + 'px',
                left: e.pageX + 10 + 'px'
            });
     });
     });
});
});

2024년 11월 29일 (금) 23:47 기준 최신판

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

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

        if (isCollapsed) {
            $this.next('.custom-content').hide();
        } else {
            $this.next('.custom-content').show();
        }
    });

    // 접기 상태를 확인하고 초기화하는 코드
    $('.custom-toggle').each(function() {
        var $this = $(this);
        var collapsedState = $this.data('collapsed');

        // '유형'에 맞는 접기 상태 설정
        if (collapsedState !== undefined) {
            if (collapsedState === true) {
                $this.next('.custom-content').hide();
            } else {
                $this.next('.custom-content').show();
            }
        }
    });

    // .toggle-collapse 클릭 이벤트 핸들러
    $('.toggle-collapse').click(function() {
        var $this = $(this);
        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;

        // 지정된 행 수만큼 다음 행을 즉시 표시/숨김
        var $row = $this.closest('tr');
        for (var i = 0; i < rowsToToggle; i++) {
            $row = $row.next();
            if ($row.length) {
                $row.toggle(); // 슬라이드 없이 즉시 토글
            }
        }

        // 상태 토글
        $this.data('collapsed', !isCollapsed);
        $this.text($this.data('collapsed') ? expandText : collapseText);
    });

    // .toggle-collapse 클릭 이벤트 핸들러
    $('.toggle-collapse').click(function() {
        var $this = $(this);
        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;

        // 지정된 행 수만큼 다음 행을 즉시 표시/숨김
        var $row = $this.closest('tr');
        for (var i = 0; i < rowsToToggle; i++) {
            $row = $row.next();
            if ($row.length) {
                $row.toggle(); // 슬라이드 없이 즉시 토글
            }
        }

        // 상태 토글
        $this.data('collapsed', !isCollapsed);
        $this.text($this.data('collapsed') ? expandText : collapseText);
    });

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