| 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 |  |  |         source: function (request, response) { | 
            
                                                        
            
                                    
            
            
                | 22 |  |  |             jQuery.getJSON(Routing.generate('zikulausersmodule_livesearch_getusers', { fragment: request.term }), function(data) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |                 response(data); | 
            
                                                        
            
                                    
            
            
                | 24 |  |  |             }); | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |         }, | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |         response: function(event, ui) { | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |             if (ui.content.length === 0) { | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |                 jQuery('#' + fieldName + 'LiveSearch').append('<div class="empty-message">' + Translator.__('No results found!') + '</div>'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |             } else { | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |                 jQuery('#' + fieldName + 'LiveSearch .empty-message').remove(); | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |         }, | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |         focus: function(event, ui) { | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |             jQuery('#' + fieldName + 'Selector').val(ui.item.uname); | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |             return false; | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |         }, | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |         select: function(event, ui) { | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |             jQuery('#' + fieldName).val(ui.item.uid); | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |             jQuery('#' + fieldName + 'Avatar').html(ui.item.avatar); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |             return false; | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |     }) | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |     .autocomplete('instance')._renderItem = function(ul, item) { | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         return jQuery('<div class="suggestion">') | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |             .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>') | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             .appendTo(ul); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |     }; | 
            
                                                        
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                        
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.