Don't use closures for event callbacks.

This commit is contained in:
Nicolas Stepien 2013-02-22 22:52:13 +01:00
parent 1bc2c17e41
commit 6b87f9c977
2 changed files with 16 additions and 10 deletions

View File

@ -2000,9 +2000,8 @@
innerHTML: "<span>[&nbsp;" + (type === 'hide' ? '-' : '+') + "&nbsp;]</span>",
href: 'javascript:;'
});
$.on(a, 'click', function() {
return ThreadHiding.toggle(thread);
});
a.setAttribute('data-fullid', thread.fullID);
$.on(a, 'click', ThreadHiding.toggle);
return a;
},
saveHiddenState: function(thread, makeStub) {
@ -2022,6 +2021,9 @@
return localStorage.setItem("4chan-hide-t-" + g.BOARD, JSON.stringify(hiddenThreadsCatalog));
},
toggle: function(thread) {
if (!(thread instanceof Thread)) {
thread = g.threads[this.dataset.fullid];
}
if (thread.isHidden) {
ThreadHiding.show(thread);
} else {
@ -2188,9 +2190,7 @@
innerHTML: "<span>[&nbsp;" + (type === 'hide' ? '-' : '+') + "&nbsp;]</span>",
href: 'javascript:;'
});
$.on(a, 'click', function() {
return ReplyHiding.toggle(post);
});
$.on(a, 'click', ReplyHiding.toggle);
return a;
},
saveHiddenState: function(post, isHiding, thisPost, makeStub, hideRecursively) {
@ -2214,7 +2214,9 @@
}
return $.set("hiddenPosts." + g.BOARD, hiddenPosts);
},
toggle: function(post) {
toggle: function() {
var post;
post = Get.postFromNode(this);
if (post.isHidden) {
ReplyHiding.show(post);
} else {

View File

@ -953,7 +953,8 @@ ThreadHiding =
className: "#{type}-thread-button"
innerHTML: "<span>[&nbsp;#{if type is 'hide' then '-' else '+'}&nbsp;]</span>"
href: 'javascript:;'
$.on a, 'click', -> ThreadHiding.toggle thread
a.setAttribute 'data-fullid', thread.fullID
$.on a, 'click', ThreadHiding.toggle
a
saveHiddenState: (thread, makeStub) ->
@ -970,6 +971,8 @@ ThreadHiding =
localStorage.setItem "4chan-hide-t-#{g.BOARD}", JSON.stringify hiddenThreadsCatalog
toggle: (thread) ->
unless thread instanceof Thread
thread = g.threads[@dataset.fullid]
if thread.isHidden
ThreadHiding.show thread
else
@ -1092,7 +1095,7 @@ ReplyHiding =
className: "#{type}-reply-button"
innerHTML: "<span>[&nbsp;#{if type is 'hide' then '-' else '+'}&nbsp;]</span>"
href: 'javascript:;'
$.on a, 'click', -> ReplyHiding.toggle post
$.on a, 'click', ReplyHiding.toggle
a
saveHiddenState: (post, isHiding, thisPost, makeStub, hideRecursively) ->
@ -1112,7 +1115,8 @@ ReplyHiding =
delete hiddenPosts.threads[post.thread]
$.set "hiddenPosts.#{g.BOARD}", hiddenPosts
toggle: (post) ->
toggle: ->
post = Get.postFromNode @
if post.isHidden
ReplyHiding.show post
else