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'> <td class='excerpt'>
<h3> <h3>
{{#if flaggedPost.topic.isPrivateMessage}} {{#if flaggedPost.topic.isPrivateMessage}}
<span class="private-message-glyph">{{icon envelope}}</span> <span class="private-message-glyph">{{fa-icon envelope}}</span>
{{/if}} {{/if}}
{{topic-status topic=flaggedPost.topic}} {{topic-status topic=flaggedPost.topic}}
<a href='{{unbound flaggedPost.url}}'>{{flaggedPost.topic.title}}</a> <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'; 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); 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); 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), var url = Ember.Handlebars.get(this, property, options),
matches = url.match(/\//g); matches = url.match(/\//g);
@ -9,4 +9,3 @@ export default Handlebars.registerHelper('shorten-url', function(property, optio
url = url.replace(/^www\./, ''); url = url.replace(/^www\./, '');
return url.substring(0, 80); 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), var topic = Ember.Handlebars.get(this, property, options),
title = topic.get('fancy_title'); title = topic.get('fancy_title');

View file

@ -9,6 +9,10 @@ var deprecatedViewHelpers = {
'discourse-activity-filter': 'activity-filter' 'discourse-activity-filter': 'activity-filter'
}; };
var renamedHelpers = {
icon: "fa-icon"
};
export default { export default {
name: 'deprecations', name: 'deprecations',
initialize: function(container) { initialize: function(container) {
@ -24,5 +28,14 @@ export default {
return Ember.Handlebars.helpers.view.call(this, helper, options); 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}} {{/if}}
<h1> <h1>
{{#if showPrivateMessageGlyph}} {{#if showPrivateMessageGlyph}}
<span class="private-message-glyph">{{icon envelope}}</span> <span class="private-message-glyph">{{fa-icon envelope}}</span>
{{/if}} {{/if}}
{{#if topic.category.parentCategory}} {{#if topic.category.parentCategory}}
{{bound-category-link topic.category.parentCategory}} {{bound-category-link topic.category.parentCategory}}
@ -40,14 +40,14 @@
</button> </button>
{{/if}} {{/if}}
<button {{action showLogin}} class='btn btn-primary btn-small login-button'> <button {{action showLogin}} class='btn btn-primary btn-small login-button'>
{{icon user}} {{i18n log_in}} {{fa-icon user}} {{i18n log_in}}
</button> </button>
{{/unless}} {{/unless}}
<ul class='icons clearfix' role='navigation'> <ul class='icons clearfix' role='navigation'>
{{#if currentUser}} {{#if currentUser}}
<li class='notifications'> <li class='notifications'>
<a class='icon' href="#" {{action showNotifications target="view"}} data-notifications="notifications-dropdown" id='user-notifications' title='{{i18n notifications.title}}'> <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> </a>
{{#if currentUser.unread_notifications}} {{#if currentUser.unread_notifications}}
<a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a> <a href='#' class='badge-notification unread-notifications'>{{currentUser.unread_notifications}}</a>
@ -60,7 +60,7 @@
<li> <li>
{{#if loginRequired}} {{#if loginRequired}}
<a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}> <a id='search-button' class='icon expand' href='#' aria-hidden="true" {{action showLogin}}>
{{icon search}} {{fa-icon search}}
</a> </a>
{{else}} {{else}}
<a id='search-button' <a id='search-button'
@ -68,7 +68,7 @@
href='#' href='#'
data-dropdown="search-dropdown" data-dropdown="search-dropdown"
title='{{i18n search.title}}'> title='{{i18n search.title}}'>
{{icon search label="search.title"}} {{fa-icon search label="search.title"}}
</a> </a>
{{/if}} {{/if}}
</li> </li>
@ -79,7 +79,7 @@
aria-hidden="true" aria-hidden="true"
id="site-map" id="site-map"
{{action showLogin}}> {{action showLogin}}>
{{icon bars}} {{fa-icon bars}}
</a> </a>
{{else}} {{else}}
<a class='icon' <a class='icon'
@ -88,7 +88,7 @@
href="#" href="#"
title='{{i18n site_map}}' title='{{i18n site_map}}'
id="site-map"> id="site-map">
{{icon bars label="site_map"}} {{fa-icon bars label="site_map"}}
</a> </a>
{{/if}} {{/if}}
{{#if currentUser.site_flagged_posts_count}} {{#if currentUser.site_flagged_posts_count}}

View file

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