Last active
August 29, 2015 14:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jquery sortable for team / gallery priority ordering | |
$(function() { | |
var container = $('.sortable-container'); | |
//* user resorts list | |
container.sortable({ | |
update: function( event, ui ) { | |
update_via_ajax(); | |
} | |
}); | |
//* remove item from list | |
$(document).on('click', '.image .glyphicon-remove', function(e) { | |
$(this).parent().remove(); | |
update_via_ajax(); | |
}); | |
function update_via_ajax() { | |
//* get post IDs in new list order | |
var sortList = $('.ui-sortable-handle').map(function () { | |
return $(this).data('post-id'); | |
}) // reduce to low-level array | |
.get(); | |
//* ajax request to update ACF repeater field | |
$.ajax({ | |
type : "post", | |
datatype : 'json', | |
url : hipgive_ajax.ajaxurl, | |
data : ({ action: 'hipgive_ajax', ajax_method : 'sort_images', value: sortList }), | |
success: function(response) { | |
// update badge index - no baring on actual list order in back end | |
$('.badge').each(function(index) { | |
$(this).html(index+1); | |
}); | |
container.fadeTo( "fast", 1, function() { | |
// Animation complete | |
}); | |
}, | |
error: function(x, t, m) { | |
console.log( x, t, m); | |
} | |
}); // ajax request | |
// fade out container while ajax processes | |
container.fadeTo( "slow" , 0.3, function() { | |
// Animation complete. | |
}); | |
} // end udpate_via_ajax() | |
}); // sortable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment