Advanced Summernote with AJAX, Fuse Fuzzy Search, Avatars and ID Bindings
I needed to create a chat application for a NodeJS project, one of the main elements is a form input where users can post their initial messages. I was having i
I needed to create a chat application for a NodeJS project, one of the main elements is a form input where users can post their initial messages. I was having issues with adding @mentions into a summernote lite text area - turned out to be a lot of work so I thought I'd post my code here in case anyone else needs a leg up.. It's all part of my little attempts to put back a little of what I've taken out from this excellent forum
This isn't really intended to be a tutorial but I'll briefly explain what the code does:
Takes live data from an internal (JSON Array) API feed - would work on any public API data format for this one is [{"uid":73382,"firstname":"Joe","surname":"Bloggs","image":"73382.jpg"}
Uses Summernote hints to facilitate an @mentions type search of users in the API above
Uses Fuse.js to provide fuzzy search, firstnames and surnames can be weighted in the search
Includes preloaded avatars in the selection list, its very lightweight
Includes a nifty shimmering placeholder whilst images load
fallback avatar for when images don't load
Changes the stored image filename on-the-fly - I have the users avatar stored in three different versions on the server, but only one filename listed in the db (DUH) so I had to change the listed filename from what is in the db 12345.jpg to the one we plan to use that is stored in the file system 12345-avatar100.jpg
Uses a hidden txt field to send an array of selected @mentions UIDs during submit for backend processing
Real-time preview 'Tagged Users' in a list below the textarea - this also includes the users avatar.
Notes Doesn't like to work with jquery slim hence the 'full fat' version here jquery="cdn"
Its reasonably difficult to debug as some of the errors are completely silent, use your AI of choice to help you - it'll do a grand job. Wapplers internal AI is a great place to start - it's getting really good.
The search allows for seperate weighting for each search term - A threshold of 0.0 requires a perfect match (of both letters and location), a threshold of 1.0 would match anything. Theres more info on the fuzzy search here, Its great for small to reasonably large datasets.: