MediaWiki:Common.js: Difference between revisions

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


/* 각주 팝업창 위치 보정 DOM */
/* 각주 팝업창 위치 보정 DOM */
document.body.addEventListener(
    'DOMNodeInserted',
    function (e) {
        if (e.target.classList && e.target.classList.contains('rt-tooltip')) {
            requestAnimationFrame(function () {
                var bodyRect = document.body.getBoundingClientRect();
                var tooltipRect = e.target.getBoundingClientRect();
                var tooltipTop = tooltipRect.top - bodyRect.top;
                var tooltipLeft = tooltipRect.left - bodyRect.left;
                var tooltipHeight = tooltipRect.height;
                var tooltipWidth = tooltipRect.width;
                var windowHeight = window.innerHeight;
                var windowWidth = window.innerWidth;
                var scrollY = window.scrollY || window.pageYOffset;
                var scrollX = window.scrollX || window.pageXOffset;
                // 툴팁이 화면 위쪽으로 나타날 경우 보정
                if (tooltipTop < 0) {
                    e.target.style.top = (scrollY + 10) + 'px';
                }
                // 툴팁이 화면 아래쪽으로 나타날 경우 보정
                if ((tooltipTop + tooltipHeight) > windowHeight) {
                    e.target.style.top = (scrollY + windowHeight - tooltipHeight - 10) + 'px';
                }
                // 툴팁이 화면 왼쪽으로 나타날 경우 보정
                if (tooltipLeft < 0) {
                    e.target.style.left = (scrollX + 10) + 'px';
                }
                // 툴팁이 화면 오른쪽으로 나타날 경우 보정
                if ((tooltipLeft + tooltipWidth) > windowWidth) {
                    e.target.style.left = (scrollX + windowWidth - tooltipWidth - 10) + 'px';
                }
            });
        }
    },
    false
);
/*
document.body.addEventListener(
document.body.addEventListener(
     'DOMNodeInserted',
     'DOMNodeInserted',
Line 79: Line 120:
     false
     false
);
);
 
*/
/* 우클릭 방지  */
/* 우클릭 방지  */
window.oncontextmenu = function (e) {
window.oncontextmenu = function (e) {