<commit_before>/*
* Unobtrusive autocomplete
*
* To use it, you just have to include the HTML attribute autocomplete
* with the autocomplete URL as the value
*
*   Example:
*       <input type="text" data-autocomplete="/url/to/autocomplete">
* 
* Optionally, you can use a jQuery selector to specify a field that can
* be updated with the element id whenever you find a matching value
*
*   Example:
*       <input type="text" data-autocomplete="/url/to/autocomplete" id_element="#id_field">
*/

$(document).ready(function(){
  $('input[data-autocomplete]').live('focus', function(i){
		this.delimiter = $(this).attr('data-delimiter') || null;
		_selfinput = this;
		function split( val ) {
			return val.split( _selfinput.delimiter );
		}
		function extractLast( term ) {
			return split( term ).pop();
		}
		
    $(this).autocomplete({
      source: $(this).attr('data-autocomplete'),
			search: function() {
				// custom minLength
				var term = extractLast( this.value );
				if ( term.length < 2 ) {
					return false;
				}
			},
			select: function( event, ui ) {
				var terms = split( this.value );
				// remove the current input
				terms.pop();
				// add the selected item
				terms.push( ui.item.value );
				// add placeholder to get the comma-and-space at the end
				console.log(_selfinput.delimiter);
				if (_selfinput.delimiter != null) {
					terms.push( "" );
					this.value = terms.join( _selfinput.delimiter );
				} else {
					this.value = terms.join("");
				};
				
				return false;
			}

    });
  });
});<commit_msg>better focus control, style with ui-state-hover for keyboard action removal of jquery .live debugging removed fixing sending-all-terms bug<commit_after>/*
* Unobtrusive autocomplete
*
* To use it, you just have to include the HTML attribute autocomplete
* with the autocomplete URL as the value
*
*   Example:
*       <input type="text" data-autocomplete="/url/to/autocomplete">
* 
* Optionally, you can use a jQuery selector to specify a field that can
* be updated with the element id whenever you find a matching value
*
*   Example:
*       <input type="text" data-autocomplete="/url/to/autocomplete" id_element="#id_field">
*/

$(document).ready(function(){
  $('input[data-autocomplete]').each(function(i){
		this.delimiter = $(this).attr('data-delimiter') || null;
		_selfinput = this;
		function split( val ) {
			return val.split( _selfinput.delimiter );
		}
		function extractLast( term ) {
			return split( term ).pop();
		}
		
    $(this).autocomplete({
			source: function( request, response ) {
				$.getJSON( $(_selfinput).attr('data-autocomplete'), {
				term: extractLast( request.term )
				}, response );
			},
			search: function() {
				// custom minLength
				var term = extractLast( this.value );
				if ( term.length < 2 ) {
					return false;
				}
			},
			focus: function() {
							// prevent value inserted on focus
				return false;
			},
			select: function( event, ui ) {
				var terms = split( this.value );
				// remove the current input
				terms.pop();
				// add the selected item
				terms.push( ui.item.value );
				// add placeholder to get the comma-and-space at the end
				if (_selfinput.delimiter != null) {
					terms.push( "" );
					this.value = terms.join( _selfinput.delimiter );
				} else {
					this.value = terms.join("");
				};
				
				return false;
			}

    });
  });
});
{'fraction_non_alphanumeric': 0.13939035217519977, 'fraction_numerical': 0.0005918910920390648, 'mean_word_length': 2.9348079161816063, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7240920', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1019, 'n_words': 300}