我正在使用FullCalendar插件,尝试使其在被拖入营业时间之外的区域时无法放置新事件。我已经做到了不能拖动到当前日期之前的任何日期,但不知道如何防止周末被拖动。
我不想采用硬编码的解决方案,并且必须针对特定的周末采用if than语句,因为如果我想在某个特定周的周三添加营业时间,只允许在下午1点至4点之间怎么办? 因此,我需要一种动态解决方案,可以传递一些JSON,例如事件:handles和businessHours也可以处理。
这是我目前示例的fiddle链接:http://jsfiddle.net/htexjtg6/。
我不想采用硬编码的解决方案,并且必须针对特定的周末采用if than语句,因为如果我想在某个特定周的周三添加营业时间,只允许在下午1点至4点之间怎么办? 因此,我需要一种动态解决方案,可以传递一些JSON,例如事件:handles和businessHours也可以处理。
$(document).ready(function() {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
drop: function() {
// is the "remove after drop" checkbox checked?
if ($('#drop-remove').is(':checked')) {
// if so, remove the element from the "Draggable Events" list
$(this).remove();
}
},
/* This constrains it to today or later */
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01' // hard coded must have
},
businessHours: {
start: moment().format('HH:mm'), /* Current Hour/Minute 24H format */
end: '17:00' // 5pm
}
});
});
这是我目前示例的fiddle链接:http://jsfiddle.net/htexjtg6/。