New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested delegate elements cause swipe event duplication #5311

Closed
nathanathan opened this Issue Nov 20, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@nathanathan

nathanathan commented Nov 20, 2012

Here's a jsfiddle the reproduces the problem:
http://jsfiddle.net/NMDxE/24/
If you swipe on the red square, the delegate functions will both fire twice. If you change them to use another type of event, for example a click event, they only fire once.

This can cause major problems with swiping in nested Backbone.js views.

I posted this issue on the jQuery forums a couple weeks ago as well but I'm not sure if anyone noticed and has plans to fix it:
http://forum.jquery.com/topic/swipe-events-fire-twice-on-nested-delegator-elements

I also posted the issue to the jQuery issue tracker but they seem to think it's more likely a jQm problem:
http://bugs.jquery.com/ticket/12864

@arschmitz

This comment has been minimized.

Show comment
Hide comment
@arschmitz

arschmitz Nov 21, 2012

Member

This is because the event is bubbling up through both divs you have delegated to. this DOES happen with click as well as you can see here http://jsfiddle.net/NMDxE/27/ also note it is not possible to stop propagation on delegated events as noted here http://api.jquery.com/event.stopImmediatePropagation/#notes-0
Update: @nathanathan sorry i misread your issue the first time i see your issue now and it does seem to be related to our custom swipe event. im looking at this now

Member

arschmitz commented Nov 21, 2012

This is because the event is bubbling up through both divs you have delegated to. this DOES happen with click as well as you can see here http://jsfiddle.net/NMDxE/27/ also note it is not possible to stop propagation on delegated events as noted here http://api.jquery.com/event.stopImmediatePropagation/#notes-0
Update: @nathanathan sorry i misread your issue the first time i see your issue now and it does seem to be related to our custom swipe event. im looking at this now

@jaspermdegroot

This comment has been minimized.

Show comment
Hide comment
@jaspermdegroot

jaspermdegroot Nov 21, 2012

Member

This fiddle shows how to make this work: http://jsfiddle.net/NMDxE/30/

Member

jaspermdegroot commented Nov 21, 2012

This fiddle shows how to make this work: http://jsfiddle.net/NMDxE/30/

@arschmitz

This comment has been minimized.

Show comment
Hide comment
@arschmitz

arschmitz Nov 21, 2012

Member

@nathanathan The reason this happens in your original fiddles is because the swipe events are not triggered on a specific element and bubble like most events they are triggered on a set of coordinates therefore when you have overlapping elements like this it can cause them to be triggered multiple times. to achieve your desired effect use @uGoMobi solution above.

Member

arschmitz commented Nov 21, 2012

@nathanathan The reason this happens in your original fiddles is because the swipe events are not triggered on a specific element and bubble like most events they are triggered on a set of coordinates therefore when you have overlapping elements like this it can cause them to be triggered multiple times. to achieve your desired effect use @uGoMobi solution above.

@nathanathan

This comment has been minimized.

Show comment
Hide comment
@nathanathan

nathanathan Nov 21, 2012

I'm hoping there is another solution. I want to be able to attach swipe events on nested Backbone views and uGoMobi's solution requires rewriting Backbone's delegateEvents function in a way that might have some side effects.

nathanathan commented Nov 21, 2012

I'm hoping there is another solution. I want to be able to attach swipe events on nested Backbone views and uGoMobi's solution requires rewriting Backbone's delegateEvents function in a way that might have some side effects.

@ghost ghost assigned arschmitz Dec 5, 2012

arschmitz added a commit that referenced this issue May 8, 2013

Swipe: change to use triggerCustomEvent Fixes #5311 - Nested delegate…
… elements cause swipe event duplication
@arschmitz

This comment has been minimized.

Show comment
Hide comment
@arschmitz

arschmitz May 8, 2013

Member

this is fixed by commit 3367ec5

Member

arschmitz commented May 8, 2013

this is fixed by commit 3367ec5

@arschmitz arschmitz closed this May 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment