<commit_before>(function ($) {
	"use strict";

	var defaultOptions = {
		tagClass: 'badge badge-info',
		itemId: function(item) {
			return item ? item.toString() : item;
		},
		itemLabel: function(item) {
			return this.itemId(item);
		}
	};

	function TagsInput(element, options) {
		this.$element = $(element);
		this.multiple = (element.tagName === 'SELECT' && element.getAttribute('multiple'));

		this.$container = $('<div class="bootstrap-tagsinput"><input size="1" type="text" /></div>');
		this.$element.hide();
		this.$element.after(this.$container);

		this.build(options);
	}

	TagsInput.prototype = {
		constructor: TagsInput,

		addItem: function(item) {
			// Ignore falsey values, except false
			if (item !== false && !item)
				return;

			// Throw an error when trying to add an object while the itemId option was not set
			if (typeof item === "object" && this.options.itemId === defaultOptions.itemId)
				throw("Can't add objects when itemId option is not set");

			// Ignore strings only containg whitespace
			if (item.toString().match(/^\s*$/))
				return;

			// Ignore items allready added
			if ($.inArray(item, this.getItems()) !== -1)
				return;

			var $tag = $('<span class="tag ' + htmlEncode(this.options.tagClass) + '"><span class="text"></span><i class="icon-white icon-remove" data-role="remove"></i></span>');
			$(".text", $tag).text(this.options.itemLabel(item));
			$tag.data('item', item);

			$('input', this.$container).before($tag);

			if (this.$element[0].tagName === 'SELECT') {
				this.$element.append($('<option value="' + htmlEncode(this.options.itemId(item)) + '" selected>' + htmlEncode(item) + '</option>'));
			}

			this.$element.val(this.getValueFromTags(), true);
		},

		removeItem: function(item) {
			$('.tag', this.$container).filter(function(index) {
				return $(this).data('item') === item;
			}).remove();

			this.$element.val(this.getValueFromTags(), true);
		},

		// Returns the values from the items
		getValueFromTags: function() {
			var options = this.options;
			return $.map(this.getItems(), function(item) { return options.itemId(item); });
		},

		// Returns the items added as tags
		getItems: function() {
			return $.map($('.tag', this.$container), function(tag) { return $(tag).data('item'); });
		},

		build: function(options) {
			this.options = $.extend({}, defaultOptions, options);

			makeFunctionOption(this.options, 'itemId');
			makeFunctionOption(this.options, 'itemLabel');

			this.$container.on('keydown', 'input', $.proxy(function(event) {<commit_msg>Always focus input when clicking in tags input container<commit_after>(function ($) {
	"use strict";

	var defaultOptions = {
		tagClass: 'badge badge-info',
		itemId: function(item) {
			return item ? item.toString() : item;
		},
		itemLabel: function(item) {
			return this.itemId(item);
		}
	};

	function TagsInput(element, options) {
		this.$element = $(element);
		this.multiple = (element.tagName === 'SELECT' && element.getAttribute('multiple'));

		this.$container = $('<div class="bootstrap-tagsinput"><input size="1" type="text" /></div>');
		this.$element.hide();
		this.$element.after(this.$container);

		this.build(options);
	}

	TagsInput.prototype = {
		constructor: TagsInput,

		addItem: function(item) {
			// Ignore falsey values, except false
			if (item !== false && !item)
				return;

			// Throw an error when trying to add an object while the itemId option was not set
			if (typeof item === "object" && this.options.itemId === defaultOptions.itemId)
				throw("Can't add objects when itemId option is not set");

			// Ignore strings only containg whitespace
			if (item.toString().match(/^\s*$/))
				return;

			// Ignore items allready added
			if ($.inArray(item, this.getItems()) !== -1)
				return;

			var $tag = $('<span class="tag ' + htmlEncode(this.options.tagClass) + '"><span class="text"></span><i class="icon-white icon-remove" data-role="remove"></i></span>');
			$(".text", $tag).text(this.options.itemLabel(item));
			$tag.data('item', item);

			$('input', this.$container).before($tag);

			if (this.$element[0].tagName === 'SELECT') {
				this.$element.append($('<option value="' + htmlEncode(this.options.itemId(item)) + '" selected>' + htmlEncode(item) + '</option>'));
			}

			this.$element.val(this.getValueFromTags(), true);
		},

		removeItem: function(item) {
			$('.tag', this.$container).filter(function(index) {
				return $(this).data('item') === item;
			}).remove();

			this.$element.val(this.getValueFromTags(), true);
		},

		// Returns the values from the items
		getValueFromTags: function() {
			var options = this.options;
			return $.map(this.getItems(), function(item) { return options.itemId(item); });
		},

		// Returns the items added as tags
		getItems: function() {
			return $.map($('.tag', this.$container), function(tag) { return $(tag).data('item'); });
		},

		build: function(options) {
			this.options = $.extend({}, defaultOptions, options);

			makeFunctionOption(this.options, 'itemId');
			makeFunctionOption(this.options, 'itemLabel');

			this.$container.on('click', $.proxy(function(event) {
				$('input', this.$container).focus();
			}, this));

			this.$container.on('keydown', 'input', $.proxy(function(event) {
{'fraction_non_alphanumeric': 0.19399011030810193, 'fraction_numerical': 0.0011411182959300114, 'mean_word_length': 4.037356321839081, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '484070', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1615, 'n_words': 371}