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

편집 요약 없음
태그: 되돌려진 기여
편집 요약 없음
 
(같은 사용자의 중간 판 61개는 보이지 않습니다)
1번째 줄: 1번째 줄:
/**
/* MediaWiki:Common.js */
* 이 스크립트는 위키백과 전체에 적용됩니다. 고칠 때는 주의해주세요.
mw.hook('wikipage.content').add(function ($content) {
* [[위키백과:위키프로젝트 시스템]] 참고
*
* 스크립트를 넣을 때는 충분한 설명, 출처를 넣어주세요! 이후 관리가 어려워집니다.
**/


mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () {
    var initialized = {};
/* Begin of mw.loader.using callback */


/**
     $content.find('[class*="mw-customtoggle-"]').each(function () {
* Map addPortletLink to mw.util
        var classList = (this.className || '').split(/\s+/);
*
* @deprecated: Use mw.util.addPortletLink instead.
*/
mw.log.deprecate( window, 'addPortletLink', mw.util.addPortletLink,
'Use mw.util.addPortletLink instead' );
/**
* Extract a URL parameter from the current URL
*
* @deprecated: Use mw.util.getParamValue with proper escaping
*/
mw.log.deprecate( window, 'getURLParamValue', mw.util.getParamValue, 'Use mw.util.getParamValue instead' );
/**
* Test if an element has a certain class
*
* @deprecated:  Use $(element).hasClass() instead.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
     return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );
/**
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 5
*/
// CSS
var extraCSS = mw.util.getParamValue( 'withCSS' );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
importStylesheet( extraCSS );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
}
}
// JS
var extraJS = mw.util.getParamValue( 'withJS' );
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
importScript( extraJS );
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
}
}


/**
        classList.forEach(function (cls) {
* Import more specific scripts if necessary
            if (cls.indexOf('mw-customtoggle-') !== 0) {
*/
                return;
            }


if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
            var suffix = cls.substring('mw-customtoggle-'.length);
    /* file description page scripts */
    importScript( 'MediaWiki:Common.js/file.js' );
}


