X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FAutocomplete%2FAutocomplete.js;h=2b031cc3132aa0d4878a123e718437099dac367a;hb=4915b0cb9ef71e9efadea26ada7a3a936f48cccc;hp=e799c11e50ae14ced17c0bf9ddb3e58f2bee4cd5;hpb=17dcf1c3170bc905e3b0fdffc804d6f7229ac61b;p=quix0rs-gnu-social.git diff --git a/plugins/Autocomplete/Autocomplete.js b/plugins/Autocomplete/Autocomplete.js index e799c11e50..2b031cc313 100644 --- a/plugins/Autocomplete/Autocomplete.js +++ b/plugins/Autocomplete/Autocomplete.js @@ -1,38 +1,53 @@ -$(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, { - multiple: true, - multipleSeparator: " ", - minChars: 1, - formatItem: function(row, i, max){ - return '@' + row.screen_name + ' (' + row.name + ')'; - }, - formatMatch: function(row, i, max){ - return '@' + row.screen_name; - }, - formatResult: function(row){ - return '@' + row.screen_name; - } - }); +(function(SN, $) { + +var origInit = SN.Init.NoticeFormSetup; +SN.Init.NoticeFormSetup = function(form) { + origInit(form); + + // Only attach to traditional-style forms + var textarea = form.find('.notice_data-text:first'); + if (textarea.length == 0) { + return; + } + + function fullName(row) { + if (typeof row.fullname == "string" && row.fullname != '') { + return row.nickname + ' (' + row.fullname + ')'; + } else { + return row.nickname; } - ); - $.getJSON($('address .url')[0].href+'/api/laconica/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){ + } + + var apiUrl = $('#autocomplete-api').attr('data-url'); + textarea.autocomplete(apiUrl, { + multiple: true, + multipleSeparator: " ", + minChars: 1, + formatItem: function(row, i, max){ + row = eval("(" + row + ")"); + // the display:inline is because our INSANE stylesheets + // override the standard display of all img tags for no + // good reason. + var div = $('
') + .find('img').attr('src', row.avatar).end() + .find('span').text(fullName(row)).end() + return div.html(); + }, + formatMatch: function(row, i, max){ + row = eval("(" + row + ")"); + return row.nickname; + }, + formatResult: function(row){ + row = eval("(" + row + ")"); + switch(row.type) + { + case 'user': + return '@' + row.nickname; + case 'group': return '!' + row.nickname; - }, - formatResult: function(row){ - return '!' + row.nickname; - } - }); + } } - ); -}); + }); +}; + +})(SN, jQuery);