diff --git a/app/assets/javascripts/drag.js b/app/assets/javascripts/drag.js index 0ebd534..9a1b605 100644 --- a/app/assets/javascripts/drag.js +++ b/app/assets/javascripts/drag.js @@ -1,7 +1,11 @@ $(document).on('turbolinks:load', function() { + var table = document.querySelector('.table-draggable'); + + if (table == null) return; + var were = $('.order.was').map(function() { return $(this).data('order') }); - tableDragger(document.querySelector('.table-draggable'), { + tableDragger(table, { mode: 'row', onlyBody: true, dragHandler: '.handle' @@ -9,7 +13,7 @@ $(document).on('turbolinks:load', function() { // Al soltar, reordenamos toda la tabla $('.post_order').val(function(i,v) { return were[i]; }); // Mostramos el nuevo orden tambiƩn - $('.order.is').text(function(i,v) { console.log(i, were[i]); return were[i]; }); + $('.order.is').text(function(i,v) { return were[i]; }); // Solo mostramos el valor anterior si no coincide con el valor // actual. Como lo mostramos entre comillas, usamos el atributo // data-order del