* 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

@ -2,7 +2,6 @@
//= require jquery-ui-1.10.3.min.js
//= require jquery.hotkeys.js
//= require jquery.timeout.js
//= require typeahead.min.js
//= require rails.js
//= require common.js
//= require_self

View File

@ -6,19 +6,30 @@
Danbooru.Artist.initialize_check_name_link();
if (Danbooru.meta("enable-auto-complete") === "true") {
Danbooru.Artist.initialize_typeahead();
Danbooru.Artist.initialize_auto_complete();
}
}
}
Danbooru.Artist.initialize_typeahead = function() {
$("#quick_search_name").typeahead({
name: "artists",
remote: "/artists.json?search[name]=*%QUERY*",
limit: 10,
valueKey: "name",
template: function(context) {
return "<p>" + context.name.replace(/_/g, " ") + "</p>";
Danbooru.Artist.initialize_auto_complete = function() {
$("#quick_search_name").autocomplete({
source: function(req, resp) {
$.ajax({
url: "/artists.json",
data: {
"search[name]": "*" + req.term + "*"
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name,
value: tag.name
};
}));
}
});
}
});
}

View File

@ -14,13 +14,25 @@
Danbooru.Pool.initialize_add_to_pool_link = function() {
$("#add-to-pool-dialog").dialog({autoOpen: false});
$("#c-pool-elements #a-new input[type=text]").typeahead({
name: "pools",
remote: "/pools.json?search[is_active]=true&search[name_matches]=%QUERY",
limit: 10,
valueKey: "name",
template: function(context) {
return "<p>" + context.name.replace(/_/g, " ") + "</p>";
$("#c-pool-elements #a-new input[type=text]").autocomplete({
source: function(req, resp) {
$.ajax({
url: "/pools.json",
data: {
"search[is_active]": "true"
"search[name_matches]": req.term
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name.replace(/_/g, " "),
value: tag.name
};
}));
}
});
}
});

View File

@ -36,13 +36,36 @@
}
Danbooru.Post.initialize_tag_autocomplete = function() {
$("#tags").typeahead({
name: "tags",
remote: "/tags.json?search[order]=count&search[name_matches]=%QUERY*",
limit: 10,
valueKey: "name",
template: function(context) {
return "<p class=\"category-" + context.category + "\"><a>" + context.name + "</a></p>";
$("#tags,#post_tag_string,#upload_tag_string").autocomplete({
focus: function() {
return false;
},
select: function(event, ui) {
var terms = this.value.match(/\S+/g);
terms.pop();
terms.push(ui.item.value);
this.value = terms.join(" ") + " ";
return false;
},
source: function(req, resp) {
var term = req.term.match(/\S+/g).pop();
$.ajax({
url: "/tags.json",
data: {
"search[order]": "count",
"search[name_matches]": term + "*"
},
method: "get",
minLength: 2,
success: function(data) {
resp($.map(data, function(tag) {
return {
label: tag.name,
value: tag.name
};
}));
}
});
}
});
}

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
};
}));
}
});
}
});
}
}
})();

View File

@ -50,27 +50,6 @@ a.blacklisted-active {
background-color: rgba(0,0,0,0.1);
}
.tt-suggestions {
background: white;
display: block;
border: 1px solid black;
margin: 0;
padding: 0;
}
.tt-suggestion {
background: white;
padding: 0.25em 0.5em;
}
.tt-is-under-cursor {
background: $highlight_color;
}
.tt-suggestion p {
margin: 0;
}
#has-parent-relationship-preview, #has-children-relationship-preview {
overflow-x: auto;
white-space: nowrap;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 208 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long