From 9edd934754c15982043136fc9ef7678f6ebdad8b Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 11 Jan 2015 22:50:26 -0700 Subject: [PATCH] Fix image hovering --- builds/appchan-x.user.js | 20 +++++++++++++++++++- builds/crx/script.js | 20 +++++++++++++++++++- src/Images/ImageHover.coffee | 8 ++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index 9f4e20d05..40e85819b 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -11916,7 +11916,7 @@ return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover); }, mouseover: function(e) { - var el, error, file, isVideo, maxHeight, maxWidth, post, scale, _ref; + var el, error, file, height, isVideo, left, maxHeight, maxWidth, padding, post, right, scale, width, x, _ref, _ref1, _ref2; post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this); file = post.file; isVideo = file.isVideo; @@ -11930,6 +11930,12 @@ } else { el = $.el((isVideo ? 'video' : 'img')); el.dataset.fullID = post.fullID; + $.on(el, 'error', error); + el.src = file.URL; + } + if (Conf['Restart when Opened']) { + ImageCommon.rewind(el); + ImageCommon.rewind(this); } el.id = 'ihover'; $.add(Header.hover, el); @@ -11940,6 +11946,18 @@ el.play(); } } + _ref1 = (function() { + var _i, _len, _ref1, _results; + _ref1 = file.dimensions.split('x'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + x = _ref1[_i]; + _results.push(+x); + } + return _results; + })(), width = _ref1[0], height = _ref1[1]; + _ref2 = this.getBoundingClientRect(), left = _ref2.left, right = _ref2.right; + padding = 16; maxWidth = Math.max(left, doc.clientWidth - right); maxHeight = doc.clientHeight - 16; scale = Math.min(1, maxWidth / width, maxHeight / height); diff --git a/builds/crx/script.js b/builds/crx/script.js index 15430f7b2..00b299e10 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -11943,7 +11943,7 @@ return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover); }, mouseover: function(e) { - var el, error, file, isVideo, maxHeight, maxWidth, post, scale, _ref; + var el, error, file, height, isVideo, left, maxHeight, maxWidth, padding, post, right, scale, width, x, _ref, _ref1, _ref2; post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this); file = post.file; isVideo = file.isVideo; @@ -11957,6 +11957,12 @@ } else { el = $.el((isVideo ? 'video' : 'img')); el.dataset.fullID = post.fullID; + $.on(el, 'error', error); + el.src = file.URL; + } + if (Conf['Restart when Opened']) { + ImageCommon.rewind(el); + ImageCommon.rewind(this); } el.id = 'ihover'; $.add(Header.hover, el); @@ -11967,6 +11973,18 @@ el.play(); } } + _ref1 = (function() { + var _i, _len, _ref1, _results; + _ref1 = file.dimensions.split('x'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + x = _ref1[_i]; + _results.push(+x); + } + return _results; + })(), width = _ref1[0], height = _ref1[1]; + _ref2 = this.getBoundingClientRect(), left = _ref2.left, right = _ref2.right; + padding = 16; maxWidth = Math.max(left, doc.clientWidth - right); maxHeight = doc.clientHeight - 16; scale = Math.min(1, maxWidth / width, maxHeight / height); diff --git a/src/Images/ImageHover.coffee b/src/Images/ImageHover.coffee index adf0e986f..82a518df8 100755 --- a/src/Images/ImageHover.coffee +++ b/src/Images/ImageHover.coffee @@ -34,13 +34,21 @@ ImageHover = else el = $.el (if isVideo then 'video' else 'img') el.dataset.fullID = post.fullID + $.on el, 'error', error + el.src = file.URL + if Conf['Restart when Opened'] + ImageCommon.rewind el + ImageCommon.rewind @ el.id = 'ihover' $.add Header.hover, el if isVideo el.loop = true el.controls = false el.play() if Conf['Autoplay'] + [width, height] = (+x for x in file.dimensions.split 'x') + {left, right} = @getBoundingClientRect() + padding = 16 maxWidth = Math.max left, doc.clientWidth - right maxHeight = doc.clientHeight - 16 scale = Math.min 1, maxWidth / width, maxHeight / height