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

How to trigger drag after a delay - on touch and hold for x ms? #182

Closed
kennethlynne opened this issue Aug 27, 2015 · 5 comments
Closed
Labels

Comments

@kennethlynne
Copy link

I need to be able to disable drag and only enable it when the user holds an item for x ms. What is the best way to achieve this?

@kennethlynne
Copy link
Author

The proposed solution on bevacqua/angularjs-dragula#15:

var heldForThreeSeconds = 3000
var itemWasClicked
document.body.addEventListener('mousedown', function () {
  itemWasClicked = new Date()
})
dragula({
  moves: function () {
    return new Date() - itemWasClicked > heldForThreeSeconds
  }
}

does not work, as the moves callback is only called initially.

@bevacqua
Copy link
Owner

bevacqua commented Oct 5, 2015

Added an API endpoint lift that resolves your UC, but you'll need to do some work on your end. The below piece of code is very rough but it does work.

var drake = dragula(containers, {
  moves: function () {
    if (lifted) {
      lifted = false;
      return true;
    }
  }
});
document.body.addEventListener('mousedown', function (e) {
  setTimeout(function () {
    lifted = true;
    drake.lift(e.target);
  }, 3000)
})
  • drake.lift still checks if the item moves(), so you'll need to work around that
  • drake.lift won't work if an element is already being dragged, so you'll have to end drags before calling lift.

@bevacqua
Copy link
Owner

bevacqua commented Oct 5, 2015

@kennethlynne please give the PR branch a try and let me know whether it works as you'd expect.

@kennethlynne
Copy link
Author

Awesome, thanks! It is on my todo, I will probably not look into it before next week. We worked our way around the problem, but this will be a nice improvement.

@bevacqua
Copy link
Owner

bevacqua commented Nov 3, 2015

Use Slack for support requests. See #248.

@bevacqua bevacqua closed this as completed Nov 3, 2015
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