开发者

fullcalendar : updating option function callbacks after init

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').fullCa开发者_JAVA百科lendar('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?


Obviously I am sure you have already worked around this issue, but for anyone who may come across this problem, here is how I worked around it.

 $(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) {eventClickCustom(event)}
  });

var eventClickCustom = function(event)
{
    //do what you want here, you can can update this function all you want.
}

//then later
var eventClickCustom = function(event)
{
   //updated version of the function
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