2012-03-14 59 views
9

我已經設置FullCalendar接受丟棄,它可以。但可拖動的對象,我用回覆構建的:'無效'似乎無法識別FullCalendar上的日期爲可丟棄,並返回。這裏是我的代碼:Fullcalendar:即使fullcalendar接受丟棄,可拖動對象拒絕fullcalendar作爲可丟棄

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html><head> 

    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> 
    <title>mydrag</title> 
    <script src="fullcalendar-bundle.js" type="text/javascript"></script> 
</head><body> 
<div id="mydrag" style="width: 200px; height: 100px; background-color: red;">My Drag</div> 
<div id="calendar"></div> 


<script type="text/javascript"> 
function onExternalEventDrop(date, allDay) { 
    alert("Dropped on " + date + " with allDay=" + allDay); 
} 

$('#mydrag').each(function() { 

    // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 
    // it doesn't need to have a start or end 
    var eventObject = { 
     title: 'MyDrag Title' 
    }; 

    // store the Event Object in the DOM element so we can get to it later 
    $(this).data('eventObject', eventObject); 

    // make the event draggable using jQuery UI 
    $(this).draggable({ 
     helper: 'clone', 
     //revert: 'invalid', 
     revert: function(droppableObj) { 
      //if false then no socket object drop occurred. 
      if(droppableObj === false) { 
       //revert the .myselector object by returning true 
       alert('Not a droppable object'); 
       return true; 
      } 
      else { 
       //droppableObj was returned, 
       //we can perform additional checks here if we like 
       //alert(droppableObj.attr('id')); would work fine 
       //return false so that the .myselector object does not revert 
       return false; 
      } 
     }, 
     revertDuration: 500, // original position after the drag 
     start: function(e, ui) { 
      $(ui.helper).css('width', $(this).css('width')); 
     } 
    }); 

}); 

$('#calendar').fullCalendar({ 
    aspectRatio: 2.25, 
    header: { 
     left: '', 
     center: 'title', 
     right: 'prev,next' 
    }, 
    columnFormat: { 
     month: 'dddd' 
    }, 
    droppable: true, 
    drop: onExternalEventDrop 
}); 

</script> 
</body></html> 

當我拖動拖動元素到日曆,元素會恢復(這意味着日曆日期並不被認爲是有效的投擲的)......但回落回調以預期的警報觸發(提示FullCalendar將可拖動的操作識別爲有效)。我期望這個可拖動的不應該恢復。我在做什麼或期待錯誤?我已經搜遍了,但沒有找到任何解釋。任何幫助將不勝感激。

更新:忘了提,我所說的 「fullcalendar-bundle.js」 是一個包含以下文件:

  • 的jQuery 1.5.2
  • jQuery UI的1.8.11
  • fullcalendar 1.5.2插件

另一個更新:我剛剛嘗試過FullCalendar 1.5.3版本,但看到相同的行爲。

回答

5

這可以幫助你:阻力

工作版本和下降http://jsfiddle.net/wkKfB/15/

解決方案dragobj =假的是,你需要投擲的事件綁定到日曆使拖動知道什麼DOM對象是可下載在這裏看到工作示例:http://jsfiddle.net/CZQkm/3/ & & http://jsfiddle.net/DEsdN/12/ *直到這裏

您的版本,但有一些調整。通過我在這裏jsfiddl-ED您的問題的方式:http://jsfiddle.net/wkKfB/16/)(問題是有約束力的外部事件)

良好的文件駐留在這裏:http://arshaw.com/fullcalendar/docs/dropping/droppable/

的問題是,你需要從外部添加這些拖動事件。

你可以改變CSS並使之適合你的使用。

報價 * [從上面的文檔中可以看到外部拖放。] * http://arshaw.com/fullcalendar/docs/dropping/droppable/

>  How can I use this to add events??? 
>  
>  Good question. It is a common need to have an "external list of events" that can be dragged onto the calendar. 
>  
>  While the droppable option deals with generic jQuery UI draggables and is not specifically tailored to adding events, it is possible to 
> achieve this with a few lines of code. Follow the 
> external-dragging.html example in FullCalendar's download. You can 
> also view the example online. 
>  
>  In short, you must call renderEvent yourself in the drop callback. 

另一個鏈接:http://arshaw.com/js/fullcalendar-1.5.3/demos/external-dragging.html

要捕捉你需要添加該代碼的外部事件,但上面的例子有所有設置你應該清楚

/* initialize the external events 
    -----------------------------------------------------------------*/ 
$('#external-events div.external-event').each(function() { 

    // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 
    // it doesn't need to have a start or end 
    var eventObject = { 
     title: $.trim($(this).text()) // use the element's text as the event title 
    }; 

    // store the Event Object in the DOM element so we can get to it later 
    $(this).data('eventObject', eventObject); 

    // 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 
-----------------------------------------------------------------*/