Skip to content

Instantly share code, notes, and snippets.

@madhur
Created December 21, 2011 09:23
Show Gist options
  • Save madhur/1505353 to your computer and use it in GitHub Desktop.
Save madhur/1505353 to your computer and use it in GitHub Desktop.
Color coded SharePoint 2010 Calendar
_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');
var SEPARATOR = "|||";
function WaitForCalendarToLoad()
{
if (SP.UI.ApplicationPages.CalendarNotify.$4a)
{
var OldCalendarNotify =
SP.UI.ApplicationPages.CalendarNotify.$4a;
SP.UI.ApplicationPages.CalendarNotify.$4a = function ()
{
OldCalendarNotify();
ColourCalendar();
}
}
if (SP.UI.ApplicationPages.CalendarNotify.$4b)
{
var OldCalendarNotify =
SP.UI.ApplicationPages.CalendarNotify.$4b;
SP.UI.ApplicationPages.CalendarNotify.$4b = function ()
{
OldCalendarNotify();
ColourCalendar();
}
}
}
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 'business unit attendance matrix':
colour = '#4FDB51';
break;
case 'business unit tech reviews/sss schedule':
colour = '#4FB8DB';
break;
case 'business partner status updates':
colour = "#F08616";
break;
case 'business unit tech reviews':
colour = "#F55875";
break;
case 'town halls/ roundtable schedule':
colour = "#E0F558";
break;
case 'investment management and lfo review schedules':
colour = "#F558D5";
break;
case 'employee meetings':
colour = "#6E80FA";
break;
case 'staff meetings':
colour = "#FF4040";
break;
}
return colour;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment