Adding color to Sharepoint 2007 calendar (MOSS)

Found a good walk through for this the other day

http://planetwilson.blogspot.com/2007/09/sharepoint-2007-colour-color-calendar.html

Note: The code does not copy right, and if you change the lables at the end of the code keep them in lower case. I ended up wasting some time on that little messup.

Calendar Color

Here is a little easier way to copy the java script that is listed on the blog that I linked above.


<script>
var SEPARATOR = "|||";

var nodes, category;

nodes = document.getElementsByTagName("a");

for(var i = 0; i < nodes.length; i++)
{

 if(nodes&#91;i&#93;.innerText.indexOf(SEPARATOR) != -1)
 {
    UpdateCalendarEntryText(nodes&#91;i&#93;);

    var foundNode = nodes&#91;i&#93;;
    var trap = 0;

    while(foundNode.nodeName.toLowerCase() != "td")
    {
       foundNode = foundNode.parentNode;

       trap++;
       if(trap > 10)
       {
          break; // don't want to end up in a loop

            }
    }

    var colour = GetCalendarColour(category);
    if(colour != "")

       foundNode.style.background = colour;
 }
}

function UpdateCalendarEntryText(anchorNode)
{

 var children = anchorNode.childNodes;
 for(var i = 0; i < children.length; i++)
 {

    if(children&#91;i&#93;.nodeType == 3 && children&#91;i&#93;.nodeValue.indexOf(SEPARATOR) != -1)
    {
       var parts = children&#91;i&#93;.nodeValue.split(SEPARATOR);

       category = parts&#91;0&#93;;
       children&#91;i&#93;.nodeValue = parts&#91;1&#93;;
    }

    else
       UpdateCalendarEntryText(children&#91;i&#93;);
 }
}

function GetCalendarColour(desc)
{

 var colour;
 switch(desc.toLowerCase())
 {
    case "appointment":

       colour = "#ffd266";
       break;
    case "birthday":

       colour = "#ae99dc";
       break;
    case "business":

       colour = "#8aabe0";
       break;
    case "important":

       colour = "#e77379";
       break;
    case "vacation":

       colour = "#fffa91";
       break;
    default:
       colour = "";
 }

 return colour;
}

</script>

One Response to Adding color to Sharepoint 2007 calendar (MOSS)

Leave a comment