简体   繁体   English

FullCalendar修改调整大小的标题

[英]FullCalendar Modify Header on Resize

I'm using FullCalendar and I'm attempting to make it responsive by changing the view when the window size is below a certain size: 我正在使用FullCalendar ,我试图通过在窗口大小低于特定大小时更改视图来使其响应:

windowResize : function(view) {
    if ($(window).width() < 500) {
        $('#calendar').fullCalendar('changeView', 'basicDay');
    } else {
        $('#calendar').fullCalendar('changeView', 'month');
    }
    // modify the header (remove options for month and week and remove title)
}

That works fine but how can I modify the header (remove options for month and week and remove title)? 这工作正常但我怎么能修改标题(删除月和周的选项并删除标题)? You can see an example of the calendar here . 您可以在此处查看日历示例。

Header is set as such: 标题设置如下:

$('#calendar').fullCalendar({
    header : {
        left : 'prev,next today',
        center : 'title',
        right : 'month,basicWeek,basicDay'
    }
});

I needed a responsive script too, but the best i get was: 我也需要一个响应式脚本,但我得到的最好的是:

var view = 'month';
var header = {
            left : "title",
            center : "",
            right : "prev,next month,basicWeek,basicDay today"
    };
if ($(window).width() <= 480) {
    view = 'basicDay';
    header = {
        left : 'prev,next today',
        center : '',
        right : ''
    };
}
var acalendar = $("#ccalendar").fullCalendar(
            {
                            lang : "pt-BR",
                            defaultView : view,
                            header : header
             }

Maybe you can rebuild de calendar on resize. 也许你可以在resize上重建de calendar。

You can simply remove or hide it using jquery, 您可以使用jquery删除或隐藏它,

 $(".fc-header-title").hide();
 $(".fc-button-month").hide();
 $(".fc-button-basicWeek").hide();
windowResize:function(view){
    var isBigScreen = $(window).width() > 768;
    if(isBigScreen){
       $('.fc-agendaWeek-button').show();
       $('#calendar').fullCalendar('changeView', 'agendaWeek');
    }else{
       $('.fc-agendaWeek-button').hide();
       $('#calendar').fullCalendar('changeView', 'agendaDay');
    } 
}

basically,you need to find the class you want to hide and use jquery hide(). 基本上,你需要找到你想要隐藏的类并使用jquery hide()。

if you don't want the option of month, week, or day just remove it from the properties block. 如果您不想要月,周或日的选项,只需从属性块中删除它。

$('#calendar').fullCalendar({
header : {
    left : 'prev,next today',
    center : 'title',
    right : 'month'
}});

Notice that I removed 'basicWeek', 'basicDay' from the right section. 请注意,我从右侧部分删除了'basicWeek','basicDay'。 This code will only display the month view option. 此代码仅显示月视图选项。 FullCalendar provides you with a sort of a template for the header in which you have the left, center, and right section. FullCalendar为您提供了一种左侧,中间和右侧部分的标题模板。 You only have to declare what you need. 你只需申报你需要的东西。 In this link you will find all the buttons options that you may have in the header: 在此链接中,您将找到标题中可能包含的所有按钮选项:

http://arshaw.com/fullcalendar/docs/display/header/ http://arshaw.com/fullcalendar/docs/display/header/

Good Luck! 祝好运!

The following solution takes advantage of the fact that Javascript objects be accessed as if they were associative arrays . 以下解决方案利用了Javascript对象被访问的事实, 就好像它们是关联数组一样 One downside to this method is that the options need to be set inside the Calendar object before the calendar can be initialised, including events. 此方法的一个缺点是,在初始化Calendar之前,需要在Calendar对象内设置选项,包括事件。

The Calendar.views object stores a list of objects that correspond with the various views available to this calendar, eg Calendar.views.agendaDay is an object that contains the initialisation options for agendaDay . Calendar.views对象存储与此日历可用的各种视图对应的对象列表,例如Calendar.views.agendaDay是包含agendaDay初始化选项agendaDay

Calendar.whichView determines the name of the view to initialise based on the width of the window. Calendar.whichView根据窗口的宽度确定要初始化的视图的名称。

Working Example: http://jsfiddle.net/7jbuzu7x/ 工作示例: http//jsfiddle.net/7jbuzu7x/

var Calendar = {
  e: $('#calendar'),

  views: {
    agendaDay: {
      defaultView: 'agendaDay',
      slotDuration: '00:15:00',
      minTime: '00:00:00',
      maxTime: '20:00:00',
      header: {
        right: 'prev,next today',
        left: 'title'
      }
    },
    agendaWeek: {
      defaultView: 'agendaWeek',
      slotDuration: '00:30:00',
      minTime: '09:00:00',
      maxTime: '17:00:00',
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'agendaDay,agendaWeek,month'
      }
    }
  },

  resize: function() {
    if (Calendar.whichView($(document).width()) !== Calendar.e.fullCalendar('getView')) {
      Calendar.e.fullCalendar('destroy');
      Calendar.init();
    } 
  },

  whichView: function(width) {
    if (width < 601) {
      return 'agendaDay';
    } else {
      return 'agendaWeek';
    }
  },

  init: function() {
    Calendar.e.fullCalendar(Calendar['views'][Calendar.whichView($(document).width())]);
  }
}

$(function() {
  Calendar.init();
  $(window).resize(Calendar.resize);
});

Working Example : Working Example 工作示例: 工作示例

$('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        windowResize: function (view) {
            var view = getView();
            //Change view during window resize
            $('#calendar').fullCalendar('changeView', view);
            //Update header during window resize
            $('#calendar').fullCalendar('updateHeader',getHeader(), view);                
        },
        defaultDate: new Date(),
        editable: true,
        eventLimit: true,

    });

    function getHeader() 
        {
     if (window.innerWidth < 768) {
         return {
             left: 'prev today',
             center: 'title',
             right: 'next'
         };

     }
     else {
         return {
             left: 'prev,next today ',
             center: 'title',
             right: 'month,basicWeek,basicDay'
         }
     }
 }
 function getView() 
        {
     if (window.innerWidth < 768) {
         return "basicDay";
     }
     else {
     return "month";
     }
 }

fullcalendar.js fullcalendar.js

Add this line inside constructor 在构造函数中添加此行

t.updateHeader = updateHeader;

And add this function 并添加此功能

function updateHeader(newHeader, currentView)
    {
        t.options.header = newHeader;
        headerElement = header.render();

        updateHeaderTitle();
        updateTodayButton();
        header.activateButton(currentView);

        //replace current header with new header
        if (headerElement) {
            $("div.fc-toolbar").remove();
            element.prepend(headerElement);
        }
    }
   windowResize: function (view) {
      if ($(window).width() < 500) {
        $(this).fullCalendar('option', {
          header: {
            left: 'prev,next',
            center: '',
            right: 'basicDay'
          }
        });
        $(this).fullCalendar('changeView', 'basicDay');
      } else {
        $(this).fullCalendar('option', {
          header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
          }
        });
        $(this).fullCalendar('changeView', 'month');
      }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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