Show parent category on category badges

This commit is contained in:
Neil Lalonde 2014-03-19 16:04:53 -04:00
parent 2842952a76
commit c649959e34
8 changed files with 35 additions and 9 deletions

View File

@ -79,6 +79,9 @@ function categoryLinkHTML(category, options) {
if (options.hash.allowUncategorized) {
categoryOptions.allowUncategorized = true;
}
if (options.hash.showParent) {
categoryOptions.showParent = true;
}
if (options.hash.categories) {
categoryOptions.categories = Em.Handlebars.get(this, options.hash.categories, options);
}

View File

@ -83,7 +83,8 @@ Discourse.HTML = {
var name = Em.get(category, 'name'),
description = Em.get(category, 'description'),
restricted = Em.get(category, 'read_restricted'),
html = "<a href=\"" + Discourse.getURL("/category/") + Discourse.Category.slugFor(category) + "\" ";
url = Discourse.getURL("/category/") + Discourse.Category.slugFor(category),
html = "<a href=\"" + url + "\" ";
html += "data-drop-close=\"true\" class=\"badge-category" + (restricted ? ' restricted' : '' ) + "\" ";
@ -101,6 +102,15 @@ Discourse.HTML = {
html += ">" + name + "</a>";
}
if (opts.showParent && category.get('parent_category_id')) {
var parent = Discourse.Category.findById(category.get('parent_category_id'));
html = "<a class='badge-category-parent' style=\"" + (Discourse.HTML.categoryStyle(parent)||'') +
"\" href=\"" + url + "\"><span class='category-name'>" +
(Em.get(parent, 'read_restricted') ? "<i class='fa fa-group'></i> " : "") +
Em.get(parent, 'name') + "</span></a>" +
html;
}
return html;
}

View File

@ -42,7 +42,7 @@
{{#unless controller.hideCategory}}
<td class="category">
{{categoryLink topic.category}}
{{categoryLink topic.category showParent=true}}
</td>
{{/unless}}

View File

@ -37,7 +37,7 @@
</td>
{{#unless hideCategory}}
<td class='category'>{{boundCategoryLink category}}</td>
<td class='category'>{{boundCategoryLink category showParent=true}}</td>
{{/unless}}
<td class='posters'>

View File

@ -30,7 +30,7 @@
</div>
<div class="topic-item-stats clearfix">
<div class='category'>
{{categoryLink category}}
{{categoryLink category showParent=true}}
</div>
<div class="pull-right">
<div class='num posts'>

View File

@ -28,7 +28,7 @@
<div class="topic-item-stats clearfix">
{{#unless controller.hideCategory}}
<div class='category'>
{{categoryLink category}}
{{categoryLink category showParent=true}}
</div>
{{/unless}}

View File

@ -18,18 +18,31 @@
// Category badge
// --------------------------------------------------
.badge-category {
padding: 6px;
color: $tertiary_text_color;
.badge-category, .badge-category-parent {
font-size: 12px;
font-weight: bold;
white-space: nowrap;
display: inline-block;
line-height: 1;
}
.badge-category {
padding: 6px;
color: $tertiary_text_color;
&[href] {
color: $tertiary_text_color;
}
}
.badge-category-parent {
padding: 6px 2px;
width: 2px;
.category-name {
display: none;
}
&:before {
content: "\a0";
}
}
.d-dropdown .badge-category {

View File

@ -256,7 +256,7 @@ a.star {
display: none;
}
a.badge-category {
a.badge-category, a.badge-category-parent {
font-size: 10px;
}