autocomplete: unify menu item rendering.
* Use `Danbooru.Autocomplete.render_item` for all menu item rendering. Fixes usernames not being colorized when completing mentions, and post counts not being shown when completing pools on the /pools page. * Make the /pools page autocomplete pool names the same way that the pool:<name> metatag does. Previously autocomplete on the /pools page listed most recently updated pools first; now it lists largest pools first.
This commit is contained in:
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
Danbooru.Autocomplete.initialize_all = function() {
|
Danbooru.Autocomplete.initialize_all = function() {
|
||||||
if (Danbooru.meta("enable-auto-complete") === "true") {
|
if (Danbooru.meta("enable-auto-complete") === "true") {
|
||||||
|
$.widget("ui.autocomplete", $.ui.autocomplete, {
|
||||||
|
_renderItem: Danbooru.Autocomplete.render_item,
|
||||||
|
});
|
||||||
|
|
||||||
Danbooru.Autocomplete.enable_local_storage = this.test_local_storage();
|
Danbooru.Autocomplete.enable_local_storage = this.test_local_storage();
|
||||||
this.initialize_tag_autocomplete();
|
this.initialize_tag_autocomplete();
|
||||||
this.initialize_mention_autocomplete($(".autocomplete-mentions textarea"));
|
this.initialize_mention_autocomplete($(".autocomplete-mentions textarea"));
|
||||||
@@ -189,10 +193,6 @@
|
|||||||
Danbooru.Autocomplete.normal_source(req.term, resp);
|
Danbooru.Autocomplete.normal_source(req.term, resp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.merge($fields_multiple, $fields_single).each(function(i, field) {
|
|
||||||
$(field).data("uiAutocomplete")._renderItem = Danbooru.Autocomplete.render_item;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Danbooru.Autocomplete.initialize_artist_autocomplete = function($fields) {
|
Danbooru.Autocomplete.initialize_artist_autocomplete = function($fields) {
|
||||||
@@ -211,56 +211,24 @@
|
|||||||
success: function(data) {
|
success: function(data) {
|
||||||
resp($.map(data, function(artist) {
|
resp($.map(data, function(artist) {
|
||||||
return {
|
return {
|
||||||
|
type: "tag",
|
||||||
label: artist.name.replace(/_/g, " "),
|
label: artist.name.replace(/_/g, " "),
|
||||||
value: artist.name
|
value: artist.name,
|
||||||
|
category: <%= Tag.categories.artist %>,
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.Autocomplete.initialize_pool_autocomplete = function($fields) {
|
Danbooru.Autocomplete.initialize_pool_autocomplete = function($fields) {
|
||||||
$fields.autocomplete({
|
$fields.autocomplete({
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
source: function(req, resp) {
|
source: function(req, resp) {
|
||||||
$.ajax({
|
Danbooru.Autocomplete.pool_source(req.term, resp);
|
||||||
url: "/pools.json",
|
},
|
||||||
data: {
|
|
||||||
"search[name_matches]": req.term,
|
|
||||||
"limit": 10
|
|
||||||
},
|
|
||||||
method: "get",
|
|
||||||
success: function(data) {
|
|
||||||
resp($.map(data, function(pool) {
|
|
||||||
return {
|
|
||||||
label: pool.name.replace(/_/g, " "),
|
|
||||||
value: pool.name,
|
|
||||||
category: pool.category
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var render_pool = function(list, pool) {
|
|
||||||
var $link = $("<a/>").addClass("pool-category-" + pool.category).text(pool.label);
|
|
||||||
return $("<li/>").data("item.autocomplete", pool).append($link).appendTo(list);
|
|
||||||
};
|
|
||||||
|
|
||||||
$fields.each(function(i, field) {
|
|
||||||
$(field).data("uiAutocomplete")._renderItem = render_pool;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,6 +248,7 @@
|
|||||||
success: function(data) {
|
success: function(data) {
|
||||||
resp($.map(data, function(wiki_page) {
|
resp($.map(data, function(wiki_page) {
|
||||||
return {
|
return {
|
||||||
|
type: "tag",
|
||||||
label: wiki_page.title.replace(/_/g, " "),
|
label: wiki_page.title.replace(/_/g, " "),
|
||||||
value: wiki_page.title,
|
value: wiki_page.title,
|
||||||
category: wiki_page.category_name
|
category: wiki_page.category_name
|
||||||
@@ -289,15 +258,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var render_wiki_page = function(list, wiki_page) {
|
|
||||||
var $link = $("<a/>").addClass("tag-type-" + wiki_page.category).text(wiki_page.label);
|
|
||||||
return $("<li/>").data("item.autocomplete", wiki_page).append($link).appendTo(list);
|
|
||||||
};
|
|
||||||
|
|
||||||
$fields.each(function(i, field) {
|
|
||||||
$(field).data("uiAutocomplete")._renderItem = render_wiki_page;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Danbooru.Autocomplete.normal_source = function(term, resp) {
|
Danbooru.Autocomplete.normal_source = function(term, resp) {
|
||||||
@@ -545,7 +505,7 @@
|
|||||||
return {
|
return {
|
||||||
type: "pool",
|
type: "pool",
|
||||||
label: pool.name.replace(/_/g, " "),
|
label: pool.name.replace(/_/g, " "),
|
||||||
value: metatag + ":" + pool.name,
|
value: (metatag ? (metatag + ":" + pool.name) : pool.name),
|
||||||
post_count: pool.post_count,
|
post_count: pool.post_count,
|
||||||
category: pool.category
|
category: pool.category
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user