要素の元のインデックスを (たとえば を介してdata()
) 保存し、並べ替え後に保存されたインデックスと現在のインデックスを比較することができます (それらが等しくない場合、位置が変更されています)。その後、保存されたインデックスを更新します。
$( "#accordion" )
.accordion({
header: "> div > h3",
collapsible: true
})
.sortable({
axis: "y",
handle: "h3",
stop: function( event, ui ) {
var items=[];
ui.item.siblings().andSelf().each(function(){
//compare data('index') and the real index
if($(this).data('index')!=$(this).index()){
items.push(this.id);
}
});
// IE doesn't register the blur when sorting
// so trigger focusout handlers to remove .ui-state-focus
ui.item.children( "h3" ).triggerHandler( "focusout" );
if(items.length)alert(items.join(','));
ui.item.parent().trigger('stop');
}
}).on('stop',function(){
$(this).children().each(function(i){$(this).data('index',i)});
}).trigger('stop');
http://jsfiddle.net/DHCaA/2/