Add Italian holidays into fullcalendar

萝らか妹 提交于 2019-12-02 04:27:20

问题


I use FullCalendar in my application and its working.

Now I need to change the color of Italian holidays into red. I did it for weekends but:

  1. I don't know how to add holidays in calendar.
  2. How can i change their color.

This is my code :

<script>
    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev',
            center: 'title',
            right: 'next',
        },
        defaultView: 'month',
        lang: 'it',
        height: 600,
        dayClick: function(date, jsEvent, view) {
            // Changing BG color
            $(this).css('background-color', 'green');
            //Create modal here
            $('#myModal').modal();
            // Show Date in SPAN
            $('#spnDate').html(date.format('DD/MM/YYYY'));
            // Put Date value in a variable 
            $('#date').attr('value', date.format('DD/MM/YYYY'));

        },
        editable: true,
    });
</script>

回答1:


You should use another eventSource that provides the holidays. These events can have a property like holiday, that specify that the event is indeed a holiday.

Based on this holiday, you can change the background color of the day with eventRender

You will have to add the following code to var calendar = $('#calendar').fullCalendar({:

eventSources: [
    {
        url: 'fullcalendar/holidays' // url to get holiday events
    }
    // any other sources...
],
eventRender: function(event, element, view) {
    // lets test if the event has a property called holiday. 
    // If so and it matches '1', change the background of the correct day
    if (event.holiday == '1') {
        var dateString = event.start.format("YYYY-MM-DD");

        $(view.el[0]).find('.fc-day[data-date=' + dateString + ']')
                        .css('background-color', '#FAA732');
    }
},

Your JSON object should look like this:

[{"title":"Christmas","start":"2014-12-25","holiday":"1"},{"title":"Another holiday","start":"2014-10-14","holiday":"1"}]



来源:https://stackoverflow.com/questions/26361913/add-italian-holidays-into-fullcalendar

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