Advertisement
jamboljack

Calendar Drag n Drop

Jun 22nd, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. $(document).ready(function() {
  3.       /* initialize the external events
  4.       -----------------------------------------------------------------*/
  5.       $('#external-events .fc-event').each(function() {      
  6.          // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
  7.          // it doesn't need to have a start or end
  8.          var eventObject = {
  9.             title: $.trim($(this).text()) // use the element's text as the event title
  10.          };        
  11.          // store the Event Object in the DOM element so we can get to it later
  12.          $(this).data('eventObject', eventObject);        
  13.          // make the event draggable using jQuery UI
  14.          $(this).draggable({
  15.             zIndex: 999,
  16.             revert: true,      // will cause the event to go back to its
  17.             revertDuration: 0  //  original position after the drag
  18.          });        
  19.       });      
  20.       /* initialize the calendar
  21.       -----------------------------------------------------------------*/      
  22.       $('#calendar').fullCalendar({
  23.          header: {
  24.             left: 'prev,next today',
  25.             center: 'title',
  26.             right: 'month,agendaWeek,agendaDay'
  27.          },
  28.          editable: true,
  29.          droppable: true, // this allows things to be dropped onto the calendar !!!
  30.          drop: function(date) { // this function is called when something is dropped        
  31.             // retrieve the dropped element's stored Event Object
  32.             var originalEventObject = $(this).data('eventObject');            
  33.             // we need to copy it, so that multiple events don't have a reference to the same object
  34.             var copiedEventObject = $.extend({}, originalEventObject);            
  35.             // assign it the date that was reported
  36.             copiedEventObject.start = date;            
  37.             // render the event on the calendar
  38.             // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
  39.             $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);            
  40.             // is the "remove after drop" checkbox checked?
  41.             if ($('#drop-remove').is(':checked')) {
  42.                // if so, remove the element from the "Draggable Events" list
  43.                $(this).remove();
  44.             }            
  45.          }
  46.       });            
  47.    });
  48. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement