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('rt-tooltip')) {
         if (e.target.classList && e.target.classList.contains('reference')) {
             tooltip = e.target;
             var referenceId = e.target.getAttribute('href').replace('#', '');
             adjustTooltipPosition(e.clientX, e.clientY);
            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) {
             adjustTooltipPosition(e.clientX, e.clientY);
             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 adjustTooltipPosition(mouseX, mouseY) {
     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 - 10; // 팝업이 마우스 위로 올라가지 않도록 보정
         var tooltipTop = mouseY + 20;
         var tooltipLeft = mouseX + 10; // 팝업이 마우스 옆으로 올라가지 않도록 보정
         var tooltipLeft = mouseX + 20;


         // 팝업이 브라우저 창 아래쪽으로 벗어나는 경우 보정
         // 팝업이 브라우저 창 아래쪽으로 벗어나는 경우
         if ((tooltipTop + tooltipHeight) > windowHeight) {
         if ((tooltipTop + tooltipHeight) > windowHeight) {
             tooltipTop = windowHeight - tooltipHeight - 10;
             tooltipTop = windowHeight - tooltipHeight - 20;
         }
         }


         // 팝업이 브라우저 창 오른쪽으로 벗어나는 경우 보정
         // 팝업이 브라우저 창 오른쪽으로 벗어나는 경우
         if ((tooltipLeft + tooltipWidth) > windowWidth) {
         if ((tooltipLeft + tooltipWidth) > windowWidth) {
             tooltipLeft = windowWidth - tooltipWidth - 10;
             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';
     }
     }
});
});


/*
/*