-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullcalendar.views.js
executable file
·138 lines (131 loc) · 5.39 KB
/
fullcalendar.views.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// $Id$
(function ($) {
Drupal.behaviors.fullCalendar = function(context) {
$('#fullcalendar-content').hide(); //hide the failover display
$('#fullcalendar:not(.fc-processed)').addClass('fc-processed').fullCalendar({
defaultView: Drupal.settings.fullcalendar.defaultView,
theme: Drupal.settings.fullcalendar.theme,
header: {
left: Drupal.settings.fullcalendar.left,
center: Drupal.settings.fullcalendar.center,
right: Drupal.settings.fullcalendar.right
},
eventClick: function(calEvent, jsEvent, view) {
if (Drupal.settings.fullcalendar.colorbox) {
// Open in colorbox if exists, else open in new window.
if ($.colorbox) {
$.colorbox({href:calEvent.url, iframe:true, width:'80%', height:'80%'});
}
}
else {
if (Drupal.settings.fullcalendar.sameWindow) {
window.open(calEvent.url, _self);
}
else {
window.open(calEvent.url);
}
}
return false;
},
year: (Drupal.settings.fullcalendar.year) ? Drupal.settings.fullcalendar.year : undefined,
month: (Drupal.settings.fullcalendar.month) ? Drupal.settings.fullcalendar.month : undefined,
day: (Drupal.settings.fullcalendar.day) ? Drupal.settings.fullcalendar.day : undefined,
timeFormat: {
agenda: (Drupal.settings.fullcalendar.clock) ? 'HH:mm{ - HH:mm}' : Drupal.settings.fullcalendar.agenda,
'': (Drupal.settings.fullcalendar.clock) ? 'HH:mm' : 'h(:mm)t'
},
axisFormat: (Drupal.settings.fullcalendar.clock) ? 'HH:mm' : 'h(:mm)tt',
weekMode: Drupal.settings.fullcalendar.weekMode,
firstDay: Drupal.settings.fullcalendar.firstDay,
monthNames: Drupal.settings.fullcalendar.monthNames,
monthNamesShort: Drupal.settings.fullcalendar.monthNamesShort,
dayNames: Drupal.settings.fullcalendar.dayNames,
dayNamesShort: Drupal.settings.fullcalendar.dayNamesShort,
allDayText: Drupal.settings.fullcalendar.allDayText,
buttonText: {
today: Drupal.settings.fullcalendar.todayString,
day: Drupal.settings.fullcalendar.dayString,
week: Drupal.settings.fullcalendar.weekString,
month: Drupal.settings.fullcalendar.monthString
},
events: function(start, end, callback) {
// Load events from AJAX callback, if set.
if (Drupal.settings.fullcalendar.ajax_callback) {
// TODO: refactor to use "data:" block to pass arg attributes from filters
var argattr = "";
if (window.location.href.indexOf('?') != -1) {
argattr = window.location.href.slice(window.location.href.indexOf('?'));
}
var argdate = new Date((start.getTime()+end.getTime())/2);
var argdateStr = argdate.getFullYear() + "-" + (argdate.getMonth()+1)
$.ajax({
url: Drupal.settings.fullcalendar.ajax_callback + '/' + argdateStr + argattr,
dataType: 'json',
success: function(events) {
callback(events);
}
});
return; // Don't load events from page.
}
var events = [];
$('.fullcalendar_event').each(function() {
$(this).find('.fullcalendar_event_details').each(function() {
events.push({
field: $(this).attr('field'),
index: $(this).attr('index'),
nid: $(this).attr('nid'),
title: $(this).attr('title'),
start: $(this).attr('start'),
end: $(this).attr('end'),
url: $(this).attr('href'),
allDay: ($(this).attr('allDay') === '1'),
className: $(this).attr('cn'),
editable: $(this).attr('editable')
});
if ($(this).parent().find('.fc-flyout').length) {
events[events.length-1].flyout = $(this).parent().find('.fc-flyout');
}
});
});
callback(events);
},
eventRender: function( event, element, view ) {
if (event.flyout) {
element.children('a').prepend(event.flyout);
Drupal.attachBehaviors(element);
}
},
eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
$.post(Drupal.settings.basePath + 'fullcalendar/ajax/update/drop/'+ event.nid,
'field=' + event.field + '&index=' + event.index + '&day_delta=' + dayDelta + '&minute_delta=' + minuteDelta + '&all_day=' + allDay,
fullcalendarUpdate);
return false;
},
eventResize: function(event, dayDelta, minuteDelta, revertFunc) {
$.post(Drupal.settings.basePath + 'fullcalendar/ajax/update/resize/'+ event.nid,
'field=' + event.field + '&index=' + event.index + '&day_delta=' + dayDelta + '&minute_delta=' + minuteDelta,
fullcalendarUpdate);
return false;
},
loading: function( isLoading, view ) {
// Show thobber while working.
$(this).find('h2.fc-header-title').toggleClass( 'fc-ajaxing', isLoading );
}
});
var fullcalendarUpdate = function(response) {
var result = Drupal.parseJson(response);
if ($('#fullcalendar-status').text() === '') {
$('#fullcalendar-status').html(result.msg).slideDown();
} else {
$('#fullcalendar-status').html(result.msg).effect('highlight', {}, 5000);
}
return false;
};
$('.fullcalendar-status-close').live('click', function() {
$('#fullcalendar-status').slideUp();
return false;
});
//trigger a window resize so that calendar will redraw itself as it loads funny in some browsers occasionally
$(window).resize();
};
})(jQuery);