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

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
/* MediaWiki:Common.js */
/* MediaWiki:Common.js */
mw.hook('wikipage.content').add(function ($content) {
mw.hook('wikipage.content').add(function ($content) {
    // mw-customtoggle로 시작하는 버튼 탐색
     $content.find('[class*="mw-customtoggle-"]').each(function () {
     $content.find('[class*="mw-customtoggle-"]').each(function () {
         var $toggle = $(this);
         var $toggle = $(this);
12번째 줄: 11번째 줄:


                 if ($target.length) {
                 if ($target.length) {
                    // 클릭 시 jQuery slideToggle을 이용한 부드러운 애니메이션
                     $toggle.off('click.smoothSlide').on('click.smoothSlide', function (e) {
                     $toggle.off('click.smoothSlide').on('click.smoothSlide', function (e) {
                         var $collapsibleContent = $target.find('.mw-collapsible-content');
                         var $contentTarget = $target.find('.mw-collapsible-content');
                         var $animTarget = $collapsibleContent.length ? $collapsibleContent : $target;
                         var $animTarget = $contentTarget.length ? $contentTarget : $target;


                         $animTarget.stop(true, true).slideToggle(200);
                        // 너비 고정 후 슬라이드 실행
                         $animTarget.stop(true, true).slideToggle(200, function () {
                            // 애니메이션 완료 후 잔여 inline style 제거
                            if ($(this).is(':visible')) {
                                $(this).css('display', '');
                            }
                        });
                     });
                     });
                 }
                 }

2026년 8월 20일 (목) 14:45 판

/* MediaWiki:Common.js */
mw.hook('wikipage.content').add(function ($content) {
    $content.find('[class*="mw-customtoggle-"]').each(function () {
        var $toggle = $(this);
        var classList = ($toggle.attr('class') || '').split(/\s+/);

        classList.forEach(function (cls) {
            if (cls.indexOf('mw-customtoggle-') === 0) {
                var targetId = 'mw-customcollapsible-' + cls.replace('mw-customtoggle-', '');
                var $target = $('#' + targetId);

                if ($target.length) {
                    $toggle.off('click.smoothSlide').on('click.smoothSlide', function (e) {
                        var $contentTarget = $target.find('.mw-collapsible-content');
                        var $animTarget = $contentTarget.length ? $contentTarget : $target;

                        // 너비 고정 후 슬라이드 실행
                        $animTarget.stop(true, true).slideToggle(200, function () {
                            // 애니메이션 완료 후 잔여 inline style 제거
                            if ($(this).is(':visible')) {
                                $(this).css('display', '');
                            }
                        });
                    });
                }
            }
        });
    });
});