2

I'm trying to use jquery-ui sortable(), the function has has to work on both mobile devices and desktop computers.

sortable() works fine when I use the mouse button or the touch screen on my laptop but not in mobile devices.

The app is built using Ruby on rails. I added jQuery using a gem but 'jQuery UI' and 'jQuery UI Touch Punch' by copying the source files into app/assets/javascripts.

The application.js has following lines:

//= require jquery
//= require jquery-ui
//= require jquery.ui.touch-punch.min
//= require jquery_ujs
//= require_directory ./jquery_plugins
//= require bootstrap.min

In the source of the app, I can find the following lines:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.ui.touch-punch.min.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>

It seems like it does not matter if I remove jquery.ui.touch-punch.min.js (which I thought should solve this problem) from the source.

Any advice is appreciated :-)

bjarkig82
  • 558
  • 4
  • 13
  • Have you tried requiring touch punch last so anything that happens in `jquery_ujs` doesn't overwrite it? – Omni Jul 09 '14 at 00:46
  • Thanks for your reply, but that seemed to make no difference :-/ – bjarkig82 Jul 09 '14 at 10:32
  • What does your app-specific js file look like? For instance, if you are sorting projects, you should have a projects.js (or projects.js.coffee) file that looks like: jQuery -> $('#projects').sortable axis: 'y' update: -> $.post($(this).data('update-url'), $(this).sortable('serialize')) – Mark Jul 13 '14 at 04:02

1 Answers1

0

I prefer Touchpunch for the rails asset pipeline. Works perfect with android and ios devices.

Gemfile

gem 'touchpunch-rails'

application.js

//= require jquery.ui.touch-punch
Stef Hej
  • 1,367
  • 2
  • 14
  • 23