<commit_before>/**
 * SuggestionInput
 * @author <NAME> <<EMAIL>>
 */

(function ($) {
	$.fn.suggestionInput = function (options) {

		var si = this;
		si.timeout = false;
		si.kb = new SuggestionInputKeyboard;
		si.suggestListContainerDefaultClass = 'suggestion-input-typeahead';
		si.suggestionInputContainerDefaultClass = 'suggestion-input-container';
		si.settings = $.extend({
			startSuggest: 3,
			openOnClick: false,
			suggestTimeout: 350,
			suggestListContainerClass: 'dropdown-menu',
			suggestionInputContainerClass: '',
			suggestListActiveClass: 'active',
			dataLinkName: 'suggestionInput',
			filterAlias: 'suggestionInputValue'
		}, options);

		/**
		 * Get suggestion input container
		 * @param $input
		 * @returns {XML|*}
		 */
		this.getSuggestionInputContainer = function ($input) {
			return $($input).parent('.' + si.suggestionInputContainerDefaultClass);
		};

		/**
		 * Create suggestion input container
		 * @param $input
		 * @returns {XML|*}
		 */
		this.createSuggestionInputContainer = function ($input) {
			if ($input.parent().hasClass(si.suggestionInputContainerDefaultClass)) {
				return $input.parent();
			} else {
				var container = $('<div/>').addClass(si.suggestionInputContainerDefaultClass);
				$input.before(container);
				container.append($input);
				return container;
			}
		};

		/**
		 * Get link to signal
		 * @param $input
		 * @returns {*}
		 */
		this.getSignalLink = function ($input) {
			var data = $($input).data(si.settings.dataLinkName);
			if (data == undefined) {
				return false;
			}
			return data.replace('%25' + si.settings.filterAlias + '%25', $($input).val());
		};

		/**
		 * Create SuggestListContainer
		 * @param $input
		 * @returns {*}
		 */
		this.createSuggestListContainer = function ($input) {
			var suggestionInputContainer = si.getSuggestionInputContainer($input);

			if ($input.next().hasClass(si.suggestListContainerDefaultClass)) {
				var suggestListContainer = $input.next();
			} else {
				var suggestListContainer = $('<ul/>').addClass(si.suggestListContainerDefaultClass);
				suggestionInputContainer.append(suggestListContainer);
			}

			suggestListContainer
				.addClass(si.settings.suggestListContainerClass)
				.css({
					minWidth: $($input).innerWidth() + "px"
				})
				.hide();

			$($input).css({
				marginBottom: "0px"
			});

			return suggestListContainer;
		};

		/**
		 * Get SuggestListContainer
		 * @param $input
		 * @returns {*}
		 */
		this.getSuggestListContainer = function ($input) {
			var suggestionInputContainer = si.getSuggestionInputContainer($input);
			return suggestionInputContainer.find('.' + si.suggestListContainerDefaultClass);
		};

		/**
		 * Hide SuggestListContainer
		 * @param $input
		 */
		this.hideSuggestListContainer = function ($input) {
			var suggestListContainer = si.getSuggestListContainer($input);
			if (suggestListContainer.is(':visible')) {
				suggestListContainer.hide();
			}
		};

		/**
		 * Show SuggestListContainer
		 * @param $input
		 */
		this.showSuggestListContainer = function ($input) {
			var suggestListContainer = si.getSuggestListContainer($input);
			if (suggestListContainer.is(':hidden')) {
				suggestListContainer.show();
			}
		};

		/**
		 * Event onChange
		 * @returns {boolean}
		 */
		this.onChange = function () {
			return false;
		};

		/**
		 * Event onBlur
		 * @param e
		 */
		this.onBlur = function (e) {
			var $input = $(this);
			setTimeout(function () {
				si.hideSuggestListContainer($input);
			}, 200);
		};

		/**
		 * Event onSuggest
		 * @param e
		 * @returns {boolean}
		 */
		this.onSuggest = function (e) {
			var $input = $(this);
			var suggestListContainer = si.getSuggestListContainer($input);

			// reset timeout
			if (si.timeout != false) clearTimeout(si.timeout);

			si.timeout = setTimeout(function () {

				// If not signal link or press kb.control key then stop suggest
				if (si.kb.control(e) || si.kb.escape(e)) {
					return false;
				}

				// Start suggest only when the value is longer than i.options.startSuggest
				// and hide suggestList
				if (si.settings.openOnClick == true) {
					if (e.type != 'click' && $input.val().length < si.settings.startSuggest) {
						return false;
					}
				} else {
					if ($input.val().length < si.settings.startSuggest) {
						return false;
					}
				}

				// Send ajax request
				$.ajax(si.getSignalLink($input), {
					success: function (payload) {
						suggestListContainer.children().remove();

						var showData = payload.use;
						if (payload.show) {
							showData = payload.show;
						}

						if (payload.use) {
							$.each(payload.use, function (i, v) {
								var item = $('<li/>')
									.html(showData[i])
									.attr('data-value', v)
									.mouseover(function () {
										suggestListContainer.children().removeClass(si.settings.suggestListActiveClass);
										$(this).addClass(si.settings.suggestListActiveClass);
									})
									.click(function (e) {
										si.hideSuggestListContainer($input);<commit_msg>Fix options openOnClick<commit_after>/**
 * SuggestionInput
 * @author <NAME> <<EMAIL>>
 */

(function ($) {
	$.fn.suggestionInput = function (options) {

		var si = this;
		si.timeout = false;
		si.kb = new SuggestionInputKeyboard;
		si.suggestListContainerDefaultClass = 'suggestion-input-typeahead';
		si.suggestionInputContainerDefaultClass = 'suggestion-input-container';
		si.settings = $.extend({
			startSuggest: 3,
			openOnClick: false,
			suggestTimeout: 350,
			suggestListContainerClass: 'dropdown-menu',
			suggestionInputContainerClass: '',
			suggestListActiveClass: 'active',
			dataLinkName: 'suggestionInput',
			filterAlias: 'suggestionInputValue'
		}, options);

		/**
		 * Get suggestion input container
		 * @param $input
		 * @returns {XML|*}
		 */
		this.getSuggestionInputContainer = function ($input) {
			return $($input).parent('.' + si.suggestionInputContainerDefaultClass);
		};

		/**
		 * Create suggestion input container
		 * @param $input
		 * @returns {XML|*}
		 */
		this.createSuggestionInputContainer = function ($input) {
			if ($input.parent().hasClass(si.suggestionInputContainerDefaultClass)) {
				return $input.parent();
			} else {
				var container = $('<div/>').addClass(si.suggestionInputContainerDefaultClass);
				$input.before(container);
				container.append($input);
				return container;
			}
		};

		/**
		 * Get link to signal
		 * @param $input
		 * @returns {*}
		 */
		this.getSignalLink = function ($input) {
			var data = $($input).data(si.settings.dataLinkName);
			if (data == undefined) {
				return false;
			}
			return data.replace('%25' + si.settings.filterAlias + '%25', $($input).val());
		};

		/**
		 * Create SuggestListContainer
		 * @param $input
		 * @returns {*}
		 */
		this.createSuggestListContainer = function ($input) {
			var suggestionInputContainer = si.getSuggestionInputContainer($input);

			if ($input.next().hasClass(si.suggestListContainerDefaultClass)) {
				var suggestListContainer = $input.next();
			} else {
				var suggestListContainer = $('<ul/>').addClass(si.suggestListContainerDefaultClass);
				suggestionInputContainer.append(suggestListContainer);
			}

			suggestListContainer
				.addClass(si.settings.suggestListContainerClass)
				.css({
					minWidth: $($input).innerWidth() + "px"
				})
				.hide();

			$($input).css({
				marginBottom: "0px"
			});

			return suggestListContainer;
		};

		/**
		 * Get SuggestListContainer
		 * @param $input
		 * @returns {*}
		 */
		this.getSuggestListContainer = function ($input) {
			var suggestionInputContainer = si.getSuggestionInputContainer($input);
			return suggestionInputContainer.find('.' + si.suggestListContainerDefaultClass);
		};

		/**
		 * Hide SuggestListContainer
		 * @param $input
		 */
		this.hideSuggestListContainer = function ($input) {
			var suggestListContainer = si.getSuggestListContainer($input);
			if (suggestListContainer.is(':visible')) {
				suggestListContainer.hide();
			}
		};

		/**
		 * Show SuggestListContainer
		 * @param $input
		 */
		this.showSuggestListContainer = function ($input) {
			var suggestListContainer = si.getSuggestListContainer($input);
			if (suggestListContainer.is(':hidden')) {
				suggestListContainer.show();
			}
		};

		/**
		 * Event onChange
		 * @returns {boolean}
		 */
		this.onChange = function () {
			return false;
		};

		/**
		 * Event onBlur
		 * @param e
		 */
		this.onBlur = function (e) {
			var $input = $(this);
			setTimeout(function () {
				si.hideSuggestListContainer($input);
			}, 200);
		};

		/**
		 * Event onSuggest
		 * @param e
		 * @returns {boolean}
		 */
		this.onSuggest = function (e) {
			var $input = $(this);
			var suggestListContainer = si.getSuggestListContainer($input);

			// reset timeout
			if (si.timeout != false) clearTimeout(si.timeout);

			si.timeout = setTimeout(function () {

				// If not signal link or press kb.control key then stop suggest
				if (si.kb.control(e) || si.kb.escape(e)) {
					return false;
				}

				// Start suggest only when the value is longer than i.options.startSuggest
				// and hide suggestList
				if (si.settings.openOnClick == true) {
					if (e.type != 'click' &&  $input.val().length < si.settings.startSuggest) {
						return false;
					}else if(e.type == 'click' && suggestListContainer.is(':visible')){
						return false;
					}
				} else {
					if ($input.val().length < si.settings.startSuggest) {
						return false;
					}
				}

				// Send ajax request
				$.ajax(si.getSignalLink($input), {
					success: function (payload) {
						suggestListContainer.children().remove();

						var showData = payload.use;
						if (payload.show) {
							showData = payload.show;
						}

						if (payload.use) {
							$.each(payload.use, function (i, v) {
								var item = $('<li/>')
									.html(showData[i])
									.attr('data-value', v)
									.mouseover(function () {
										suggestListContainer.children().removeClass(si.settings.suggestListActiveClass);
										$(this).addClass(si.settings.suggestListActiveClass);
									})
									.click(function (e) {
										si.hideSuggestListContainer($input);
{'fraction_non_alphanumeric': 0.14622641509433962, 'fraction_numerical': 0.0023584905660377358, 'mean_word_length': 3.128600405679513, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, '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': '1439531', 'n_tokens_mistral': 3988, 'n_tokens_neox': 2984, 'n_words': 595}