<commit_before>(function($)
{
	function TextExtAutocomplete()
	{
	};

	$.fn.textext.TextExtAutocomplete = TextExtAutocomplete;
	$.fn.textext.addPlugin('autocomplete', TextExtAutocomplete);

	var p = TextExtAutocomplete.prototype,
		
		CSS_DOT            = '.',
		CSS_SELECTED       = 'text-selected',
		CSS_DOT_SELECTED   = CSS_DOT + CSS_SELECTED,
		CSS_SUGGESTION     = 'text-suggestion',
		CSS_DOT_SUGGESTION = CSS_DOT + CSS_SUGGESTION,

		OPT_ENABLED         = 'dropdown.enabled',
		OPT_MAX_HEIGHT      = 'dropdown.maxHeight',
		OPT_DIRECTION       = 'dropdown.direction',
		OPT_HTML_DROPDOWN   = 'html.dropdown',
		OPT_HTML_SUGGESTION = 'html.suggestion',

		EVENT_HIDE_DROPDOWN   = 'hideDropdown',
		EVENT_SHOW_DROPDOWN   = 'showDropdown',
		EVENT_GET_SUGGESTIONS = 'getSuggestions',
		EVENT_SET_SUGGESTIONS = 'setSuggestions',

		POSITION_ABOVE = 'above',
		POSITION_BELOW = 'below',

		DEFAULT_OPTS = {
			dropdown : {
				enabled   : true,
				position : POSITION_BELOW
			},

			html : {
				dropdown   : '<div class="text-dropdown"><div class="text-list"/></div>',
				suggestion : '<div class="text-suggestion"><span class="text-label"/></div>'
			}
		}
		;

	p.init = function(parent)
	{
		var self = this;

		self.baseInit(parent, DEFAULT_OPTS);

		var input = self.input(),
			container
			;

		if(self.opts(OPT_ENABLED) === true)
		{
			self.on({
				click          : self.onClick,
				blur           : self.onBlur,
				otherKeyUp     : self.onOtherKeyUp,
				deleteKeyUp    : self.onOtherKeyUp,
				backspaceKeyUp : self.onBackspaceKeyUp,
				downKeyDown    : self.onDownKeyDown,
				upKeyDown      : self.onUpKeyDown,
				enterKeyDown   : self.onEnterKeyDown,
				escapeKeyUp    : self.onEscapeKeyUp,
				setSuggestions : self.onSetSuggestions,
				showDropdown   : self.onShowDropdown,
				hideDropdown   : self.onHideDropdown,
				postInvalidate : self.positionDropdown
			});

			input.after(self.opts(OPT_HTML_DROPDOWN));
			container = self.getDropdownContainer();
			container
				.mouseover(function(e) { self.onMouseOver(e) })
				.addClass('text-position-' + self.opts(OPT_DIRECTION))
				;

			self.positionDropdown();
		}
	};

	/**
	 * Returns top level dropdown container HTML element.
	 * @author agorbatchev
	 * @date 2011/08/15
	 */
	p.getDropdownContainer = function()
	{
		return this.input().siblings('.text-dropdown');
	};

	//--------------------------------------------------------------------------------
	// User mouse/keyboard input
	
	p.onMouseOver = function(e)
	{
		var self   = this,
			target = $(e.target)
			;

		if(target.is(CSS_DOT_SUGGESTION))
		{
			self.clearSelected();
			target.addClass(CSS_SELECTED);
		}
	};

	p.onClick = function(e)
	{
		var self   = this,
			target = $(e.target)
			;

		if(target.is(CSS_DOT_SUGGESTION))
			self.selectFromDropdown();
	};

	p.onBlur = function(e)
	{
		var self = this;

		// use timeout here so that onClick has a chance to fire because if
		// dropdown is hidden when clicked, onClick doesn't fire
		if(self.isDropdownVisible())
			setTimeout(function() { self.trigger(EVENT_HIDE_DROPDOWN) }, 100);
	};

	p.onBackspaceKeyUp = function(e)
	{
		var self = this,
			isEmpty = self.input().val().length > 0
			;

		if(isEmpty || self.isDropdownVisible())
			self.getSuggestions();
	};

	p.onOtherKeyUp = function(e)
	{
		this.getSuggestions();
	};

	p.onDownKeyDown = function(e)
	{
		var self = this;

		self.isDropdownVisible()
			? self.toggleNextSuggestion() 
			: self.getSuggestions()
			;
	};

	p.onUpKeyDown = function(e)
	{
		this.togglePreviousSuggestion();
	};

	p.onEnterKeyDown = function(e)
	{
		var self = this;

		if(self.isDropdownVisible())
			self.selectFromDropdown();
	};

	p.onEscapeKeyUp = function(e)
	{
		var self = this;

		if(self.isDropdownVisible())
			self.trigger(EVENT_HIDE_DROPDOWN);
	};

	//--------------------------------------------------------------------------------
	// Core functionality

	/**
	 * Positions dropdown either below or above the input based on the `dropdown.position`
	 * option specified, which could be either `above` or `below`.
	 * @author agorbatchev
	 * @date 2011/08/15
	 */
	p.positionDropdown = function()
	{
		var self      = this,
			container = self.getDropdownContainer(),
			direction = self.opts(OPT_DIRECTION),
			height    = self.core().getWrapContainer().outerHeight(),
			css       = {}
			;

		css[direction === POSITION_ABOVE ? 'bottom' : 'top'] = height + 'px';
		container.css(css);
	};

	p.getSuggestionElements = function()
	{
		return this.getDropdownContainer().find(CSS_DOT_SUGGESTION);
	};

	p.setSelectedSuggestion = function(suggestion)
	{
		if(!suggestion)
			return;

		var self   = this,
			all    = self.getSuggestionElements(),
			target = all.first(),
			item, i
			;
<commit_msg>Fixed autocomplete still looking for the old `direction` option.<commit_after>(function($)
{
	function TextExtAutocomplete()
	{
	};

	$.fn.textext.TextExtAutocomplete = TextExtAutocomplete;
	$.fn.textext.addPlugin('autocomplete', TextExtAutocomplete);

	var p = TextExtAutocomplete.prototype,
		
		CSS_DOT            = '.',
		CSS_SELECTED       = 'text-selected',
		CSS_DOT_SELECTED   = CSS_DOT + CSS_SELECTED,
		CSS_SUGGESTION     = 'text-suggestion',
		CSS_DOT_SUGGESTION = CSS_DOT + CSS_SUGGESTION,

		OPT_ENABLED         = 'dropdown.enabled',
		OPT_MAX_HEIGHT      = 'dropdown.maxHeight',
		OPT_POSITION        = 'dropdown.position',
		OPT_HTML_DROPDOWN   = 'html.dropdown',
		OPT_HTML_SUGGESTION = 'html.suggestion',

		EVENT_HIDE_DROPDOWN   = 'hideDropdown',
		EVENT_SHOW_DROPDOWN   = 'showDropdown',
		EVENT_GET_SUGGESTIONS = 'getSuggestions',
		EVENT_SET_SUGGESTIONS = 'setSuggestions',

		POSITION_ABOVE = 'above',
		POSITION_BELOW = 'below',

		DEFAULT_OPTS = {
			dropdown : {
				enabled   : true,
				position : POSITION_BELOW
			},

			html : {
				dropdown   : '<div class="text-dropdown"><div class="text-list"/></div>',
				suggestion : '<div class="text-suggestion"><span class="text-label"/></div>'
			}
		}
		;

	p.init = function(parent)
	{
		var self = this;

		self.baseInit(parent, DEFAULT_OPTS);

		var input = self.input(),
			container
			;

		if(self.opts(OPT_ENABLED) === true)
		{
			self.on({
				click          : self.onClick,
				blur           : self.onBlur,
				otherKeyUp     : self.onOtherKeyUp,
				deleteKeyUp    : self.onOtherKeyUp,
				backspaceKeyUp : self.onBackspaceKeyUp,
				downKeyDown    : self.onDownKeyDown,
				upKeyDown      : self.onUpKeyDown,
				enterKeyDown   : self.onEnterKeyDown,
				escapeKeyUp    : self.onEscapeKeyUp,
				setSuggestions : self.onSetSuggestions,
				showDropdown   : self.onShowDropdown,
				hideDropdown   : self.onHideDropdown,
				postInvalidate : self.positionDropdown
			});

			input.after(self.opts(OPT_HTML_DROPDOWN));
			container = self.getDropdownContainer();
			container
				.mouseover(function(e) { self.onMouseOver(e) })
				.addClass('text-position-' + self.opts(OPT_POSITION))
				;

			self.positionDropdown();
		}
	};

	/**
	 * Returns top level dropdown container HTML element.
	 * @author agorbatchev
	 * @date 2011/08/15
	 */
	p.getDropdownContainer = function()
	{
		return this.input().siblings('.text-dropdown');
	};

	//--------------------------------------------------------------------------------
	// User mouse/keyboard input
	
	p.onMouseOver = function(e)
	{
		var self   = this,
			target = $(e.target)
			;

		if(target.is(CSS_DOT_SUGGESTION))
		{
			self.clearSelected();
			target.addClass(CSS_SELECTED);
		}
	};

	p.onClick = function(e)
	{
		var self   = this,
			target = $(e.target)
			;

		if(target.is(CSS_DOT_SUGGESTION))
			self.selectFromDropdown();
	};

	p.onBlur = function(e)
	{
		var self = this;

		// use timeout here so that onClick has a chance to fire because if
		// dropdown is hidden when clicked, onClick doesn't fire
		if(self.isDropdownVisible())
			setTimeout(function() { self.trigger(EVENT_HIDE_DROPDOWN) }, 100);
	};

	p.onBackspaceKeyUp = function(e)
	{
		var self = this,
			isEmpty = self.input().val().length > 0
			;

		if(isEmpty || self.isDropdownVisible())
			self.getSuggestions();
	};

	p.onOtherKeyUp = function(e)
	{
		this.getSuggestions();
	};

	p.onDownKeyDown = function(e)
	{
		var self = this;

		self.isDropdownVisible()
			? self.toggleNextSuggestion() 
			: self.getSuggestions()
			;
	};

	p.onUpKeyDown = function(e)
	{
		this.togglePreviousSuggestion();
	};

	p.onEnterKeyDown = function(e)
	{
		var self = this;

		if(self.isDropdownVisible())
			self.selectFromDropdown();
	};

	p.onEscapeKeyUp = function(e)
	{
		var self = this;

		if(self.isDropdownVisible())
			self.trigger(EVENT_HIDE_DROPDOWN);
	};

	//--------------------------------------------------------------------------------
	// Core functionality

	/**
	 * Positions dropdown either below or above the input based on the `dropdown.position`
	 * option specified, which could be either `above` or `below`.
	 * @author agorbatchev
	 * @date 2011/08/15
	 */
	p.positionDropdown = function()
	{
		var self      = this,
			container = self.getDropdownContainer(),
			direction = self.opts(OPT_POSITION),
			height    = self.core().getWrapContainer().outerHeight(),
			css       = {}
			;

		css[direction === POSITION_ABOVE ? 'bottom' : 'top'] = height + 'px';
		container.css(css);
	};

	p.getSuggestionElements = function()
	{
		return this.getDropdownContainer().find(CSS_DOT_SUGGESTION);
	};

	p.setSelectedSuggestion = function(suggestion)
	{
		if(!suggestion)
			return;

		var self   = this,
			all    = self.getSuggestionElements(),
			target = all.first(),
			item, i
			;

{'fraction_non_alphanumeric': 0.1620012533946104, 'fraction_numerical': 0.004177982034677251, 'mean_word_length': 2.8162614587485053, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '1346722', 'n_tokens_mistral': 3838, 'n_tokens_neox': 3256, 'n_words': 560}