3 Jappix - An open social platform
4 These are the autocompletion tools JS script for Jappix
6 -------------------------------------------------
10 Last revision: 12/11/10
14 // Sort an array with insensitivity to the case
15 function caseInsensitiveSort(a, b) {
16 // Put the two strings into lower case
27 // Creates an array with the autocompletion results
28 function processAutocompletion(query, id) {
29 // Replace forbidden characters in regex
30 query = escapeRegex(query);
32 // Create an empty array
33 var results = new Array();
35 // Search in the roster
36 $('#' + id + ' .user').each(function() {
37 var nick = $(this).find('.name').text();
38 var regex = new RegExp('(^)' + query, 'gi');
45 results = results.sort(caseInsensitiveSort);
47 // Return the results array
51 // Resets the autocompletion tools
52 function resetAutocompletion(hash) {
53 $('#' + hash + ' .message-area').removeAttr('data-autocompletion-pointer').removeAttr('data-autocompletion-query');
56 // Autocompletes the chat input nick
57 function createAutocompletion(hash) {
59 var vSelector = $('#' + hash + ' .message-area');
60 var value = vSelector.val();
62 resetAutocompletion(hash);
63 var query = vSelector.attr('data-autocompletion-query');
65 // The autocompletion has not been yet launched
66 if(query == undefined) {
68 vSelector.attr('data-autocompletion-query', query);
72 var pointer = vSelector.attr('data-autocompletion-pointer');
76 i = parseInt(pointer);
78 // We get the nickname
79 var nick = processAutocompletion(query, hash)[i];
81 // Shit, this is my nick!
82 if((nick != undefined) && (nick.toLowerCase() == getMUCNick(hash).toLowerCase())) {
87 nick = processAutocompletion(query, hash)[i];
91 if(nick != undefined) {
94 quoteMyNick(hash, nick);
97 vSelector.attr('data-autocompletion-pointer', i);