From 4a19c292fb444dca840591a5ccec960d63ab57b8 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Sun, 13 Sep 2009 21:44:17 -0400 Subject: Make a new REST service for the autocomplete plugin, significantly reducing the size of the responses. Also enables caching in the browser. --- plugins/Autocomplete/Autocomplete.js | 51 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'plugins/Autocomplete/Autocomplete.js') diff --git a/plugins/Autocomplete/Autocomplete.js b/plugins/Autocomplete/Autocomplete.js index dfadea004..3eff685a8 100644 --- a/plugins/Autocomplete/Autocomplete.js +++ b/plugins/Autocomplete/Autocomplete.js @@ -1,38 +1,37 @@ $(document).ready(function(){ - $.getJSON($('address .url')[0].href+'/api/statuses/friends.json?user_id=' + current_user['id'] + '&lite=true&callback=?', - function(friends){ - $('#notice_data-text').autocomplete(friends, { + $('#notice_data-text').autocomplete($('address .url')[0].href+'/plugins/Autocomplete/autocomplete.json', { multiple: true, multipleSeparator: " ", minChars: 1, formatItem: function(row, i, max){ - return '@' + row.screen_name + ' (' + row.name + ')'; + row = eval("(" + row + ")"); + switch(row.type) + { + case 'user': + return row.nickname + ' (' + row.fullname + ')'; + case 'group': + return row.nickname + ' (' + row.fullname + ')'; + } }, formatMatch: function(row, i, max){ - return '@' + row.screen_name; + row = eval("(" + row + ")"); + switch(row.type) + { + case 'user': + return row.nickname; + case 'group': + return row.nickname; + } }, formatResult: function(row){ - return '@' + row.screen_name; + row = eval("(" + row + ")"); + switch(row.type) + { + case 'user': + return '@' + row.nickname; + case 'group': + return '!' + row.nickname; + } } }); - } - ); - $.getJSON($('address .url')[0].href+'/api/statusnet/groups/list.json?user_id=' + current_user['id'] + '&callback=?', - function(groups){ - $('#notice_data-text').autocomplete(groups, { - multiple: true, - multipleSeparator: " ", - minChars: 1, - formatItem: function(row, i, max){ - return '!' + row.nickname + ' (' + row.fullname + ')'; - }, - formatMatch: function(row, i, max){ - return '!' + row.nickname; - }, - formatResult: function(row){ - return '!' + row.nickname; - } - }); - } - ); }); -- cgit v1.2.3-54-g00ecf