aboutsummaryrefslogtreecommitdiff
path: root/js/lib/autocomplete.js
blob: eb59f51aac4ace65144aedf5d9fb87cbb754b8db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * 
 */
elgg.provide('elgg.autocomplete');

elgg.autocomplete.init = function() {
	$('.elgg-input-autocomplete').autocomplete({
		source: elgg.autocomplete.url, //gets set by input/autocomplete
		minLength: 1,
		select: function(event, ui) {
			var item = ui.item;
			$(this).val(item.name);
	
			var hidden = $(this).next();
			hidden.val(item.guid);
		}
	})
	
	//@todo This seems convoluted
	.data("autocomplete")._renderItem = function(ul, item) {
		switch (item.type) {
			case 'user':
			case 'group':
				r = item.icon + item.name + ' - ' + item.desc;
				break;

			default:
				r = item.name + ' - ' + item.desc;
				break;
		}
		
		return $("<li/>")
			.data("item.autocomplete", item)
			.append(r)
			.appendTo(ul);
	};
};

elgg.register_event_handler('init', 'system', elgg.autocomplete.init);