diff --git a/4chan_x.user.js b/4chan_x.user.js index d0593fb44..0ebf03c24 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -522,27 +522,23 @@ return localStorage.setItem("" + g.NAMESPACE + this.id + ".position", this.style.cssText); }; hoverstart = function(_arg) { - var asap, asapTest, cb, el, endEvents, event, initialEvent, o, root, _i, _len, _ref; - root = _arg.root, el = _arg.el, initialEvent = _arg.initialEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb; + var asap, asapTest, cb, el, endEvents, event, latestEvent, o, root, _i, _len, _ref; + root = _arg.root, el = _arg.el, latestEvent = _arg.latestEvent, endEvents = _arg.endEvents, asapTest = _arg.asapTest, cb = _arg.cb; o = { root: root, el: el, style: el.style, cb: cb, endEvents: endEvents.split(' '), - mousemove: function(e) { - return initialEvent = e; - }, + latestEvent: latestEvent, clientHeight: doc.clientHeight, clientWidth: doc.clientWidth }; o.hover = hover.bind(o); o.hoverend = hoverend.bind(o); - root.addEventListener('mousemove', o.mousemove, false); asap = function() { if (asapTest()) { - root.removeEventListener('mousemove', o.mousemove, false); - return o.hover(initialEvent); + return o.hover(o.latestEvent); } else { return o.timeout = setTimeout(asap, 25); } @@ -557,6 +553,7 @@ }; hover = function(e) { var clientX, clientY, height, left, right, style, top; + this.latestEvent = e; height = this.el.offsetHeight; clientX = e.clientX, clientY = e.clientY; top = clientY - 120; @@ -582,7 +579,6 @@ this.root.removeEventListener(event, this.hoverend, false); } this.root.removeEventListener('mousemove', this.hover, false); - this.root.removeEventListener('mousemove', this.mousemove, false); clearTimeout(this.timeout); if (this.cb) { return this.cb.call(this); @@ -2942,7 +2938,7 @@ UI.hover({ root: this, el: qp, - initialEvent: e, + latestEvent: e, endEvents: 'mouseout click', cb: QuotePreview.mouseout, asapTest: function() { @@ -3758,7 +3754,7 @@ UI.hover({ root: this, el: el, - initialEvent: e, + latestEvent: e, endEvents: 'mouseout click', asapTest: function() { return el.naturalHeight; diff --git a/lib/ui.coffee b/lib/ui.coffee index 0982f9e9a..5ebf1571e 100644 --- a/lib/ui.coffee +++ b/lib/ui.coffee @@ -286,26 +286,23 @@ UI = (-> d.removeEventListener 'mouseup', @up, false localStorage.setItem "#{g.NAMESPACE}#{@id}.position", @style.cssText - hoverstart = ({root, el, initialEvent, endEvents, asapTest, cb}) -> + hoverstart = ({root, el, latestEvent, endEvents, asapTest, cb}) -> o = { root: root el: el style: el.style cb: cb - endEvents: endEvents.split ' ' - mousemove: (e) -> initialEvent = e + endEvents: endEvents.split ' ' + latestEvent: latestEvent clientHeight: doc.clientHeight clientWidth: doc.clientWidth } o.hover = hover.bind o o.hoverend = hoverend.bind o - # Set position once content is loaded. - root.addEventListener 'mousemove', o.mousemove, false asap = -> if asapTest() - root.removeEventListener 'mousemove', o.mousemove, false - o.hover initialEvent + o.hover o.latestEvent else o.timeout = setTimeout asap, 25 asap() @@ -314,6 +311,7 @@ UI = (-> root.addEventListener event, o.hoverend, false root.addEventListener 'mousemove', o.hover, false hover = (e) -> + @latestEvent = e height = @el.offsetHeight {clientX, clientY} = e @@ -340,9 +338,8 @@ UI = (-> hoverend = -> @el.parentNode.removeChild @el for event in @endEvents - @root.removeEventListener event, @hoverend, false - @root.removeEventListener 'mousemove', @hover, false - @root.removeEventListener 'mousemove', @mousemove, false + @root.removeEventListener event, @hoverend, false + @root.removeEventListener 'mousemove', @hover, false clearTimeout @timeout @cb.call @ if @cb diff --git a/src/features.coffee b/src/features.coffee index 914ec0e19..eb51308e2 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -1768,7 +1768,7 @@ QuotePreview = UI.hover root: @ el: qp - initialEvent: e + latestEvent: e endEvents: 'mouseout click' cb: QuotePreview.mouseout asapTest: -> qp.firstElementChild @@ -2313,7 +2313,7 @@ ImageHover = UI.hover root: @ el: el - initialEvent: e + latestEvent: e endEvents: 'mouseout click' asapTest: -> el.naturalHeight $.on el, 'error', ImageHover.error