미디어위키:Common.js: 두 판 사이의 차이
둘러보기로 이동
검색으로 이동
잔글편집 요약 없음 |
잔글편집 요약 없음 |
||
4번째 줄: | 4번째 줄: | ||
if ($toc.length) { | if ($toc.length) { | ||
console.log('목차가 감지되었습니다.'); | console.log('목차가 감지되었습니다.'); | ||
// 스크롤 가능한 목차 설정 | |||
$toc.css({ | |||
position: 'fixed', | |||
top: '20px', // 상단에서의 거리 | |||
right: '20px', // 오른쪽에서의 거리 | |||
width: '250px', // 목차 너비 | |||
maxHeight: '80vh', // 화면 높이의 80%까지만 사용 | |||
overflowY: 'auto', // 세로 스크롤 활성화 | |||
zIndex: 1000, // 다른 요소 위에 표시 | |||
}); | |||
// 페이지 내용 간 여백 조정 | |||
$('#content').css('margin-right', '280px'); | |||
} else { | } else { | ||
console. | console.warn('목차가 없습니다.'); | ||
} | } | ||
}); | }); |
2025년 1월 21일 (화) 11:06 판
mw.hook('wikipage.content').add(function ($content) {
// 목차(#toc)가 있는지 확인
const $toc = $content.find('#toc');
if ($toc.length) {
console.log('목차가 감지되었습니다.');
// 스크롤 가능한 목차 설정
$toc.css({
position: 'fixed',
top: '20px', // 상단에서의 거리
right: '20px', // 오른쪽에서의 거리
width: '250px', // 목차 너비
maxHeight: '80vh', // 화면 높이의 80%까지만 사용
overflowY: 'auto', // 세로 스크롤 활성화
zIndex: 1000, // 다른 요소 위에 표시
});
// 페이지 내용 간 여백 조정
$('#content').css('margin-right', '280px');
} else {
console.warn('목차가 없습니다.');
}
});
mw.hook('wikipage.content').add(function($content) {
// 모든 주석 <sup> 태그 선택
const refs = $content.find('sup.reference');
refs.each(function() {
const $ref = $(this);
const refId = $ref.find('a').attr('href'); // <a> 태그의 href 속성에서 ID 가져오기
if (refId) {
const refContent = $(refId).html(); // 주석 내용 가져오기
// 팝업용 컨테이너 생성
const $tooltip = $('<div>')
.addClass('ref-tooltip')
.html(refContent)
.css({
display: 'none',
position: 'absolute',
border: '1px solid #ccc',
background: '#fff',
padding: '10px',
'z-index': 1000,
'box-shadow': '0 4px 8px rgba(0,0,0,0.1)',
});
// 팝업을 DOM에 추가
$('body').append($tooltip);
// 마우스 이벤트 처리
$ref.on('mouseenter', function(event) {
$tooltip.css({
top: event.pageY + 10,
left: event.pageX + 10,
}).fadeIn(200);
});
$ref.on('mousemove', function(event) {
$tooltip.css({
top: event.pageY + 10,
left: event.pageX + 10,
});
});
$ref.on('mouseleave', function() {
$tooltip.fadeOut(200);
});
}
});
});