<commit_before>/*
---

name: List

description: Provide a list of items.

license: MIT-style license.

authors:
	- <NAME> (<EMAIL>)

requires:
	- Control
	- ListStyle

provides:
	- List

...
*/

Moobile.List = new Class({

	Extends: Moobile.Control,

	selectedItem: null,

	selectedItemIndex: -1,

	options: {
		className: 'list',
		styleName: Moobile.ListStyle.Default
	},

	build: function(element) {

		this.parent(element);

		var content = this.getElement('ul');
		if (content == null) {
			content = new Element('ul');
			content.ingest(this.content);
			content.inject(this.content);
		}

		this.content = content;

		return this;
	},

	setSelectedItem: function(selectedItem) {

		if (selectedItem.isSelectable() == false)
			return this;

		if (this.selectedItem == selectedItem)
			return this;

		if (this.selectedItem) {
			this.selectedItem.setSelected(false);
			this.selectedItem = null;
			this.fireEvent('deselect', this.selectedItem);
		}

		if (selectedItem) {
			this.selectedItem = selectedItem;
			this.selectedItem.setSelected(true);
			this.fireEvent('select', this.selectedItem);
		}

		this.selectedItemIndex = selectedItem ? this.childViews.indexOf(selectedItem) : -1;

		return this;
	},

	setSelectedItemIndex: function(index) {

		var selectedItem = this.childViews[index];
		if (selectedItem) {
			this.setSelectedItem(selectedItem);
		}

		return this;
	},

	addItem: function(item, where, context) {
		return this.addChildView(item, where, context);
	},

	getItem: function(name) {
		return this.getChildView(name);
	},

	removeItem: function(item) {
		return this.removeChildView(item);
	},

	clearItems: function() {
		return this.removeChildViews();
	},

	didAddChildView: function(item) {

		this.parent(item);

		if (item instanceof Moobile.ListItem) {
			item.addEvent('click', this.bound('onItemClick'));
			item.addEvent('mouseup', this.bound('onItemMouseUp'));
			item.addEvent('mousedown', this.bound('onItemMouseDown'));
		}

		return this;
	},

	didRemoveChildView: function(item) {

		this.parent(item);

		if (item instanceof Moobile.ListItem) {
			item.removeEvent('click', this.bound('onItemClick'));
			item.removeEvent('mouseup', this.bound('onItemMouseUp'));
			item.removeEvent('mousedown', this.bound('onItemMouseDown'));
		}

		return this;
	},

	onItemClick: function(e) {
		var item = e.target;
		if (this.selectable) this.setSelectedItem(item);
		this.fireEvent('click', e);
		return this;
	},

	onItemMouseUp: function(e) {
		var item = e.target;
		if (this.highlightable) item.setHighlighted(false);
		this.fireEvent('mouseup', e);
		return this;
	},

	onItemMouseDown: function(e) {
		var item = e.target;
		if (this.highlightable) item.setHighlighted(true);
		this.fireEvent('mousedown', e);
		return this;
	}

});
<commit_msg>Fixed a bug where deselecting and item was not possible<commit_after>/*
---

name: List

description: Provide a list of items.

license: MIT-style license.

authors:
	- <NAME> (<EMAIL>)

requires:
	- Control
	- ListStyle

provides:
	- List

...
*/

Moobile.List = new Class({

	Extends: Moobile.Control,

	selectedItem: null,

	selectedItemIndex: -1,

	options: {
		className: 'list',
		styleName: Moobile.ListStyle.Default
	},

	build: function(element) {

		this.parent(element);

		var content = this.getElement('ul');
		if (content == null) {
			content = new Element('ul');
			content.ingest(this.content);
			content.inject(this.content);
		}

		this.content = content;

		return this;
	},

	setSelectedItem: function(selectedItem) {

		if (selectedItem && selectedItem.isSelectable() == false)
			return this;

		if (this.selectedItem == selectedItem)
			return this;

		if (this.selectedItem) {
			this.selectedItem.setSelected(false);
			this.selectedItem = null;
			this.fireEvent('deselect', this.selectedItem);
		}

		if (selectedItem) {
			this.selectedItem = selectedItem;
			this.selectedItem.setSelected(true);
			this.fireEvent('select', this.selectedItem);
		}

		this.selectedItemIndex = selectedItem ? this.childViews.indexOf(selectedItem) : -1;

		return this;
	},

	setSelectedItemIndex: function(index) {
		this.setSelectedItem(this.childViews[index] || null);
		return this;
	},

	addItem: function(item, where, context) {
		return this.addChildView(item, where, context);
	},

	getItem: function(name) {
		return this.getChildView(name);
	},

	removeItem: function(item) {
		return this.removeChildView(item);
	},

	clearItems: function() {
		return this.removeChildViews();
	},

	didAddChildView: function(item) {

		this.parent(item);

		if (item instanceof Moobile.ListItem) {
			item.addEvent('click', this.bound('onItemClick'));
			item.addEvent('mouseup', this.bound('onItemMouseUp'));
			item.addEvent('mousedown', this.bound('onItemMouseDown'));
		}

		return this;
	},

	didRemoveChildView: function(item) {

		this.parent(item);

		if (item instanceof Moobile.ListItem) {
			item.removeEvent('click', this.bound('onItemClick'));
			item.removeEvent('mouseup', this.bound('onItemMouseUp'));
			item.removeEvent('mousedown', this.bound('onItemMouseDown'));
		}

		return this;
	},

	onItemClick: function(e) {
		var item = e.target;
		if (this.selectable) this.setSelectedItem(item);
		this.fireEvent('click', e);
		return this;
	},

	onItemMouseUp: function(e) {
		var item = e.target;
		if (this.highlightable) item.setHighlighted(false);
		this.fireEvent('mouseup', e);
		return this;
	},

	onItemMouseDown: function(e) {
		var item = e.target;
		if (this.highlightable) item.setHighlighted(true);
		this.fireEvent('mousedown', e);
		return this;
	}

});

{'fraction_non_alphanumeric': 0.14731182795698924, 'fraction_numerical': 0.0007168458781362007, 'mean_word_length': 4.201304753028891, 'pattern_counts': {'":': 0, '<': 7, '<?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': '475349', 'n_tokens_mistral': 2109, 'n_tokens_neox': 1868, 'n_words': 366}