MediaWiki:Common.js: Difference between revisions
From LOTR-TCG Wiki
No edit summary |
No edit summary |
||
| (37 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
var tooltips = document.querySelectorAll('.tooltip span'); | var tooltips = document.querySelectorAll('.tooltip > span'); | ||
for (var i = 0; i < tooltips.length; i++){ | |||
//tooltips with card images in them tend to be big and in some contexts, | |||
// they might cover up the screen and make it difficult to un-hover. In | |||
// those cases, the image can be clicked to temporarily disable the hover | |||
// for 1 second, which gives the system time to realize the mouse has moved. | |||
// On mobile... | |||
tooltips[i].addEventListener("click", function(e) | |||
{ | |||
this.classList.add("click-disabled"); | |||
document.body.tabIndex = "-1"; | |||
document.body.focus(); | |||
var that = this; | |||
setTimeout(function() { | |||
that.classList.remove("click-disabled"); | |||
}, 1000); | |||
}, false); | |||
} | |||
window.onmousemove = function (e) { | window.onmousemove = function (e) { | ||
| Line 6: | Line 27: | ||
yoffset = (e.clientY + 20); | yoffset = (e.clientY + 20); | ||
for (var i = 0; i < tooltips.length; i++) { | for (var i = 0; i < tooltips.length; i++) { | ||
var tooltip_rect = tooltips[i].getBoundingClientRect(); | var tooltip_rect = tooltips[i].getBoundingClientRect(); | ||
if(tooltip_rect.width == 0) | |||
continue; | |||
var x = xoffset, y = yoffset; | |||
console.log(tooltip_rect); | // console.log(tooltip_rect); | ||
// console.log("Width: " + window.innerWidth); | |||
// console.log("Height: " + window.innerHeight); | |||
// console.log("X: " + x); | |||
// console.log("Y: " + y); | |||
if (( | if ((xoffset + tooltip_rect.width) > window.innerWidth) // Out on the right | ||
x = -tooltip_rect.width | x = window.innerWidth - tooltip_rect.width; | ||
if (( | if ((yoffset + tooltip_rect.height) > window.innerHeight) // Out on the bottom | ||
y = -tooltip_rect.height | y = window.innerHeight - tooltip_rect.height; | ||
console.log("X: " + x); | // console.log("X: " + x); | ||
console.log("Y: " + y); | // console.log("Y: " + y); | ||
tooltips[i].style.top = y + 'px'; | tooltips[i].style.top = y + 'px'; | ||
tooltips[i].style.left = x + 'px'; | tooltips[i].style.left = x + 'px'; | ||
} | } | ||
}; | }; | ||
Latest revision as of 03:04, 30 September 2021
/* Any JavaScript here will be loaded for all users on every page load. */
var tooltips = document.querySelectorAll('.tooltip > span');
for (var i = 0; i < tooltips.length; i++){
//tooltips with card images in them tend to be big and in some contexts,
// they might cover up the screen and make it difficult to un-hover. In
// those cases, the image can be clicked to temporarily disable the hover
// for 1 second, which gives the system time to realize the mouse has moved.
// On mobile...
tooltips[i].addEventListener("click", function(e)
{
this.classList.add("click-disabled");
document.body.tabIndex = "-1";
document.body.focus();
var that = this;
setTimeout(function() {
that.classList.remove("click-disabled");
}, 1000);
}, false);
}
window.onmousemove = function (e) {
var xoffset = (e.clientX + 20),
yoffset = (e.clientY + 20);
for (var i = 0; i < tooltips.length; i++) {
var tooltip_rect = tooltips[i].getBoundingClientRect();
if(tooltip_rect.width == 0)
continue;
var x = xoffset, y = yoffset;
// console.log(tooltip_rect);
// console.log("Width: " + window.innerWidth);
// console.log("Height: " + window.innerHeight);
// console.log("X: " + x);
// console.log("Y: " + y);
if ((xoffset + tooltip_rect.width) > window.innerWidth) // Out on the right
x = window.innerWidth - tooltip_rect.width;
if ((yoffset + tooltip_rect.height) > window.innerHeight) // Out on the bottom
y = window.innerHeight - tooltip_rect.height;
// console.log("X: " + x);
// console.log("Y: " + y);
tooltips[i].style.top = y + 'px';
tooltips[i].style.left = x + 'px';
}
};