use bind/unbind

This commit is contained in:
James Campos 2011-03-27 17:09:47 -07:00
parent 03e8924634
commit 3d49dfe7cc
2 changed files with 54 additions and 54 deletions

View File

@ -520,7 +520,7 @@
_results = []; _results = [];
for (_i = 0, _len = thumbs.length; _i < _len; _i++) { for (_i = 0, _len = thumbs.length; _i < _len; _i++) {
thumb = thumbs[_i]; thumb = thumbs[_i];
_results.push(thumb.addEventListener('mouseover', imageHover.cb.mouseover, true)); _results.push($.bind(thumb, 'mouseover', imageHover.cb.mouseover));
} }
return _results; return _results;
}, },
@ -532,8 +532,8 @@
$.show(img); $.show(img);
imageHover.winHeight = d.body.clientHeight; imageHover.winHeight = d.body.clientHeight;
imageHover.winWidth = d.body.clientWidth; imageHover.winWidth = d.body.clientWidth;
target.addEventListener('mousemove', imageHover.cb.mousemove, true); $.bind(target, 'mousemove', imageHover.cb.mousemove);
return target.addEventListener('mouseout', imageHover.cb.mouseout, true); return $.bind(target, 'mouseout', imageHover.cb.mouseout);
}, },
mousemove: function(e) { mousemove: function(e) {
var bot, clientX, clientY, img, imgHeight, top; var bot, clientX, clientY, img, imgHeight, top;
@ -552,8 +552,8 @@
img = $('#iHover'); img = $('#iHover');
$.hide(img); $.hide(img);
img.src = null; img.src = null;
target.removeEventListener('mousemove', imageHover.cb.mousemove, true); $.unbind(target, 'mousemove', imageHover.cb.mousemove);
return target.removeEventListener('mouseout', imageHover.cb.mouseout, true); return $.unbind(target, 'mouseout', imageHover.cb.mouseout);
} }
} }
}; };
@ -905,11 +905,11 @@
_ref = $$('input[type="checkbox"]', div); _ref = $$('input[type="checkbox"]', div);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i]; input = _ref[_i];
input.addEventListener('change', changeCheckbox, true); $.bind(input, 'change', changeCheckbox);
} }
$('a.sauce', div).addEventListener('click', editSauce, true); $.bind($('a.sauce', div), 'click', editSauce);
$('textarea', div).addEventListener('change', changeValue, true); $.bind($('textarea', div), 'change', changeValue);
$('input[type="button"]', div).addEventListener('click', clearHidden, true); $.bind($('input[type="button"]', div), 'click', clearHidden);
return $.append(d.body, div); return $.append(d.body, div);
}; };
parseResponse = function(responseText) { parseResponse = function(responseText) {
@ -1449,7 +1449,7 @@
_ref = $$('input[type=checkbox]', div); _ref = $$('input[type=checkbox]', div);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
input = _ref[_i]; input = _ref[_i];
input.addEventListener('click', changeCheckbox, true); $.bind(input, 'click', changeCheckbox);
name = input.name; name = input.name;
if (name === 'autoL') { if (name === 'autoL') {
input.checked = GM_getValue('autoG', true); input.checked = GM_getValue('autoG', true);
@ -1458,10 +1458,10 @@
} }
switch (name) { switch (name) {
case 'autoL': case 'autoL':
input.addEventListener('click', updateAuto, true); $.bind(input, 'click', updateAuto);
break; break;
case 'verbose': case 'verbose':
input.addEventListener('click', updateVerbose, true); $.bind(input, 'click', updateVerbose);
} }
} }
if (!(g.verbose = GM_getValue('verbose', true))) { if (!(g.verbose = GM_getValue('verbose', true))) {
@ -1469,8 +1469,8 @@
} }
interval = $('input[name=interval]', div); interval = $('input[name=interval]', div);
interval.value = GM_getValue('Interval', 10); interval.value = GM_getValue('Interval', 10);
interval.addEventListener('change', updateInterval, true); $.bind(interval, 'change', updateInterval);
$('input[type=button]', div).addEventListener('click', updateNow, true); $.bind($('input[type=button]'), 'click', updateNow);
d.body.appendChild(div); d.body.appendChild(div);
if (GM_getValue('autoG')) { if (GM_getValue('autoG')) {
return updateAuto.call($("input[name=autoL]", div)); return updateAuto.call($("input[name=autoL]", div));
@ -1696,7 +1696,7 @@
el.tabIndex = 1; el.tabIndex = 1;
} }
recaptcha = $('#recaptcha_response_field'); recaptcha = $('#recaptcha_response_field');
recaptcha.addEventListener('keydown', recaptchaListener, true); $.bind(recaptcha, 'keydown', recaptchaListener);
scroll = function() { scroll = function() {
var bottom, height, i, reply, _len, _ref; var bottom, height, i, reply, _len, _ref;
height = d.body.clientHeight; height = d.body.clientHeight;
@ -1728,9 +1728,9 @@
break; break;
} }
} }
$("select", expand).addEventListener('change', changeValue, true); $.bind($('select', expand), 'change', changeValue);
$("select", expand).addEventListener('change', imageTypeChange, true); $.bind($('select', expand), 'change', imageTypeChange);
$("input", expand).addEventListener('click', imageExpandClick, true); $.bind($('input', expand), 'click', imageExpandClick);
$.before(delform.firstChild, expand); $.before(delform.firstChild, expand);
g.callbacks.push(function(root) { g.callbacks.push(function(root) {
var thumb, thumbs, _i, _len, _results; var thumb, thumbs, _i, _len, _results;
@ -1738,7 +1738,7 @@
_results = []; _results = [];
for (_i = 0, _len = thumbs.length; _i < _len; _i++) { for (_i = 0, _len = thumbs.length; _i < _len; _i++) {
thumb = thumbs[_i]; thumb = thumbs[_i];
thumb.parentNode.addEventListener('click', imageClick, true); $.bind(thumb.parentNode, 'click', imageClick);
_results.push(g.expand ? imageToggle(thumb.parentNode) : void 0); _results.push(g.expand ? imageToggle(thumb.parentNode) : void 0);
} }
return _results; return _results;
@ -1943,8 +1943,8 @@
}); });
} }
if ($.config('Keybinds')) { if ($.config('Keybinds')) {
d.addEventListener('keydown', keydown, true); $.bind(d, 'keydown', keydown);
d.addEventListener('keypress', keypress, true); $.bind(d, 'keypress', keypress);
} }
if (g.REPLY) { if (g.REPLY) {
if ($.config('Image Preloading')) { if ($.config('Image Preloading')) {
@ -1979,7 +1979,7 @@
if ($.config('Unread Count')) { if ($.config('Unread Count')) {
g.replies = []; g.replies = [];
d.title = '(0) ' + d.title; d.title = '(0) ' + d.title;
window.addEventListener('scroll', scroll, true); $.bind(window, 'scroll', scroll);
g.callbacks.push(function(root) { g.callbacks.push(function(root) {
g.replies = g.replies.concat($$('td.reply, td.replyhl', root)); g.replies = g.replies.concat($$('td.reply, td.replyhl', root));
return updateTitle(); return updateTitle();
@ -1992,12 +1992,12 @@
if ($.config('Image Expansion')) { if ($.config('Image Expansion')) {
start = start.nextSibling; start = start.nextSibling;
} }
d.addEventListener('DOMNodeInserted', stopPropagation, true); $.bind(d, 'DOMNodeInserted', stopPropagation);
threadF(start); threadF(start);
d.removeEventListener('DOMNodeInserted', stopPropagation, true); $.unbind(d, 'DOMNodeInserted', stopPropagation);
} }
if ($.config('Auto Watch')) { if ($.config('Auto Watch')) {
$('form[name="post"]').addEventListener('submit', autoWatch, true); $.bind($('form[name=post]'), 'submit', autoWatch);
} }
if ($.config('Thread Navigation')) { if ($.config('Thread Navigation')) {
arr = $$('div > span.filesize, form > span.filesize'); arr = $$('div > span.filesize, form > span.filesize');
@ -2058,7 +2058,7 @@
as = $$('span.abbr a'); as = $$('span.abbr a');
for (_m = 0, _len6 = as.length; _m < _len6; _m++) { for (_m = 0, _len6 = as.length; _m < _len6; _m++) {
a = as[_m]; a = as[_m];
a.addEventListener('click', expandComment, true); $.bind(a, 'click', expandComment);
} }
} }
} }
@ -2067,5 +2067,5 @@
callback = _ref4[_n]; callback = _ref4[_n];
callback(); callback();
} }
d.body.addEventListener('DOMNodeInserted', nodeInserted, true); $.bind(d.body, 'DOMNodeInserted', nodeInserted);
}).call(this); }).call(this);

