Rename {{icon}} helper to {{fa-icon}} for future Ember

compatibility.
This commit is contained in:
Robin Ward 2014-09-09 17:29:05 -04:00
parent cec6b64a45
commit 62c9e4228d
10 changed files with 38 additions and 33 deletions

View file

@ -42,7 +42,7 @@
<td class='excerpt'>
<h3>
{{#if flaggedPost.topic.isPrivateMessage}}
<span class="private-message-glyph">{{icon envelope}}</span>
<span class="private-message-glyph">{{fa-icon envelope}}</span>
{{/if}}
{{topic-status topic=flaggedPost.topic}}
<a href='{{unbound flaggedPost.url}}'>{{flaggedPost.topic.title}}</a>

View file

@ -199,22 +199,3 @@ Handlebars.registerHelper('link-domain', function(property, options) {
}
}
});
/**
Renders a font-awesome icon with an optional i18n string as hidden text for
screen readers.
@method icon
@for Handlebars
**/
Handlebars.registerHelper('icon', function(icon, options) {
var labelKey, html;
if (options.hash) { labelKey = options.hash.label; }
html = "<i class='fa fa-" + icon + "'";
if (labelKey) { html += " aria-hidden='true'"; }
html += "></i>";
if (labelKey) {
html += "<span class='sr-only'>" + I18n.t(labelKey) + "</span>";
}
return new safe(html);
});

View file

@ -1,5 +1,5 @@
import { categoryLinkHTML } from 'discourse/lib/html-builder';
export default Handlebars.registerHelper('category-link', function(property, options) {
Handlebars.registerHelper('category-link', function(property, options) {
return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options);
});

View file

@ -0,0 +1,12 @@
Handlebars.registerHelper('fa-icon', function(icon, options) {
var labelKey;
if (options.hash) { labelKey = options.hash.label; }
var html = "<i class='fa fa-" + icon + "'";
if (labelKey) { html += " aria-hidden='true'"; }
html += "></i>";
if (labelKey) {
html += "<span class='sr-only'>" + I18n.t(labelKey) + "</span>";
}
return new Handlebars.SafeString(html);
});

View file

@ -1,3 +1,3 @@
export default Handlebars.registerHelper('shorten-text', function(property, options) {
Handlebars.registerHelper('shorten-text', function(property, options) {
return Ember.Handlebars.get(this, property, options).substring(0,35);
});

View file

@ -1,4 +1,4 @@
export default Handlebars.registerHelper('shorten-url', function(property, options) {
Handlebars.registerHelper('shorten-url', function(property, options) {
var url = Ember.Handlebars.get(this, property, options),
matches = url.match(/\//g);
@ -9,4 +9,3 @@ export default Handlebars.registerHelper('shorten-url', function(property, optio
url = url.replace(/^www\./, '');
return url.substring(0, 80);
});

View file

@ -1,4 +1,4 @@
export default Handlebars.registerHelper('topic-link', function(property, options) {
Handlebars.registerHelper('topic-link', function(property, options) {
var topic = Ember.Handlebars.get(this, property, options),
title = topic.get('fancy_title');

View file

@ -9,6 +9,10 @@ var deprecatedViewHelpers = {
'discourse-activity-filter': 'activity-filter'
};
var renamedHelpers = {
icon: "fa-icon"
};
export default {
name: 'deprecations',
initialize: function(container) {
@ -24,5 +28,14 @@ export default {
return Ember.Handlebars.helpers.view.call(this, helper, options);
});
});
Ember.keys(renamedHelpers).forEach(function(old) {
var newName = renamedHelpers[old];
Ember.Handlebars.registerHelper(old, function() {
Em.warn("The `" + old +"` helper is deprecated. Use `" + newName + "` instead.");
var newHelper = container.lookupFactory('helper:' + newName);
return newHelper.apply(this, Array.prototype.slice.call(arguments));
});
});
}
};

View file

@ -11,7 +11,7 @@
{{/if}}
<h1>
{{#if showPrivateMessageGlyph}}
<span class="private-message-glyph">{{icon envelope}}</span>
<span class="private-message-glyph">{{fa-icon envelope}}</span>
{{/if}}
{{#if topic.category.parentCategory}}
{{bound-category-link topic.category.parentCategory}}
@ -40,14 +40,14 @@
</button>
{{/if}}
<button {{action showLogin}} class='btn btn-primary btn-small login-button'>
{{icon user}} {{i18n log_in}}
{{fa-icon user}} {{i18n log_in}}
</button>
{{/unless}}
<ul class='icons clearfix' role='navigation'>
{{#if currentUser}}
<li class='notifications'>
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'>
{{icon comment label="notifications.title"}}
{{fa-icon comment label="notifications.title"}}
</a>
{{#if currentUser.unread_notifications}}
<a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a>
@ -60,7 +60,7 @@
<li>
{{#if loginRequired}}
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
{{icon search}}
{{fa-icon search}}
</a>
{{else}}
<a id='search-button'
@ -68,7 +68,7 @@
href='#'
data-dropdown="search-dropdown"
title='{{i18n search.title}}'>
{{icon search label="search.title"}}
{{fa-icon search label="search.title"}}
</a>
{{/if}}
</li>
@ -79,7 +79,7 @@
aria-hidden="true"
id="site-map"
{{action showLogin}}>
{{icon bars}}
{{fa-icon bars}}
</a>
{{else}}
<a class='icon'
@ -88,7 +88,7 @@
href="#"
title='{{i18n site_map}}'
id="site-map">
{{icon bars label="site_map"}}
{{fa-icon bars label="site_map"}}
</a>
{{/if}}
{{#if currentUser.site_flagged_posts_count}}

View file

@ -17,7 +17,7 @@
{{#if editingTopic}}
{{#if isPrivateMessage}}
<span class="private-message-glyph">{{icon envelope}}</span>
<span class="private-message-glyph">{{fa-icon envelope}}</span>
{{else}}
{{category-chooser valueAttribute="id" value=newCategoryId source=category_id}}
{{/if}}