Skip to content

Instantly share code, notes, and snippets.

@courtsimas
Created September 10, 2011 18:58
Show Gist options
  • Save courtsimas/1208648 to your computer and use it in GitHub Desktop.
Save courtsimas/1208648 to your computer and use it in GitHub Desktop.
a little sortable magic
$("ul#sidebar_whatever").sortable({
placeholder: "ui-state-highlight",
update: function(event, ui) { //this is where we'll do some updating crap
$("ul#sidebar_whatever").find('li.widget').each(function(){
var val = $(this).find('input.hidden_cool_input').val();// this val will be like "124,1"
var result = val.split(',');
var order = $("ul#sidebar_whatever li.widget").index($(this))//getting the order of the current element in the loop
result[1] = order; // we're reassigning the order
$(this).find('input.hidden_cool_input').val(result.toString());//we're putting the values back in, as "124,0" or "125,3" or whatever.
})
}
});
/*class ".ui-state-highlight" is a class that will highlight where you are supposed to drag the small widget.*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment