From 6b87f9c977dc7ed56946d80723cd8ef21b29a9b0 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 22 Feb 2013 22:52:13 +0100 Subject: [PATCH] Don't use closures for event callbacks. --- 4chan_x.user.js | 16 +++++++++------- src/features.coffee | 10 +++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 79b11f3b1..68e095be9 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2000,9 +2000,8 @@ innerHTML: "[ " + (type === 'hide' ? '-' : '+') + " ]", 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: "[ " + (type === 'hide' ? '-' : '+') + " ]", 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 { diff --git a/src/features.coffee b/src/features.coffee index fb8126163..9a8508f2e 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -953,7 +953,8 @@ ThreadHiding = className: "#{type}-thread-button" innerHTML: "[ #{if type is 'hide' then '-' else '+'} ]" 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: "[ #{if type is 'hide' then '-' else '+'} ]" 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