, , , , , .
jQuery UI Draggable, .
The event is copied when the user drags the event while holding down the ctrl key, while the original event remains in place and a new event is created in which the dragged jQuery object is discarded.
let ctrlIsPressed = false;
function setEventsCopyable(isCopyable) {
ctrlIsPressed = !ctrlIsPressed;
$("#calendar").fullCalendar("option", "eventStartEditable", !isCopyable);
$(".fc-event").draggable("option", "disabled", !isCopyable);
}
$(document).keydown(function(e) {
if (e.ctrlKey && !ctrlIsPressed) {
setEventsCopyable(true);
}
});
$(document).keyup(function(e) {
if (ctrlIsPressed) {
setEventsCopyable(false);
}
});
$("#calendar").fullCalendar({
defaultView: "basicWeek",
events: [
{
title: "Event 1",
start: moment(),
end: moment().add(1, "d")
},
{
title: "Event 2",
start: moment().add(1, "d"),
end: moment().add(2, "d")
}
],
editable: true,
droppable: true,
eventAfterAllRender(event, element, view) {
$(".fc-event").each(function() {
const $event = $(this);
const event = $event.data("fcSeg").footprint.eventDef;
$event.data("event", event);
$event.draggable({
disabled: true,
helper: "clone",
revert: true,
revertDuration: 0,
zIndex: 999,
stop(event, ui) {
if (ctrlIsPressed) {
setEventsCopyable(true);
}
}
});
});
}
});
Working Codepen .
source
share