autocomplete: update html data attributes.
* Remove the `source` and `weight` html data attributes (no longer used). * Make the `type` html data attribute properly indicate the completion type. Valid types: `tag`, `tag-alias`, `tag-abbreviation`, `tag-autocorrect`, `tag-other-name`.
This commit is contained in:
@@ -180,10 +180,8 @@ Autocomplete.render_item = function(list, item) {
|
|||||||
$link.append($post_count);
|
$link.append($post_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === "tag") {
|
if (/^tag/.test(item.type)) {
|
||||||
$link.addClass("tag-type-" + item.category);
|
$link.addClass("tag-type-" + item.category);
|
||||||
} else if (item.type === "tag_autocorrect") {
|
|
||||||
$link.addClass(`tag-type-${item.category} tag-type-autocorrect`);
|
|
||||||
} else if (item.type === "user") {
|
} else if (item.type === "user") {
|
||||||
var level_class = "user-" + item.level.toLowerCase();
|
var level_class = "user-" + item.level.toLowerCase();
|
||||||
$link.addClass(level_class);
|
$link.addClass(level_class);
|
||||||
@@ -194,7 +192,7 @@ Autocomplete.render_item = function(list, item) {
|
|||||||
var $menu_item = $("<div/>").append($link);
|
var $menu_item = $("<div/>").append($link);
|
||||||
var $list_item = $("<li/>").data("item.autocomplete", item).append($menu_item);
|
var $list_item = $("<li/>").data("item.autocomplete", item).append($menu_item);
|
||||||
|
|
||||||
var data_attributes = ["type", "source", "antecedent", "value", "category", "post_count", "weight"];
|
var data_attributes = ["type", "antecedent", "value", "category", "post_count"];
|
||||||
data_attributes.forEach(attr => {
|
data_attributes.forEach(attr => {
|
||||||
$list_item.attr(`data-autocomplete-${attr.replace(/_/g, "-")}`, item[attr]);
|
$list_item.attr(`data-autocomplete-${attr.replace(/_/g, "-")}`, item[attr]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
color: var(--autocomplete-arrow-color);
|
color: var(--autocomplete-arrow-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
a.tag-type-autocorrect .autocomplete-antecedent {
|
li[data-autocomplete-type="tag-autocorrect"] .autocomplete-antecedent {
|
||||||
text-decoration: dotted underline;
|
text-decoration: dotted underline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ class AutocompleteService
|
|||||||
tags = Tag.from(union).order(post_count: :desc).limit(limit).includes(:consequent_aliases)
|
tags = Tag.from(union).order(post_count: :desc).limit(limit).includes(:consequent_aliases)
|
||||||
|
|
||||||
tags.map do |tag|
|
tags.map do |tag|
|
||||||
{ type: "tag", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: tag.tag_alias_for_pattern(string)&.antecedent_name }
|
antecedent = tag.tag_alias_for_pattern(string)&.antecedent_name
|
||||||
|
type = antecedent.present? ? "tag-alias" : "tag"
|
||||||
|
{ type: type, label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: antecedent }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -100,7 +102,7 @@ class AutocompleteService
|
|||||||
tags = Tag.nonempty.abbreviation_matches(string).order(post_count: :desc).limit(limit)
|
tags = Tag.nonempty.abbreviation_matches(string).order(post_count: :desc).limit(limit)
|
||||||
|
|
||||||
tags.map do |tag|
|
tags.map do |tag|
|
||||||
{ type: "tag", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: "/" + tag.abbreviation }
|
{ type: "tag-abbreviation", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: "/" + tag.abbreviation }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,7 +111,7 @@ class AutocompleteService
|
|||||||
tags = Tag.nonempty.autocorrect_matches(string).limit(limit)
|
tags = Tag.nonempty.autocorrect_matches(string).limit(limit)
|
||||||
|
|
||||||
tags.map do |tag|
|
tags.map do |tag|
|
||||||
{ type: "tag_autocorrect", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: string }
|
{ type: "tag-autocorrect", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: string }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -124,7 +126,7 @@ class AutocompleteService
|
|||||||
tags.map do |tag|
|
tags.map do |tag|
|
||||||
other_names = tag.artist&.other_names.to_a + tag.wiki_page&.other_names.to_a
|
other_names = tag.artist&.other_names.to_a + tag.wiki_page&.other_names.to_a
|
||||||
antecedent = other_names.find { |other_name| other_name.ilike?(string) }
|
antecedent = other_names.find { |other_name| other_name.ilike?(string) }
|
||||||
{ type: "tag", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: antecedent }
|
{ type: "tag-other-name", label: tag.pretty_name, value: tag.name, category: tag.category, post_count: tag.post_count, antecedent: antecedent }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user