Is it possible to show profile avatars when searching usernames?
Just like Twitter and Facebook is it possible to make the profile avatar show up in the auto complete drop down when you type the username in a search field / receipient box?
Best Answers
-
hgtonight MVP
Welcome to the community!
Yes, but it will break with the next major release as 2.2 switched to a more modern token plugin rather than the autocomplete plugin currently in 2.1.
You need to override the Autocomplete method on the UserController and then modify the formatting of items via the Autocompleter JS plugin.
public function UserController_AutoComplete_Create($Sender) { $Sender->DeliveryType(DELIVERY_TYPE_NONE); $Q = GetIncomingValue('q'); $UserModel = new UserModel(); $Data = $UserModel->GetLike(array('u.Name' => $Q), 'u.Name', 'asc', 10, 0); foreach($Data->Result() as $User) { echo htmlspecialchars($User->Name) . '|' . Gdn_Format::Text($User->UserID) . '|' . UserPhoto($User) . "\n"; } $Sender->Render(); } public function MessagesController_Render_Before($Sender) { $Sender->AddJsFile($this->GetResource('js/avatarandnames.js', FALSE, FALSE)); }
And for the JS file (named avatarandnames.js in this example):
jQuery(document).ready(function($) { $.Autocompleter.defaults['formatItem'] = function(row) { return row[2] + row[0]; }; });
What this does is append the user avatar to the backend auto-complete function. Then it parses that data on the front end for display.
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
8 -
hgtonight MVP
I do not know when 2.3 (which is the next open source release) will be released, although @Linc has hinted the beta cycle will be coming here: http://vanillaforums.org/discussion/27490/getting-ready-for-2-1-1
The new token plugin seems like it will be easier to plug into.
Basically, I wouldn't worry about it breaking. Just make a note so you remember when 2.3 comes out.
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
5
Answers
Welcome to the community!
Yes, but it will break with the next major release as 2.2 switched to a more modern token plugin rather than the autocomplete plugin currently in 2.1.
You need to override the Autocomplete method on the UserController and then modify the formatting of items via the Autocompleter JS plugin.
And for the JS file (named avatarandnames.js in this example):
What this does is append the user avatar to the backend auto-complete function. Then it parses that data on the front end for display.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Thanks for your reply - do you know when 2.2 is being released. So if we used this code it will prevent us from updating to 2.2?
I do not know when 2.3 (which is the next open source release) will be released, although @Linc has hinted the beta cycle will be coming here: http://vanillaforums.org/discussion/27490/getting-ready-for-2-1-1
The new token plugin seems like it will be easier to plug into.
Basically, I wouldn't worry about it breaking. Just make a note so you remember when 2.3 comes out.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Next openxsource version is 2.3 and not 2.2
There was an error rendering this rich post.