github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/root/js/matrix.calendar.js (about) 1 2 $(document).ready(function(){ 3 4 maruti.init(); 5 6 $('#add-event-submit').click(function(){ 7 maruti.add_event(); 8 }); 9 10 $('#event-name').keypress(function(e){ 11 if(e.which == 13) { 12 maruti.add_event(); 13 } 14 }); 15 }); 16 17 maruti = { 18 19 // === Initialize the fullCalendar and external draggable events === // 20 init: function() { 21 // Prepare the dates 22 var date = new Date(); 23 var d = date.getDate(); 24 var m = date.getMonth(); 25 var y = date.getFullYear(); 26 27 $('#fullcalendar').fullCalendar({ 28 header: { 29 left: 'prev,next', 30 center: 'title', 31 right: 'month,basicWeek,basicDay' 32 }, 33 editable: true, 34 droppable: true, // this allows things to be dropped onto the calendar !!! 35 drop: function(date, allDay) { // this function is called when something is dropped 36 37 // retrieve the dropped element's stored Event Object 38 var originalEventObject = $(this).data('eventObject'); 39 40 // we need to copy it, so that multiple events don't have a reference to the same object 41 var copiedEventObject = $.extend({}, originalEventObject); 42 43 // assign it the date that was reported 44 copiedEventObject.start = date; 45 copiedEventObject.allDay = allDay; 46 47 // render the event on the calendar 48 // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/) 49 $('#fullcalendar').fullCalendar('renderEvent', copiedEventObject, true); 50 51 // is the "remove after drop" checkbox checked? 52 53 // if so, remove the element from the "Draggable Events" list 54 $(this).remove(); 55 56 } 57 }); 58 this.external_events(); 59 }, 60 61 // === Adds an event if name is provided === // 62 add_event: function(){ 63 if($('#event-name').val() != '') { 64 var event_name = $('#event-name').val(); 65 $('#external-events .panel-content').append('<div class="external-event ui-draggable label label-inverse">'+event_name+'</div>'); 66 this.external_events(); 67 $('#modal-add-event').modal('hide'); 68 $('#event-name').val(''); 69 } else { 70 this.show_error(); 71 } 72 }, 73 74 // === Initialize the draggable external events === // 75 external_events: function(){ 76 /* initialize the external events 77 -----------------------------------------------------------------*/ 78 $('#external-events div.external-event').each(function() { 79 // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 80 // it doesn't need to have a start or end 81 var eventObject = { 82 title: $.trim($(this).text()) // use the element's text as the event title 83 }; 84 85 // store the Event Object in the DOM element so we can get to it later 86 $(this).data('eventObject', eventObject); 87 88 // make the event draggable using jQuery UI 89 $(this).draggable({ 90 zIndex: 999, 91 revert: true, // will cause the event to go back to its 92 revertDuration: 0 // original position after the drag 93 }); 94 }); 95 }, 96 97 // === Show error if no event name is provided === // 98 show_error: function(){ 99 $('#modal-error').remove(); 100 $('<div style="border-radius: 5px; top: 70px; font-size:14px; left: 50%; margin-left: -70px; position: absolute;width: 140px; background-color: #f00; text-align: center; padding: 5px; color: #ffffff;" id="modal-error">Enter event name!</div>').appendTo('#modal-add-event .modal-body'); 101 $('#modal-error').delay('1500').fadeOut(700,function() { 102 $(this).remove(); 103 }); 104 } 105 106 107 };