这是在视图之间切换甚至拥有自定义菜单的方法:
将标题右侧的初始化设置为空白:
'header' => [ 'left'=>'today','center'=>'prev, title, next','right'=> ''],
(也就是Yii2中的格式,纯javascript类似)
使用jquery添加自定义标题html,使用jquery绑定一个函数来点击事件,创建一个函数来处理不同的情况并更改日历视图。
该功能已被彻底注释,此代码正在运行并正在生产中。
这是创建自定义右上角标题的 javascript,其中覆盖了标准完整日历按钮的处理:
var htm = '<div class="dropdown" style="display:-webkit-inline-box"><button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Bytt Visning</button><div class="dropdown-menu pull-right" style="width:170px" aria-labelledby="dropdownMenu2"><button class="dropdown-item fc-agendaDay-button fc-button fc-state-default fc-state-active" type="button">Dag</button><button class="dropdown-item fc-agendaWeek-button fc-button fc-state-default" type="button">Uke</button><button class="dropdown-item fc-month-button fc-button fc-state-default" type="button">Måned</button><button class="dropdown-item fc-listYear-button fc-button fc-state-default" type="button">År</button></div></div><button type="button" class="btn btn-secondary fc-listDay-button fc-button fc-state-default toggle"><i class="fa fa-toggle-off"></i></button><button type="button" class="btn btn-secondary fc-listWeek-button fc-button fc-state-default hidden toggle"><i class="fa fa-toggle-off"></i></button><button type="button" class="btn btn-secondary fc-listMonth-button fc-button fc-state-default hidden toggle"><i class="fa fa-toggle-off"></i></button>';
$(document).on('ready', function () {
$('.fc-right').append(htm);
$('.fc-listYear-button').on('click', {name:'listYear'},myChangeView);
$('.fc-month-button').on('click', {name:'month', toggle: 'listMonth'},myChangeView);
$('.fc-listMonth-button').on('click', {name:'listMonth', toggle: 'month'},myChangeView);
$('.fc-agendaWeek-button ').on('click', {name:'agendaWeek', toggle: 'listWeek'},myChangeView);
$('.fc-listWeek-button ').on('click', {name:'listWeek', toggle: 'agendaWeek'},myChangeView);
$('.fc-agendaDay-button').on('click', {name:'agendaDay', toggle: 'listDay'},myChangeView);
$('.fc-listDay-button').on('click', {name:'listDay', toggle: 'agendaDay'},myChangeView);
function myChangeView(event) {
if(event.data.toggle)//button with corresponding toggle button or toggle button
{
if(event.data.name.indexOf('list') == 0)//toggle button
{
if($('.fc-'+event.data.name+'-button').html() == '<i class="fa fa-toggle-on"></i>') //is it already toggled on?
{
$('.fc-'+event.data.name+'-button').html('<i class="fa fa-toggle-off"></i>'); //toggle to off
$('#calendar').fullCalendar('changeView', event.data.toggle);//render the opposite view to the current view (toggle views)
return; //do not proceed to the rest of the code
}
else //it was not already toggled on
{
$('.toggle').addClass('hidden'); //hide all toggles
$('.fc-'+event.data.name+'-button').html('<i class="fa fa-toggle-on"></i>');//toggle to on
$('.fc-'+event.data.name+'-button').removeClass('hidden'); //show that one toggle
}
}
else //button with corresponding toggle button (in dropdown menu)
{
$('.toggle').addClass('hidden'); //hide all toggles
$('.toggle').html('<i class="fa fa-toggle-off"></i>'); //toggle to off
$('.fc-'+event.data.toggle+'-button').removeClass('hidden'); //show that one toggle
}
}
else
{
$('.toggle').addClass('hidden'); //hide all toggles
$('.toggle').html('<i class="fa fa-toggle-off"></i>'); //reset all toggles to off
}
$('#calendar').fullCalendar('changeView', event.data.name); //render the requested view
};
});