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

Use Hammer for touch ONLY, not mouse #1048

Open
BillyWM opened this issue Nov 18, 2016 · 4 comments
Open

Use Hammer for touch ONLY, not mouse #1048

BillyWM opened this issue Nov 18, 2016 · 4 comments

Comments

@BillyWM
Copy link

BillyWM commented Nov 18, 2016

I don't want Hammer doing anything with my mouse events. They're handled separately. No, I don't want to call preventDefault or stopPropagation() on them - I want it to get completely out of the way!

How do I set up hammer to do this?

Note I'm really not interested in writing an special handling to dance around Hammer (I included Hammer in the first place to get AWAY from kludge-y event juggling). It should just mind its own business and leave my mouse events alone, and there should be an option for this.

@BillyWM BillyWM changed the title Use Hammer for touch ONLY, not mouse delete Nov 18, 2016
@BillyWM BillyWM closed this as completed Nov 18, 2016
@BillyWM BillyWM changed the title delete Use Hammer for touch ONLY, not mouse Nov 18, 2016
@BillyWM BillyWM reopened this Nov 18, 2016
@ck86
Copy link

ck86 commented Nov 23, 2016

if ('ontouchstart' in window) {
  // do what ever you want with hammer?
}

@BillyWM
Copy link
Author

BillyWM commented Nov 25, 2016

Doesn't work.

You have a touchscreen laptop (now very common. Windows 10 is designed around it!). It can do both touch and click. Hammer is still interfering with clicks, making them do unwanted things. This doesn't solve the problem.

@jasco
Copy link

jasco commented Nov 29, 2016

What I found easiest was to ignore mouse events by checking the pointerType before processing within the Hammer event handler and allowing mouse events to propagate.

For example

function (event) {
    if (event.pointerType === 'touch') {
        // handle the touch event
    }
}

Edit: It looks like you may need to monitor issue #547. I have not noticed a problem but now I will look more closely.

@BillyWM
Copy link
Author

BillyWM commented Dec 5, 2016

Thanks. Yeah I ended up doing something like that (actually checking e.srcEvent instanceof MouseEvent - you'll find that 'MouseEvent' in window even on mobile. Correct me if I'm wrong, but this is the case on iOS and Android).

Still it would be make it clearer if this was part of the API, maybe initializing a recognizer with e.g.

new Hammer.Tap({
    event: "doubletap",
    taps: 2,
    pointerType: Hammer.POINTER_TOUCH
});

with the option to instead pass POINTER_MOUSE or POINTER_ALL, or whatever other pointers come along (POINTER_DUCK_HUNT_LIGHT_GUN?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants