autocomplete: move artist/pool/wiki autocompletion to autocomplete.js.

* Move all autocomplete code to autocomplete.js.

* Mark autocompleted fields with `data-autocomplete="<type>"` attributes,
  instead of hardcoding input field IDs in the javascript.
This commit is contained in:
evazion
2018-02-18 16:19:32 -06:00
parent a058a77c07
commit 962842815d
12 changed files with 118 additions and 137 deletions

View File

@@ -5,10 +5,6 @@
if ($("#c-artists").length) {
Danbooru.Artist.initialize_check_name();
Danbooru.Artist.initialize_shortcuts();
if (Danbooru.meta("enable-auto-complete") === "true") {
Danbooru.Artist.initialize_autocomplete();
}
}
}
@@ -43,46 +39,8 @@
});
}
};
Danbooru.Artist.initialize_autocomplete = function() {
var $fields = $("#search_name,#quick_search_name");
$fields.autocomplete({
minLength: 1,
source: function(req, resp) {
$.ajax({
url: "/artists.json",
data: {
"search[name]": req.term + "*",
"search[is_active]": true,
"search[order]": "post_count",
"limit": 10
},
method: "get",
success: function(data) {
resp($.map(data, function(artist) {
return {
label: artist.name.replace(/_/g, " "),
value: artist.name
};
}));
}
});
}
});
var render_artist = function(list, artist) {
var $link = $("<a/>").addClass("tag-type-1").text(artist.label);
return $("<li/>").data("item.autocomplete", artist).append($link).appendTo(list);
};
$fields.each(function(i, field) {
$(field).data("uiAutocomplete")._renderItem = render_artist;
});
}
})();
$(document).ready(function() {
Danbooru.Artist.initialize_all();
});