简体   繁体   中英

fullcalendar remember user option eg. month/week/day in cookie

How could I modify the fullcalendar plugin so that this saves the different click methods dayClick etc in a cookie? The next time this calendar is opened if would default to the user preference.

Already using the cookie plugin: https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js

Update of working cookie code following answer:

var calendarView = (!$.cookie('calendarDefaultView')) ? 'month' : $.cookie('calendarDefaultView');  
$calendar.fullCalendar({
    defaultView: calendarView,
    viewDisplay: function(view){
        $.cookie('calendarDefaultView', view.name, {expires:7, path: '/'});
    },

The two fullcalendar methods you need are:

//pull viewName from the cookie or set as default
var viewName='month'; //or basicWeek, basicDay, agendaWeek, agendaDay
$("#fullcalendar").fullCalendar( 'changeView', viewName );

and

$('#fullcalendar').fullCalendar({
        viewDisplay: function( view )
        {
           //save your cookie here, it's triggered each time the view changes
        }
});

This should put you on the right path. I didn't look at saving the cookie b/c I think you have that under control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM