<commit_before>/*
 UI components 
 (c) <NAME>, 2008,2012
 All rights reserved.
 Assumes Binding.js already loaded
*/

Meeko.UI = (function() {

var _ = Meeko.stuff, extend = _.extend, forEach = _.forEach;
var DOM = Meeko.DOM, $id = DOM.$id, $ = DOM.$, $$ = DOM.$$;
var xbl = Meeko.xbl, Binding = xbl.Binding, baseBinding = xbl.baseBinding;

function declareProperties(obj, props) {
	forEach(props.split(/\s+/), function(prop) {
		var Prop = ucFirst(prop);
		var getter = 'get' + Prop, setter = 'set' + Prop;
		Object.defineProperty(obj, prop, {
			get: obj[getter],
			set: obj[setter]
		});
	});
}

function ucFirst(text) {
	return text.substr(0,1).toUpperCase() + text.substr(1);
}

var box = baseBinding.evolve({

setHidden: function(state) {
	var element = this.boundElement;
	element.hidden = !!state;
},

getHidden: function() {
	var element = this.boundElement;
	return element.hidden;
}

});

declareProperties(box.prototype, 'hidden');

var treeitem = baseBinding.evolve({

getListElement: function() {

	var element = this.boundElement;
	var children = element.children;
	for (var node, i=0; node=children.item(i); i++) {
		switch (node.tagName.toLowerCase()) {
			case "ol": case "ul": case "select": return node;	
		}
	}	
	return null;
		
},
setSelected: function(state) { // NOTE treeitem is ignorant of whether multiple treeitems can be selected
	var element = this.boundElement;
	element.setAttribute("aria-selected", !!state);
},
getSelected: function() {
	var element = this.boundElement;
	var state = element.getAttribute("aria-selected");
	return (/^true$/i.test(state));	
},
setExpanded: function(state) {
	
	var element = this.boundElement;
	var listEl = this.getListElement();
	if (!listEl) throw "";
	list.getBindingFor(listEl).setHidden(state);

},
getExpanded: function() {
	
	var element = this.boundElement;
	var listEl = this.getListElement();
	if (!listEl) throw "";
	return list.getBindingFor(listEl).getHidden();

}

});

declareProperties(treeitem.prototype, 'listElement selected expanded');

var listitem = treeitem;

var list = box.evolve({

getItems: function() {
	
	var element = this.boundElement;
	return element.children;

},

setHidden: function(state) {
	var element = this.boundElement;
	element.hidden = !!state;
},

getHidden: function() {
	var element = this.boundElement;
	return element.hidden;
}

});

declareProperties(list.prototype, 'hidden');


var tree = box.evolve({

getListElement: treeitem.prototype.getListElement,

getSelectedItem: function() { // FIXME this only searches the top list, not the whole tree

	var items = list.getBindingFor(this.getListElement()).getItems();
	var n = items.length;
	for (var i=0; i<n; i++) {
		var node = items.item(i);
		var binding = treeitem.getBindingFor(node);
		if (binding.getSelected()) return node;
	}
	return null;
		
},
selectItem: function(item) {

	var listEl = this.getListElement();
	if (item && item.parentNode != listEl) throw "Element doesn't exist in list";
	var items = list.getBindingFor(listEl).getItems();
	var n = items.length;
	for (var i=0; i<n; i++) {
		var node = items[i];
		var binding = treeitem.getBindingFor(node);
		if (node === item) binding.setSelected(true);
		if (node !== item) binding.setSelected(false);
	}
	this.signalChange();
		
},
signalChange: function() {
	
	var element = this.boundElement;
	var document = element.ownerDocument;
	var event = document.createEvent("Event");
	event.initEvent("change", false, true);
	return element.dispatchEvent(event);
			
}

},
[
{
	type: "click",
	action: function(event) {
		var element = this.boundElement;
		var item = event.target;
		while (item.tagName.toLowerCase() != "li") {
			if (item == element) return;
			item = item.parentNode;
		}
		this.selectItem(item);
	}
}
]);

declareProperties(tree.prototype, 'listElement selectedIndex selectedItem');


var navtreeitem = treeitem.evolve({

getView: function() {
	
	var element = this.boundElement;
	var document = element.ownerDocument;
	var ref = this.boundElement.firstElementChild;
	var tagName = ref.tagName.toLowerCase();
	switch(tagName) {
	case "a":
		if (!ref.getAttribute("href")) break;
		var href = ref.href;
//		var base = document.documentURI + "#";
		var base = document.URL + "#";
		if (href.indexOf(base) != 0) break;
		var id = href.replace(base, "");
		return $id(id);<commit_msg>Was assuming document.URL wouldn't have a hash (#)<commit_after>/*
 UI components 
 (c) <NAME>, 2008,2012
 All rights reserved.
 Assumes Binding.js already loaded
*/

Meeko.UI = (function() {

var _ = Meeko.stuff, extend = _.extend, forEach = _.forEach;
var DOM = Meeko.DOM, $id = DOM.$id, $ = DOM.$, $$ = DOM.$$;
var xbl = Meeko.xbl, Binding = xbl.Binding, baseBinding = xbl.baseBinding;

function declareProperties(obj, props) {
	forEach(props.split(/\s+/), function(prop) {
		var Prop = ucFirst(prop);
		var getter = 'get' + Prop, setter = 'set' + Prop;
		Object.defineProperty(obj, prop, {
			get: obj[getter],
			set: obj[setter]
		});
	});
}

function ucFirst(text) {
	return text.substr(0,1).toUpperCase() + text.substr(1);
}

var box = baseBinding.evolve({

setHidden: function(state) {
	var element = this.boundElement;
	element.hidden = !!state;
},

getHidden: function() {
	var element = this.boundElement;
	return element.hidden;
}

});

declareProperties(box.prototype, 'hidden');

var treeitem = baseBinding.evolve({

getListElement: function() {

	var element = this.boundElement;
	var children = element.children;
	for (var node, i=0; node=children.item(i); i++) {
		switch (node.tagName.toLowerCase()) {
			case "ol": case "ul": case "select": return node;	
		}
	}	
	return null;
		
},
setSelected: function(state) { // NOTE treeitem is ignorant of whether multiple treeitems can be selected
	var element = this.boundElement;
	element.setAttribute("aria-selected", !!state);
},
getSelected: function() {
	var element = this.boundElement;
	var state = element.getAttribute("aria-selected");
	return (/^true$/i.test(state));	
},
setExpanded: function(state) {
	
	var element = this.boundElement;
	var listEl = this.getListElement();
	if (!listEl) throw "";
	list.getBindingFor(listEl).setHidden(state);

},
getExpanded: function() {
	
	var element = this.boundElement;
	var listEl = this.getListElement();
	if (!listEl) throw "";
	return list.getBindingFor(listEl).getHidden();

}

});

declareProperties(treeitem.prototype, 'listElement selected expanded');

var listitem = treeitem;

var list = box.evolve({

getItems: function() {
	
	var element = this.boundElement;
	return element.children;

},

setHidden: function(state) {
	var element = this.boundElement;
	element.hidden = !!state;
},

getHidden: function() {
	var element = this.boundElement;
	return element.hidden;
}

});

declareProperties(list.prototype, 'hidden');


var tree = box.evolve({

getListElement: treeitem.prototype.getListElement,

getSelectedItem: function() { // FIXME this only searches the top list, not the whole tree

	var items = list.getBindingFor(this.getListElement()).getItems();
	var n = items.length;
	for (var i=0; i<n; i++) {
		var node = items.item(i);
		var binding = treeitem.getBindingFor(node);
		if (binding.getSelected()) return node;
	}
	return null;
		
},
selectItem: function(item) {

	var listEl = this.getListElement();
	if (item && item.parentNode != listEl) throw "Element doesn't exist in list";
	var items = list.getBindingFor(listEl).getItems();
	var n = items.length;
	for (var i=0; i<n; i++) {
		var node = items[i];
		var binding = treeitem.getBindingFor(node);
		if (node === item) binding.setSelected(true);
		if (node !== item) binding.setSelected(false);
	}
	this.signalChange();
		
},
signalChange: function() {
	
	var element = this.boundElement;
	var document = element.ownerDocument;
	var event = document.createEvent("Event");
	event.initEvent("change", false, true);
	return element.dispatchEvent(event);
			
}

},
[
{
	type: "click",
	action: function(event) {
		var element = this.boundElement;
		var item = event.target;
		while (item.tagName.toLowerCase() != "li") {
			if (item == element) return;
			item = item.parentNode;
		}
		this.selectItem(item);
	}
}
]);

declareProperties(tree.prototype, 'listElement selectedIndex selectedItem');


var navtreeitem = treeitem.evolve({

getView: function() {
	
	var element = this.boundElement;
	var document = element.ownerDocument;
	var ref = this.boundElement.firstElementChild;
	var tagName = ref.tagName.toLowerCase();
	switch(tagName) {
	case "a":
		if (!ref.getAttribute("href")) break;
		var href = ref.href;
//		var base = document.documentURI + "#";
		var base = document.URL.replace(/#.*$/, '')  + "#";
		if (href.indexOf(base) != 0) break;
		var id = href.replace(base, "");
		return $id(id);
{'fraction_non_alphanumeric': 0.15493119266055047, 'fraction_numerical': 0.0034403669724770644, 'mean_word_length': 4.433644859813084, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 5, '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': '3409860', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2901, 'n_words': 722}