View File

@ -356,7 +356,7 @@ imageHover =
node: (root) -> node: (root) ->
thumbs = $$ 'img[md5]', root thumbs = $$ 'img[md5]', root
for thumb in thumbs for thumb in thumbs
thumb.addEventListener 'mouseover', imageHover.cb.mouseover, true $.bind thumb, 'mouseover', imageHover.cb.mouseover
mouseover: (e) -> mouseover: (e) ->
{target, clientX, clientY} = e {target, clientX, clientY} = e
img = $ '#iHover' img = $ '#iHover'
@ -364,8 +364,8 @@ imageHover =
$.show img $.show img
imageHover.winHeight = d.body.clientHeight imageHover.winHeight = d.body.clientHeight
imageHover.winWidth = d.body.clientWidth imageHover.winWidth = d.body.clientWidth
target.addEventListener 'mousemove', imageHover.cb.mousemove, true $.bind target, 'mousemove', imageHover.cb.mousemove
target.addEventListener 'mouseout', imageHover.cb.mouseout, true $.bind target, 'mouseout', imageHover.cb.mouseout
mousemove: (e) -> mousemove: (e) ->
{clientX, clientY} = e {clientX, clientY} = e
img = $ '#iHover' img = $ '#iHover'
@ -387,8 +387,8 @@ imageHover =
img = $ '#iHover' img = $ '#iHover'
$.hide img $.hide img
img.src = null img.src = null
target.removeEventListener 'mousemove', imageHover.cb.mousemove, true $.unbind target, 'mousemove', imageHover.cb.mousemove
target.removeEventListener 'mouseout', imageHover.cb.mouseout, true $.unbind target, 'mouseout', imageHover.cb.mouseout
imageClick = (e) -> imageClick = (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey return if e.shiftKey or e.altKey or e.ctrlKey
@ -660,10 +660,10 @@ options = ->
div = ui.dialog 'options', 'center', html div = ui.dialog 'options', 'center', html
for input in $$ 'input[type="checkbox"]', div for input in $$ 'input[type="checkbox"]', div
input.addEventListener 'change', changeCheckbox, true $.bind input, 'change', changeCheckbox
$('a.sauce', div).addEventListener 'click', editSauce, true $.bind $('a.sauce', div), 'click', editSauce
$('textarea', div).addEventListener 'change', changeValue, true $.bind $('textarea', div), 'change', changeValue
$('input[type="button"]', div).addEventListener 'click', clearHidden, true $.bind $('input[type="button"]', div), 'click', clearHidden
$.append d.body, div $.append d.body, div
parseResponse = (responseText) -> parseResponse = (responseText) ->
@ -1093,7 +1093,7 @@ updaterMake = ->
div = ui.dialog 'updater', 'bottomright', html div = ui.dialog 'updater', 'bottomright', html
for input in $$ 'input[type=checkbox]', div for input in $$ 'input[type=checkbox]', div
input.addEventListener 'click', changeCheckbox, true $.bind input, 'click', changeCheckbox
name = input.name name = input.name
if name is 'autoL' if name is 'autoL'
input.checked = GM_getValue 'autoG', true input.checked = GM_getValue 'autoG', true
@ -1101,18 +1101,18 @@ updaterMake = ->
input.checked = GM_getValue name, true input.checked = GM_getValue name, true
switch name switch name
when 'autoL' when 'autoL'
input.addEventListener 'click', updateAuto, true $.bind input, 'click', updateAuto
when 'verbose' when 'verbose'
input.addEventListener 'click', updateVerbose, true $.bind input, 'click', updateVerbose
unless g.verbose = GM_getValue 'verbose', true unless g.verbose = GM_getValue 'verbose', true
$("#timer", div).hidden = true $("#timer", div).hidden = true
interval = $ 'input[name=interval]', div interval = $ 'input[name=interval]', div
interval.value = GM_getValue 'Interval', 10 interval.value = GM_getValue 'Interval', 10
interval.addEventListener 'change', updateInterval, true $.bind interval, 'change', updateInterval
$('input[type=button]', div).addEventListener 'click', updateNow, true $.bind $('input[type=button]'), 'click', updateNow
d.body.appendChild div d.body.appendChild div
@ -1328,7 +1328,7 @@ else
for el in $$ '#recaptcha_table a' for el in $$ '#recaptcha_table a'
el.tabIndex = 1 el.tabIndex = 1
recaptcha = $ '#recaptcha_response_field' recaptcha = $ '#recaptcha_response_field'
recaptcha.addEventListener('keydown', recaptchaListener, true) $.bind recaptcha, 'keydown', recaptchaListener
scroll = -> scroll = ->
height = d.body.clientHeight height = d.body.clientHeight
@ -1352,15 +1352,15 @@ if $.config 'Image Expansion'
if option.textContent is imageType if option.textContent is imageType
option.selected = true option.selected = true
break break
$("select", expand).addEventListener 'change', changeValue, true $.bind $('select', expand), 'change', changeValue
$("select", expand).addEventListener 'change', imageTypeChange, true $.bind $('select', expand), 'change', imageTypeChange
$("input", expand).addEventListener 'click', imageExpandClick, true $.bind $('input', expand), 'click', imageExpandClick
$.before delform.firstChild, expand $.before delform.firstChild, expand
g.callbacks.push (root) -> g.callbacks.push (root) ->
thumbs = $$ 'img[md5]', root thumbs = $$ 'img[md5]', root
for thumb in thumbs for thumb in thumbs
thumb.parentNode.addEventListener 'click', imageClick, true $.bind thumb.parentNode, 'click', imageClick
if g.expand then imageToggle thumb.parentNode if g.expand then imageToggle thumb.parentNode
if $.config 'Image Hover' if $.config 'Image Hover'
@ -1499,8 +1499,8 @@ if $.config 'Reply Navigation'
$.after el, span $.after el, span
if $.config 'Keybinds' if $.config 'Keybinds'
d.addEventListener 'keydown', keydown, true $.bind d, 'keydown', keydown
d.addEventListener 'keypress', keypress, true $.bind d, 'keypress', keypress
if g.REPLY if g.REPLY
if $.config 'Image Preloading' if $.config 'Image Preloading'
@ -1521,7 +1521,7 @@ if g.REPLY
if $.config 'Unread Count' if $.config 'Unread Count'
g.replies = [] g.replies = []
d.title = '(0) ' + d.title d.title = '(0) ' + d.title
window.addEventListener 'scroll', scroll, true $.bind window, 'scroll', scroll
g.callbacks.push (root) -> g.callbacks.push (root) ->
g.replies = g.replies.concat $$ 'td.reply, td.replyhl', root g.replies = g.replies.concat $$ 'td.reply, td.replyhl', root
updateTitle() updateTitle()
@ -1532,12 +1532,12 @@ else #not reply
start = $ 'form[name=delform] > *' start = $ 'form[name=delform] > *'
start = start.nextSibling if $.config 'Image Expansion' #skip over image expansion dialog start = start.nextSibling if $.config 'Image Expansion' #skip over image expansion dialog
#don't confuse other scripts #don't confuse other scripts
d.addEventListener('DOMNodeInserted', stopPropagation, true) $.bind d, 'DOMNodeInserted', stopPropagation
threadF start threadF start
d.removeEventListener('DOMNodeInserted', stopPropagation, true) $.unbind d, 'DOMNodeInserted', stopPropagation
if $.config 'Auto Watch' if $.config 'Auto Watch'
$('form[name="post"]').addEventListener('submit', autoWatch, true) $.bind $('form[name=post]'), 'submit', autoWatch
if $.config 'Thread Navigation' if $.config 'Thread Navigation'
arr = $$ 'div > span.filesize, form > span.filesize' arr = $$ 'div > span.filesize, form > span.filesize'
@ -1586,7 +1586,7 @@ else #not reply
if $.config 'Comment Expansion' if $.config 'Comment Expansion'
as = $$('span.abbr a') as = $$('span.abbr a')
for a in as for a in as
a.addEventListener('click', expandComment, true) $.bind a, 'click', expandComment
callback() for callback in g.callbacks callback() for callback in g.callbacks
d.body.addEventListener('DOMNodeInserted', nodeInserted, true) $.bind d.body, 'DOMNodeInserted', nodeInserted