MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 66: | Line 66: | ||
document.body.addEventListener('mouseenter', function (e) { | document.body.addEventListener('mouseenter', function (e) { | ||
if (e.target.classList && e.target.classList.contains(' | if (e.target.classList && e.target.classList.contains('reference')) { | ||
var referenceId = e.target.getAttribute('href').replace('#', ''); | |||
var popup = document.getElementById(referenceId); | |||
if (popup) { | |||
tooltip = popup; | |||
showTooltip(e.clientX, e.clientY); | |||
} | |||
} | } | ||
}); | }); | ||
| Line 74: | Line 78: | ||
document.body.addEventListener('mousemove', function (e) { | document.body.addEventListener('mousemove', function (e) { | ||
if (tooltip) { | if (tooltip) { | ||
showTooltip(e.clientX, e.clientY); | |||
} | } | ||
}); | }); | ||
| Line 80: | Line 84: | ||
document.body.addEventListener('mouseleave', function (e) { | document.body.addEventListener('mouseleave', function (e) { | ||
if (tooltip) { | if (tooltip) { | ||
tooltip.style.display = 'none'; | |||
tooltip = null; | tooltip = null; | ||
} | } | ||
}); | }); | ||
function | function showTooltip(mouseX, mouseY) { | ||
var tooltipRect = tooltip.getBoundingClientRect(); | var tooltipRect = tooltip.getBoundingClientRect(); | ||
var tooltipHeight = tooltipRect.height; | var tooltipHeight = tooltipRect.height; | ||
| Line 91: | Line 96: | ||
var windowWidth = window.innerWidth; | var windowWidth = window.innerWidth; | ||
var tooltipTop = mouseY | var tooltipTop = mouseY + 20; | ||
var tooltipLeft = mouseX + | var tooltipLeft = mouseX + 20; | ||
// 팝업이 브라우저 창 아래쪽으로 벗어나는 경우 | // 팝업이 브라우저 창 아래쪽으로 벗어나는 경우 | ||
if ((tooltipTop + tooltipHeight) > windowHeight) { | if ((tooltipTop + tooltipHeight) > windowHeight) { | ||
tooltipTop = windowHeight - tooltipHeight - | tooltipTop = windowHeight - tooltipHeight - 20; | ||
} | } | ||
// 팝업이 브라우저 창 오른쪽으로 벗어나는 경우 | // 팝업이 브라우저 창 오른쪽으로 벗어나는 경우 | ||
if ((tooltipLeft + tooltipWidth) > windowWidth) { | if ((tooltipLeft + tooltipWidth) > windowWidth) { | ||
tooltipLeft = windowWidth - tooltipWidth - | tooltipLeft = windowWidth - tooltipWidth - 20; | ||
} | } | ||
tooltip.style.top = tooltipTop + 'px'; | tooltip.style.top = tooltipTop + 'px'; | ||
tooltip.style.left = tooltipLeft + 'px'; | tooltip.style.left = tooltipLeft + 'px'; | ||
tooltip.style.display = 'block'; | |||
} | } | ||
}); | }); | ||
/* | /* | ||