2 const $tagstring = $("#trace_tagstring");
3 const $help = $tagstring.siblings(".form-text");
4 const help = $help.text();
5 const $tags = $("<ul>")
6 .addClass("list-unstyled d-inline-flex flex-wrap column-gap-1 ms-1 mb-0")
7 .appendTo($tagstring.parent());
9 function updateTags() {
10 const tagstring = $tagstring.val();
11 let names, delimitedHelp;
13 // Split the tags the same way as Trace#tagstring= does, which
14 // only counts ASCII whitespace, unlike \s and trim()
15 if (tagstring.includes(",")) {
16 names = tagstring.split(",")
17 .map(name => name.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, ""))
18 .filter(name => name);
19 delimitedHelp = OSM.i18n.t("javascripts.traces.tagstring.comma_delimited");
21 names = tagstring.split(/[\t\n\v\f\r ]+/).filter(name => name);
22 delimitedHelp = OSM.i18n.t("javascripts.traces.tagstring.space_delimited");
25 // Nothing to show unless there's more than one tag
26 if (names.length < 2) names = [];
28 $help.text(names.length > 0 ? delimitedHelp : help);
31 .map(name => $("<li>").addClass("badge text-bg-secondary mt-1").text(name));
32 $tags.empty().append(...items);
35 $tagstring.on("input", updateTags);