X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FAutocomplete%2FAutocomplete.js;h=2b031cc3132aa0d4878a123e718437099dac367a;hb=0b53b6768e03932f4beec6b6655763e6ecedc36d;hp=f39c1a7a7233437477f290ddab7929c4cc4d4827;hpb=daae13df1c2d202cba0769803a9ef03892495ccb;p=quix0rs-gnu-social.git diff --git a/plugins/Autocomplete/Autocomplete.js b/plugins/Autocomplete/Autocomplete.js index f39c1a7a72..2b031cc313 100644 --- a/plugins/Autocomplete/Autocomplete.js +++ b/plugins/Autocomplete/Autocomplete.js @@ -1,4 +1,15 @@ -$(document).ready(function(){ +(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 + ')'; @@ -6,27 +17,37 @@ $(document).ready(function(){ return row.nickname; } } - $('#notice_data-text').autocomplete($('address .url')[0].href+'/plugins/Autocomplete/autocomplete.json', { - multiple: true, - multipleSeparator: " ", - minChars: 1, - formatItem: function(row, i, max){ - row = eval("(" + row + ")"); - return fullName(row); - }, - 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; - } - } - }); -}); + + 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; + } + } + }); +}; + +})(SN, jQuery);