<commit_before>$(document).ready(function() {
	if($('tr[data-file]').length==0){
		$('.file_upload_filename').addClass('highlight');
	}
	
	$('#file_action_panel').attr('activeAction', false);

	//drag/drop of files
	$('#fileList tr td.filename').draggable(dragOptions);
	$('#fileList tr[data-type="dir"] td.filename').droppable(folderDropOptions);
	$('div.crumb').droppable(crumbDropOptions);
	$('#plugins>ul>li:first-child').data('dir','');
	$('#plugins>ul>li:first-child').droppable(crumbDropOptions);
	
	// Sets the file-action buttons behaviour :
	$('tr').live('mouseenter',function(event) {
		FileActions.display($(this).children('td.filename'));
	});
	$('tr').live('mouseleave',function(event) {
		FileActions.hide();
	});

	// Sets the file link behaviour :
	$('td.filename a').live('click',function(event) {
		event.preventDefault();
		var filename=$(this).parent().parent().data('file');
		if(!FileList.isLoading(filename)){
			var mime=$(this).parent().parent().data('mime');
			var type=$(this).parent().parent().data('type');
			var action=FileActions.getDefault(mime,type);
			if(action){
				action(filename);
			}
		}
	});
	
	// Sets the select_all checkbox behaviour :
	$('#select_all').click(function() {
		if($(this).attr('checked')){
			// Check all
			$('td.filename input:checkbox').attr('checked', true);
			$('td.filename input:checkbox').parent().parent().addClass('selected');
		}else{
			// Uncheck all
			$('td.filename input:checkbox').attr('checked', false);
			$('td.filename input:checkbox').parent().parent().removeClass('selected');
		}
		procesSelection();
	});
	
	$('td.filename input:checkbox').live('click',function() {
		var selectedCount=$('td.filename input:checkbox:checked').length;
		$(this).parent().parent().toggleClass('selected');
		if(!$(this).attr('checked')){
			$('#select_all').attr('checked',false);
		}else{
			if(selectedCount==$('td.filename input:checkbox').length){
				$('#select_all').attr('checked',true);
			}
		}
		procesSelection();
	});
	
	$('#file_newfolder_form').submit(function(event) {
		event.preventDefault();
		$.ajax({
			url: 'ajax/newfolder.php',
			data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(),
			complete: function(data){boolOperationFinished(data, function(){
				var date=new Date();
				FileList.addDir($('#file_newfolder_name').val(),0,date);
				$('#file_newfolder_name').val('New Folder');
				$('#file_newfolder_name').blur();
			});}
		});
		$('#emptyfolder').remove();
	});
	
	$('#file_newfolder_name').click(function(){
		if($('#file_newfolder_name').val() == 'New Folder'){
			$('#file_newfolder_name').val('');
		}
	});
	
	$('.download').click('click',function(event) {
		var files=getSelectedFiles('name').join(';');
		
		//send the browser to the download location
		var dir=$('#dir').val()||'/';
// 		alert(files);
		window.location='ajax/download.php?files='+encodeURIComponent(files)+'&dir='+encodeURIComponent(dir);
		return false;
	});
	
	$('.delete').click(function(event) {
		var fileNames=getSelectedFiles('name');
		var files=fileNames.join(';');
		var lastFileName=fileNames.pop();
		if(fileNames.length>0){
			fileNames=fileNames.join(', ')+' and '+lastFileName;
		}else{
			fileNames=lastFileName;
		}

		$( "#delete-confirm" ).dialog({
			resizable: false,
			height:200,
			modal: true,
			title:"Delete "+fileNames,
			buttons: {
				"Delete": function() {
					$( this ).dialog( "close" );
					$.ajax({
						url: 'ajax/delete.php',
						data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files),
						complete: function(data){
							boolOperationFinished(data, function(){
								var files=getSelectedFiles('name');
							for(var i=0;i<files.length;i++){
								FileList.remove(files[i]);
							}
							procesSelection();
							});
						}
					});
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		
		return false;
	});

	$('.file_upload_start').live('change',function(){
		var form=$(this).parent().parent();
		var uploadId=form.attr('data-upload-id');
		var files=this.files;
		var target=form.children('iframe');
		var totalSize=0;
		for(var i=0;i<files.length;i++){
			totalSize+=files[i].size;
		}
		if(totalSize>$('#max_upload').val()){
			$( "#uploadsize-message" ).dialog({
				modal: true,
				buttons: {
					Close: function() {
						$( this ).dialog( "close" );
					}
				}
			});
		}else{
			target.load(function(){
				var response=jQuery.parseJSON(target.contents().find('body').text());
				//set mimetype and if needed filesize
				if(response){
					for(var i=0;i<response.length;i++){
						var file=response[i];
						$('tr[data-file="'+file.name+'"]').data('mime',file.mime);
						if(size=='Pending'){
							$('tr[data-file='+file.name+'] td.filesize').text(file.size);
						}
						FileList.loadingDone(file.name);
					}
				}
			});
			form.submit();
			var date=new Date();
			for(var i=0;i<files.length;i++){
				if(files[i].size>0){
					var size=files[i].size;
				}else{
					var size='Pending';
				}
				FileList.addFile(files[i].name,size,date,true);
			}

			//clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading
			var clone=form.clone();
			uploadId++;
			clone.attr('data-upload-id',uploadId);
			clone.attr('target','file_upload_target_'+uploadId);
			clone.children('iframe').attr('name','file_upload_target_'+uploadId)
			clone.insertBefore(form);
			form.hide();
		}
		$('#emptyfolder').remove();
	});
	
	//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
	if(navigator.userAgent.search(/konqueror/i)==-1){
		$('.file_upload_start').attr('multiple','multiple')
	}

	//if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder
	var crumb=$('div.crumb').first();
	while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){<commit_msg>dont need to remove the empty folder message twice<commit_after>$(document).ready(function() {
	if($('tr[data-file]').length==0){
		$('.file_upload_filename').addClass('highlight');
	}
	
	$('#file_action_panel').attr('activeAction', false);

	//drag/drop of files
	$('#fileList tr td.filename').draggable(dragOptions);
	$('#fileList tr[data-type="dir"] td.filename').droppable(folderDropOptions);
	$('div.crumb').droppable(crumbDropOptions);
	$('#plugins>ul>li:first-child').data('dir','');
	$('#plugins>ul>li:first-child').droppable(crumbDropOptions);
	
	// Sets the file-action buttons behaviour :
	$('tr').live('mouseenter',function(event) {
		FileActions.display($(this).children('td.filename'));
	});
	$('tr').live('mouseleave',function(event) {
		FileActions.hide();
	});

	// Sets the file link behaviour :
	$('td.filename a').live('click',function(event) {
		event.preventDefault();
		var filename=$(this).parent().parent().data('file');
		if(!FileList.isLoading(filename)){
			var mime=$(this).parent().parent().data('mime');
			var type=$(this).parent().parent().data('type');
			var action=FileActions.getDefault(mime,type);
			if(action){
				action(filename);
			}
		}
	});
	
	// Sets the select_all checkbox behaviour :
	$('#select_all').click(function() {
		if($(this).attr('checked')){
			// Check all
			$('td.filename input:checkbox').attr('checked', true);
			$('td.filename input:checkbox').parent().parent().addClass('selected');
		}else{
			// Uncheck all
			$('td.filename input:checkbox').attr('checked', false);
			$('td.filename input:checkbox').parent().parent().removeClass('selected');
		}
		procesSelection();
	});
	
	$('td.filename input:checkbox').live('click',function() {
		var selectedCount=$('td.filename input:checkbox:checked').length;
		$(this).parent().parent().toggleClass('selected');
		if(!$(this).attr('checked')){
			$('#select_all').attr('checked',false);
		}else{
			if(selectedCount==$('td.filename input:checkbox').length){
				$('#select_all').attr('checked',true);
			}
		}
		procesSelection();
	});
	
	$('#file_newfolder_form').submit(function(event) {
		event.preventDefault();
		$.ajax({
			url: 'ajax/newfolder.php',
			data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(),
			complete: function(data){boolOperationFinished(data, function(){
				var date=new Date();
				FileList.addDir($('#file_newfolder_name').val(),0,date);
				$('#file_newfolder_name').val('New Folder');
				$('#file_newfolder_name').blur();
			});}
		});
	});
	
	$('#file_newfolder_name').click(function(){
		if($('#file_newfolder_name').val() == 'New Folder'){
			$('#file_newfolder_name').val('');
		}
	});
	
	$('.download').click('click',function(event) {
		var files=getSelectedFiles('name').join(';');
		
		//send the browser to the download location
		var dir=$('#dir').val()||'/';
// 		alert(files);
		window.location='ajax/download.php?files='+encodeURIComponent(files)+'&dir='+encodeURIComponent(dir);
		return false;
	});
	
	$('.delete').click(function(event) {
		var fileNames=getSelectedFiles('name');
		var files=fileNames.join(';');
		var lastFileName=fileNames.pop();
		if(fileNames.length>0){
			fileNames=fileNames.join(', ')+' and '+lastFileName;
		}else{
			fileNames=lastFileName;
		}

		$( "#delete-confirm" ).dialog({
			resizable: false,
			height:200,
			modal: true,
			title:"Delete "+fileNames,
			buttons: {
				"Delete": function() {
					$( this ).dialog( "close" );
					$.ajax({
						url: 'ajax/delete.php',
						data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files),
						complete: function(data){
							boolOperationFinished(data, function(){
								var files=getSelectedFiles('name');
							for(var i=0;i<files.length;i++){
								FileList.remove(files[i]);
							}
							procesSelection();
							});
						}
					});
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		
		return false;
	});

	$('.file_upload_start').live('change',function(){
		var form=$(this).parent().parent();
		var uploadId=form.attr('data-upload-id');
		var files=this.files;
		var target=form.children('iframe');
		var totalSize=0;
		for(var i=0;i<files.length;i++){
			totalSize+=files[i].size;
		}
		if(totalSize>$('#max_upload').val()){
			$( "#uploadsize-message" ).dialog({
				modal: true,
				buttons: {
					Close: function() {
						$( this ).dialog( "close" );
					}
				}
			});
		}else{
			target.load(function(){
				var response=jQuery.parseJSON(target.contents().find('body').text());
				//set mimetype and if needed filesize
				if(response){
					for(var i=0;i<response.length;i++){
						var file=response[i];
						$('tr[data-file="'+file.name+'"]').data('mime',file.mime);
						if(size=='Pending'){
							$('tr[data-file='+file.name+'] td.filesize').text(file.size);
						}
						FileList.loadingDone(file.name);
					}
				}
			});
			form.submit();
			var date=new Date();
			for(var i=0;i<files.length;i++){
				if(files[i].size>0){
					var size=files[i].size;
				}else{
					var size='Pending';
				}
				FileList.addFile(files[i].name,size,date,true);
			}

			//clone the upload form and hide the new one to allow users to start a new upload while the old one is still uploading
			var clone=form.clone();
			uploadId++;
			clone.attr('data-upload-id',uploadId);
			clone.attr('target','file_upload_target_'+uploadId);
			clone.children('iframe').attr('name','file_upload_target_'+uploadId)
			clone.insertBefore(form);
			form.hide();
		}
	});
	
	//add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
	if(navigator.userAgent.search(/konqueror/i)==-1){
		$('.file_upload_start').attr('multiple','multiple')
	}

	//if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder
	var crumb=$('div.crumb').first();
	while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){
{'fraction_non_alphanumeric': 0.21845764854614413, 'fraction_numerical': 0.00269700800674252, 'mean_word_length': 4.30917225950783, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5128486', 'n_tokens_mistral': 4642, 'n_tokens_neox': 3919, 'n_words': 601}