1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 07:30:10 +01:00

Prevent images from hovering off-page

This entirely affects the "imageHoverFollowCursor" option.
This commit is contained in:
Zixaphir 2015-03-18 20:48:02 -07:00 committed by czaks
parent 5f043d0a29
commit cad8019068

View File

@ -140,13 +140,21 @@ function imageHoverStart(e) { //Pashe, anonish, WTFPL
if (isVideo(getFileExtension(fullUrl))) {return;} if (isVideo(getFileExtension(fullUrl))) {return;}
hoverImage = $('<img id="chx_hoverImage" src="'+fullUrl+'" />'); hoverImage = $('<img id="chx_hoverImage" src="'+fullUrl+'" />');
if (getSetting("imageHoverFollowCursor")) { if (getSetting("imageHoverFollowCursor")) {
var size = $this.parents('.file').find('.unimportant').text().match(/\b(\d+)x(\d+)\b/),
maxWidth = $(window).width(),
maxHeight = $(window).height(),
var scale = Math.min(1, maxWidth / size[1], maxHeight / size[2]);
hoverImage.css({ hoverImage.css({
"position" : "absolute", "position" : "absolute",
"z-index" : 101, "z-index" : 101,
"pointer-events": "none", "pointer-events": "none",
"max-width" : $(window).width(), "width" : size[1] + "px",
"max-height" : $(window).height(), "height" : size[2] + "px",
"max-width" : (size[1] * scale) + "px",
"max-height" : (size[2] * scale) + "px",
'left' : e.pageX, 'left' : e.pageX,
'top' : imgTop, 'top' : imgTop,
}); });