From d48719ab1ce1df58440d5bfce9c3b162bbe2d076 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 10 Nov 2014 08:48:35 -0700 Subject: [PATCH] Ignore jQuery and duplicates in CommandRegistry::findCommands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that jQuery has been patched to add inline listeners and inline listeners are reported from findCommands, there’s no reason to include commands based on $.fn.events. Also, we need to ensure the same command doesn’t get added to the list twice since it could get added by both inline and selector-based listeners. --- src/command-registry.coffee | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/command-registry.coffee b/src/command-registry.coffee index 2ca5fd93d..fb9edbf3b 100644 --- a/src/command-registry.coffee +++ b/src/command-registry.coffee @@ -130,15 +130,18 @@ class CommandRegistry # * `jQuery` Present if the command was registered with the legacy # `$::command` method. findCommands: ({target}) -> + commandNames = new Set commands = [] currentTarget = target loop for commandName, listeners of @selectorBasedListenersByCommandName for listener in listeners if currentTarget.webkitMatchesSelector?(listener.selector) - commands.push - name: commandName - displayName: _.humanizeEventName(commandName) + unless commandNames.has(commandName) + commandNames.add(commandName) + commands.push + name: commandName + displayName: _.humanizeEventName(commandName) break if currentTarget is @rootNode currentTarget = currentTarget.parentNode @@ -146,13 +149,9 @@ class CommandRegistry for name, listeners of @inlineListenersByCommandName if listeners.has(target) - commands.push({name, displayName: _.humanizeEventName(name)}) - - for name, displayName of $(target).events() when displayName - commands.push({name, displayName, jQuery: true}) - - for name, displayName of $(window).events() when displayName - commands.push({name, displayName, jQuery: true}) + unless commandNames.has(name) + commandNames.add(name) + commands.push({name, displayName: _.humanizeEventName(name)}) commands