<commit_before>function smf_fileUpload(oOptions)
{
	// Default values in case oOptions isn't defined.
	var dOptions = {
		url: smf_prepareScriptUrl(smf_scripturl) + 'action=uploadAttach;sa=add;' + smf_session_var + '=' + smf_session_id,
		dataType: 'json',
		dropZone: $('.drop_zone'),
		singleFileUploads:false,
		forceIframeTransport: false,
		autoUpload: false,
		paramName: 'attachment[]',
		acceptFileTypes: /(\.|\/)(doc|gif|jpg|mpg|pdf|png|txt|zip)$/i,
		maxFileSize: 128000, // 128 KB
		disableImageResize: /Android(?!.*Chrome)|Opera/
			.test(window.navigator.userAgent),
		previewMaxWidth: 100,
		previewMaxHeight: 100,
		previewCrop: false,
		maxNumberOfFiles: 10,
		limitMultiFileUploads: 10,
		limitMultiFileUploadSize: 1000000,
		smf_mainDiv: '#fileupload',
		smf_containerDiv: '#files',
		smf_text: {}
	};

	$.extend(true, dOptions, oOptions);

	var uploadButton = $('<a/>')
		.addClass('button_submit uploadButton')
		.prop('disabled', true)
		.text(dOptions.smf_text.upload)
		.one('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data();

			data.instance.submit().always(function () {
				$this.remove();
			});
		}),
	cancelButton = $('<a/>')
		.addClass('button_submit cancelButton')
		.prop('disabled', false)
		.text(dOptions.smf_text.cancel)
		.one('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data(),
				node = $(data.instance.context);

			// Gotta remove this from the number of files.
			--numberOfFiles;

			// And remove this file's size from the total.
			totalSize = totalSize - data.currentFile.size;

			// Need to remove this entry from the track array
			fileUpload.track = $.grep(fileUpload.track,
				function(o,i) { return o === data.index; },
			true);

			// And actually remove the button and the node.
			$this.remove();
			data.currentNode.fadeOut('slow', function() {
				data.currentNode.remove();
				data.instance.abort();
			});
		}),
	deleteButton = $('<a />')
		.addClass('button_submit deleteButton you_sure')
		.prop('disabled', false)
		.text(dOptions.smf_text.deleteAttach)
		.on('click', function (e) {

			var $this = $(this),
				mainData = $this.data(),
				node = $(mainData.context);

			// Let the server know you want to delete the file you just recently uploaded...
			$.ajax({
				url: smf_prepareScriptUrl(smf_scripturl) + 'action=uploadAttach;sa=delete;attach='+ mainData.currentFile['attachID'] +';' + smf_session_var + '=' + smf_session_id,
				type: 'GET',
				dataType: 'json',
				success: function (data, textStatus, xhr) {
					// Gotta remove this from the number of files.
					--numberOfFiles;

					// And remove this file's size from the total.
					totalSize = totalSize - mainData.currentFile['size'];

					// Replace the delete button with the "cancel" one.
					$this.replaceWith(cancelButton.clone(true).data(mainData));

					// Don't remove the entire node, just leave a message.
					node.find('.file_details').fadeOut('slow', function() {
						node.find('.file_details').text(dOptions.smf_text.attachDeleted);
						node.find('.file_details').fadeIn('slow', function() {
						});
					});

					// Remove the BBC tag.
					node.find('.file_info').empty();

					// Lastly, abort the whole thing.
					mainData.abort();
				},
				error: function (xhr, textStatus, errorThrown) {
					// Lastly, abort the whole thing.
					mainData.abort();

					node
						.find('.file_info')
						.append($('<p/>').text((typeof file.error !== 'undefined' ? file.error : dOptions.smf_text.genericError)));

					node.removeClass('descbox').addClass('errorbox');
				}
			});
		}),
	insertBBC = $('<a />')
		.addClass('button_submit insertBBC')
		.prop('disabled', false)
		.text(dOptions.smf_text.insertBBC)
		.on('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data(),
				node = $(data.context);

			// Get the text field value.
			oTag = node.find('input[name=attachBBC]').val();

			$('#' + oEditorID).data('sceditor').sourceEditorInsertText(oTag);
		}),
	uploadAll = $('<a/>')
		.addClass('button_submit uploadAllButton')
		.prop('disabled', true)
		.text(dOptions.smf_text.uploadAll)
		.one('click', function (e) {
			e.preventDefault();
			for (i=0; i < fileUpload.length; i++) {
				fileUpload[i].data.submit().always(function () {

				});
			}
		}),
	cancelAll = $('<a/>')
		.addClass('button_submit cancelAllButton')
		.prop('disabled', false)
		.text(dOptions.smf_text.cancelAll)
		.on('click', function (e) {
			e.preventDefault();

			var $this = $(this),
				data = $this.data(),
				node = $(data.context);

			// Gotta remove everything.
			numberOfFiles = 0;

			// And this stuff too!.
			totalSize = 0;

			// Reset!
			fileIndicator = false;

			$(fileUpload.track).each(function(index, i) {

				$('#attach_holder_' + i).fadeOut('slow', function() {
					$('#attach_holder_' + i).remove();
				});
			});

			// Remove both upload and cancel all buttons.
			$('.cancelAllButton').fadeOut('slow', function() {
				$(this).remove();
			});

			$('.uploadAllButton').fadeOut('slow', function() {
				$(this).remove();
			});

			// Reset the track array too!
			fileUpload.track = [];

			// Finally, abort all the things!
			data.abort();
		}),
	numberOfTimes = 0,
	numberOfFiles = 0,
	totalSize = 0,
	fileIndicator = false,
	uniqueID = 0

	fileUpload =  $(dOptions.smf_mainDiv).fileupload(dOptions)
		.on('fileuploadadd', function (e, data) {

			// Track the number of times this event has been fired.
			++numberOfTimes;

			// Show some general controls.
			if (!fileIndicator){
				fileIndicator = true;

				$('.attachControl')
					.append(cancelAll.clone(true).data(data))
					.append(uploadAll.clone(true).data(data));

				// Keep track of each unique file added
				fileUpload.track = [];
			}

			// Create a master and empty div.
			data.context = $('<div/>').addClass('attach_container').appendTo(dOptions.smf_containerDiv);

			// Perhaps we just want to cancel...
			data.justCancel = false;

			// Append the file.
			$.each(data.files, function (index, file) {

				// Set a unique identifier for this file.
				++uniqueID;

				var node = $('<div/>').addClass('attach_holder descbox')
				.attr('id', 'attach_holder_' + uniqueID)
				.html('<div class="file_details"></div><div class="file_info"></div><div class="file_buttons clear"><div class="progressBar"><span></span></div>');

				// Hide the progress bar, we don't want to show it just yet!
				node.find('.progressBar').hide();

				node.find('.file_details')
						.append($('<p/>').text(file.name));

				// Need to pass some stuff to the upload and cancel buttons.
				toButtons = {uniqueID: uniqueID, currentFile: file, currentNode: node, instance: data};

				// Append the current node info so it would be easier for the buttons to target it.
				node.find('.file_buttons')
						.append(cancelButton.clone(true).data(toButtons))
						.append(uploadButton.clone(true).data(toButtons));

				node.appendTo(data.context);
				fileUpload.track.push(uniqueID);
			});
		})
		.on('fileuploadsend', function (e, data) {

			// Show the progress bar.
			data.context.find('.progressBar').fadeIn();

		})
		.on('fileuploadprocessalways', function (e, data) {
			var index = data.index,
				file = data.files[index],<commit_msg>Current work so far<commit_after>function smf_fileUpload(oOptions)
{
	// Default values in case oOptions isn't defined.
	var dOptions = {
		url: smf_prepareScriptUrl(smf_scripturl) + 'action=uploadAttach;sa=add;' + smf_session_var + '=' + smf_session_id,
		dataType: 'json',
		dropZone: $('.drop_zone'),
		singleFileUploads:false,
		forceIframeTransport: false,
		autoUpload: false,
		paramName: 'attachment[]',
		acceptFileTypes: /(\.|\/)(doc|gif|jpg|mpg|pdf|png|txt|zip)$/i,
		maxFileSize: 128000, // 128 KB
		disableImageResize: /Android(?!.*Chrome)|Opera/
			.test(window.navigator.userAgent),
		previewMaxWidth: 100,
		previewMaxHeight: 100,
		previewCrop: false,
		maxNumberOfFiles: 10,
		limitMultiFileUploads: 10,
		limitMultiFileUploadSize: 1000000,
		smf_mainDiv: '#fileupload',
		smf_containerDiv: '#files',
		smf_text: {}
	};

	$.extend(true, dOptions, oOptions);

	var uploadButton = $('<a/>')
		.addClass('button_submit uploadButton')
		.prop('disabled', true)
		.text(dOptions.smf_text.upload)
		.one('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data(),
				node = $('#attach_holder_' + data.uniqueID);

			// Show the progress bar.
			node.find('.progressBar').fadeIn();

			data.instance.submit();
			$this.remove();
		}),
	cancelButton = $('<a/>')
		.addClass('button_submit cancelButton')
		.prop('disabled', false)
		.text(dOptions.smf_text.cancel)
		.one('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data(),
				node = $(data.instance.context);

			// Gotta remove this from the number of files.
			--numberOfFiles;

			// And remove this file's size from the total.
			totalSize = totalSize - data.currentFile.size;

			// Need to remove this entry from the track array
			fileUpload.track = $.grep(fileUpload.track,
				function(o,i) { return o === data.index; },
			true);

			// And actually remove the button and the node.
			$this.remove();
			data.currentNode.fadeOut('slow', function() {
				data.currentNode.remove();
				data.instance.abort();
			});
		}),
	deleteButton = $('<a />')
		.addClass('button_submit deleteButton you_sure')
		.prop('disabled', false)
		.text(dOptions.smf_text.deleteAttach)
		.on('click', function (e) {

			var $this = $(this),
				mainData = $this.data(),
				node = $(mainData.context);

			// Let the server know you want to delete the file you just recently uploaded...
			$.ajax({
				url: smf_prepareScriptUrl(smf_scripturl) + 'action=uploadAttach;sa=delete;attach='+ mainData.currentFile['attachID'] +';' + smf_session_var + '=' + smf_session_id,
				type: 'GET',
				dataType: 'json',
				success: function (data, textStatus, xhr) {
					// Gotta remove this from the number of files.
					--numberOfFiles;

					// And remove this file's size from the total.
					totalSize = totalSize - mainData.currentFile['size'];

					// Replace the delete button with the "cancel" one.
					$this.replaceWith(cancelButton.clone(true).data(mainData));

					// Don't remove the entire node, just leave a message.
					node.find('.file_details').fadeOut('slow', function() {
						node.find('.file_details').text(dOptions.smf_text.attachDeleted);
						node.find('.file_details').fadeIn('slow', function() {
						});
					});

					// Remove the BBC tag.
					node.find('.file_info').empty();

					// Lastly, abort the whole thing.
					mainData.abort();
				},
				error: function (xhr, textStatus, errorThrown) {
					// Lastly, abort the whole thing.
					mainData.abort();

					node
						.find('.file_info')
						.append($('<p/>').text((typeof file.error !== 'undefined' ? file.error : dOptions.smf_text.genericError)));

					node.removeClass('descbox').addClass('errorbox');
				}
			});
		}),
	insertBBC = $('<a />')
		.addClass('button_submit insertBBC')
		.prop('disabled', false)
		.text(dOptions.smf_text.insertBBC)
		.on('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data(),
				node = $(data.context);

			// Get the text field value.
			oTag = node.find('input[name=attachBBC]').val();

			$('#' + oEditorID).data('sceditor').sourceEditorInsertText(oTag);
		}),
	uploadAll = $('<a/>')
		.addClass('button_submit uploadAllButton')
		.prop('disabled', true)
		.text(dOptions.smf_text.uploadAll)
		.one('click', function (e) {
			e.preventDefault();
			var $this = $(this),
				data = $this.data();

			// Show the progress bar.
			data.context.find('.progressBar').fadeIn();

			data.submit();
		}),
	cancelAll = $('<a/>')
		.addClass('button_submit cancelAllButton')
		.prop('disabled', false)
		.text(dOptions.smf_text.cancelAll)
		.on('click', function (e) {
			e.preventDefault();

			var $this = $(this),
				data = $this.data(),
				node = $(data.context);

			// Gotta remove everything.
			numberOfFiles = 0;

			// And this stuff too!.
			totalSize = 0;

			// Reset!
			fileIndicator = false;

			$(fileUpload.track).each(function(index, i) {

				$('#attach_holder_' + i).fadeOut('slow', function() {
					$('#attach_holder_' + i).remove();
				});
			});

			// Remove both upload and cancel all buttons.
			$('.cancelAllButton').fadeOut('slow', function() {
				$(this).remove();
			});

			$('.uploadAllButton').fadeOut('slow', function() {
				$(this).remove();
			});

			// Reset the track array too!
			fileUpload.track = [];

			// Finally, abort all the things!
			data.abort();
		}),
	numberOfTimes = 0,
	numberOfFiles = 0,
	totalSize = 0,
	fileIndicator = false,
	uniqueID = 0

	fileUpload =  $(dOptions.smf_mainDiv).fileupload(dOptions)
		.on('fileuploadadd', function (e, data) {

			// Track the number of times this event has been fired.
			++numberOfTimes;

			// Create a master and empty div.
			data.context = $('<div/>').addClass('attach_container').appendTo(dOptions.smf_containerDiv);

			// Show some general controls.
			if (!fileIndicator){
				// Keep track of each unique file added
				fileUpload.track = [];
			}

			// Append the file.
			$.each(data.files, function (index, file) {

				// Set a unique identifier for this file.
				++uniqueID;

				var node = $('<div/>').addClass('attach_holder descbox')
				.attr('id', 'attach_holder_' + uniqueID)
				.html('<div class="file_details"></div><div class="file_info"></div><div class="file_buttons clear"><div class="progressBar"><span></span></div>');

				// Hide the progress bar, we don't want to show it just yet!
				node.find('.progressBar').hide();

				node.find('.file_details')
						.append($('<p/>').text(file.name));

				// Need to pass some stuff to the upload and cancel buttons.
				toButtons = {uniqueID: uniqueID, currentFile: file, currentNode: node, instance: data};

				// Append the current node info so it would be easier for the buttons to target it.
				node.find('.file_buttons')
						.append(cancelButton.clone(true).data(toButtons))
						.append(uploadButton.clone(true).data(toButtons));

				node.appendTo(data.context);
				fileUpload.track.push(uniqueID);
			});

			// Show some general controls.
			if (!fileIndicator){
				fileIndicator = true;

				$('.attachControl')
					.append(cancelAll.clone(true).data(data))
					.append(uploadAll.clone(true).data(data));
			}
		})
		.on('fileuploadprocessalways', function (e, data) {
			var index = data.index,
				file = data.files[index],
{'fraction_non_alphanumeric': 0.17168612989141568, 'fraction_numerical': 0.004438981083111384, 'mean_word_length': 3.3713432835820893, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5512683', 'n_tokens_mistral': 5767, 'n_tokens_neox': 4728, 'n_words': 1078}