FileList={ update:function(fileListHtml) { $('#fileList').empty().html(fileListHtml); }, addFile:function(name,size,lastModified){ var html=''; html+=''; html+=''+name+''; html+=''+size+''; html+=''+lastModified+''; html+=''; html+=''; FileList.insertElement(name,'file',$(html)); }, addDir:function(name,size,lastModified){ var html=''; html+=''; html+=''+name+''; html+=''+size+''; html+=''+lastModified+''; html+=''; html+=''; FileList.insertElement(name,'dir',$(html)); }, refresh:function(data) { result = jQuery.parseJSON(data.responseText); if(typeof(result.data.breadcrumb) != 'undefined'){ updateBreadcrumb(result.data.breadcrumb); } FileList.update(result.data.files); resetFileActionPanel(); }, remove:function(name){ $('tr[data-file="'+name+'"]').remove(); }, insertElement:function(name,type,element){ //find the correct spot to insert the file or folder var fileElements=$('tr[data-file][data-type="'+type+'"]'); var pos; if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){ pos=0; }else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){ pos=fileElements.length-1; }else{ for(var pos=1;pos0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){ break; } } } $(fileElements[pos]).after(element); } }