<commit_before>/**
 * Select
 */
Garnish.Select = Garnish.Base.extend({

	// Properties
	// =========================================================================

	$container: null,
	$items: null,
	$selectedItems: null,

	mousedownX: null,
	mousedownY: null,
	mouseUpTimeout: null,
	callbackFrame: null,

	$focusable: null,
	$first: null,
	first: null,
	$last: null,
	last: null,

	// Public methods
	// =========================================================================

	/**
	 * Constructor
	 */
	init: function(container, items, settings)
	{
		this.$container = $(container);

		// Param mapping
		if (!settings && $.isPlainObject(items))
		{
			// (container, settings)
			settings = items;
			items = null;
		}

		// Is this already a select?
		if (this.$container.data('select'))
		{
			Garnish.log('Double-instantiating a select on an element');
			this.$container.data('select').destroy();
		}

		this.$container.data('select', this);

		this.setSettings(settings, Garnish.Select.defaults);

		this.$items = $();
		this.$selectedItems = $();

		this.addItems(items);

		// --------------------------------------------------------------------

		this.addListener(this.$container, 'click', function(ev)
		{
			if (this.ignoreClick)
			{
				this.ignoreClick = false;
			}
			else
			{
				// deselect all items on container click
				this.deselectAll(true);
			}
		});
	},

	// --------------------------------------------------------------------

	/**
	 * Get Item Index
	 */
	getItemIndex: function($item)
	{
		return this.$items.index($item[0]);
	},

	/**
	 * Is Selected?
	 */
	isSelected: function($item)
	{
		return $item.hasClass(this.settings.selectedClass);
	},

	/**
	 * Select Item
	 */
	selectItem: function($item)
	{
		if (!this.settings.multi)
		{
			this.deselectAll();
		}

		this.$first = this.$last = $item;
		this.first = this.last = this.getItemIndex($item);

		this.setFocusableItem($item);
		$item.focus();

		this._selectItems($item);
	},

	selectAll: function()
	{
		if (!this.settings.multi || !this.$items.length)
		{
			return;<commit_msg>Select::isSelected() is now only concerned with if it's in $selectedItems<commit_after>/**
 * Select
 */
Garnish.Select = Garnish.Base.extend({

	// Properties
	// =========================================================================

	$container: null,
	$items: null,
	$selectedItems: null,

	mousedownX: null,
	mousedownY: null,
	mouseUpTimeout: null,
	callbackFrame: null,

	$focusable: null,
	$first: null,
	first: null,
	$last: null,
	last: null,

	// Public methods
	// =========================================================================

	/**
	 * Constructor
	 */
	init: function(container, items, settings)
	{
		this.$container = $(container);

		// Param mapping
		if (!settings && $.isPlainObject(items))
		{
			// (container, settings)
			settings = items;
			items = null;
		}

		// Is this already a select?
		if (this.$container.data('select'))
		{
			Garnish.log('Double-instantiating a select on an element');
			this.$container.data('select').destroy();
		}

		this.$container.data('select', this);

		this.setSettings(settings, Garnish.Select.defaults);

		this.$items = $();
		this.$selectedItems = $();

		this.addItems(items);

		// --------------------------------------------------------------------

		this.addListener(this.$container, 'click', function(ev)
		{
			if (this.ignoreClick)
			{
				this.ignoreClick = false;
			}
			else
			{
				// deselect all items on container click
				this.deselectAll(true);
			}
		});
	},

	// --------------------------------------------------------------------

	/**
	 * Get Item Index
	 */
	getItemIndex: function($item)
	{
		return this.$items.index($item[0]);
	},

	/**
	 * Is Selected?
	 */
	isSelected: function(item)
	{
		if (Garnish.isJquery(item))
		{
			if (!item[0])
			{
				return false;
			}

			item = item[0];
		}

		return ($.inArray(item, this.$selectedItems) != -1);
	},

	/**
	 * Select Item
	 */
	selectItem: function($item)
	{
		if (!this.settings.multi)
		{
			this.deselectAll();
		}

		this.$first = this.$last = $item;
		this.first = this.last = this.getItemIndex($item);

		this.setFocusableItem($item);
		$item.focus();

		this._selectItems($item);
	},

	selectAll: function()
	{
		if (!this.settings.multi || !this.$items.length)
		{
			return;
{'fraction_non_alphanumeric': 0.2812933025404157, 'fraction_numerical': 0.0011547344110854503, 'mean_word_length': 2.5704863973619125, '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': '2325041', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1333, 'n_words': 258}