/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
            if (initialized[suffix]) {
/** Collapsible tables *********************************************************
                return;
*
            }
*  Description: Allows tables to be collapsed, showing only the header. See
*              [[:en:Wikipedia:NavFrame]].
*  Maintainers: [[:en:User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = '숨기기';
var expandCaption = '보이기';


window.collapseTable = function ( tableIndex ) {
            initialized[suffix] = true;
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );


    if ( !Table || !Button ) {
            var targetId = 'mw-customcollapsible-' + suffix;
        return false;
    }


    var Rows = Table.rows;
            /*
    var i;
            * 중복 ID가 있을 수 있으므로
            * #id 대신 attribute selector 사용
            */
            var $targets = $content.find('[id="' + targetId + '"]');


    if ( Button.firstChild.data === collapseCaption ) {
            if (!$targets.length) {
        for ( i = 1; i < Rows.length; i++ ) {
                return;
            Rows[i].style.display = 'none';
             }
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};


function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;


    function handleButtonLink( index, e ) {
            /*
        window.collapseTable( index );
            * =====================================================
        e.preventDefault();
            * 특수형
    }
            *
            * 아나운서 표처럼:
            *
            * [상단 버튼 wrapper]
            * [실제 내용 패널]
            *
            * 두 요소가 같은 ID를 공유하고,
            * 실제 패널 안에 wikitable이 있는 구조
            * =====================================================
            */
            var $specialPanel = $targets.filter(function () {
                return $(this).find('table.wikitable').length > 0;
            });


    for ( i = 0; i < Tables.length; i++ ) {
            if ($targets.length > 1 && $specialPanel.length) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
                initStackedCollapsible(
                    $content,
                    cls,
                    $targets
                );


            /* only add button and increment count if there is a header row to work with */
                return;
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
             }
            if ( !HeaderRow ) continue;
             var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;


            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );


             var Button    = document.createElement( 'span' );
             /*
            var ButtonLink = document.createElement( 'a' );
            * =====================================================
            var ButtonText = document.createTextNode( collapseCaption );
            * 일반 MediaWiki collapsible
            * =====================================================
            */
            initNormalCollapsible(
                $content,
                cls,
                $targets.first()
            );
        });
    });


            Button.className = 'collapseButton';  /* Styles are declared in Common.css */


            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );


            Button.appendChild( document.createTextNode( '[' ) );
    /*
            Button.appendChild( ButtonLink );
    * =============================================================
            Button.appendChild( document.createTextNode( ']' ) );
    * 일반 펼치기 · 접기
    * =============================================================
    */
    function initNormalCollapsible($content, cls, $target) {


            Header.insertBefore( Button, Header.firstChild );
        var $toggles = $content.find('.' + cls);
             tableIndex++;
 
        /*
        * 일반 MediaWiki 구조:
        *
        * .mw-collapsible
        *  └ .mw-collapsible-content
        *
        * content가 있으면 content만 애니메이션
        */
        var $contentTarget = $target.children('.mw-collapsible-content');
 
        if (!$contentTarget.length) {
             $contentTarget = $target.find('.mw-collapsible-content').first();
         }
         }
    }


    for ( i = 0; i < tableIndex; i++ ) {
        var $animTarget = $contentTarget.length
         if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            ? $contentTarget
             window.collapseTable( i );
            : $target;
        }
 
         else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
 
            var element = NavigationBoxes[i];
        /*
            while ((element = element.parentNode)) {
        * 현재 상태를 기준으로 초기 aria 설정
                 if ( $( element ).hasClass( 'outercollapse' ) ) {
        */
                     window.collapseTable ( i );
         var initiallyOpen = $animTarget.is(':visible');
                    break;
 
        $toggles.attr(
            'aria-expanded',
             initiallyOpen ? 'true' : 'false'
        );
 
 
         $toggles
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {
 
                e.preventDefault();
                e.stopImmediatePropagation();
 
 
                /*
                * 애니메이션 중 재클릭 방지
                */
                 if ($animTarget.is(':animated')) {
                     return false;
                 }
                 }
            }
        }
    }
}


mw.hook( 'wikipage.content' ).add( createCollapseButtons );


/* ([[위키백과:관리자 요청/2007년 5월#스크립트 추가 요청]]) */
                var opening = !$animTarget.is(':visible');
/** Dynamic Navigation Bars (experimental) *************************************
*
*  Description: See [[:en:Wikipedia:NavFrame]].
*  Maintainers: UNMAINTAINED
*/
// set up the words in your language
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';


/**
* Shows and hides content and picture (if available) of navigation bars
* Parameters:
*    indexNavigationBar: the index of navigation bar to be toggled
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;


    if ( !NavFrame || !NavToggle ) {
                /*
        return false;
                * -------------------------------------------------
    }
                * 펼치기
                * -------------------------------------------------
                */
                if (opening) {


    /* if shown now */
                    /*
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
                    * MediaWiki collapsed 상태 제거
        for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) {
                    */
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                    $target.removeClass('mw-collapsed');
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;


    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }


    event.preventDefault();
                    /*
};
                    * 내용만 펼침
                    */
                    $animTarget
                        .stop(true, true)
                        .hide()
                        .slideDown(250, function () {


/* adds show/hide-button to navigation bars */
                            /*
function createNavigationBarToggleButton() {
                            * jQuery 애니메이션 inline style 정리
    var indexNavigationBar = 0;
                            */
    var NavFrame;
                            $(this).css({
    var NavChild;
                                height: '',
    /* iterate over all < div >-elements */
                                overflow: '',
    var divs = document.getElementsByTagName( 'div' );
                                paddingTop: '',
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
                                paddingBottom: '',
        /* if found a navigation bar */
                                marginTop: '',
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
                                marginBottom: ''
                            });
                        });


            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );


            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
                    $toggles.attr('aria-expanded', 'true');
            /**
            * Check if any children are already hidden.  This loop is here for backwards compatibility:
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
            * the content visible without JavaScript support), the new recommended way is to add the class
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
            */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                 }
                 }
            }
 
            if ( isCollapsed ) {
 
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                /*
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                * -------------------------------------------------
                        NavChild.style.display = 'none';
                * 접기
                    }
                * -------------------------------------------------
                */
                else {
 
                    $animTarget
                        .stop(true, true)
                        .slideUp(250, function () {
 
                            /*
                            * 애니메이션 종료 후 collapsed 복원
                            */
                            $target.addClass('mw-collapsed');
 
                            $(this).css({
                                display: 'none',
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
                        });
 
 
                    $toggles.attr('aria-expanded', 'false');
                 }
                 }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );


            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
 
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                 return false;
                 if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
             });
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
             }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
     }
     }
}


mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );


/***** 그림 정보 틀을 자동으로 불러옴 ********
* Adds a link to subpages of current page
* from commons.wikimedia.org
*  Maintainers: [[User:Yonidebest]], [[User:Dschwen]]
*  [[사용자:Kwj2772]]가 수정
*  JSconfig items: bool 'loadAutoInformationTemplate'
*                      (true=enabled (default), false=disabled)
* JSConfig를 사용하지 않도록 수정함. --[[사용자:Klutzy|klutzy]] ([[사용자토론:Klutzy|토론]]) 2009년 9월 27일 (일) 20:33 (KST)
****/
if (mw.config.get('wgCanonicalSpecialPageName') == 'Upload') {
  importScript('MediaWiki:Upload.js');
}


/* 인터랙티브 지도. 영어 위키백과에서 가져옴. -- [[사용자:ChongDae]] 2010년 3월 28일 (일) 02:08 (KST) */
    /*
/**
    * =============================================================
* WikiMiniAtlas
    * 아나운서형 특수 펼치기 · 접기
*
    * =============================================================
* Description: WikiMiniAtlas is a popup click and drag world map.
    *
*             This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
    * DOM 예:
*             The script itself is located on meta because it is used by many projects.
    *
*             See [[Meta:WikiMiniAtlas]] for more information.  
    * [남성 버튼 wrapper]
* Maintainers: [[User:Dschwen]]
    * [남성 실제 패널]
*/
    * [여성 버튼 wrapper]
( function () {
    * [여성 실제 패널]
    var require_wikiminiatlas = false;
    *
    var coord_filter = /geohack/;
    * 패널을 이동시키지 않고
    $( function () {
    * 원래 DOM 위치에서 펼친다.
        $( 'a.external.text' ).each( function( key, link ) {
    *
             if ( link.href && coord_filter.exec( link.href ) ) {
    * 중요한 점:
                require_wikiminiatlas = true;
    *
                // break from loop
    * wrapper와 panel을 둘 다 애니메이션하지 않는다.
                return false;
    *
            }
    * 버튼 wrapper는 즉시 교체하고,
         } );
    * 실제 패널 하나만 slide 애니메이션한다.
         if ( $( 'div.kmldata' ).length ) {
    *
             require_wikiminiatlas = true;
    * 따라서 이중 움직임이나
    * 중간 겹침 현상이 최소화된다.
    * =============================================================
    */
    function initStackedCollapsible($content, cls, $targets) {
 
        /*
        * wikitable이 들어 있는 요소를 실제 패널로 사용
        */
        var $panel = $targets.filter(function () {
             return $(this).find('table.wikitable').length > 0;
         }).first();
 
         if (!$panel.length) {
             return;
         }
         }
         if ( require_wikiminiatlas ) {
 
             mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
 
         /*
        * 실제 패널이 아닌 동일 ID 요소 중
        * 해당 toggle을 포함하는 요소 = 상단 버튼 wrapper
        */
        var $topWrapper = $targets.not($panel).filter(function () {
             return $(this).find('.' + cls).length > 0;
        }).first();
 
        if (!$topWrapper.length) {
            return;
         }
         }
    } );
} )();


/**
* Fix for Windows XP Unicode font rendering
*/
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
    mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
                '.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}


/**
        var $topToggle = $topWrapper.find('.' + cls).first();
* 편집 안내 ****************************************************
         var $panelToggle = $panel.find('.' + cls).first();
*
 
* 생존 인물에 대한 편집 안내. 영어 위키백과에서 가져옴 - ChongDae
* Maintainers: [[User:RockMFR]]
*/
function addEditIntro( name ) {
    $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
         el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
    } );
}


if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
        if (!$topToggle.length || !$panelToggle.length) {
    $( function () {
        var cats = mw.config.get('wgCategories');
        if ( !cats ) {
             return;
             return;
         }
         }
        if ( $.inArray( '살아있는 사람', cats ) !== -1 || $.inArray( '생사 불명', cats ) !== -1 ) {
            addEditIntro( '틀:BLP_편집_안내' );
        }
    } );
}


mw.loader.load('//code.jquery.com/jquery-3.6.0.min.js');


$(document).ready(function() {
    var toggleBtns = $('.toggleBtn');
    toggleBtns.each(function() {
        var toggleId = $(this).attr("id");
        var contentId = toggleId.replace("toggle", "collapsible");
        var content = $("#" + contentId);
        var toggleTextId = toggleId.replace("toggle", "toggleText");
        var toggleText = $("#" + toggleTextId);
       
        content.hide();
       
        $(this).click(function() {
            content.slideToggle(300);
            if (content.css("display") == "none") {
                toggleText.html("[ 펼치기 · 접기 ]");
            } else {
                toggleText.html("[ 펼치기 · 접기 ]");
            }
        });
    });
});


document.addEventListener("DOMContentLoaded", function () {
        /*
    document.querySelectorAll(".mw-collapsible").forEach(table => {
        * =========================================================
        let toggle = table.querySelector(".mw-collapsible-toggle");
        * 최초 상태
       
        * =========================================================
         if (toggle) {
        */
             toggle.addEventListener("click", function (event) {
        $panel
                event.preventDefault();
            .stop(true, true)
               
            .addClass('mw-collapsed')
                if (table.classList.contains("mw-collapsed")) {
            .hide()
                    table.style.overflow = "hidden";
            .css({
                    table.style.maxHeight = "0px";
                height: '',
                    table.style.opacity = "0";
                overflow: '',
                    table.classList.remove("mw-collapsed");
                paddingTop: '',
                   
                paddingBottom: '',
                    setTimeout(() => {
                marginTop: '',
                        table.style.maxHeight = table.scrollHeight + "px";
                marginBottom: ''
                        table.style.opacity = "1";
            });
                        table.style.transition = "max-height 0.5s ease-in, opacity 0.3s ease-in";
 
                    }, 10);
 
                } else {
         $topWrapper
                    table.style.maxHeight = table.scrollHeight + "px";
             .stop(true, true)
                    table.style.opacity = "1";
            .show()
                    table.style.transition = "max-height 0.5s ease-out, opacity 0.3s ease-out";
            .css({
                   
                height: '',
                    setTimeout(() => {
                overflow: '',
                        table.style.maxHeight = "0px";
                paddingTop: '',
                        table.style.opacity = "0";
                paddingBottom: '',
                        table.classList.add("mw-collapsed");
                marginTop: '',
                     }, 10);
                marginBottom: ''
            });
 
 
        $topToggle.attr('aria-expanded', 'false');
        $panelToggle.attr('aria-expanded', 'false');
 
 
 
        /*
        * =========================================================
        * 위쪽 버튼 클릭 → 펼치기
        * =========================================================
        */
        $topToggle
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {
 
                e.preventDefault();
                e.stopImmediatePropagation();
 
 
                /*
                * 애니메이션 중 재클릭 방지
                */
                if ($panel.is(':animated')) {
                    return false;
                }
 
 
                /*
                * 이미 열려 있으면 중단
                */
                if ($panel.is(':visible')) {
                     return false;
                 }
                 }
                /*
                * -------------------------------------------------
                * 상단 버튼 wrapper는 즉시 숨김
                *
                * wrapper 자체를 애니메이션하지 않으므로
                * 이중 움직임이 발생하지 않는다.
                * -------------------------------------------------
                */
                $topWrapper
                    .stop(true, true)
                    .hide();
                /*
                * MediaWiki collapsed 상태 제거
                */
                $panel.removeClass('mw-collapsed');
                /*
                * -------------------------------------------------
                * 실제 패널 하나만 부드럽게 펼침
                * -------------------------------------------------
                */
                $panel
                    .stop(true, true)
                    .hide()
                    .slideDown(260, function () {
                        /*
                        * animation 종료 후
                        * jQuery가 만든 inline style 정리
                        */
                        $(this).css({
                            height: '',
                            overflow: '',
                            paddingTop: '',
                            paddingBottom: '',
                            marginTop: '',
                            marginBottom: ''
                        });
                    });
                /*
                * ARIA
                */
                $topToggle.attr('aria-expanded', 'true');
                $panelToggle.attr('aria-expanded', 'true');
                return false;
             });
             });
        }
    });
});




