Skip to content

Commit

Permalink
added a rule to skip addEventListener hook only if element is used as…
Browse files Browse the repository at this point in the history
… a container to hold delegated events for children philc#1404
  • Loading branch information
Maxim Baz committed Jan 3, 2015
1 parent 29f0471 commit dacf625
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pages/addEventListener_hook.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ _addEventListener = Element::addEventListener
Element::addEventListener = (type, listener, useCapture) ->
if type == "click"
unless @hasAttribute "vimium-has-onclick-listener"
@setAttribute "vimium-has-onclick-listener", ""
skipCounter = 0
if @hasAttribute "vimium-skip-onclick-listener"
skipCounter = parseInt @getAttribute("vimium-skip-onclick-listener")

if skipCounter is 0
@setAttribute "vimium-has-onclick-listener", ""
else
@setAttribute "vimium-skip-onclick-listener", skipCounter - 1

_addEventListener.apply this, arguments

if window.event?
Expand Down
4 changes: 4 additions & 0 deletions pages/jQuery_delegatedEvents_hook.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Object.defineProperty window, "jQuery",
if selectors.indexOf("#{sep}#{selector}#{sep}") < 0
element.setAttribute attrKey, selectors + selector + sep

# jQuery will use addEventListener, but we don't want to hook this particular call.
skipCounter = parseInt element.getAttribute("vimium-skip-onclick-listener") || "0"
element.setAttribute "vimium-skip-onclick-listener", skipCounter + 1

return on_.apply @, arguments

return jQuery
Expand Down

0 comments on commit dacf625

Please sign in to comment.