mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Split out common functions into discourse-common
module
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
import { registerUnbound } from 'discourse-common/lib/helpers';
|
||||
|
||||
export function iconClasses(icon, params) {
|
||||
let classes = "fa fa-" + icon;
|
||||
if (params.modifier) { classes += " fa-" + params.modifier; }
|
||||
if (params['class']) { classes += ' ' + params['class']; }
|
||||
return classes;
|
||||
}
|
||||
|
||||
export function iconHTML(icon, params) {
|
||||
params = params || {};
|
||||
|
||||
var html = "<i class='" + iconClasses(icon, params) + "'";
|
||||
if (params.title) { html += ` title='${I18n.t(params.title)}'`; }
|
||||
if (params.label) { html += " aria-hidden='true'"; }
|
||||
html += "></i>";
|
||||
if (params.label) {
|
||||
html += "<span class='sr-only'>" + I18n.t(params.label) + "</span>";
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
registerUnbound('fa-icon', function(icon, params) {
|
||||
return new Handlebars.SafeString(iconHTML(icon, params));
|
||||
});
|
Reference in New Issue
Block a user