<commit_before>
// This function is called when the button is clicked or the return key is pressed
var addSong = function() {
	// get the url
	var url = $('#enqueueInput').val();
	if(!(url === "")){
		// set enqueuing to true
		Session.set('enqueuing', true);

		Meteor.call('enqueue', url, function(error, result) {
			if(!error){
				if(result){
					// set the input field to empty
					$('#enqueueInput').val("");
					// leave the focus
					$('#enqueueInput').blur();
				}
				else{
					alert("A Problem Occured");
				}
			}
			// if there was an error handle it
			else{
				if(error.error == "url_invalid"){
					alert("Not a valid URL");
				}				
			}

			// when the enqueue method has returned, set the flag to false
			Session.set('enqueuing', false);
		});
		
	}
}

Template.enqueue.helpers({
	enqueuing: function () {
		// states whether the user is just enqueuing a song and waiting for it
		// to appear in the playlist
		return Session.get('enqueuing');
	},
	// disables the enqueue input when enqueuing
	disabled: function() {
		if(Session.get('enqueuing')){
			return "disabled";
		} 
		else{
			return "";
		}
	}
});


Template.enqueue.events({
	'click #enqueueButton': function (event) {
		if(!Session.get('enqueuing')){
			addSong();
		}
	},
	'keypress #enqueueInput': function (event) {
		// Enter / Return
		if(event.charCode == 13 && !Session.get('enqueuing')){
			addSong();
		}
		// Escape
		else if(event.charCode == 27){
			$('#enqueueInput').blur();
		}<commit_msg>Changed the song enqueuing from pure JavaScript events to a from field. This improves cross browser support and is semantically more correct. |  resolves #3<commit_after>
// This function is called when the button is clicked or the return key is pressed
var addSong = function() {
	// get the url
	var url = $('#enqueueInput').val();
	if(!(url === "")){
		// set enqueuing to true
		Session.set('enqueuing', true);

		Meteor.call('enqueue', url, function(error, result) {
			if(!error){
				if(result){
					// set the input field to empty
					$('#enqueueInput').val("");
					// leave the focus
					$('#enqueueInput').blur();
				}
				else{
					alert("A Problem Occured");
				}
			}
			// if there was an error handle it
			else{
				if(error.error == "url_invalid"){
					alert("Not a valid URL");
				}
			}

			// when the enqueue method has returned, set the flag to false
			Session.set('enqueuing', false);
		});

	}
}

Template.enqueue.helpers({
	enqueuing: function () {
		// states whether the user is just enqueuing a song and waiting for it
		// to appear in the playlist
		return Session.get('enqueuing');
	},
	// disables the enqueue input when enqueuing
	disabled: function() {
		if(Session.get('enqueuing')){
			return "disabled";
		}
		else{
			return "";
		}
	}
});


Template.enqueue.events({
	'submit #enqueueForm': function (event) {
		// prevent Default form behaviour
		event.preventDefault();
		// if the user is not enqueuing right now, add the song
		if(!Session.get('enqueuing')){
			addSong();
		}
	},
	'keypress #enqueueInput': function (event) {
		// Escape
		// Lose focus on the input field
		if(event.charCode == 27){
			$('#enqueueInput').blur();
		}
{'fraction_non_alphanumeric': 0.15307402760351319, 'fraction_numerical': 0.00219573400250941, 'mean_word_length': 3.021437578814628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3068422', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1025, 'n_words': 314}