jquery-ui sortable | How to get it work on iPad/touchdevices?

IpadJquery UiScrollTouchJquery Ui-Sortable

Ipad Problem Overview


How do I get the jQuery-UI sortable feature working on iPad and other touch devices?

http://jqueryui.com/demos/sortable/

I tried to using event.preventDefault();, event.cancelBubble=true;, and event.stopPropagation(); with the touchmove and the scroll events, but the result was that the page does not scroll any longer.

Any ideas?

Ipad Solutions


Solution 1 - Ipad

Found a solution (only tested with iPad until now!)!

https://github.com/furf/jquery-ui-touch-punch

Solution 2 - Ipad

To make sortable work on mobile. Im using touch-punch like this:

$("#target").sortable({
  // option: 'value1',
  // otherOption: 'value2',
});

$("#target").disableSelection();

Take note of adding disableSelection(); after creating the sortable instance.

Solution 3 - Ipad

The solution provided by @eventhorizon works 100%. However, when you enable it on phones, you will get problems in scrolling in most cases, and in my case, my accordion stopped working since it went non-clickable. A workaround to solve it is to make the dragging initializable by an icon, for example, then make sortable use it to initialize the dragging like this:

$("#sortableDivId").sortable({
        handle: ".ui-icon"
});

where you pass the class name of what you'd like as an initializer.

Solution 4 - Ipad

Tom, I have added following code to mouseProto._touchStart event:

var time1Sec;
var ifProceed = false, timerStart = false;
mouseProto._touchStart = function (event) {

    var self = this;

    // Ignore the event if another widget is already being handled
    if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
        return;
    }

    if (!timerStart) {
        time1Sec = setTimeout(function () {
            ifProceed = true;
        }, 1000);
        timerStart=true;
    }
    if (ifProceed) {
        // Set the flag to prevent other widgets from inheriting the touch event
        touchHandled = true;

        // Track movement to determine if interaction was a click
        self._touchMoved = false;

        // Simulate the mouseover event
        simulateMouseEvent(event, 'mouseover');

        // Simulate the mousemove event
        simulateMouseEvent(event, 'mousemove');

        // Simulate the mousedown event
        simulateMouseEvent(event, 'mousedown');
        ifProceed = false;
         timerStart=false;
        clearTimeout(time1Sec);
    }
};

Solution 5 - Ipad

The link for the top-voted Answer is now broken.

To get jQuery UI Sortable working on mobile:

  1. Add this JavaScript file to your project.
  2. Reference that JS file on your page.

For more information, check out this link.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioneventhorizonView Question on Stackoverflow
Solution 1 - IpadeventhorizonView Answer on Stackoverflow
Solution 2 - IpadvpibanoView Answer on Stackoverflow
Solution 3 - IpadAbdulrazak ZakiehView Answer on Stackoverflow
Solution 4 - IpadKaran DubalView Answer on Stackoverflow
Solution 5 - IpadCardi DeMonaco JrView Answer on Stackoverflow