MediaWiki:Common.js: Difference between revisions

From LOTR-TCG Wiki
No edit summary
No edit summary
Line 18: Line 18:
     console.log("Width: " + window.innerWidth);
     console.log("Width: " + window.innerWidth);
     console.log("Height: " + window.innerHeight);
     console.log("Height: " + window.innerHeight);
    console.log("X: " + x);
    console.log("Y: " + y);
    
    
     if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right
     if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right

Revision as of 00:03, 30 September 2021

/* Any JavaScript here will be loaded for all users on every page load. */
var tooltips = document.querySelectorAll('.tooltip span');

window.onmousemove = function (e) {
    var xoffset = (e.clientX + 20),
        yoffset = (e.clientY + 20);
    for (var i = 0; i < tooltips.length; i++) {
    	var x = xoffset, y = yoffset;
    	
    	tooltips[i].style.top = y + 'px';
        tooltips[i].style.left = x + 'px';
    	
    	var tooltip_rect = tooltips[i].getBoundingClientRect();
    	if(tooltip_rect.width == 0)
    		continue;
    	
    	console.log(tooltip_rect);
    	console.log("Width: " + window.innerWidth);
    	console.log("Height: " + window.innerHeight);
    	console.log("X: " + x);
    	console.log("Y: " + y);
    	
    	if ((tooltip_rect.x + tooltip_rect.width + xoffset) > window.innerWidth) // Out on the right
    		x = window.innerWidth - tooltip_rect.width;  
		if ((tooltip_rect.y + tooltip_rect.height + yoffset) > window.innerHeight) // Out on the bottom
    		y = window.innerHeight - tooltip_rect.height;    // Align on the top
    	
    	console.log("X: " + x);
    	console.log("Y: " + y);
        tooltips[i].style.top = y + 'px';
        tooltips[i].style.left = x + 'px';
    }
};