We have a similar requirement where we need to show different color for different categories. We created a calculated column and stored the categories along with the title with "|" as separator.
Pls find the javascript code below.
_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');
var SEPARATOR = "|||";
function WaitForCalendarToLoad() {
// we will slightly rewrite this existing function as defined originally in SP.UI.ApplicationPages.Calendar.debug.js
var pwold$4a = SP.UI.ApplicationPages.CalendarNotify.$4a
SP.UI.ApplicationPages.CalendarNotify.$4a = function () {
pwold$4a();
ColourCalendar();
}
SP.UI.ApplicationPages.CalendarViewBase.prototype.resetSelection = function () {
ULSSPg: ;
if (SP.UI.ApplicationPages.CalendarViewBase.prototype.$4u_1) {
SP.UI.ApplicationPages.CalendarViewBase.prototype.$4u_1.$1D();
}
setTimeout("ColourCalendar()", 200);
}
// This code is added to hide the header (i.e. Chrome Type) of calendar
$(".ms-WPHeader").hide();
}
function ColourCalendar() {
if ($('a:contains(' + SEPARATOR + ')') != null) {
$('a:contains(' + SEPARATOR + ')').each(
function (i) {
$box = $(this).parents('div[title]');
var colour = GetColourCodeFromCategory(GetCategory(this.innerHTML));
this.innerHTML = GetActualText(this.innerHTML);
$($box).attr("title", GetActualText($($box).attr("title")));
$box.css('background-color', colour);
});
}
}
function GetActualText(originalText) {
var parts = originalText.split(SEPARATOR);
return parts[0] + parts[2];
}
function GetCategory(originalText) {
var parts = originalText.split(SEPARATOR);
return parts[1];
}
function GetColourCodeFromCategory(category) {
var colour = null;
switch (category.trim().toLowerCase()) {
case 'department':
colour = '#fef8d6';
break;
case 'company':
colour = '#d0ffbc';
break;
case 'personal':
colour = "#feebcd";
break;
case 'community':
colour = "#c8f0ff";
break;
}
return colour;
}