Reputation: 51
In my summernote hint option I have the following
hint: {
match: /\B[@!](\w*)$/,
search: function (keyword, callback) {
callback($.grep(mentions, function (i) {
user = mentionData[i];
return user.name.indexOf(keyword) === 0;
}));
},
template: function...
content: function (i) {
var user = mentionData[i];
return $('<span>@' + user.username + '</span>')[0];
}
}
I want to be able to insert the @ or ! symbol (whichever one the user initiated the hint with) into the content option. Is there a way to pass the keyword to the content function? or is there a way specific to summernote to do this?
Upvotes: 4
Views: 2035
Reputation: 41
You can use array hints, example:
hint:[
{
words: ['apple', 'orange', 'watermelon', 'lemon'],
match: /\b(\w{1,})$/,
search: function (keyword, callback) {
callback($.grep(this.words, function (item) {
return item.indexOf(keyword) === 0;
}));
},
{
mentions: ['jayden', 'sam', 'alvin', 'david'],
match: /\B@(\w*)$/,
search: function (keyword, callback) {
callback($.grep(this.mentions, function (item) {
return item.indexOf(keyword) == 0;
}));
},
content: function (item) {
return '@' + item;
}
}
]
}
},
Upvotes: 4