new option: dropAccept

This commit is contained in:
Adam Shaw 2010-07-03 17:09:14 -07:00
parent c0c144569f
commit 1f02eb5f91
4 changed files with 54 additions and 24 deletions

View file

@ -1161,11 +1161,7 @@ function Agenda(element, options, methods) {
/* External dragging
-----------------------------------------------------*/
view.isExternalDraggable = function(_element) {
return _element.parentNode != daySegmentContainer[0] && _element.parentNode != slotSegmentContainer[0];
};
view.dragStart = function(ev) {
view.dragStart = function(_dragElement, ev, ui) {
hoverListener.start(function(cell) {
clearOverlay();
if (cell) {
@ -1180,11 +1176,11 @@ function Agenda(element, options, methods) {
}, ev);
};
view.dragStop = function(ev, ui) {
view.dragStop = function(_dragElement, ev, ui) {
var cell = hoverListener.stop();
clearOverlay();
if (cell) {
view.trigger('drop', ev.target, cellDate(cell), cellIsAllDay(cell), ev, ui);
view.trigger('drop', _dragElement, cellDate(cell), cellIsAllDay(cell), ev, ui);
}
};

View file

@ -562,11 +562,7 @@ function Grid(element, options, methods) {
/* External dragging
------------------------------------------------------*/
view.isExternalDraggable = function(_element) {
return _element.parentNode != segmentContainer[0];
};
view.dragStart = function(ev, ui) {
view.dragStart = function(_dragElement, ev, ui) {
hoverListener.start(function(cell) {
clearOverlay();
if (cell) {
@ -575,12 +571,12 @@ function Grid(element, options, methods) {
}, ev);
};
view.dragStop = function(ev, ui) {
view.dragStop = function(_dragElement, ev, ui) {
var cell = hoverListener.stop();
clearOverlay();
if (cell) {
var d = cellDate(cell);
view.trigger('drop', ev.target, d, true, ev, ui);
view.trigger('drop', _dragElement, d, true, ev, ui);
}
};

View file

@ -821,21 +821,34 @@ $.fn.fullCalendar = function(options) {
$(window).resize(windowResize);
/* External event dropping
--------------------------------------------------------*/
if (options.droppable) {
var _dragElement;
$(document)
.bind('dragstart', function(ev, ui) {
if (view.isExternalDraggable(ev.target)) {
view.dragStart(ev, ui);
var _e = ev.target;
var e = $(_e);
if (!e.parents('.fc').length) { // not already inside a calendar
var accept = options.dropAccept;
if (!accept || ($.isFunction(accept) ? accept.call(_e, e) : e.is(accept))) {
_dragElement = _e;
view.dragStart(_dragElement, ev, ui);
}
}
})
.bind('dragstop', function(ev, ui) {
if (view.isExternalDraggable(ev.target)) {
view.dragStop(ev, ui);
if (_dragElement) {
view.dragStop(_dragElement, ev, ui);
_dragElement = null;
}
});
}
// let's begin...
changeView(options.defaultView);

View file

@ -13,21 +13,18 @@
var y = date.getFullYear();
$('#calendar').fullCalendar({
editable: true,
droppable: true,
drop: function(date, allDay) {
console.log('drop', date, allDay);
},
//defaultView: 'agendaWeek',
//isRTL: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
},
editable: true,
events: [
{
title: 'All Day Event',
@ -78,7 +75,28 @@
$('.external-event').draggable({
revert: true,
revertDuration: 0
revertDuration: 0,
zIndex: 999
});
$('#calendar2').fullCalendar({
droppable: true,
dropAccept: '.for-calendar2',
/*
dropAccept: function(e) {
console.log(e);
console.log(this);
return e.text() == 'Draggable 1';
},
*/
drop: function(date, allDay) {
console.log('drop 2nd calendar', date, allDay);
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
}
});
});
@ -119,6 +137,11 @@
cursor: pointer;
}
#calendar2 {
width: 900px;
margin-top: 50px;
}
</style>
</head>
<body>
@ -126,7 +149,9 @@
<div id='external-events'>
<div class='external-event'>Draggable 1</div>
<div class='external-event'>Draggable 2</div>
<div class='external-event'>Draggable 3</div>
<div class='external-event for-calendar2'>Draggable 3</div>
</div>
<div style='clear:both'></div>
<div id='calendar2'></div>
</body>
</html>