description = row.description || $(row.element).data('description'),
ret = '';
if (icon) {
- ret += '<i class="crm-i ' + icon + '"></i> ';
+ ret += '<i class="crm-i ' + icon + '" aria-hidden="true"></i> ';
}
if (color) {
ret += '<span class="crm-select-item-color" style="background-color: ' + color + '"></span> ';
return ret + _.escape(row.text) + (description ? '<div class="crm-select2-row-description"><p>' + _.escape(description) + '</p></div>' : '');
}
+ /**
+ * Helper to generate an icon with alt text.
+ *
+ * See also smarty `{icon}` and CRM_Core_Page::crmIcon() functions
+ *
+ * @param string icon
+ * The Font Awesome icon class to use.
+ * @param string text
+ * Alt text to display.
+ * @param mixed condition
+ * This will only display if this is truthy.
+ *
+ * @return string
+ * The formatted icon markup.
+ */
+ CRM.utils.formatIcon = function (icon, text, condition) {
+ if (typeof condition !== 'undefined' && !condition) {
+ return '';
+ }
+ var title = '';
+ var sr = '';
+ if (text) {
+ text = _.escape(text);
+ title = ' title="' + text + '"';
+ sr = '<span class="sr-only">' + text + '</span>';
+ }
+ return '<i class="crm-i ' + icon + '"' + title + ' aria-hidden="true"></i>' + sr;
+ };
+
/**
* Wrapper for select2 initialization function; supplies defaults
* @param options object
placeholder = settings.placeholder || $el.data('placeholder') || $el.attr('placeholder') || $('option[value=""]', $el).text();
if (m.length && placeholder === m) {
iconClass = $el.attr('class').match(/(fa-\S*)/)[1];
- out = '<i class="crm-i ' + iconClass + '"></i> ' + out;
+ out = '<i class="crm-i ' + iconClass + '" aria-hidden="true"></i> ' + out;
}
return out;
};
}
_.each(createLinks, function(link) {
markup += ' <a class="crm-add-entity crm-hover-button" href="' + link.url + '">' +
- '<i class="crm-i ' + (link.icon || 'fa-plus-circle') + '"></i> ' +
+ '<i class="crm-i ' + (link.icon || 'fa-plus-circle') + '" aria-hidden="true"></i> ' +
_.escape(link.label) + '</a>';
});
markup += '</div>';
*/
var currencyTemplate;
CRM.formatMoney = function(value, onlyNumber, format) {
- var decimal, separator, sign, i, j, result;
+ var precision, decimal, separator, sign, i, j, result;
if (value === 'init' && format) {
currencyTemplate = format;
return;
}
format = format || currencyTemplate;
- result = /1(.?)234(.?)56/.exec(format);
- if (result === null) {
+ if ((result = /1(.?)234(.?)56/.exec(format)) !== null) { // If value is formatted to 2 decimals
+ precision = 2;
+ }
+ else if ((result = /1(.?)234(.?)6/.exec(format)) !== null) { // If value is formatted to 1 decimal
+ precision = 1;
+ }
+ else if ((result = /1(.?)235/.exec(format)) !== null) { // If value is formatted to zero decimals
+ precision = false;
+ }
+ else {
return 'Invalid format passed to CRM.formatMoney';
}
separator = result[1];
- decimal = result[2];
+ decimal = precision ? result[2] : false;
sign = (value < 0) ? '-' : '';
//extracting the absolute value of the integer part of the number and converting to string
i = parseInt(value = Math.abs(value).toFixed(2)) + '';
j = ((j = i.length) > 3) ? j % 3 : 0;
- result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : '');
- if ( onlyNumber ) {
+ result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (precision ? decimal + Math.abs(value - i).toFixed(precision).slice(2) : '');
+ if (onlyNumber) {
return result;
}
- return format.replace(/1.*234.*56/, result);
+ switch (precision) {
+ case 2:
+ return format.replace(/1.*234.*56/, result);
+ case 1:
+ return format.replace(/1.*234.*6/, result);
+ case false:
+ return format.replace(/1.*235/, result);
+ }
};
CRM.angRequires = function(name) {