MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
Line 62: Line 62:


/* 각주 팝업창 위치 보정 DOM */
/* 각주 팝업창 위치 보정 DOM */
document.addEventListener('DOMContentLoaded', function () {
    var tooltip = null;
    document.body.addEventListener('mouseenter', function (e) {
        if (e.target.classList && e.target.classList.contains('rt-tooltip')) {
        console.log('event');
            var referenceId = e.target.getAttribute('href').replace('#', '');
            console.log(referenceId);
            var popup = document.getElementById(referenceId);
            if (popup) {
                tooltip = popup;
                showTooltip(e.clientX, e.clientY);
            }
        }
    });
    document.body.addEventListener('mousemove', function (e) {
        if (tooltip) {
            showTooltip(e.clientX, e.clientY);
        }
    });
    document.body.addEventListener('mouseleave', function (e) {
        if (tooltip) {
            tooltip.style.display = 'none';
            tooltip = null;
        }
    });
    function showTooltip(mouseX, mouseY) {
        var tooltipRect = tooltip.getBoundingClientRect();
        var tooltipHeight = tooltipRect.height;
        var tooltipWidth = tooltipRect.width;
        var windowHeight = window.innerHeight;
        var windowWidth = window.innerWidth;
        var tooltipTop = mouseY + 20;
        var tooltipLeft = mouseX + 20;
        // 팝업이 브라우저 창 아래쪽으로 벗어나는 경우
        if ((tooltipTop + tooltipHeight) > windowHeight) {
            tooltipTop = windowHeight - tooltipHeight - 20;
        }
        // 팝업이 브라우저 창 오른쪽으로 벗어나는 경우
        if ((tooltipLeft + tooltipWidth) > windowWidth) {
        console.log((tooltipLeft + tooltipWidth),  windowWidth)
            tooltipLeft = windowWidth - tooltipWidth - 20;
            console.log(tooltipLeft);
        }
        tooltip.style.top = tooltipTop + 'px';
        tooltip.style.left = tooltipLeft + 'px';
        tooltip.style.display = 'block';
    }
});
/*
document.body.addEventListener(
document.body.addEventListener(
     'DOMNodeInserted',
     'DOMNodeInserted',
Line 136: Line 76:
     false
     false
);
);
*/
 


/* 우클릭 방지  */
/* 우클릭 방지  */