CRM.utils.formatDate = function(input, outputFormat) {
return input ? $.datepicker.formatDate(outputFormat || CRM.config.dateInputFormat, CRM.utils.makeDate(input)) : '';
};
+
+ // Used to set appropriate text color for a given background
+ CRM.utils.colorContrast = function (hexcolor) {
+ hexcolor = hexcolor.replace(/[ #]/g, '');
+ var r = parseInt(hexcolor.substr(0, 2), 16),
+ g = parseInt(hexcolor.substr(2, 2), 16),
+ b = parseInt(hexcolor.substr(4, 2), 16),
+ yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
+ return (yiq >= 128) ? 'black' : 'white';
+ };
+
})(jQuery, _);
});
$('input.crm-contact-tagset').each(function() {
$.each($(this).select2('data'), function (i, tag) {
- tags.push('<span class="crm-tag-item" title="' + (tag.description || '') + '"' + (tag.color ? 'style="color: #fff; background-color: ' + tag.color + ';"' : '') + '>' + tag.label + '</span>');
+ tags.push('<span class="crm-tag-item" title="' + (tag.description || '') + '"' + (tag.color ? 'style="color: ' + CRM.utils.colorContrast(tag.color) + '; background-color: ' + tag.color + ';"' : '') + '>' + tag.label + '</span>');
});
});
// contact summary tabs and search forms both listen for this event