|
//<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |
|
|
|
// enter category colors here, cat has to match your calendar's Category choices |
|
// the key is to make a Calculated column called EventTitle defined like this: =Title&" ["&Category&"]" |
|
// set your calendar View to use this field instead of Title for Week View, Month View and Day View title. |
|
// then it's easy to use jQuery to find all the cats and color them - see Colorize function |
|
var colors = [ |
|
{ |
|
'cat': 'Appointment', |
|
'color': '#37817e', |
|
'fore': 'black', |
|
'show': true |
|
}, |
|
{ |
|
'cat': 'Birthday', |
|
'color': '#790c1a', |
|
'fore': 'black', |
|
'show': true |
|
}, |
|
{ |
|
'cat': 'Conference', |
|
'color': '#5240ba', |
|
'fore': 'white', |
|
'show': true |
|
}, |
|
{ |
|
'cat': 'Sick', |
|
'color': '#FF0055', |
|
'fore': 'white', |
|
'show': true |
|
}, |
|
{ |
|
'cat': 'Vacation', |
|
'color': 'green', |
|
'fore': 'white', |
|
'show': true |
|
}, |
|
{ |
|
'cat': 'Working from home', |
|
'color': '#FF4499', |
|
'fore': 'white', |
|
'show': true |
|
}]; |
|
|
|
$(document).ready(function() |
|
{ |
|
|
|
setTimeout(Colorize, 100); |
|
$("#colors").toggle(); |
|
}); |
|
|
|
function setFilter(title,checked) |
|
{ |
|
|
|
for (i = 0; i < colors.length; i++) |
|
{ |
|
|
|
if(colors[i].cat==title) |
|
colors[i].show=checked; |
|
} |
|
applyFilter(); |
|
} |
|
|
|
function applyFilter() |
|
{ |
|
for (i = 0; i < colors.length; i++) |
|
{ |
|
if(colors[i].show==true) |
|
$("div[title$='\\[" + colors[i].cat + "\\]']").show(); |
|
else |
|
$("div[title$='\\[" + colors[i].cat + "\\]']").hide(); |
|
} |
|
} |
|
|
|
function showColors() |
|
{ |
|
var chkId=""; |
|
var html = "<h2>Filter by calendar categories</h2>Use checkboxes to show/hide categories.<table>"; |
|
for (i = 0; i < colors.length; i++) |
|
{ |
|
chkId = colors[i].cat.replace(/\s/g, ''); |
|
html += "<tr><td style='padding:10px;background-color:"+ colors[i].color +";color:white'>" + colors[i].cat + "</td><td><input type='checkbox' onclick=\"setFilter('"+ colors[i].cat +"',this.checked)\" title='check-"+ chkId +"'><td></tr>" |
|
} |
|
html+="</table><a href='javascript:showColors();'>Close</a>" |
|
$("#colors").html(html); |
|
for (i = 0; i < colors.length; i++) |
|
{ |
|
chkId = colors[i].cat.replace(/\s/g, ''); |
|
if(colors[i].show==true) |
|
$("input[title='check-" + chkId + "']").attr('checked','checked'); |
|
} |
|
$("#colors").toggle(); |
|
} |
|
|
|
function Colorize() |
|
{ |
|
|
|
$(".ms-acal-time").hide(); |
|
|
|
for (i = 0; i < colors.length; i++) |
|
{ |
|
$("div[title$='\\[" + colors[i].cat + "\\]']").css('background-color', colors[i].color); |
|
|
|
|
|
} |
|
|
|
$("a").click(function() |
|
{ |
|
//alert('click2'); |
|
setTimeout(Colorize, 100); |
|
}); |
|
applyFilter(); |
|
} |
|
|
|
/* |
|
<a href='javascript:showColors()'>Category Colors and Filtering</a><span style='z-index:100000;position:absolute; top:40px;background-color:#FFFFFF; border-radius: 25px; |
|
border: 2px solid #c0c0c0;padding:30px' id='colors' /> |
|
|
|
*/ |
|
|
|
// BONUS, expand all events |
|
function expandCal() { |
|
|
|
setTimeout(expandCalCheck, 500); |
|
} |
|
function expandCalCheck() { |
|
var a=$("a.ms-cal-nav", $("div.ms-acal-rootdiv:last>div")).get(0); |
|
if (a) { |
|
for (var r=0; r<6; r++) { |
|
var a=$("a.ms-cal-nav", $("div.ms-acal-rootdiv:last>div").get(r)).get(0); |
|
if (a) |
|
if (a.innerText.indexOf("more") >= 0) |
|
a.click(); |
|
} |
|
} |
|
} |
|
ExecuteOrDelayUntilScriptLoaded(expandCal, "sp.ui.applicationpages.calendar.js"); |
This also includes checkbox filtering for each category