external-dragging-jqueryui.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.js'></script>
  6. <script src='https://cdn.jsdelivr.net/npm/[email protected]/jquery-ui.js'></script>
  7. <script src='../../bundle/dist/index.global.js'></script>
  8. <script>
  9. document.addEventListener('DOMContentLoaded', function() {
  10. new FullCalendar.ThirdPartyDraggable({
  11. mirrorSelector: '.ui-draggable-dragging'
  12. })
  13. /* initialize the external events
  14. -----------------------------------------------------------------*/
  15. $('#external-events .fc-event').each(function() {
  16. // store data so the calendar knows to render an event upon drop
  17. $(this).attr('data-event', JSON.stringify({
  18. title: $.trim($(this).text()), // use the element's text as the event title
  19. stick: true // maintain when user navigates (see docs on the renderEvent method)
  20. }));
  21. // make the event draggable using jQuery UI
  22. $(this).draggable({
  23. zIndex: 999,
  24. revert: true, // will cause the event to go back to its
  25. revertDuration: 0 // original position after the drag
  26. });
  27. });
  28. /* initialize the calendar
  29. -----------------------------------------------------------------*/
  30. var calendarEl = document.getElementById('calendar');
  31. var calendar = new FullCalendar.Calendar(calendarEl, {
  32. headerToolbar: {
  33. left: 'prev,next today',
  34. center: 'title',
  35. right: 'dayGridMonth,timeGridWeek,timeGridDay'
  36. },
  37. editable: true,
  38. droppable: true, // this allows things to be dropped onto the calendar
  39. drop: function(arg) {
  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. $(arg.draggedEl).remove();
  44. }
  45. }
  46. });
  47. calendar.render();
  48. });
  49. </script>
  50. <style>
  51. body {
  52. margin-top: 40px;
  53. font-size: 14px;
  54. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  55. }
  56. #wrap {
  57. width: 1100px;
  58. margin: 0 auto;
  59. }
  60. #external-events {
  61. float: left;
  62. width: 150px;
  63. padding: 0 10px;
  64. border: 1px solid #ccc;
  65. background: #eee;
  66. text-align: left;
  67. }
  68. #external-events h4 {
  69. font-size: 16px;
  70. margin-top: 0;
  71. padding-top: 1em;
  72. }
  73. #external-events .fc-event {
  74. margin: 10px 0;
  75. cursor: pointer;
  76. }
  77. #external-events p {
  78. margin: 1.5em 0;
  79. font-size: 11px;
  80. color: #666;
  81. }
  82. #external-events p input {
  83. margin: 0;
  84. vertical-align: middle;
  85. }
  86. #calendar {
  87. float: right;
  88. width: 900px;
  89. }
  90. </style>
  91. </head>
  92. <body>
  93. <div id='wrap'>
  94. <div id='external-events'>
  95. <h4>Draggable Events</h4>
  96. <div class='fc-event'>My Event 1</div>
  97. <div class='fc-event'>My Event 2</div>
  98. <div class='fc-event'>My Event 3</div>
  99. <div class='fc-event'>My Event 4</div>
  100. <div class='fc-event'>My Event 5</div>
  101. <p>
  102. <input type='checkbox' id='drop-remove' />
  103. <label for='drop-remove'>remove after drop</label>
  104. </p>
  105. </div>
  106. <div id='calendar'></div>
  107. <div style='clear:both'></div>
  108. </div>
  109. </body>
  110. </html>