Friday, April 6, 2012

Open SharePoint Calendar overlay events in modal dialog

I have calendar control with calendar overlays in a page to show calendar events to end-user. All calendar overlay events opens in a new window. But my client wanted to open those events in modal dialog, not in new window.

Then I used the below code in my page(where calendar control presents) using content editor webpart.

// load our function to the delayed load list
_spBodyOnLoadFunctionNames.push('calendarEventLinkIntercept');

// hook into the existing SharePoint calendar load function.
function calendarEventLinkIntercept()
{
if (SP.UI.ApplicationPages.CalendarNotify.$4a)
{
var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4a;
SP.UI.ApplicationPages.CalendarNotify.$4a = function ()
{
OldCalendarNotify();
bindEventClickHandler();
}
}
if (SP.UI.ApplicationPages.CalendarNotify.$4b)
{
var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4b;
SP.UI.ApplicationPages.CalendarNotify.$4b = function ()
{
OldCalendarNotify();
bindEventClickHandler();

}
}
// future service pack change may go here!
// if (SP.UI.ApplicationPages.CalendarNotify.???)
}

function bindEventClickHandler() {
$('.ms-acal-rootdiv a').click(function(){EditLink2(this,'WPQ2');return false;});
}


All overlay were opening in modal dialog :) [Just copy and paste the code]

Note: Find your calendar control's 'WPQ#' and replace the 'WPQ2' in bindEventClickHandler() with your 'WPQ#'. For some control the number changes. Ex: If you control with 'WPQ3' then replace 'WPQ2' with 'WPQ3' in bindEventClickHandler(). You can find that number in status bar of your browser on mouse over the month changing arrows.