<commit_before>// manages behavior of feedback form
define(['util/util','trim','jquery'],function(util,trim,$) {
	'use strict';

		// PRIVATE PROPERTIES
		var _sendBtn;
		var _feedbackStatus;

		var _commentInput;
		var _emailInput;

		// PUBLIC METHODS
		function init()
		{
			_sendBtn = document.getElementById('feedback-form-btn');
			_sendBtn.addEventListener("click",_sendBtnClicked,false);

			_feedbackStatus = document.getElementById('feedback-status');

			_commentInput = document.querySelector('#feedback-box #comment');
			_emailInput = document.querySelector('#feedback-box #email');

			if (util.isEventSupported('input'))
			{
				_commentInput.addEventListener('input', _onFeedbackFormInput);
				_emailInput.addEventListener('input', _onFeedbackFormInput);
			}
		}

		// the form is being hidden, hide the feedback status
		function hide()
		{
			_feedbackStatus.classList.add('hide');
			_updateFeedbackForm();
		}

		// PRIVATE PROPERTIES
		function _sendBtnClicked(evt)
		{
			evt.preventDefault(); // stop the form from submitting
			_feedbackFormSend();
			return false;
		}

		function _onFeedbackFormInput(evt)
		{
			_updateFeedbackForm();
		}

		function _isFeedbackFormMessagePresent() {
			var message = _commentInput.value;
			message = message.trim();

			return message.length > 0;
		}

		function _updateFeedbackForm() {
			if (_isFeedbackFormMessagePresent()) {
				_sendBtn.disabled = false;
			} else {
				_sendBtn.disabled = true;
			}
		}

		function _feedbackFormSend() 
		{
			var agent = '\nUser agent: ' + navigator.userAgent;
 
			var transmission = {
				message: _commentInput.value,
				from: _emailInput.value,
				agent: agent
			};

			$.ajax({
					url     : '/feedback',
					type    : 'POST',
					dataType: 'json',
					data    : JSON.stringify(transmission),
					contentType: 'application/json',
					success : _onSuccess,
					error   : _onError
			});  
			
		}

		// on submitting success, clear out values and post success message.
		function _onSuccess(data)
		{
			_feedbackStatus.innerHTML = "Thanks for the feedback!";
			_feedbackStatus.classList.remove('hide');
			_commentInput.value = '';
			_updateFeedbackForm();
		}

		// on submitting error, clear out values and post failure message.
		function _onError(xhr, err)
		{
			_feedbackStatus.innerHTML = "Error sending feedback, please <a href='/'>reload</a> and try again!";
			_feedbackStatus.classList.remove('hide');
			_commentInput.value = '';
			_emailInput.value = '';
			_updateFeedbackForm();
		}

	return {
		init:init,
		hide:hide
	};
});<commit_msg>Enables send button if input event isn't supported<commit_after>// manages behavior of feedback form
define(['util/util','trim','jquery'],function(util,trim,$) {
	'use strict';

		// PRIVATE PROPERTIES
		var _sendBtn;
		var _feedbackStatus;

		var _commentInput;
		var _emailInput;

		// PUBLIC METHODS
		function init()
		{
			_sendBtn = document.getElementById('feedback-form-btn');
			_sendBtn.addEventListener("click",_sendBtnClicked,false);

			_feedbackStatus = document.getElementById('feedback-status');

			_commentInput = document.querySelector('#feedback-box #comment');
			_emailInput = document.querySelector('#feedback-box #email');

			if (util.isEventSupported('input'))
			{
				_commentInput.addEventListener('input', _onFeedbackFormInput);
				_emailInput.addEventListener('input', _onFeedbackFormInput);
			}
			else
			{
				_sendBtn.disabled = '';
			}
		}

		// the form is being hidden, hide the feedback status
		function hide()
		{
			_feedbackStatus.classList.add('hide');
			_updateFeedbackForm();
		}

		// PRIVATE PROPERTIES
		function _sendBtnClicked(evt)
		{
			evt.preventDefault(); // stop the form from submitting
			_feedbackFormSend();
			return false;
		}

		function _onFeedbackFormInput(evt)
		{
			_updateFeedbackForm();
		}

		function _isFeedbackFormMessagePresent() {
			var message = _commentInput.value;
			message = message.trim();

			return message.length > 0;
		}

		function _updateFeedbackForm() {
			if (_isFeedbackFormMessagePresent()) {
				_sendBtn.disabled = false;
			} else {
				_sendBtn.disabled = true;
			}
		}

		function _feedbackFormSend() 
		{
			var agent = '\nUser agent: ' + navigator.userAgent;
 
			var transmission = {
				message: _commentInput.value,
				from: _emailInput.value,
				agent: agent
			};

			$.ajax({
					url     : '/feedback',
					type    : 'POST',
					dataType: 'json',
					data    : JSON.stringify(transmission),
					contentType: 'application/json',
					success : _onSuccess,
					error   : _onError
			});  
			
		}

		// on submitting success, clear out values and post success message.
		function _onSuccess(data)
		{
			_feedbackStatus.innerHTML = "Thanks for the feedback!";
			_feedbackStatus.classList.remove('hide');
			_commentInput.value = '';
			_updateFeedbackForm();
		}

		// on submitting error, clear out values and post failure message.
		function _onError(xhr, err)
		{
			_feedbackStatus.innerHTML = "Error sending feedback, please <a href='/'>reload</a> and try again!";
			_feedbackStatus.classList.remove('hide');
			_commentInput.value = '';
			_emailInput.value = '';
			_updateFeedbackForm();
		}

	return {
		init:init,
		hide:hide
	};
});
{'fraction_non_alphanumeric': 0.12316491897044804, 'fraction_numerical': 0.00038131553860819826, 'mean_word_length': 3.4914383561643834, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4037553', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1587, 'n_words': 345}