Skip to content

Detecting Longpress #243

@ttseng

Description

@ttseng

I would like to enable draggable elements on my page on a longpress. I tried implementing this using mouseup and mousedown in javascript as follows:

  $('.stepNode').mouseup(function(){
              // console.log('clear timing');
              clearTimeout(pressTimer);
              $('.stepNode').draggable('disable');
              $('body').tap();
              return false;
            }).mousedown(function(){
                element = $(this);
              pressTimer = window.setTimeout(function(){
                // console.log('enabling dragging');
                makeCurrentStep(element);
                $('.stepNode').draggable('enable');
              }, 500);
              return false;
            });

You can check that this works on a desktop here: http://bip-android-test.herokuapp.com/projects/776/steps/mobile?auth_token=yC7dCCh8Lfkr8CxLfZ4Z&tree_width=2
The block that you long click on becomes highlighted in yellow after a short delay and becomes draggable.

But when I check it on mobile, the mousedown event doesn't seem to be registered on a long press.

Is there a way to implement long press using jquery-ui-touch-punch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions