最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - fullcalendar remember user option eg. monthweekday in cookie - Stack Overflow

programmeradmin1浏览0评论

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: .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: '/'});
    },

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./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: '/'});
    },
Share Improve this question edited Sep 24, 2012 at 22:27 John Magnolia asked Sep 24, 2012 at 21:23 John MagnoliaJohn Magnolia 16.8k39 gold badges169 silver badges274 bronze badges 1
  • In version 2 I had to change viewDisplay to viewRender for this to work. ie. viewRender: function( view , element) { .... – PhoebeB Commented Nov 24, 2015 at 9:46
Add a ment  | 

1 Answer 1

Reset to default 11

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.

发布评论

评论列表(0)

  1. 暂无评论