<commit_before>// **************************************************************** //
// ui.js - Scripts involving the user interface	

// Custom interface listener functions
function dragImageListener(ev, url) {
	var img = document.createElement('img');
	img.src = url;
	img.width = '15px'; 
	ev.dataTransfer.setDragImage(img, 20, 20);	
}

function ondragoverCall(ev) {
	ev.preventDefault();

	// Change the background color of the file being dropped on
	for(var i = 0; i < ev.target.parentNode.childNodes.length; i++) 
		ev.target.parentNode.childNodes[i].style.backgroundColor = 'transparent';
	ev.target.style.backgroundColor = '#E7ECFA';
}

function ondropCall(ev) {
	ev.preventDefault();
	var droppedId = ev.target.id;
	var draggedId = ev.dataTransfer.getData('id');	
	var droppedOn = document.getElementById(droppedId);
	var draggedFile = document.getElementById(draggedId);

	// Change the background color of the file being dragged over 
	for(var i = 0; i < droppedOn.parentNode.childNodes.length; i++) 
		droppedOn.parentNode.childNodes[i].style.backgroundColor = 'transparent';
	droppedOn.style.backgroundColor = '#E7ECFA';

	messageBox('Transferring files');

	// Base cases in which files are dragged and dropped within their host views
	if(draggedFile.obj.panel == droppedOn.obj.panel) {
		if(draggedFile.obj.panel === 'local') 
			socket.emit('command', 'putlocally', 
						draggedFile.obj, droppedOn.obj);
		else socket.emit('command', 'putremotely', 
						draggedFile.obj, droppedOn.obj);
	}
	// Execute sftp PUT command if local file is dragged to remote dir
	else if(draggedFile.obj.panel == 'local') { 
		socket.emit('command', 'put', draggedFile.obj, droppedOn.obj);
		console.log('Put command transmitted to the server!');
	}
	// Execute sftp GET command if remote file is dragged to local dir
	else if(draggedFile.obj.panel == 'remote') {
		socket.emit('command', 'get', draggedFile.obj, droppedOn.obj);	
		console.log('Get command transmitted to the server!');
	}
	// Error-check if the file panel is invalid
	else console.log('Cannot determine host origin of dragged file!');

	console.log("Dragged and dropped ("+draggedId+") onto ("+droppedId+")");
}

// **************************************************************** //
// Usage: (current working dir, files json, local or remote host view)
function showDirectory(path, files, panel) {
	console.log('--> in showDirectory()');

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	// Display the current working directory in the footer
	var input = document.createElement('input');
	input.id = panel+'cwd';
	input.type = 'text';
	input.className = 'cwd';
	input.placeholder = path;
	input.panel = panel;

	// Insert the placeholder upon clicking the go to footer
	input.onclick = function() { this.value = this.placeholder; };

	// Contact the server to change the directory upon enter key press
	input.onkeydown = function() {
		if(event.keyCode == 13) {
			var newDir = {
				'path'		: this.value,
				'panel'		: panel,
				'filename'	: ''
			};
			this.value = '';
			socket.emit('command', 'cd', newDir);
		}
	}
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	// Replace placeholder if the input already exists otherwise create one 
	if(document.contains(document.getElementById(panel+'cwd'))) {
		document.getElementById(panel+'cwd').placeholder = path;	
	} else document.getElementById(panel+'Footer').appendChild(input);<commit_msg>Added an onblur function to snap the footer placeholder back into place once the input is out of focus<commit_after>// **************************************************************** //
// ui.js - Scripts involving the user interface	

// Custom interface listener functions
function dragImageListener(ev, url) {
	var img = document.createElement('img');
	img.src = url;
	img.width = '15px'; 
	ev.dataTransfer.setDragImage(img, 20, 20);	
}

function ondragoverCall(ev) {
	ev.preventDefault();

	// Change the background color of the file being dropped on
	for(var i = 0; i < ev.target.parentNode.childNodes.length; i++) 
		ev.target.parentNode.childNodes[i].style.backgroundColor = 'transparent';
	ev.target.style.backgroundColor = '#E7ECFA';
}

function ondropCall(ev) {
	ev.preventDefault();
	var droppedId = ev.target.id;
	var draggedId = ev.dataTransfer.getData('id');	
	var droppedOn = document.getElementById(droppedId);
	var draggedFile = document.getElementById(draggedId);

	// Change the background color of the file being dragged over 
	for(var i = 0; i < droppedOn.parentNode.childNodes.length; i++) 
		droppedOn.parentNode.childNodes[i].style.backgroundColor = 'transparent';
	droppedOn.style.backgroundColor = '#E7ECFA';

	messageBox('Transferring files');

	// Base cases in which files are dragged and dropped within their host views
	if(draggedFile.obj.panel == droppedOn.obj.panel) {
		if(draggedFile.obj.panel === 'local') 
			socket.emit('command', 'putlocally', 
						draggedFile.obj, droppedOn.obj);
		else socket.emit('command', 'putremotely', 
						draggedFile.obj, droppedOn.obj);
	}
	// Execute sftp PUT command if local file is dragged to remote dir
	else if(draggedFile.obj.panel == 'local') { 
		socket.emit('command', 'put', draggedFile.obj, droppedOn.obj);
		console.log('Put command transmitted to the server!');
	}
	// Execute sftp GET command if remote file is dragged to local dir
	else if(draggedFile.obj.panel == 'remote') {
		socket.emit('command', 'get', draggedFile.obj, droppedOn.obj);	
		console.log('Get command transmitted to the server!');
	}
	// Error-check if the file panel is invalid
	else console.log('Cannot determine host origin of dragged file!');

	console.log("Dragged and dropped ("+draggedId+") onto ("+droppedId+")");
}

// **************************************************************** //
// Usage: (current working dir, files json, local or remote host view)
function showDirectory(path, files, panel) {
	console.log('--> in showDirectory()');

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	// Display the current working directory in the footer
	var input = document.createElement('input');
	input.id = panel+'cwd';
	input.type = 'text';
	input.className = 'cwd';
	input.placeholder = path;
	input.panel = panel;

	// Insert the placeholder upon clicking the go to footer
	input.onclick = function() { this.value = this.placeholder; };
	input.onblur = function() {
		input.value = '';
	};

	// Contact the server to change the directory upon enter key press
	input.onkeydown = function() {
		if(event.keyCode == 13) {
			var newDir = {
				'path'		: this.value,
				'panel'		: panel,
				'filename'	: ''
			};
			this.value = '';
			this.blur();
			socket.emit('command', 'cd', newDir);
		}
	}
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	// Replace placeholder if the input already exists otherwise create one 
	if(document.contains(document.getElementById(panel+'cwd'))) {
		document.getElementById(panel+'cwd').placeholder = path;	
	} else document.getElementById(panel+'Footer').appendChild(input);
{'fraction_non_alphanumeric': 0.18027210884353742, 'fraction_numerical': 0.003401360544217687, 'mean_word_length': 3.685922974767596, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7610669', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2139, 'n_words': 569}