app/assets/javascripts/binda/components/sortable.js in binda-0.1.0 vs app/assets/javascripts/binda/components/sortable.js in binda-0.1.1

- old
+ new

@@ -1,32 +1,37 @@ /** * SORTABLE */ + +var sortableOptions = { + stop: function(event, ui) + { + ui.item.css('z-index', 0) + }, + placeholder: "ui-state-highlight", + update: function () + { + if ( $('.popup-warning').length > 0 ) + { + $('.sortable').addClass('sortable--disabled') + $('.popup-warning').removeClass('popup-warning--hidden') + $(this).sortable('option','disabled', true) + } + let url = $(this).data('update-url') + let data = $(this).sortable('serialize') + // If there is a pagination update accordingly + data = data.concat(`&id=${$(this).attr('id')}`) + $.post( url, data ) + } + } + export default function() { if ( $('.sortable').length > 0 ) { // Initialize sortable item - $('.sortable') - .sortable({ - stop: function(event, ui){ - ui.item.css('z-index', 0) - }, - placeholder: "ui-state-highlight", - update: function () { - if ( $('.popup-warning').length > 0 ) { - $('.sortable').addClass('sortable--disabled') - $('.popup-warning').removeClass('popup-warning--hidden') - $(this).sortable('option','disabled', true) - } - let url = $(this).data('update-url') - let data = $(this).sortable('serialize') - // If there is a pagination update accordingly - data = data.concat(`&id=${$(this).attr('id')}`) - $.post( url, data ) - } - }) + $('.sortable').sortable( sortableOptions ) // Check if sortable item needs handles $('.sortable').each( function() { if ( $(this).find('.sortable--handle').length > 0 ) \ No newline at end of file