Use sub-category badge on categories page too

This commit is contained in:
Neil Lalonde 2014-03-27 15:05:46 -04:00
parent 32b7405941
commit 5d4995640b
5 changed files with 10 additions and 10 deletions

View File

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

View File

@ -70,6 +70,7 @@ Discourse.HTML = {
@param {Boolean} opts.allowUncategorized Whether we allow rendering of the uncategorized category (default false) @param {Boolean} opts.allowUncategorized Whether we allow rendering of the uncategorized category (default false)
@param {Boolean} opts.showParent Whether to visually show whether category is a sub-category (default false) @param {Boolean} opts.showParent Whether to visually show whether category is a sub-category (default false)
@param {Boolean} opts.link Whether this category badge should link to the category (default true) @param {Boolean} opts.link Whether this category badge should link to the category (default true)
@param {String} opts.extraClasses add this string to the class attribute of the badge
@returns {String} the html category badge @returns {String} the html category badge
**/ **/
categoryBadge: function(category, opts) { categoryBadge: function(category, opts) {
@ -87,9 +88,11 @@ Discourse.HTML = {
restricted = Em.get(category, 'read_restricted'), restricted = Em.get(category, 'read_restricted'),
url = Discourse.getURL("/category/") + Discourse.Category.slugFor(category), url = Discourse.getURL("/category/") + Discourse.Category.slugFor(category),
elem = (opts.link === false ? 'span' : 'a'), elem = (opts.link === false ? 'span' : 'a'),
extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''),
html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" "; html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" ";
html += "data-drop-close=\"true\" class=\"badge-category" + (restricted ? ' restricted' : '' ) + "\" "; html += "data-drop-close=\"true\" class=\"badge-category" + (restricted ? ' restricted' : '' ) +
extraClasses + "\" ";
// Add description if we have it // Add description if we have it
if (description) html += "title=\"" + Handlebars.Utils.escapeExpression(description) + "\" "; if (description) html += "title=\"" + Handlebars.Utils.escapeExpression(description) + "\" ";
@ -107,7 +110,7 @@ Discourse.HTML = {
if (opts.showParent && category.get('parent_category_id')) { if (opts.showParent && category.get('parent_category_id')) {
var parent = Discourse.Category.findById(category.get('parent_category_id')); var parent = Discourse.Category.findById(category.get('parent_category_id'));
html = "<span class='badge-wrapper'><" + elem + " class='badge-category-parent' style=\"" + (Discourse.HTML.categoryStyle(parent)||'') + html = "<span class='badge-wrapper'><" + elem + " class='badge-category-parent" + extraClasses + "' style=\"" + (Discourse.HTML.categoryStyle(parent)||'') +
"\" href=\"" + (opts.link === false ? '' : url) + "\"><span class='category-name'>" + "\" href=\"" + (opts.link === false ? '' : url) + "\"><span class='category-name'>" +
(Em.get(parent, 'read_restricted') ? "<i class='fa fa-group'></i> " : "") + (Em.get(parent, 'read_restricted') ? "<i class='fa fa-group'></i> " : "") +
Em.get(parent, 'name') + "</span></" + elem + ">" + Em.get(parent, 'name') + "</span></" + elem + ">" +

View File

@ -18,7 +18,7 @@
<div> <div>
<div class="pull-left"> <div class="pull-left">
{{#if controller.ordering}}<i class="fa fa-bars"></i>{{/if}} {{#if controller.ordering}}<i class="fa fa-bars"></i>{{/if}}
{{categoryLink this allowUncategorized=true}} {{categoryLink this allowUncategorized=true extraClasses="bigger"}}
{{#if unreadTopics}} {{#if unreadTopics}}
<a href={{unbound unreadUrl}} class='badge new-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a> <a href={{unbound unreadUrl}} class='badge new-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a>
{{/if}} {{/if}}
@ -42,7 +42,7 @@
<div class='subcategories'> <div class='subcategories'>
{{i18n categories.subcategories}} {{i18n categories.subcategories}}
{{#each subcategories}} {{#each subcategories}}
{{categoryLink this}} {{categoryLink this showParent=true}}
{{#if unreadTopics}} {{#if unreadTopics}}
<a href={{unbound unreadUrl}} class='badge new-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a> <a href={{unbound unreadUrl}} class='badge new-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a>
{{/if}} {{/if}}

View File

@ -62,7 +62,7 @@
<div class='subcategories'> <div class='subcategories'>
{{i18n categories.subcategories}} {{i18n categories.subcategories}}
{{#each subcategory in subcategories}} {{#each subcategory in subcategories}}
{{categoryLink subcategory}} {{categoryLink subcategory showParent=true}}
{{/each}} {{/each}}
</div> </div>
</td> </td>

View File

@ -295,10 +295,6 @@
.subcategories { .subcategories {
margin-top: 10px; margin-top: 10px;
.badge-category {
font-size: 12px;
padding: 4px;
}
} }
.featured-users { .featured-users {
float: right; float: right;
@ -307,7 +303,7 @@
.category-description { .category-description {
margin-top: 10px; margin-top: 10px;
} }
.badge-category { .badge-category.bigger {
padding: 6px 10px; padding: 6px 10px;
font-size: 14px; font-size: 14px;
} }