fixes #1754; include category in wiki page api

This commit is contained in:
Toks
2013-06-23 11:42:55 -04:00
parent 40d9e0cfe1
commit 168de3215f
2 changed files with 17 additions and 5 deletions

View File

@@ -9,7 +9,9 @@
Danbooru.WikiPage.initialize_typeahead = function() {
if (Danbooru.meta("enable-auto-complete") === "true") {
$("#search_title,#quick_search_title").autocomplete({
var $fields = $("#search_title,#quick_search_title");
$fields.autocomplete({
minLength: 1,
source: function(req, resp) {
$.ajax({
@@ -20,16 +22,26 @@
},
method: "get",
success: function(data) {
resp($.map(data, function(tag) {
resp($.map(data, function(wiki_page) {
return {
label: tag.title.replace(/_/g, " "),
value: tag.title
label: wiki_page.title.replace(/_/g, " "),
value: wiki_page.title,
category: wiki_page.category_name
};
}));
}
});
}
});
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;
});
}
}
})();

View File

@@ -64,7 +64,7 @@ class WikiPage < ActiveRecord::Base
options[:except] += hidden_attributes
unless options[:builder]
options[:methods] ||= []
options[:methods] += [:creator_name]
options[:methods] += [:creator_name, :category_name]
end
hash = super(options)
hash