<commit_before>(function($,window){
	'use-strict';
	var model = {},
		view = {},
		controller = {},
		actionURL;

	//private functions

	model.formData = {};
	model.validated = null;
	model.validateField = function(data,fieldName){
		if(fieldName==='name' && data.length >= 4){
			model.formData[fieldName] = data;
		}else if(fieldName==='email' && data.length >= 6){
			model.formData[fieldName] = data;
		}else if(fieldName==='message' && data.length >= 4){
			model.formData[fieldName] = data;
		} else {
			//show form error view
			model.validated = false;
			view.validationError(fieldName);
			return false;
		}
	};

	model.submit = function(data,callback){	
		//Sending form data to server'	
		$.ajax({
			type: 'POST',
			url: actionURL,
			data: data,
			success:  function(data){
				if(data.length && callback){
					callback();
				}
			}
		});
	};

	model.validate = function(form){
		var requiredFields = {},
		formField = view.form.find('input[type="text"],input[type="email"],textarea');

		view.removeErrorClass();

		$.each(formField,function(){
			var field = $(this),
				fieldName = field.attr('name'),
				fieldValue = field.val(),
				fieldValidation = field.attr('data-validation');
			if(fieldValidation ==='required'){
				model.validateField(fieldValue,fieldName);
			} else {
				model.formData[fieldName] = fieldValue;
			}
		});

		if(typeof(model.validated)==='undefined' || model.validated!== false){
			// Submit the form data
			model.submit(model.formData);
		}
	};

	var modelPublic = {
		submit: model.submit,
		validate: model.validate
	};


	//---VIEW

	view.hideForm = function(){
		self.form.hide();
	};

	view.showForm = function(){
		if($('.form-success').length){
			$('.form-success').remove();
		}
		self.form.show();
	};

	view.clearForm = function(){
		var formField = self.form.find('input[type="text"],input[type="email"],textarea');

		$.each(formField,function(){
			var field = $(this);
			field.val('');
		});
	};

	view.removeErrorClass = function(){
		view.form.find('input, textrea').removeClass('form-input-error');
	};

	view.validationError = function(fieldName){
		view.form.find('[name="'+fieldName+'"]').focus().addClass('form-input-error');
	};

	view.sendError = function(){

	};

	view.sendSuccess = function(){
		hideForm();
		self.form.after('<div class="form-success"><h2>Thank you!</h2><h3>Your message was successfully sent.</h3><a href="#" class="btn">Okay!</a></div>');
		$('.form-success .btn').on('click',function(e){
			e.preventDefault();
			clearForm();
			showForm();
		});
	};

	var viewPublic = {
		removeErrorClass: view.removeErrorClass,
		validationError: view.validationError,
		sendError: view.sendError,
		sendSuccess: view.sendSuccess
	};


	//--CONTROLLER

	controller.formSubmit = function(e){
		e.preventDefault();
		model.validate(view.form);
	};

	var controllerPublic = {
		formSubmit: controller.formSubmit
	};

	var init = function(target,actionURL){
		console.log('ContactForm initialized');

		view.form = $(target);
		view.formParent = $(target).parent();
		actionURL = actionURL;

		view.submitBtn = view.form.find('input[type="submit"]');

		if(view.submitBtn){
			view.submitBtn.bind('click',function(e){
				controller.formSubmit(e);
			});
		}
	};

	// public methods and properties to be returned
	var formHandler = {
		model: modelPublic,
		view: viewPublic,
		controller: controllerPublic,
		init: init
	};
<commit_msg>Disabled form submit button during validation and submission states. Made form action URL optional with console log fallback. Form fields with class value of 'required' now undergo validation process.<commit_after>(function($,window){
	'use-strict';
	var model = {},
		view = {},
		controller = {},
		config = {};

	//private functions

	model.formData = {};
	model.validateField = function(data,fieldName){
		if(fieldName==='name' && data.length >= 4){
			model.formData[fieldName] = data;
		}else if(fieldName==='email' && data.length >= 6){
			model.formData[fieldName] = data;
		}else if(fieldName==='message' && data.length >= 4){
			model.formData[fieldName] = data;
		} else {
			//show form error view
			console.log(fieldName+' not valiated');
			model.validated = false;
			controller.enableSubmit();
			view.validationError(fieldName);
			return false;
		}
	};

	model.submit = function(data,callback){	
		//Sending form data to server'

		if(config.actionURL==='console'){
			console.log('Sending form data: '+data);
		} else {
			$.ajax({
				type: 'POST',
				url: config.actionURL,
				data: data,
				success:  function(data){
					if(data.length && callback){
						callback();
					}
				}
			});
		}
		
		view.clearForm();
		controller.enableSubmit();
	};

	model.validate = function(form){
		var requiredFields = {},
		formField = view.form.find('input[type="text"],input[type="email"],textarea');

		model.validated = undefined;
		controller.disableSubmit();
		view.removeErrorClass();

		$.each(formField,function(){
			var field = $(this),
				fieldName = field.attr('name'),
				fieldValue = field.val(),
				fieldClass = field.attr('class'),
				fieldValidation;

			if(fieldClass){
				fieldClass = fieldClass.split(' ');
				for(var i in fieldClass){
					if(fieldClass[i]==='required'){
						fieldValidation = true;
					}
				}
			}

			if(fieldValidation){
				model.validateField(fieldValue,fieldName);
			} else {
				model.formData[fieldName] = fieldValue;
			}
		});

		if(typeof(model.validated)==='undefined' && model.validated!== false){
			// Submit the form data
			model.submit(model.formData);
		}
	};

	var modelPublic = {
		submit: model.submit,
		validate: model.validate
	};


	//---VIEW

	view.hideForm = function(){
		view.form.hide();
	};

	view.showForm = function(){
		if($('.form-success').length){
			$('.form-success').remove();
		}
		view.form.show();
	};

	view.clearForm = function(){
		var formField = view.form.find('input[type="text"],input[type="email"],textarea');

		$.each(formField,function(){
			var field = $(this);
			field.val('');
		});
	};

	view.removeErrorClass = function(){
		view.form.find('input, textrea').removeClass('input-error');
	};

	view.validationError = function(fieldName){
		view.form.find('[name="'+fieldName+'"]').focus().addClass('input-error');
	};

	view.sendError = function(){

	};

	view.sendSuccess = function(){
		hideForm();
		self.form.after('<div class="form-success"><h2>Thank you!</h2><h3>Your message was successfully sent.</h3><a href="#" class="btn">Okay!</a></div>');
		$('.form-success .btn').on('click',function(e){
			e.preventDefault();
			clearForm();
			showForm();
		});
	};

	var viewPublic = {
		removeErrorClass: view.removeErrorClass,
		validationError: view.validationError,
		sendError: view.sendError,
		sendSuccess: view.sendSuccess
	};


	//--CONTROLLER

	controller.formSubmit = function(e){
		e.preventDefault();
		model.validate(view.form);
	};

	controller.disableSubmit = function(){
		view.submitBtn.unbind('click').addClass('disabled');
	};

	controller.enableSubmit = function(){
		view.submitBtn.bind('click',function(e){
			controller.formSubmit(e);
		}).removeClass('disabled');
	};

	var controllerPublic = {
		formSubmit: controller.formSubmit
	};

	var init = function(target,actionURL){

		view.form = $(target),
		view.formParent = $(target).parent(),
		config.actionURL = (actionURL!==undefined)? actionURL : 'console',
		view.submitBtn = view.form.find('input[type="submit"]');

		if(view.submitBtn){
			controller.enableSubmit();
		}
	};

	// public methods and properties to be returned
	var formHandler = {
		model: modelPublic,
		view: viewPublic,
		controller: controllerPublic,
		init: init
	};

{'fraction_non_alphanumeric': 0.1814863102998696, 'fraction_numerical': 0.0018252933507170795, 'mean_word_length': 3.961836998706339, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5729267', 'n_tokens_mistral': 2846, 'n_tokens_neox': 2465, 'n_words': 446}