From be8371d4c636b90f10ce9cda75caffd7411695ee Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 20 Dec 2013 04:14:53 +0100 Subject: [PATCH] Optimize Menu.makeButton(). --- src/Filtering/PostHiding.coffee | 2 +- src/Filtering/ThreadHiding.coffee | 2 +- src/Menu/Menu.coffee | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Filtering/PostHiding.coffee b/src/Filtering/PostHiding.coffee index 0c0d00660..122a7c8c4 100644 --- a/src/Filtering/PostHiding.coffee +++ b/src/Filtering/PostHiding.coffee @@ -168,7 +168,7 @@ PostHiding = className: 'stub' $.add post.nodes.stub, a if Conf['Menu'] - $.add post.nodes.stub, [$.tn(' '), Menu.makeButton()] + $.add post.nodes.stub, Menu.makeButton() $.prepend post.nodes.root, post.nodes.stub show: (post, showRecursively=Conf['Recursive Hiding']) -> diff --git a/src/Filtering/ThreadHiding.coffee b/src/Filtering/ThreadHiding.coffee index a5ecb82de..bc0068067 100644 --- a/src/Filtering/ThreadHiding.coffee +++ b/src/Filtering/ThreadHiding.coffee @@ -124,7 +124,7 @@ ThreadHiding = thread.stub = $.el 'div', className: 'stub' if Conf['Menu'] - $.add thread.stub, [a, $.tn(' '), Menu.makeButton()] + $.add thread.stub, [a, Menu.makeButton()] else $.add thread.stub, a $.prepend root, thread.stub diff --git a/src/Menu/Menu.coffee b/src/Menu/Menu.coffee index 4dd5e1eb3..23fb2ce91 100644 --- a/src/Menu/Menu.coffee +++ b/src/Menu/Menu.coffee @@ -9,22 +9,22 @@ Menu = node: -> if @isClone - button = $ '.menu-button', @nodes.info - $.on button, 'click', Menu.toggle + $.on $('.menu-button', @nodes.info), 'click', Menu.toggle return - button = Menu.makeButton() - $.add @nodes.info, [$.tn('\u00A0'), button] + $.add @nodes.info, Menu.makeButton() makeButton: do -> - a = null + frag = null -> - a or= $.el 'a', - className: 'menu-button' - innerHTML: '[]' - href: 'javascript:;' - button = a.cloneNode true - $.on button, 'click', Menu.toggle - button + unless frag + a = $.el 'a', + className: 'menu-button' + innerHTML: '[]' + href: 'javascript:;' + frag = $.nodes [$.tn(' '), a] + clone = frag.cloneNode true + $.on clone.lastElementChild, 'click', Menu.toggle + clone toggle: (e) -> try