Target user names in chat rooms with @[username].
$ component install AndreasKlein/user-targeting
<input type="text" id="input">
Initialize:
var $input = $('#input'),
getUserNames = function() { return ["John Doe", "Max Mustermann"]; },
dropdownView = UserTargeting.initDropdown($input, getUserNames);
Use targeting api:
var targeting = UserTargeting.targeting();
message = "Hi @John Doe and @Max Mustermann"
message = targeting.wrapUserNames(message, getUserNames(), "Max Mustermann");
if (targeting.referencesName(message, "John Doe")) {
//do something hip
}
You can also use targeting.referencesEveryone or targeting.referencesNameOrEveryone
MIT