demo.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. +function ($) {
  2. $(function(){
  3. // fullcalendar
  4. var date = new Date();
  5. var d = date.getDate();
  6. var m = date.getMonth();
  7. var y = date.getFullYear();
  8. var addDragEvent = function($this){
  9. // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
  10. // it doesn't need to have a start or end
  11. var eventObject = {
  12. title: $.trim($this.text()), // use the element's text as the event title
  13. className: $this.attr('class').replace('label','')
  14. };
  15. // store the Event Object in the DOM element so we can get to it later
  16. $this.data('eventObject', eventObject);
  17. // make the event draggable using jQuery UI
  18. $this.draggable({
  19. zIndex: 999,
  20. revert: true, // will cause the event to go back to its
  21. revertDuration: 0 // original position after the drag
  22. });
  23. };
  24. $('.calendar').each(function() {
  25. $(this).fullCalendar({
  26. header: {
  27. left: 'prev',
  28. center: 'title',
  29. right: 'next'
  30. },
  31. editable: true,
  32. droppable: true, // this allows things to be dropped onto the calendar !!!
  33. drop: function(date, allDay) { // this function is called when something is dropped
  34. // retrieve the dropped element's stored Event Object
  35. var originalEventObject = $(this).data('eventObject');
  36. // we need to copy it, so that multiple events don't have a reference to the same object
  37. var copiedEventObject = $.extend({}, originalEventObject);
  38. // assign it the date that was reported
  39. copiedEventObject.start = date;
  40. copiedEventObject.allDay = allDay;
  41. // render the event on the calendar
  42. // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
  43. $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
  44. // is the "remove after drop" checkbox checked?
  45. if ($('#drop-remove').is(':checked')) {
  46. // if so, remove the element from the "Draggable Events" list
  47. $(this).remove();
  48. }
  49. }
  50. ,
  51. events: [
  52. {
  53. title: 'All Day Event',
  54. start: new Date(y, m, 1),
  55. className:'b-l b-2x b-info'
  56. },
  57. {
  58. title: 'Long Event',
  59. start: new Date(y, m, d-5),
  60. end: new Date(y, m, d-2),
  61. className:'bg-success bg'
  62. },
  63. {
  64. id: 999,
  65. title: 'Event',
  66. start: new Date(y, m, d-5, 16, 0),
  67. allDay: false,
  68. className:'b-l b-2x b-warning'
  69. },
  70. {
  71. id: 999,
  72. title: 'Repeating Event',
  73. start: new Date(y, m, d+4, 16, 0),
  74. allDay: false,
  75. className:'b-l b-2x b-warning'
  76. },
  77. {
  78. title: 'Meeting',
  79. start: new Date(y, m, d, 10, 30),
  80. allDay: false,
  81. className:'b-l b-2x b-danger'
  82. },
  83. {
  84. title: 'Lunch',
  85. start: new Date(y, m, d, 12, 0),
  86. end: new Date(y, m, d, 14, 0),
  87. allDay: false,
  88. className:'b-l b-2x b-primary'
  89. },
  90. {
  91. title: 'Birthday Party',
  92. start: new Date(y, m, d+1, 19, 0),
  93. end: new Date(y, m, d+1, 22, 30),
  94. allDay: false,
  95. className:'b-l b-2x b-warning'
  96. },
  97. {
  98. title: 'Click for Google',
  99. start: new Date(y, m, 28),
  100. end: new Date(y, m, 29),
  101. url: 'http://google.com/',
  102. className:'b-l b-2x b-primary'
  103. }
  104. ]
  105. });
  106. });
  107. $('#myEvents').on('change', function(e, item){
  108. addDragEvent($(item));
  109. });
  110. $('#myEvents li > div').each(function() {
  111. addDragEvent($(this));
  112. });
  113. $(document).on('click', '#dayview', function() {
  114. $('.calendar').fullCalendar('changeView', 'agendaDay')
  115. });
  116. $('#weekview').on('click', function() {
  117. $('.calendar').fullCalendar('changeView', 'agendaWeek')
  118. });
  119. $('#monthview').on('click', function() {
  120. $('.calendar').fullCalendar('changeView', 'month')
  121. });
  122. });
  123. }(window.jQuery);