diff options
| author | Zixaphir <zixaphirmoxphar@gmail.com> | 2015-03-18 20:48:02 -0700 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2016-05-05 13:43:17 +0200 |
| commit | cad8019068cf94a1e28e8ebfcc50af56914703b8 (patch) | |
| tree | c1137183007aa7fa0346a38108a5e362d58cd46b /js/image-hover.js | |
| parent | 5f043d0a29efd6b14d3b453955af15df8630d88b (diff) | |
Prevent images from hovering off-page
This entirely affects the "imageHoverFollowCursor" option.
Diffstat (limited to 'js/image-hover.js')
| -rw-r--r-- | js/image-hover.js | 12 |
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, }); |
