|
1
|
|
|
// Copyright Zikula Foundation, licensed MIT. |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Initialises a user field with auto completion. |
|
5
|
|
|
*/ |
|
6
|
|
|
function initUserLiveSearch(fieldName) |
|
7
|
|
|
{ |
|
8
|
|
|
jQuery('#' + fieldName + 'ResetVal').click( function (event) { |
|
9
|
|
|
event.preventDefault(); |
|
10
|
|
|
jQuery('#' + fieldName).val(''); |
|
11
|
|
|
jQuery('#' + fieldName + 'Selector').val(''); |
|
12
|
|
|
}).removeClass('hidden'); |
|
13
|
|
|
|
|
14
|
|
|
if (jQuery('#' + fieldName + 'LiveSearch').length < 1) { |
|
15
|
|
|
return; |
|
16
|
|
|
} |
|
17
|
|
|
jQuery('#' + fieldName + 'LiveSearch').removeClass('hidden'); |
|
18
|
|
|
|
|
19
|
|
|
jQuery('#' + fieldName + 'Selector').autocomplete({ |
|
20
|
|
|
minLength: 1, |
|
21
|
|
|
open: function(event, ui) { |
|
|
|
|
|
|
22
|
|
|
jQuery(this).autocomplete('widget').css({ |
|
23
|
|
|
width: (jQuery(this).outerWidth() + 'px') |
|
24
|
|
|
}); |
|
25
|
|
|
}, |
|
26
|
|
|
source: function (request, response) { |
|
27
|
|
|
jQuery.getJSON(Routing.generate('zikulausersmodule_livesearch_getusers', { fragment: request.term }), function(data) { |
|
|
|
|
|
|
28
|
|
|
response(data); |
|
29
|
|
|
}); |
|
30
|
|
|
}, |
|
31
|
|
|
response: function(event, ui) { |
|
32
|
|
|
jQuery('#' + fieldName + 'LiveSearch .empty-message').remove(); |
|
33
|
|
|
if (ui.content.length === 0) { |
|
34
|
|
|
jQuery('#' + fieldName + 'LiveSearch').append('<div class="empty-message">' + Translator.__('No results found!') + '</div>'); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
}, |
|
37
|
|
|
focus: function(event, ui) { |
|
38
|
|
|
jQuery('#' + fieldName + 'Selector').val(ui.item.uname); |
|
39
|
|
|
|
|
40
|
|
|
return false; |
|
41
|
|
|
}, |
|
42
|
|
|
select: function(event, ui) { |
|
43
|
|
|
jQuery('#' + fieldName).val(ui.item.uid); |
|
44
|
|
|
jQuery('#' + fieldName + 'Avatar').html(ui.item.avatar); |
|
45
|
|
|
|
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
}) |
|
49
|
|
|
.autocomplete('instance')._renderItem = function(ul, item) { |
|
50
|
|
|
return jQuery('<div class="suggestion">') |
|
51
|
|
|
.append('<div class="media"><div class="media-left"><a href="javascript:void(0)">' + item.avatar + '</a></div><div class="media-body"><p class="media-heading">' + item.uname + '</p></div></div>') |
|
52
|
|
|
.appendTo(ul); |
|
53
|
|
|
}; |
|
54
|
|
|
} |
|
55
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.