2016-08-31 11:30:51 -04:00
|
|
|
import { registerUnbound } from 'discourse-common/lib/helpers';
|
2015-01-28 11:01:01 -05:00
|
|
|
|
2016-08-31 11:30:51 -04:00
|
|
|
export function iconClasses(icon, params) {
|
|
|
|
let classes = "fa fa-" + icon;
|
2015-02-24 13:47:46 -05:00
|
|
|
if (params.modifier) { classes += " fa-" + params.modifier; }
|
|
|
|
if (params['class']) { classes += ' ' + params['class']; }
|
2015-01-28 11:01:01 -05:00
|
|
|
return classes;
|
|
|
|
}
|
|
|
|
|
2016-01-04 15:18:09 -05:00
|
|
|
export function iconHTML(icon, params) {
|
2015-02-24 13:47:46 -05:00
|
|
|
params = params || {};
|
|
|
|
|
|
|
|
var html = "<i class='" + iconClasses(icon, params) + "'";
|
2016-05-23 16:50:18 -04:00
|
|
|
if (params.title) { html += ` title='${I18n.t(params.title)}'`; }
|
2015-02-24 13:47:46 -05:00
|
|
|
if (params.label) { html += " aria-hidden='true'"; }
|
2014-09-09 17:29:05 -04:00
|
|
|
html += "></i>";
|
2015-02-24 13:47:46 -05:00
|
|
|
if (params.label) {
|
|
|
|
html += "<span class='sr-only'>" + I18n.t(params.label) + "</span>";
|
2014-09-09 17:29:05 -04:00
|
|
|
}
|
2015-01-14 15:01:41 -05:00
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2015-01-28 11:01:01 -05:00
|
|
|
registerUnbound('fa-icon', function(icon, params) {
|
2015-02-24 13:47:46 -05:00
|
|
|
return new Handlebars.SafeString(iconHTML(icon, params));
|
2014-09-09 17:29:05 -04:00
|
|
|
});
|