Revert "don't depend on mouseout. fixes #205"

This reverts commit b7601a2bd7ea12be17a433f0a0f003554bd60870.

Conflicts:

	4chan_x.user.js
	script.coffee
This commit is contained in:
Nicolas Stepien 2011-07-31 19:18:06 +02:00
parent 040cf69ec1
commit e994b8144c
2 changed files with 22 additions and 52 deletions

View File

@ -262,27 +262,14 @@
el.style.top = clientHeight < height || top < 0 ? 0 : top + height > clientHeight ? clientHeight - height : top; el.style.top = clientHeight < height || top < 0 ? 0 : top + height > clientHeight ? clientHeight - height : top;
if (clientX < clientWidth - 400) { if (clientX < clientWidth - 400) {
el.style.left = clientX + 45; el.style.left = clientX + 45;
el.style.right = null; return el.style.right = null;
} else { } else {
el.style.left = null; el.style.left = null;
el.style.right = clientWidth - clientX + 45; return el.style.right = clientWidth - clientX + 45;
} }
/*
https://bugzilla.mozilla.org/show_bug.cgi?id=674955
`mouseout` does not fire when element removed
RESOLVED INVALID
god damn it mozzarella. when an element is removed (eg from un-inlining),
the `mouseout` event doesn't fire. we can't depend on `mouseout`, so we
simulate it by binding `mousemove` to the element and to the document. the
element binding stops the event from propogating; if the mouse has moved
off of the element, the event is not stopped, and mouseout happens.
*/
return e.stopPropagation();
}, },
hoverend: function(e) { hoverend: function(e) {
ui.el.parentNode.removeChild(ui.el); return ui.el.parentNode.removeChild(ui.el);
return d.removeEventListener('mousemove', ui.hoverend, false);
} }
}; };
/* /*
@ -2017,6 +2004,8 @@
}); });
if (conf['Quote Preview']) { if (conf['Quote Preview']) {
$.bind(link, 'mouseover', quotePreview.mouseover); $.bind(link, 'mouseover', quotePreview.mouseover);
$.bind(link, 'mousemove', ui.hover);
$.bind(link, 'mouseout', quotePreview.mouseout);
} }
if (conf['Quote Inline']) { if (conf['Quote Inline']) {
$.bind(link, 'click', quoteInline.toggle); $.bind(link, 'click', quoteInline.toggle);
@ -2149,15 +2138,15 @@
if (!quote.hash) { if (!quote.hash) {
continue; continue;
} }
_results.push($.bind(quote, 'mouseover', quotePreview.mouseover)); $.bind(quote, 'mouseover', quotePreview.mouseover);
$.bind(quote, 'mousemove', ui.hover);
_results.push($.bind(quote, 'mouseout', quotePreview.mouseout));
} }
return _results; return _results;
}); });
}, },
mouseover: function(e) { mouseover: function(e) {
var el, id, qp, quote, replyID, threadID, _i, _len, _ref, _results; var el, id, qp, quote, replyID, threadID, _i, _len, _ref, _results;
$.bind(this, 'mousemove', ui.hover);
$.bind(d, 'mousemove', quotePreview.mouseout);
qp = ui.el = $.el('div', { qp = ui.el = $.el('div', {
id: 'qp', id: 'qp',
className: 'replyhl' className: 'replyhl'
@ -2168,7 +2157,6 @@
qp.innerHTML = el.innerHTML; qp.innerHTML = el.innerHTML;
if (conf['Quote Highlighting']) { if (conf['Quote Highlighting']) {
$.addClass(el, 'qphl'); $.addClass(el, 'qphl');
quotePreview.hl = el;
} }
if (/backlink/.test(this.className)) { if (/backlink/.test(this.className)) {
replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0]; replyID = $.x('ancestor::*[@id][1]', this).id.match(/\d+/)[0];
@ -2189,12 +2177,10 @@
} }
}, },
mouseout: function() { mouseout: function() {
var hl; var el;
hl = quotePreview.hl; if (el = d.getElementById(this.hash.slice(1))) {
if (hl) { $.removeClass(el, 'qphl');
$.removeClass(hl, 'qphl');
} }
$.unbind(d, 'mousemove', quotePreview.mouseout);
return ui.hoverend(); return ui.hoverend();
}, },
parse: function(req, id, threadID) { parse: function(req, id, threadID) {
@ -2466,12 +2452,12 @@
if (!(thumb = $('img[md5]', root))) { if (!(thumb = $('img[md5]', root))) {
return; return;
} }
return $.bind(thumb, 'mouseover', imgHover.mouseover); $.bind(thumb, 'mouseover', imgHover.mouseover);
$.bind(thumb, 'mousemove', ui.hover);
return $.bind(thumb, 'mouseout', ui.hoverend);
}); });
}, },
mouseover: function(e) { mouseover: function(e) {
$.bind(this, 'mousemove', ui.hover);
$.bind(d, 'mousemove', ui.hoverend);
ui.el = $.el('img', { ui.el = $.el('img', {
id: 'iHover', id: 'iHover',
src: this.parentNode.href src: this.parentNode.href

View File

@ -183,22 +183,8 @@ ui =
el.style.left = null el.style.left = null
el.style.right = clientWidth - clientX + 45 el.style.right = clientWidth - clientX + 45
###
https://bugzilla.mozilla.org/show_bug.cgi?id=674955
`mouseout` does not fire when element removed
RESOLVED INVALID
god damn it mozzarella. when an element is removed (eg from un-inlining),
the `mouseout` event doesn't fire. we can't depend on `mouseout`, so we
simulate it by binding `mousemove` to the element and to the document. the
element binding stops the event from propogating; if the mouse has moved
off of the element, the event is not stopped, and mouseout happens.
###
e.stopPropagation()
hoverend: (e) -> hoverend: (e) ->
ui.el.parentNode.removeChild ui.el ui.el.parentNode.removeChild ui.el
d.removeEventListener 'mousemove', ui.hoverend, false
### ###
loosely follows the jquery api: loosely follows the jquery api:
@ -1582,6 +1568,8 @@ quoteBacklink =
textContent: ">>#{id}" textContent: ">>#{id}"
if conf['Quote Preview'] if conf['Quote Preview']
$.bind link, 'mouseover', quotePreview.mouseover $.bind link, 'mouseover', quotePreview.mouseover
$.bind link, 'mousemove', ui.hover
$.bind link, 'mouseout', quotePreview.mouseout
if conf['Quote Inline'] if conf['Quote Inline']
$.bind link, 'click', quoteInline.toggle $.bind link, 'click', quoteInline.toggle
unless container = $ '.container', el unless container = $ '.container', el
@ -1661,9 +1649,9 @@ quotePreview =
for quote in $$ 'a.quotelink, a.backlink', root for quote in $$ 'a.quotelink, a.backlink', root
continue unless quote.hash continue unless quote.hash
$.bind quote, 'mouseover', quotePreview.mouseover $.bind quote, 'mouseover', quotePreview.mouseover
$.bind quote, 'mousemove', ui.hover
$.bind quote, 'mouseout', quotePreview.mouseout
mouseover: (e) -> mouseover: (e) ->
$.bind @, 'mousemove', ui.hover
$.bind d, 'mousemove', quotePreview.mouseout
qp = ui.el = $.el 'div', qp = ui.el = $.el 'div',
id: 'qp' id: 'qp'
className: 'replyhl' className: 'replyhl'
@ -1672,9 +1660,7 @@ quotePreview =
id = @hash[1..] id = @hash[1..]
if el = d.getElementById id if el = d.getElementById id
qp.innerHTML = el.innerHTML qp.innerHTML = el.innerHTML
if conf['Quote Highlighting'] $.addClass el, 'qphl' if conf['Quote Highlighting']
$.addClass el, 'qphl'
quotePreview.hl = el
if /backlink/.test @className if /backlink/.test @className
replyID = $.x('ancestor::*[@id][1]', @).id.match(/\d+/)[0] replyID = $.x('ancestor::*[@id][1]', @).id.match(/\d+/)[0]
for quote in $$ 'a.quotelink', qp for quote in $$ 'a.quotelink', qp
@ -1685,9 +1671,7 @@ quotePreview =
threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', @).id threadID = @pathname.split('/').pop() or $.x('ancestor::div[@class="thread"]/div', @).id
$.cache @pathname, (-> quotePreview.parse @, id, threadID) $.cache @pathname, (-> quotePreview.parse @, id, threadID)
mouseout: -> mouseout: ->
{hl} = quotePreview $.removeClass el, 'qphl' if el = d.getElementById @hash[1..]
$.removeClass hl, 'qphl' if hl
$.unbind d, 'mousemove', quotePreview.mouseout
ui.hoverend() ui.hoverend()
parse: (req, id, threadID) -> parse: (req, id, threadID) ->
return unless (qp = ui.el) and (qp.innerHTML is "Loading #{id}...") return unless (qp = ui.el) and (qp.innerHTML is "Loading #{id}...")
@ -1857,9 +1841,9 @@ imgHover =
g.callbacks.push (root) -> g.callbacks.push (root) ->
return unless thumb = $ 'img[md5]', root return unless thumb = $ 'img[md5]', root
$.bind thumb, 'mouseover', imgHover.mouseover $.bind thumb, 'mouseover', imgHover.mouseover
$.bind thumb, 'mousemove', ui.hover
$.bind thumb, 'mouseout', ui.hoverend
mouseover: (e) -> mouseover: (e) ->
$.bind @, 'mousemove', ui.hover
$.bind d, 'mousemove', ui.hoverend
ui.el = $.el 'img' ui.el = $.el 'img'
id: 'iHover' id: 'iHover'
src: @parentNode.href src: @parentNode.href