fix sorting on newly inserted items in the file list

This commit is contained in:
Robin Appelman 2011-07-26 16:55:28 +02:00
parent 0e05a86484
commit 7b02adf715
1 changed files with 10 additions and 3 deletions

View File

@ -48,18 +48,25 @@ FileList={
var fileElements=$('tr[data-file][data-type="'+type+'"]'); var fileElements=$('tr[data-file][data-type="'+type+'"]');
var pos; var pos;
if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){ if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){
pos=0; pos=-1;
}else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){ }else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){
pos=fileElements.length-1; pos=fileElements.length-1;
}else{ }else{
for(var pos=1;pos<fileElements.length-1;pos++){ for(var pos=0;pos<fileElements.length-1;pos++){
if(name.localeCompare($(fileElements[pos]).attr('data-file'))>0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){ if(name.localeCompare($(fileElements[pos]).attr('data-file'))>0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){
break; break;
} }
} }
} }
alert(pos);
if(fileElements.length){ if(fileElements.length){
if(pos==-1){
$(fileElements[0]).before(element);
}else{
$(fileElements[pos]).after(element); $(fileElements[pos]).after(element);
}
}else if(type=='dir' && $('tr[data-file]').length>0){
$('tr[data-file]').first().before(element);
}else{ }else{
$('#fileList').append(element); $('#fileList').append(element);
} }