/* End of mw.loader.using callback */
 
} );
        /*
/* DO NOT ADD CODE BELOW THIS LINE */
        * =========================================================
        * 패널 안쪽 버튼 클릭 → 접기
        * =========================================================
        */
        $panelToggle
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {
 
                e.preventDefault();
                e.stopImmediatePropagation();
 
 
                /*
                * 애니메이션 중 재클릭 방지
                */
                if ($panel.is(':animated')) {
                    return false;
                }
 
 
                /*
                * -------------------------------------------------
                * 실제 패널 하나만 접음
                * -------------------------------------------------
                */
                $panel
                    .stop(true, true)
                    .slideUp(260, function () {
 
                        /*
                        * 패널을 완전히 닫은 뒤
                        * collapsed 상태 복원
                        */
                        $(this)
                            .addClass('mw-collapsed')
                            .css({
                                display: 'none',
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
 
 
                        /*
                        * -------------------------------------------------
                        * 원래 상단 버튼 즉시 복귀
                        *
                        * 별도 애니메이션을 하지 않기 때문에
                        * 닫힘 동작도 한 번의 움직임으로 보인다.
                        * -------------------------------------------------
                        */
                        $topWrapper
                            .stop(true, true)
                            .show()
                            .css({
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
                    });
 
 
                /*
                * ARIA
                */
                $topToggle.attr('aria-expanded', 'false');
                $panelToggle.attr('aria-expanded', 'false');
 
 
                return false;
            });
    }
 
});

2026년 8월 20일 (목) 15:13 기준 최신판

/* MediaWiki:Common.js */
mw.hook('wikipage.content').add(function ($content) {

    var initialized = {};

    $content.find('[class*="mw-customtoggle-"]').each(function () {
        var classList = (this.className || '').split(/\s+/);

        classList.forEach(function (cls) {
            if (cls.indexOf('mw-customtoggle-') !== 0) {
                return;
            }

            var suffix = cls.substring('mw-customtoggle-'.length);

            if (initialized[suffix]) {
                return;
            }

            initialized[suffix] = true;

            var targetId = 'mw-customcollapsible-' + suffix;

            /*
             * 중복 ID가 있을 수 있으므로
             * #id 대신 attribute selector 사용
             */
            var $targets = $content.find('[id="' + targetId + '"]');

            if (!$targets.length) {
                return;
            }


            /*
             * =====================================================
             * 특수형
             *
             * 아나운서 표처럼:
             *
             * [상단 버튼 wrapper]
             * [실제 내용 패널]
             *
             * 두 요소가 같은 ID를 공유하고,
             * 실제 패널 안에 wikitable이 있는 구조
             * =====================================================
             */
            var $specialPanel = $targets.filter(function () {
                return $(this).find('table.wikitable').length > 0;
            });

            if ($targets.length > 1 && $specialPanel.length) {
                initStackedCollapsible(
                    $content,
                    cls,
                    $targets
                );

                return;
            }


            /*
             * =====================================================
             * 일반 MediaWiki collapsible
             * =====================================================
             */
            initNormalCollapsible(
                $content,
                cls,
                $targets.first()
            );
        });
    });



    /*
     * =============================================================
     * 일반 펼치기 · 접기
     * =============================================================
     */
    function initNormalCollapsible($content, cls, $target) {

        var $toggles = $content.find('.' + cls);

        /*
         * 일반 MediaWiki 구조:
         *
         * .mw-collapsible
         *   └ .mw-collapsible-content
         *
         * content가 있으면 content만 애니메이션
         */
        var $contentTarget = $target.children('.mw-collapsible-content');

        if (!$contentTarget.length) {
            $contentTarget = $target.find('.mw-collapsible-content').first();
        }

        var $animTarget = $contentTarget.length
            ? $contentTarget
            : $target;


        /*
         * 현재 상태를 기준으로 초기 aria 설정
         */
        var initiallyOpen = $animTarget.is(':visible');

        $toggles.attr(
            'aria-expanded',
            initiallyOpen ? 'true' : 'false'
        );


        $toggles
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {

                e.preventDefault();
                e.stopImmediatePropagation();


                /*
                 * 애니메이션 중 재클릭 방지
                 */
                if ($animTarget.is(':animated')) {
                    return false;
                }


                var opening = !$animTarget.is(':visible');


                /*
                 * -------------------------------------------------
                 * 펼치기
                 * -------------------------------------------------
                 */
                if (opening) {

                    /*
                     * MediaWiki collapsed 상태 제거
                     */
                    $target.removeClass('mw-collapsed');


                    /*
                     * 내용만 펼침
                     */
                    $animTarget
                        .stop(true, true)
                        .hide()
                        .slideDown(250, function () {

                            /*
                             * jQuery 애니메이션 inline style 정리
                             */
                            $(this).css({
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
                        });


                    $toggles.attr('aria-expanded', 'true');
                }


                /*
                 * -------------------------------------------------
                 * 접기
                 * -------------------------------------------------
                 */
                else {

                    $animTarget
                        .stop(true, true)
                        .slideUp(250, function () {

                            /*
                             * 애니메이션 종료 후 collapsed 복원
                             */
                            $target.addClass('mw-collapsed');

                            $(this).css({
                                display: 'none',
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
                        });


                    $toggles.attr('aria-expanded', 'false');
                }


                return false;
            });
    }



    /*
     * =============================================================
     * 아나운서형 특수 펼치기 · 접기
     * =============================================================
     *
     * DOM 예:
     *
     * [남성 버튼 wrapper]
     * [남성 실제 패널]
     * [여성 버튼 wrapper]
     * [여성 실제 패널]
     *
     * 패널을 이동시키지 않고
     * 원래 DOM 위치에서 펼친다.
     *
     * 중요한 점:
     *
     * wrapper와 panel을 둘 다 애니메이션하지 않는다.
     *
     * 버튼 wrapper는 즉시 교체하고,
     * 실제 패널 하나만 slide 애니메이션한다.
     *
     * 따라서 이중 움직임이나
     * 중간 겹침 현상이 최소화된다.
     * =============================================================
     */
    function initStackedCollapsible($content, cls, $targets) {

        /*
         * wikitable이 들어 있는 요소를 실제 패널로 사용
         */
        var $panel = $targets.filter(function () {
            return $(this).find('table.wikitable').length > 0;
        }).first();

        if (!$panel.length) {
            return;
        }


        /*
         * 실제 패널이 아닌 동일 ID 요소 중
         * 해당 toggle을 포함하는 요소 = 상단 버튼 wrapper
         */
        var $topWrapper = $targets.not($panel).filter(function () {
            return $(this).find('.' + cls).length > 0;
        }).first();

        if (!$topWrapper.length) {
            return;
        }


        var $topToggle = $topWrapper.find('.' + cls).first();
        var $panelToggle = $panel.find('.' + cls).first();


        if (!$topToggle.length || !$panelToggle.length) {
            return;
        }



        /*
         * =========================================================
         * 최초 상태
         * =========================================================
         */
        $panel
            .stop(true, true)
            .addClass('mw-collapsed')
            .hide()
            .css({
                height: '',
                overflow: '',
                paddingTop: '',
                paddingBottom: '',
                marginTop: '',
                marginBottom: ''
            });


        $topWrapper
            .stop(true, true)
            .show()
            .css({
                height: '',
                overflow: '',
                paddingTop: '',
                paddingBottom: '',
                marginTop: '',
                marginBottom: ''
            });


        $topToggle.attr('aria-expanded', 'false');
        $panelToggle.attr('aria-expanded', 'false');



        /*
         * =========================================================
         * 위쪽 버튼 클릭 → 펼치기
         * =========================================================
         */
        $topToggle
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {

                e.preventDefault();
                e.stopImmediatePropagation();


                /*
                 * 애니메이션 중 재클릭 방지
                 */
                if ($panel.is(':animated')) {
                    return false;
                }


                /*
                 * 이미 열려 있으면 중단
                 */
                if ($panel.is(':visible')) {
                    return false;
                }


                /*
                 * -------------------------------------------------
                 * 상단 버튼 wrapper는 즉시 숨김
                 *
                 * wrapper 자체를 애니메이션하지 않으므로
                 * 이중 움직임이 발생하지 않는다.
                 * -------------------------------------------------
                 */
                $topWrapper
                    .stop(true, true)
                    .hide();


                /*
                 * MediaWiki collapsed 상태 제거
                 */
                $panel.removeClass('mw-collapsed');


                /*
                 * -------------------------------------------------
                 * 실제 패널 하나만 부드럽게 펼침
                 * -------------------------------------------------
                 */
                $panel
                    .stop(true, true)
                    .hide()
                    .slideDown(260, function () {

                        /*
                         * animation 종료 후
                         * jQuery가 만든 inline style 정리
                         */
                        $(this).css({
                            height: '',
                            overflow: '',
                            paddingTop: '',
                            paddingBottom: '',
                            marginTop: '',
                            marginBottom: ''
                        });
                    });


                /*
                 * ARIA
                 */
                $topToggle.attr('aria-expanded', 'true');
                $panelToggle.attr('aria-expanded', 'true');


                return false;
            });



        /*
         * =========================================================
         * 패널 안쪽 버튼 클릭 → 접기
         * =========================================================
         */
        $panelToggle
            .off('click.smoothSlide')
            .on('click.smoothSlide', function (e) {

                e.preventDefault();
                e.stopImmediatePropagation();


                /*
                 * 애니메이션 중 재클릭 방지
                 */
                if ($panel.is(':animated')) {
                    return false;
                }


                /*
                 * -------------------------------------------------
                 * 실제 패널 하나만 접음
                 * -------------------------------------------------
                 */
                $panel
                    .stop(true, true)
                    .slideUp(260, function () {

                        /*
                         * 패널을 완전히 닫은 뒤
                         * collapsed 상태 복원
                         */
                        $(this)
                            .addClass('mw-collapsed')
                            .css({
                                display: 'none',
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });


                        /*
                         * -------------------------------------------------
                         * 원래 상단 버튼 즉시 복귀
                         *
                         * 별도 애니메이션을 하지 않기 때문에
                         * 닫힘 동작도 한 번의 움직임으로 보인다.
                         * -------------------------------------------------
                         */
                        $topWrapper
                            .stop(true, true)
                            .show()
                            .css({
                                height: '',
                                overflow: '',
                                paddingTop: '',
                                paddingBottom: '',
                                marginTop: '',
                                marginBottom: ''
                            });
                    });


                /*
                 * ARIA
                 */
                $topToggle.attr('aria-expanded', 'false');
                $panelToggle.attr('aria-expanded', 'false');


                return false;
            });
    }

});