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

Add support for long press - a delay before _touchStart handles click event #290

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jayagl
Copy link

@jayagl jayagl commented Aug 24, 2017

I've changed _touchStart to only handle a touch event if touch is held for the number of milliseconds specified by the global property touchPunchDelay. The property is optional and behaviour is as before if it's not specified. This is essential if using touch-punch for enabling drag and drop on touch devices and avoiding accidental dragging on scroll.

Jay Agrawal added 3 commits August 24, 2017 10:14
_touchStart function now only _handles_ touch events if touch was held for the number of ms specified by window.touchPunchDelay. If undefined behaviour is as before.
@jayagl jayagl mentioned this pull request Aug 24, 2017
@jayagl jayagl changed the title Add support for _long press_, i.e. a delay before _touchStart handles click event Add support for long press - a delay before _touchStart handles click event Aug 24, 2017
@powerpaul17
Copy link

As this is a very useful (and in my opinion a must-have) feature, I want to ask if/when this is going to be merged?

@ndbroadbent
Copy link

ndbroadbent commented Jul 28, 2018

Awesome, thanks @jayagl! This is a good start but there's still some issues. I noticed that scrolling is still stopped after the delay. I'm using jquery UI sortable, and if the touch starts on a sortable element, i can scroll the page until the mouse event fires after touchPunchDelay. Then the page stops scrolling. For my case, I need to cancel the even if the user starts scrolling immediately. And only fire the event if they haven't moved their finger for touchPunchDelay ms.

Also for anyone else who finds this issue, you need to disable the iOS "callout" that pops up when you long press an image, and you can do that with this CSS:

img.sortable-image {
   -webkit-touch-callout: none;
}

EDIT: I think it's a problem with the way you're using this in your code. The handler functions don't always have access to the same this, so self._touchMoved isn't working as expected. You should be using a variable that is declared with the other vars in var mouseProto = ....

EDIT 2: Ohhh, this is also breaking inside nested jquery UI sortable widgets. The second touch event isn't handled so it breaks scrolling. Maybe needs a counter somewhere instead of a boolean flag.

@wallyhall
Copy link

A small app I'm involved with just got an alpha quality demo shown to a few users, they all naturally wanted to long-press on mobile to drag. I'm absolutely +1'ing this feature!

@frmeran
Copy link

frmeran commented Mar 10, 2021

// Ignore multi-touch events
if (event.originalEvent.touches.length > 1) {
    return;
}

if(event.cancelable) {
    event.preventDefault();
}

this fix it

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

Successfully merging this pull request may close these issues.

5 participants