편집 요약 없음 태그: 되돌려진 기여 |
편집 요약 없음 태그: 되돌려진 기여 |
||
| 1번째 줄: | 1번째 줄: | ||
( function () { | ( function () { | ||
'use strict'; | 'use strict'; | ||
var DURATION = 300; | var DURATION = 300; | ||
document.addEventListener( | |||
'click', | |||
function ( event ) { | |||
var toggle = event.target.closest( '.mw-customtoggle' ); | |||
if ( !toggle ) { | |||
if ( | return; | ||
return | |||
} | } | ||
var name = null; | |||
toggle.classList.forEach( function ( className ) { | |||
if ( className.indexOf( 'mw-customtoggle-' ) === 0 ) { | |||
name = className.substring( | |||
'mw-customtoggle-'.length | |||
); | |||
} | |||
} ); | |||
if ( !name ) { | |||
return; | |||
} | |||
var target = document.getElementById( | |||
'mw-customcollapsible-' + name | |||
); | ); | ||
if ( !target ) { | |||
return; | |||
} | |||
/* | |||
* 실제 내용 영역이 있으면 그것을 사용하고, | |||
* 없으면 target 자체 사용. | |||
* | |||
* 이제 toggle은 target 밖에 있으므로 | |||
* 버튼이 사라지는 문제가 없음. | |||
*/ | |||
var content = | |||
target.querySelector( '.mw-collapsible-content' ) || | |||
target; | |||
var collapsed = | |||
target.classList.contains( 'mw-collapsed' ) || | |||
window.getComputedStyle( content ).display === 'none'; | |||
/* | |||
* MediaWiki 기본 토글 방지 | |||
*/ | |||
event.preventDefault(); | |||
event.stopPropagation(); | |||
event.stopImmediatePropagation(); | |||
if ( collapsed ) { | |||
expand( target, content ); | |||
} | } else { | ||
collapse( target, content ); | |||
} | |||
}, | |||
true | |||
); | |||
function expand( target, content ) { | function expand( target, content ) { | ||
target.classList.remove( 'mw-collapsed' ); | |||
target.classList.remove( | |||
content.style.display = 'block'; | |||
content.style.height = 'auto'; | content.style.height = 'auto'; | ||
content.style.overflow = 'hidden'; | content.style.overflow = 'hidden'; | ||
var | var height = content.scrollHeight; | ||
content.style.height = '0px'; | content.style.height = '0px'; | ||
content.offsetHeight; | content.offsetHeight; | ||
var animation = | var animation = content.animate( | ||
[ | |||
{ height: '0px' }, | |||
{ height: height + 'px' } | |||
], | |||
{ | |||
duration: DURATION, | |||
easing: 'ease', | |||
fill: 'forwards' | |||
} | |||
); | |||
animation.onfinish = function () { | animation.onfinish = function () { | ||
content.style.display = ''; | content.style.display = ''; | ||
content.style.height = ''; | content.style.height = ''; | ||
| 243번째 줄: | 100번째 줄: | ||
} | } | ||
function collapse( target, content ) { | function collapse( target, content ) { | ||
var height = | |||
content. | content.getBoundingClientRect().height; | ||
content.style.height = height + 'px'; | |||
content.style.overflow = 'hidden'; | |||
content. | var animation = content.animate( | ||
[ | |||
{ height: height + 'px' }, | |||
{ height: '0px' } | |||
], | |||
{ | |||
duration: DURATION, | |||
easing: 'ease', | |||
fill: 'forwards' | |||
} | |||
); | ); | ||
animation.onfinish = function () { | animation.onfinish = function () { | ||
target.classList.add( | target.classList.add( 'mw-collapsed' ); | ||
content.style.display = 'none'; | |||
content.style.height = ''; | content.style.height = ''; | ||
content.style.overflow = ''; | content.style.overflow = ''; | ||
| 310번째 줄: | 129번째 줄: | ||
}; | }; | ||
} | } | ||
}() ); | }() ); | ||
2026년 8월 20일 (목) 13:19 판
( function () {
'use strict';
var DURATION = 300;
document.addEventListener(
'click',
function ( event ) {
var toggle = event.target.closest( '.mw-customtoggle' );
if ( !toggle ) {
return;
}
var name = null;
toggle.classList.forEach( function ( className ) {
if ( className.indexOf( 'mw-customtoggle-' ) === 0 ) {
name = className.substring(
'mw-customtoggle-'.length
);
}
} );
if ( !name ) {
return;
}
var target = document.getElementById(
'mw-customcollapsible-' + name
);
if ( !target ) {
return;
}
/*
* 실제 내용 영역이 있으면 그것을 사용하고,
* 없으면 target 자체 사용.
*
* 이제 toggle은 target 밖에 있으므로
* 버튼이 사라지는 문제가 없음.
*/
var content =
target.querySelector( '.mw-collapsible-content' ) ||
target;
var collapsed =
target.classList.contains( 'mw-collapsed' ) ||
window.getComputedStyle( content ).display === 'none';
/*
* MediaWiki 기본 토글 방지
*/
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
if ( collapsed ) {
expand( target, content );
} else {
collapse( target, content );
}
},
true
);
function expand( target, content ) {
target.classList.remove( 'mw-collapsed' );
content.style.display = 'block';
content.style.height = 'auto';
content.style.overflow = 'hidden';
var height = content.scrollHeight;
content.style.height = '0px';
content.offsetHeight;
var animation = content.animate(
[
{ height: '0px' },
{ height: height + 'px' }
],
{
duration: DURATION,
easing: 'ease',
fill: 'forwards'
}
);
animation.onfinish = function () {
content.style.display = '';
content.style.height = '';
content.style.overflow = '';
animation.cancel();
};
}
function collapse( target, content ) {
var height =
content.getBoundingClientRect().height;
content.style.height = height + 'px';
content.style.overflow = 'hidden';
var animation = content.animate(
[
{ height: height + 'px' },
{ height: '0px' }
],
{
duration: DURATION,
easing: 'ease',
fill: 'forwards'
}
);
animation.onfinish = function () {
target.classList.add( 'mw-collapsed' );
content.style.display = 'none';
content.style.height = '';
content.style.overflow = '';
animation.cancel();
};
}
}() );