diff --git a/4chan_x.user.js b/4chan_x.user.js index 366ba7ded..7802df3d9 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -218,14 +218,21 @@ return d.removeEventListener('mouseup', ui.dragend, true); }, hover: function(e) { - var bot, clientX, clientY, el, height, top; + var bot, clientHeight, clientWidth, clientX, clientY, el, height, top, _ref; clientX = e.clientX, clientY = e.clientY; el = ui.el; + _ref = d.body, clientHeight = _ref.clientHeight, clientWidth = _ref.clientWidth; height = el.offsetHeight; top = clientY - 120; bot = top + height; - el.style.top = ui.winHeight < height || top < 0 ? '0px' : bot > ui.winHeight ? ui.winHeight - height + 'px' : top + 'px'; - return el.style.left = clientX + 45 + 'px'; + el.style.top = clientHeight < height || top < 0 ? '0px' : bot > clientHeight ? clientHeight - height + 'px' : top + 'px'; + if (clientX < clientWidth - 400) { + el.style.left = clientX + 45 + 'px'; + return el.style.right = ''; + } else { + el.style.left = ''; + return el.style.right = clientWidth - clientX + 45 + 'px'; + } }, hoverend: function(e) { ui.el.style.top = 'auto'; @@ -1904,7 +1911,6 @@ })); } ui.el = qp; - ui.winHeight = d.body.clientHeight; return $.show(qp); }, parse: function(req, id, threadID) { @@ -2189,7 +2195,6 @@ el.src = null; el.src = this.parentNode.href; ui.el = el; - ui.winHeight = d.body.clientHeight; return $.show(el); } } diff --git a/script.coffee b/script.coffee index 46aa1e257..33071e396 100644 --- a/script.coffee +++ b/script.coffee @@ -136,18 +136,26 @@ ui = hover: (e) -> {clientX, clientY} = e {el} = ui + {clientHeight, clientWidth} = d.body height = el.offsetHeight top = clientY - 120 bot = top + height el.style.top = - if ui.winHeight < height or top < 0 + if clientHeight < height or top < 0 '0px' - else if bot > ui.winHeight - ui.winHeight - height + 'px' + else if bot > clientHeight + clientHeight - height + 'px' else top + 'px' - el.style.left = clientX + 45 + 'px' + + if clientX < clientWidth - 400 + el.style.left = clientX + 45 + 'px' + el.style.right = '' + else + el.style.left = '' + el.style.right = clientWidth - clientX + 45 + 'px' + hoverend: (e) -> ui.el.style.top = 'auto' $.hide ui.el @@ -1494,7 +1502,6 @@ quotePreview = threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', @).id $.cache @pathname, (-> quotePreview.parse @, id, threadID) ui.el = qp - ui.winHeight = d.body.clientHeight $.show qp parse: (req, id, threadID) -> qp = $ '#qp' @@ -1674,7 +1681,6 @@ imageHover = el.src = null el.src = @parentNode.href ui.el = el - ui.winHeight = d.body.clientHeight $.show el imgPreloading =