Detect background events

故事扮演 提交于 2019-12-11 05:53:02

问题


I am using FullCalendar in my project. I used background events, rendering="background". How can I detect if user click on the background events? I try this but it doesnot work since all dates cannot be clicked.

dayClick: function (start, end, allDay, jsEvent, view,color,calEvent) {
            if (calevent.rendering==="background") {
                alert('Click Background Event Area');
            }
            else{
            $('#modal1').modal('show');
           }

            if (start.isBefore(moment())) {
                $('#calendar').fullCalendar('unselect');
                return false;
            }
        },

回答1:


Since fullCalendar doesn't expose an "click" type event on background events, the only way I can think of to do this is essentially a DIY approach. The basic idea:

  • Handle the "select" event
  • Fetch all the events currently in fullCalenar's memory, using the "clientEvents" method.
  • Loop through them all and check whether any of them are background events, and if so, whether they overlap with the selected time period. If they do, then that's the event that was clicked on.

I haven't tested this, but it's based on some old code I found, so hopefully you get the idea:

select: function(start, end, jsEvent, view) {
    var cal = $("#calendar"); //put the ID of your calendar element here
    var evts = cal.fullCalendar('clientEvents'); //get all in-memory events
    var selectedEvent = null;

    for (i in evts) {
        if (evts[i].rendering == "background" && start.isBefore(evts[i].end) && end.isAfter(evts[i].start)) {
            selectedEvent = evts[i];
        }
    }
}

The only flaw in this is that "select" allows selection of a time period, not just a single click, so it could be that the selection is overlapping the background event, and not wholly contained within it. You might be able to adjust the logic a little bit if that doesn't suit you - e.g. to require that both start and end are within the event's boundaries.



来源:https://stackoverflow.com/questions/42477878/detect-background-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!