미디어위키:Gadget-ArticleToc.js: 두 판 사이의 차이
식물 vs 좀비 위키
새 문서: →MediaWiki:Gadget-ArticleToc.js * 데스크톱/모바일 공통 목차 위치 보정 및 자동 생성: (function () { 'use strict'; function getHeadingText(heading) { var copy = heading.cloneNode(true); var editLinks = copy.querySelectorAll( '.mw-editsection, .mw-editsection-like' ); Array.prototype.forEach.call(editLinks, function (editLink) { editLink.remove(); }); return copy.textContent.replace(/\s+/g, ' ').trim(); } function getHeadings(out... |
편집 요약 없음 |
||
| (같은 사용자의 중간 판 하나는 보이지 않습니다) | |||
| 5번째 줄: | 5번째 줄: | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
function animateList(list, expand) { | |||
var startHeight = list.getBoundingClientRect().height; | |||
var endHeight; | |||
var finished = false; | |||
var timer; | |||
function finish() { | |||
if (finished) { | |||
return; | |||
} | |||
finished = true; | |||
window.clearTimeout(timer); | |||
list.style.height = expand ? 'auto' : '0px'; | |||
list.style.pointerEvents = expand ? '' : 'none'; | |||
list.setAttribute('aria-hidden', String(!expand)); | |||
list.removeEventListener('transitionend', onTransitionEnd); | |||
} | |||
function onTransitionEnd(event) { | |||
if (event.propertyName === 'height') { | |||
finish(); | |||
} | |||
} | |||
list.style.height = startHeight + 'px'; | |||
list.style.pointerEvents = ''; | |||
list.offsetHeight; | |||
endHeight = expand ? list.scrollHeight : 0; | |||
list.addEventListener('transitionend', onTransitionEnd); | |||
list.style.height = endHeight + 'px'; | |||
timer = window.setTimeout(finish, 320); | |||
} | |||
function installNativeTocAnimation(toc) { | |||
var checkbox = toc.querySelector('.toctogglecheckbox'); | |||
var list = toc.querySelector(':scope > ul'); | |||
if (!checkbox || !list || checkbox.dataset.pvzTocAnimation === '1') { | |||
return; | |||
} | |||
checkbox.dataset.pvzTocAnimation = '1'; | |||
list.style.height = checkbox.checked ? '0px' : 'auto'; | |||
list.style.pointerEvents = checkbox.checked ? 'none' : ''; | |||
list.setAttribute('aria-hidden', String(checkbox.checked)); | |||
checkbox.addEventListener('change', function () { | |||
animateList(list, !checkbox.checked); | |||
}); | |||
} | |||
function getHeadingText(heading) { | function getHeadingText(heading) { | ||
| 46번째 줄: | 100번째 줄: | ||
toc.classList.add('pvz-custom-toc'); | toc.classList.add('pvz-custom-toc'); | ||
installNativeTocAnimation(toc); | |||
if (firstHeading) { | if (firstHeading) { | ||
| 163번째 줄: | 218번째 줄: | ||
button.setAttribute('aria-expanded', String(!isOpen)); | button.setAttribute('aria-expanded', String(!isOpen)); | ||
button.textContent = isOpen ? '펼치기' : '접기'; | button.textContent = isOpen ? '펼치기' : '접기'; | ||
list | animateList(list, !isOpen); | ||
}); | }); | ||
