Show a preview image in builtin attachment select autocomplete.

This commit is contained in:
Jan Böhmer 2020-06-01 14:51:38 +02:00
parent aa95f130db
commit f0d0a78f65
6 changed files with 65 additions and 6 deletions

View file

@ -432,6 +432,7 @@ $(document).on("ajaxUI:reload ajaxUI:start attachment:create", function () {
}
});
//@ts-ignore
$(this).typeahead({
hint: true,
highlight: true,
@ -439,7 +440,18 @@ $(document).on("ajaxUI:reload ajaxUI:start attachment:create", function () {
},
{
name: 'states',
source: engine
source: engine,
limit: 250,
templates: {
suggestion: function(data) {
if (typeof data === "string") {
return "<div>" + data + "</div>";
} else if(typeof data === "object" && typeof data.image === "string") {
return "<div class='row m-0'><div class='col-2 pl-0 pr-1'><img class='typeahead-image' src='" + data.image + "'/></div><div class='col-10'>" + data.name + "</div></div>"
}
},
},
display: 'name',
});
//Make the typeahead input fill the container (remove block-inline attr)