* Use jquery-ui's autocomplete module instead of typeahead

* Enable support for multiple tag autocomplete
This commit is contained in:
r888888888
2013-06-18 18:36:37 -07:00
parent 08463cdd9e
commit e0a14bb9eb
10 changed files with 100 additions and 68 deletions

View File

@@ -3,17 +3,32 @@
Danbooru.WikiPage.initialize_all = function() {
if ($("#c-wiki-pages").length) {
if (Danbooru.meta("enable-auto-complete") === "true") {
$("#quick_search_title,#wiki_page_title").typeahead({
name: "wiki_pages",
remote: "/wiki_pages.json?search[title]=*%QUERY*",
limit: 10,
valueKey: "title",
template: function(context) {
return "<p>" + context.title.replace(/_/g, " ") + "</p>";
}
});
}
this.initialize_typeahead();
}
}
Danbooru.WikiPage.initialize_typeahead = function() {
if (Danbooru.meta("enable-auto-complete") === "true") {
$("#quick_search_title,#wiki_page_title").autocomplete({
source: function(req, resp) {
$.ajax({
url: "/wiki_pages.json",
data: {
"search[title]": "*" + req.term + "*"
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.title.replace(/_/g, " "),
value: tag.title
};
}));
}
});
}
});
}
}
})();