Skip to content
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

Problem with preventing click event #42

Closed
madmaniak opened this issue Jan 14, 2016 · 5 comments
Closed

Problem with preventing click event #42

madmaniak opened this issue Jan 14, 2016 · 5 comments
Labels
Milestone

Comments

@madmaniak
Copy link
Member

I have such definition in layout:

        def ontap
                Dispatcher.trigger "cancel"

And it prevents me from using native <a> tag. Browser is not reacting after click.
I'm not calling e.halt or e.cancel so I expect none event will be blocked by above definition.

I think it happens here:

        Imba.Events.register('click',function(e) {
            // Only for main mousebutton, no?
            if ((e.timeStamp - lastNativeTouchTimeStamp) > lastNativeTouchTimeout) {
                var tap = new Imba.Event(e);
                tap.setType('tap');
                tap.process();
                if (tap._responder) {
                    return e.preventDefault(); // <---- HERE!
                };
            };
            // delegate the real click event
            return Imba.Events.delegate(e);
        });
@somebee
Copy link
Member

somebee commented Jan 14, 2016

You found the right place, thanks for digging into it yourself :)

ontap is a special case because it unifies touches (mobile etc) and mouse. If you use onclick instead it should work as expected. We should add a clean method for letting the tap through, but right now it will cancel the native click if any tags respond to the event with ontap. This is a hack, but you can work around it by doing:

def ontap e
    e.@responder = null
    Dispatcher.trigger "cancel"

@madmaniak
Copy link
Member Author

OK this hack works 👍

@madmaniak madmaniak reopened this Jan 14, 2016
@madmaniak
Copy link
Member Author

But the order matters and it should be:

def ontap e
    Dispatcher.trigger "cancel"
    e.@responder = null

@somebee
Copy link
Member

somebee commented Jan 14, 2016

What is this Dispatcher? Seems strange that is should matter since the code that checks for e.@responder is synchronously following ontap.

@madmaniak
Copy link
Member Author

Dispatcher is Backbone:Events.

@somebee somebee added the bug label Jan 14, 2016
@somebee somebee added this to the 0.15.0 milestone Feb 23, 2016
@somebee somebee closed this as completed Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants