summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorZixaphir <zixaphirmoxphar@gmail.com>2015-03-18 20:48:02 -0700
committerczaks <marcin@6irc.net>2016-05-05 13:43:17 +0200
commitcad8019068cf94a1e28e8ebfcc50af56914703b8 (patch)
treec1137183007aa7fa0346a38108a5e362d58cd46b /js
parent5f043d0a29efd6b14d3b453955af15df8630d88b (diff)
Prevent images from hovering off-page
This entirely affects the "imageHoverFollowCursor" option.
Diffstat (limited to 'js')
-rw-r--r--js/image-hover.js12
1 files 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 = $('<img id="chx_hoverImage" src="'+fullUrl+'" />');
+
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,
});