views:

323

answers:

1

Ok, so I have a problem with setting options whose values are callback functions when trying to set them after plugin initialization. I think this would be a common behavior, to dynamically set event callback after init'ing the calendar.

Here is a snipit of code:

 $(document).ready(function() {
  $('#calendar').fullCalendar({
   editable: false
   ,events:[{"title":"meeting.title","start":"2010-05-21 15:58:16 UTC"},{"title":"meeting.title","start":"2010-05-24 15:58:16", "url":"http://google.com"}]
 /*  ,eventClick: function(event) { 
              if (event.url) {
                  window.open(event.url);
                  return false;
              }
          }
   */
  });
 $('#calendar').fullCalendar('option', 'eventClick', function(event) {
          if (event.url) {
              window.open(event.url);
              return false;
          }
      });

});

You can see that setting the eventClick function as an init option commented out. If I do it that way, it works fine. However if I try to set it after the init, it doesn't work :(

Is the some other way to do this? Or am I stuck with having to set the behavior upfront?

A: 

The fullCalendar eventClick is a callback method. After looking through the code, I don't think you are able to add this option after the calendar has been initialized. I even tried adding the eventClick function to the calendar's data (where it stores public functions). So, the only alternative I can think of would be to attach your own event handler. You could try this:

$('#calendar').find('.fc-event,.ui-event').find('a[href]').live('click', function(){
 window.open( $(this).attr('href') );
 return false;
})

Oh and the reason I'm targeting both the .fc-event and .ui-event classes is because it changes depending if you are using the theme option.

fudgey
I appreciate that timely feedback. I was considering that very thing (using live and binding) however I was hoping for being able to call fullcalendar with the "option" arg as that works fine with other plugins (albiet more basic). I think the manner in which events are bound and triggered with fullcalendar events is what prevents this. For example binding to the child node (fc-event) rather then the fullcalendar node itself.The main question, was if it were possible to set callback methods like eventClick dynamically after the plugin as already been initialized. Thanks for your answer.
Paul Maneesilasan
Opps, I had `event.url` instead of the `href` attribute. Also, I know that is what you wanted, I'm just not sure it is possible.
fudgey