From 27ec5caf351944ae52905fb87cc23d9c72a776b7 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Wed, 18 Mar 2015 20:48:02 -0700 Subject: [PATCH] Prevent images from hovering off-page This entirely affects the "imageHoverFollowCursor" option. --- js/image-hover.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/image-hover.js b/js/image-hover.js index ac175ff4..3e4ec0c4 100644 --- a/js/image-hover.js +++ b/js/image-hover.js @@ -140,13 +140,21 @@ function imageHoverStart(e) { //Pashe, anonish, WTFPL if (isVideo(getFileExtension(fullUrl))) {return;} hoverImage = $(''); + 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({ "position" : "absolute", "z-index" : 101, "pointer-events": "none", - "max-width" : $(window).width(), - "max-height" : $(window).height(), + "width" : size[1] + "px", + "height" : size[2] + "px", + "max-width" : (size[1] * scale) + "px", + "max-height" : (size[2] * scale) + "px", 'left' : e.pageX, 'top' : imgTop, });