annotate plugins/calendar/lib/js/fullcalendar.js @ 3:f6fe4b6ae66a

calendar plugin nearly as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:56:12 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1 /*!
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2 * FullCalendar v1.6.4-rcube-1.1.3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3 * Docs & License: http://arshaw.com/fullcalendar/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4 * (c) 2013 Adam Shaw, 2014 Kolab Systems AG
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
7 /*
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
8 * Use fullcalendar.css for basic styling.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
9 * For event drag & drop, requires jQuery UI draggable.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
10 * For event resizing, requires jQuery UI resizable.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
11 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
12
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
13 (function($, undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
14
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
15
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
16 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
17
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
18 var defaults = {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
19
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
20 // display
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
21 defaultView: 'month',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
22 aspectRatio: 1.35,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
23 header: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
24 left: 'title',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
25 center: '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
26 right: 'today prev,next'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
27 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
28 weekends: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
29 weekNumbers: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
30 weekNumberCalculation: 'iso',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
31 weekNumberTitle: 'W',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
32 currentTimeIndicator: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
33
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
34 // editing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
35 //editable: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
36 //disableDragging: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
37 //disableResizing: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
38
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
39 allDayDefault: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
40 ignoreTimezone: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
41
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
42 // event ajax
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
43 lazyFetching: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
44 startParam: 'start',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
45 endParam: 'end',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
46
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
47 // time formats
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
48 titleFormat: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
49 month: 'MMMM yyyy',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
50 week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
51 day: 'dddd, MMM d, yyyy',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
52 list: 'MMM d, yyyy',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
53 table: 'MMM d, yyyy'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
54 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
55 columnFormat: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
56 month: 'ddd',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
57 week: 'ddd M/d',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
58 day: 'dddd M/d',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
59 list: 'dddd, MMM d, yyyy',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
60 table: 'MMM d, yyyy'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
61 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
62 timeFormat: { // for event elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
63 '': 'h(:mm)t' // default
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
64 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
65
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
66 // locale
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
67 isRTL: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
68 firstDay: 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
69 monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
70 monthNamesShort: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
71 dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
72 dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
73 buttonText: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
74 prev: "<span class='fc-text-arrow'>&lsaquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
75 next: "<span class='fc-text-arrow'>&rsaquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
76 prevYear: "<span class='fc-text-arrow'>&laquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
77 nextYear: "<span class='fc-text-arrow'>&raquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
78 today: 'today',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
79 month: 'month',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
80 week: 'week',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
81 day: 'day',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
82 list: 'list',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
83 table: 'table'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
84 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
85 listTexts: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
86 until: 'until',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
87 past: 'Past events',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
88 today: 'Today',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
89 tomorrow: 'Tomorrow',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
90 thisWeek: 'This week',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
91 nextWeek: 'Next week',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
92 thisMonth: 'This month',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
93 nextMonth: 'Next month',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
94 future: 'Future events',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
95 week: 'W'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
96 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
97
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
98 // list/table options
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
99 listSections: 'month', // false|'day'|'week'|'month'|'smart'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
100 listRange: 30, // number of days to be displayed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
101 listPage: 7, // number of days to jump when paging
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
102 tableCols: ['handle', 'date', 'time', 'title'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
104 // jquery-ui theming
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
105 theme: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
106 buttonIcons: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
107 prev: 'circle-triangle-w',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
108 next: 'circle-triangle-e'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
109 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
110
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
111 //selectable: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
112 unselectAuto: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
113
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
114 dropAccept: '*',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
115
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
116 handleWindowResize: true
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
117
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
118 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
119
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
120 // right-to-left defaults
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
121 var rtlDefaults = {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
122 header: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
123 left: 'next,prev today',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
124 center: '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
125 right: 'title'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
126 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
127 buttonText: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
128 prev: "<span class='fc-text-arrow'>&rsaquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
129 next: "<span class='fc-text-arrow'>&lsaquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
130 prevYear: "<span class='fc-text-arrow'>&raquo;</span>",
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
131 nextYear: "<span class='fc-text-arrow'>&laquo;</span>"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
132 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
133 buttonIcons: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
134 prev: 'circle-triangle-e',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
135 next: 'circle-triangle-w'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
136 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
137 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
138
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
139
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
140
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
141 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
142
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
143 var fc = $.fullCalendar = { version: "1.6.4-rcube-1.1.3" };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
144 var fcViews = fc.views = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
145
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
146
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
147 $.fn.fullCalendar = function(options) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
148
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
149
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
150 // method calling
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
151 if (typeof options == 'string') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
152 var args = Array.prototype.slice.call(arguments, 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
153 var res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
154 this.each(function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
155 var calendar = $.data(this, 'fullCalendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
156 if (calendar && $.isFunction(calendar[options])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
157 var r = calendar[options].apply(calendar, args);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
158 if (res === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
159 res = r;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
160 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
161 if (options == 'destroy') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
162 $.removeData(this, 'fullCalendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
163 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
164 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
165 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
166 if (res !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
167 return res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
168 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
169 return this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
170 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
171
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
172 options = options || {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
173
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
174 // would like to have this logic in EventManager, but needs to happen before options are recursively extended
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
175 var eventSources = options.eventSources || [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
176 delete options.eventSources;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
177 if (options.events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
178 eventSources.push(options.events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
179 delete options.events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
180 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
181
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
182
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
183 options = $.extend(true, {},
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
184 defaults,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
185 (options.isRTL || options.isRTL===undefined && defaults.isRTL) ? rtlDefaults : {},
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
186 options
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
187 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
188
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
189
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
190 this.each(function(i, _element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
191 var element = $(_element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
192 var calendar = new Calendar(element, options, eventSources);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
193 element.data('fullCalendar', calendar); // TODO: look into memory leak implications
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
194 calendar.render();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
195 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
196
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
197
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
198 return this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
199
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
200 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
201
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
202
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
203 // function for adding/overriding defaults
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
204 function setDefaults(d) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
205 $.extend(true, defaults, d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
206 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
207
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
208
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
209
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
210 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
211
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
212
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
213 function Calendar(element, options, eventSources) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
214 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
215
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
216
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
217 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
218 t.options = options;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
219 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
220 t.destroy = destroy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
221 t.refetchEvents = refetchEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
222 t.reportEvents = reportEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
223 t.reportEventChange = reportEventChange;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
224 t.rerenderEvents = rerenderEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
225 t.changeView = changeView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
226 t.select = select;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
227 t.unselect = unselect;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
228 t.prev = prev;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
229 t.next = next;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
230 t.prevYear = prevYear;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
231 t.nextYear = nextYear;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
232 t.today = today;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
233 t.gotoDate = gotoDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
234 t.incrementDate = incrementDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
235 t.formatDate = function(format, date) { return formatDate(format, date, options) };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
236 t.formatDates = function(format, date1, date2) { return formatDates(format, date1, date2, options) };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
237 t.getDate = getDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
238 t.getView = getView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
239 t.option = option;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
240 t.trigger = trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
241
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
242
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
243 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
244 EventManager.call(t, options, eventSources);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
245 var isFetchNeeded = t.isFetchNeeded;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
246 var fetchEvents = t.fetchEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
247
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
248
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
249 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
250 var _element = element[0];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
251 var header;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
252 var headerElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
253 var content;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
254 var tm; // for making theme classes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
255 var currentView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
256 var elementOuterWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
257 var suggestedViewHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
258 var resizeUID = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
259 var ignoreWindowResize = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
260 var lazyRendering = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
261 var date = new Date();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
262 var events = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
263 var _dragElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
264
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
265
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
266
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
267 /* Main Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
268 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
269
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
270
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
271 setYMD(date, options.year, options.month, options.date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
273
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
274 function render(inc) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
275 if (!content) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
276 initialRender();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
277 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
278 else if (elementVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
279 // mainly for the public API
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
280 calcSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
281 _renderView(inc);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
282 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
283 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
284
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
285
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
286 function initialRender() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
287 tm = options.theme ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
288 element.addClass('fc');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
289 if (options.isRTL) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
290 element.addClass('fc-rtl');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
291 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
292 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
293 element.addClass('fc-ltr');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
294 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
295 if (options.theme) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
296 element.addClass('ui-widget');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
297 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
298
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
299 content = $("<div class='fc-content' style='position:relative'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
300 .prependTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
301
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
302 header = new Header(t, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
303 headerElement = header.render();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
304 if (headerElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
305 element.prepend(headerElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
306 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
307
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
308 changeView(options.defaultView);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
309
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
310 if (options.handleWindowResize) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
311 $(window).resize(windowResize);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
312 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
313
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
314 // needed for IE in a 0x0 iframe, b/c when it is resized, never triggers a windowResize
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
315 if (!bodyVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
316 lateRender();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
317 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
318 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
319
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
320
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
321 // called when we know the calendar couldn't be rendered when it was initialized,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
322 // but we think it's ready now
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
323 function lateRender() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
324 setTimeout(function() { // IE7 needs this so dimensions are calculated correctly
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
325 if (!currentView.start && bodyVisible()) { // !currentView.start makes sure this never happens more than once
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
326 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
327 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
328 },0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
329 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
330
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
331
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
332 function destroy() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
333
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
334 if (currentView) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
335 trigger('viewDestroy', currentView, currentView, currentView.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
336 currentView.triggerEventDestroy();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
337 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
338
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
339 $(window).unbind('resize', windowResize);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
340
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
341 header.destroy();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
342 content.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
343 element.removeClass('fc fc-rtl ui-widget');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
344 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
345
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
346
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
347 function elementVisible() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
348 return element.is(':visible');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
349 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
350
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
351
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
352 function bodyVisible() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
353 return $('body').is(':visible');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
354 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
355
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
356
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
358 /* View Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
359 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
360
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
361
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
362 function changeView(newViewName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
363 if (!currentView || newViewName != currentView.name) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
364 _changeView(newViewName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
365 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
366 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
367
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
368
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
369 function _changeView(newViewName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
370 ignoreWindowResize++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
371
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
372 if (currentView) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
373 trigger('viewDestroy', currentView, currentView, currentView.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
374 unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
375 currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
376 freezeContentHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
377 currentView.element.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
378 header.deactivateButton(currentView.name);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
379 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
380
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
381 header.activateButton(newViewName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
382
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
383 currentView = new fcViews[newViewName](
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
384 $("<div class='fc-view fc-view-" + newViewName + "' style='position:relative'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
385 .appendTo(content),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
386 t // the calendar object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
387 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
388
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
389 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
390 unfreezeContentHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
391
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
392 ignoreWindowResize--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
393 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
394
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
395
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
396 function renderView(inc) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
397 if (
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
398 !currentView.start || // never rendered before
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
399 inc || date < currentView.start || date >= currentView.end // or new date range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
400 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
401 if (elementVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
402 _renderView(inc);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
403 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
404 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
405 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
406
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
407
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
408 function _renderView(inc) { // assumes elementVisible
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
409 ignoreWindowResize++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
410
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
411 if (currentView.start) { // already been rendered?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
412 trigger('viewDestroy', currentView, currentView, currentView.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
413 unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
414 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
415 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
416
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
417 freezeContentHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
418 currentView.render(date, inc || 0); // the view's render method ONLY renders the skeleton, nothing else
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
419 setSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
420 unfreezeContentHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
421 (currentView.afterRender || noop)();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
422
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
423 updateTitle();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
424 updateTodayButton();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
425
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
426 trigger('viewRender', currentView, currentView, currentView.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
427 currentView.trigger('viewDisplay', _element); // deprecated
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
428
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
429 ignoreWindowResize--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
430
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
431 getAndRenderEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
432 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
433
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
434
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
435
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
436 /* Resizing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
437 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
438
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
439
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
440 function updateSize() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
441 if (elementVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
442 unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
443 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
444 calcSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
445 setSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
446 unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
447 currentView.clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
448 currentView.trigger('viewRender', currentView);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
449 currentView.renderEvents(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
450 currentView.sizeDirty = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
451 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
452 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
453
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
454
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
455 function calcSize() { // assumes elementVisible
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
456 if (options.contentHeight) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
457 suggestedViewHeight = options.contentHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
458 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
459 else if (options.height) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
460 suggestedViewHeight = options.height - (headerElement ? headerElement.height() : 0) - vsides(content);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
461 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
462 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
463 suggestedViewHeight = Math.round(content.width() / Math.max(options.aspectRatio, .5));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
464 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
465 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
466
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
467
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
468 function setSize() { // assumes elementVisible
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
469
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
470 if (suggestedViewHeight === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
471 calcSize(); // for first time
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
472 // NOTE: we don't want to recalculate on every renderView because
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
473 // it could result in oscillating heights due to scrollbars.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
474 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
475
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
476 ignoreWindowResize++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
477 currentView.setHeight(suggestedViewHeight);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
478 currentView.setWidth(content.width());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
479 ignoreWindowResize--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
480
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
481 elementOuterWidth = element.outerWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
482 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
483
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
484
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
485 function windowResize() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
486 if (!ignoreWindowResize) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
487 if (currentView.start) { // view has already been rendered
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
488 var uid = ++resizeUID;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
489 setTimeout(function() { // add a delay
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
490 if (uid == resizeUID && !ignoreWindowResize && elementVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
491 if (elementOuterWidth != (elementOuterWidth = element.outerWidth())) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
492 ignoreWindowResize++; // in case the windowResize callback changes the height
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
493 updateSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
494 currentView.trigger('windowResize', _element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
495 ignoreWindowResize--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
496 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
497 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
498 }, 200);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
499 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
500 // calendar must have been initialized in a 0x0 iframe that has just been resized
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
501 lateRender();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
502 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
503 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
504 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
505
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
506
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
507
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
508 /* Event Fetching/Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
509 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
510 // TODO: going forward, most of this stuff should be directly handled by the view
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
511
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
512
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
513 function refetchEvents(source, lazy) { // can be called as an API method
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
514 lazyRendering = lazy || false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
515 if (!lazyRendering) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
516 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
517 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
518 fetchAndRenderEvents(source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
519 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
520
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
521
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
522 function rerenderEvents(modifiedEventID) { // can be called as an API method
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
523 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
524 renderEvents(modifiedEventID);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
525 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
526
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
528 function renderEvents(modifiedEventID) { // TODO: remove modifiedEventID hack
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
529 if (elementVisible()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
530 currentView.setEventData(events); // for View.js, TODO: unify with renderEvents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
531 currentView.renderEvents(events, modifiedEventID); // actually render the DOM elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
532 currentView.trigger('eventAfterAllRender');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
533 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
534 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
535
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
536
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
537 function clearEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
538 currentView.triggerEventDestroy(); // trigger 'eventDestroy' for each event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
539 currentView.clearEvents(); // actually remove the DOM elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
540 currentView.clearEventData(); // for View.js, TODO: unify with clearEvents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
541 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
542
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
543
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
544 function getAndRenderEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
545 if (!options.lazyFetching || isFetchNeeded(currentView.visStart, currentView.visEnd)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
546 fetchAndRenderEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
547 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
548 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
549 renderEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
550 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
551 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
552
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
553
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
554 function fetchAndRenderEvents(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
555 fetchEvents(currentView.visStart, currentView.visEnd, source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
556 // ... will call reportEvents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
557 // ... which will call renderEvents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
558 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
559
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
560
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
561 // called when event data arrives
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
562 function reportEvents(_events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
563 if (lazyRendering) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
564 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
565 lazyRendering = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
566 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
567 events = _events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
568 renderEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
569 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
570
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
571
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
572 // called when a single event's data has been changed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
573 function reportEventChange(eventID) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
574 rerenderEvents(eventID);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
575 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
576
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
577
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
578
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
579 /* Header Updating
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
580 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
581
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
582
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
583 function updateTitle() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
584 header.updateTitle(currentView.title);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
585 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
586
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
587
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
588 function updateTodayButton() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
589 var today = new Date();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
590 if (today >= currentView.start && today < currentView.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
591 header.disableButton('today');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
592 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
593 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
594 header.enableButton('today');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
595 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
596 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
597
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
598
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
599
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
600 /* Selection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
601 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
602
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
603
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
604 function select(start, end, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
605 currentView.select(start, end, allDay===undefined ? true : allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
606 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
607
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
608
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
609 function unselect() { // safe to be called before renderView
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
610 if (currentView) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
611 currentView.unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
612 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
613 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
614
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
615
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
616
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
617 /* Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
618 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
619
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
620
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
621 function prev() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
622 renderView(-1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
623 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
624
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
625
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
626 function next() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
627 renderView(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
628 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
629
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
630
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
631 function prevYear() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
632 addYears(date, -1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
633 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
634 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
635
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
636
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
637 function nextYear() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
638 addYears(date, 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
639 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
640 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
641
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
642
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
643 function today() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
644 date = new Date();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
645 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
646 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
647
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
648
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
649 function gotoDate(year, month, dateOfMonth) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
650 if (year instanceof Date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
651 date = cloneDate(year); // provided 1 argument, a Date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
652 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
653 setYMD(date, year, month, dateOfMonth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
654 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
655 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
656 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
657
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
658
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
659 function incrementDate(years, months, days) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
660 if (years !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
661 addYears(date, years);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
662 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
663 if (months !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
664 addMonths(date, months);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
665 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
666 if (days !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
667 addDays(date, days);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
668 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
669 renderView();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
670 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
671
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
672
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
673 function getDate() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
674 return cloneDate(date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
675 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
676
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
677
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
678
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
679 /* Height "Freezing"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
680 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
681
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
682
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
683 function freezeContentHeight() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
684 content.css({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
685 width: '100%',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
686 height: content.height(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
687 overflow: 'hidden'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
688 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
689 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
690
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
691
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
692 function unfreezeContentHeight() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
693 content.css({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
694 width: '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
695 height: '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
696 overflow: ''
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
697 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
698 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
699
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
700
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
701
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
702 /* Misc
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
703 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
706 function getView() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
707 return currentView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
708 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
710
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
711 function option(name, value) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
712 if (value === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
713 return options[name];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
714 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
715 if (name == 'height' || name == 'contentHeight' || name == 'aspectRatio') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
716 options[name] = value;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
717 updateSize();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
718 } else if (name.indexOf('list') == 0 || name == 'tableCols') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
719 options[name] = value;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
720 currentView.start = null; // force re-render
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
721 } else if (name == 'maxHeight') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
722 options[name] = value;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
723 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
724 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
725
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
726
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
727 function trigger(name, thisObj) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
728 if (options[name]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
729 return options[name].apply(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
730 thisObj || _element,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
731 Array.prototype.slice.call(arguments, 2)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
732 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
733 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
734 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
735
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
736
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
737
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
738 /* External Dragging
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
739 ------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
740
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
741 if (options.droppable) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
742 $(document)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
743 .bind('dragstart', function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
744 var _e = ev.target;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
745 var e = $(_e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
746 if (!e.parents('.fc').length) { // not already inside a calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
747 var accept = options.dropAccept;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
748 if ($.isFunction(accept) ? accept.call(_e, e) : e.is(accept)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
749 _dragElement = _e;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
750 currentView.dragStart(_dragElement, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
751 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
752 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
753 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
754 .bind('dragstop', function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
755 if (_dragElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
756 currentView.dragStop(_dragElement, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
757 _dragElement = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
758 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
759 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
760 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
761
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
762
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
763 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
764
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
765 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
766
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
767 function Header(calendar, options) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
768 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
770
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
771 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
772 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
773 t.destroy = destroy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
774 t.updateTitle = updateTitle;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
775 t.activateButton = activateButton;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
776 t.deactivateButton = deactivateButton;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
777 t.disableButton = disableButton;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
778 t.enableButton = enableButton;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
779
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
780
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
781 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
782 var element = $([]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
783 var tm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
784
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
785
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
786
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
787 function render() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
788 tm = options.theme ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
789 var sections = options.header;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
790 if (sections) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
791 element = $("<table class='fc-header' style='width:100%'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
792 .append(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
793 $("<tr/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
794 .append(renderSection('left'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
795 .append(renderSection('center'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
796 .append(renderSection('right'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
797 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
798 return element;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
799 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
800 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
801
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
802
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
803 function destroy() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
804 element.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
805 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
806
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
807
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
808 function renderSection(position) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
809 var e = $("<td class='fc-header-" + position + "'/>");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
810 var buttonStr = options.header[position];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
811 if (buttonStr) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
812 $.each(buttonStr.split(' '), function(i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
813 if (i > 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
814 e.append("<span class='fc-header-space'/>");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
815 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
816 var prevButton;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
817 $.each(this.split(','), function(j, buttonName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
818 if (buttonName == 'title') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
819 e.append("<span class='fc-header-title'><h2 aria-live='polite' aria-relevant='text' aria-atomic='true'>&nbsp;</h2></span>");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
820 if (prevButton) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
821 prevButton.addClass(tm + '-corner-right');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
822 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
823 prevButton = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
824 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
825 var buttonClick;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
826 if (calendar[buttonName]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
827 buttonClick = calendar[buttonName]; // calendar method
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
828 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
829 else if (fcViews[buttonName]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
830 buttonClick = function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
831 button.removeClass(tm + '-state-hover'); // forget why
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
832 calendar.changeView(buttonName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
833 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
834 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
835 if (buttonClick) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
836 var icon = options.theme ? smartProperty(options.buttonIcons, buttonName) : null; // why are we using smartProperty here?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
837 var text = smartProperty(options.buttonText, buttonName); // why are we using smartProperty here?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
838 var button = $(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
839 "<span class='fc-button fc-button-" + buttonName + " " + tm + "-state-default' role='button' tabindex='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
840 (icon ?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
841 "<span class='fc-icon-wrap'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
842 "<span class='ui-icon ui-icon-" + icon + "'/>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
843 "</span>" :
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
844 text
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
845 ) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
846 "</span>"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
847 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
848 .click(function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
849 if (!button.hasClass(tm + '-state-disabled')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
850 buttonClick();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
851 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
852 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
853 .mousedown(function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
854 button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
855 .not('.' + tm + '-state-active')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
856 .not('.' + tm + '-state-disabled')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
857 .addClass(tm + '-state-down');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
858 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
859 .mouseup(function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
860 button.removeClass(tm + '-state-down');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
861 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
862 .hover(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
863 function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
864 button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
865 .not('.' + tm + '-state-active')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
866 .not('.' + tm + '-state-disabled')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
867 .addClass(tm + '-state-hover');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
868 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
869 function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
870 button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
871 .removeClass(tm + '-state-hover')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
872 .removeClass(tm + '-state-down');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
873 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
874 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
875 .keypress(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
876 if (ev.keyCode == 13)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
877 $(ev.target).trigger('click');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
878 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
879 .appendTo(e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
880 disableTextSelection(button);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
881 if (!prevButton) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
882 button.addClass(tm + '-corner-left');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
883 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
884 prevButton = button;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
885 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
886 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
887 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
888 if (prevButton) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
889 prevButton.addClass(tm + '-corner-right');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
890 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
891 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
892 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
893 return e;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
894 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
895
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
896
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
897 function updateTitle(html) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
898 element.find('h2')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
899 .html(html);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
900 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
901
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
902
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
903 function activateButton(buttonName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
904 element.find('span.fc-button-' + buttonName)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
905 .addClass(tm + '-state-active').attr('tabindex', '-1');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
906 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
907
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
908
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
909 function deactivateButton(buttonName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
910 element.find('span.fc-button-' + buttonName)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
911 .removeClass(tm + '-state-active').attr('tabindex', '0');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
912 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
913
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
914
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
915 function disableButton(buttonName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
916 element.find('span.fc-button-' + buttonName)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
917 .addClass(tm + '-state-disabled').attr('tabindex', '-1');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
918 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
919
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
920
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
921 function enableButton(buttonName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
922 element.find('span.fc-button-' + buttonName)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
923 .removeClass(tm + '-state-disabled').attr('tabindex', '0');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
924 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
925
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
926
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
927 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
928
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
929 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
930
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
931 fc.sourceNormalizers = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
932 fc.sourceFetchers = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
933
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
934 var ajaxDefaults = {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
935 dataType: 'json',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
936 cache: false
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
937 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
938
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
939 var eventGUID = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
940
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
941
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
942 function EventManager(options, _sources) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
943 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
944
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
945
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
946 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
947 t.isFetchNeeded = isFetchNeeded;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
948 t.fetchEvents = fetchEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
949 t.addEventSource = addEventSource;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
950 t.removeEventSource = removeEventSource;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
951 t.removeEventSources = removeEventSources;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
952 t.updateEvent = updateEvent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
953 t.renderEvent = renderEvent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
954 t.removeEvents = removeEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
955 t.clientEvents = clientEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
956 t.normalizeEvent = normalizeEvent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
957
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
958
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
959 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
960 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
961 var getView = t.getView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
962 var reportEvents = t.reportEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
963
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
964
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
965 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
966 var stickySource = { events: [] };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
967 var sources = [ stickySource ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
968 var rangeStart, rangeEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
969 var currentFetchID = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
970 var pendingSourceCnt = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
971 var loadingLevel = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
972 var cache = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
973
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
974
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
975 for (var i=0; i<_sources.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
976 _addEventSource(_sources[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
977 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
978
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
979
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
980
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
981 /* Fetching
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
982 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
983
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
984
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
985 function isFetchNeeded(start, end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
986 return !rangeStart || start < rangeStart || end > rangeEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
987 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
988
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
989
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
990 function fetchEvents(start, end, src) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
991 rangeStart = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
992 rangeEnd = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
993 // partially clear cache if refreshing one source only (issue #1061)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
994 cache = typeof src != 'undefined' ? $.grep(cache, function(e) { return !isSourcesEqual(e.source, src); }) : [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
995 var fetchID = ++currentFetchID;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
996 var len = sources.length;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
997 pendingSourceCnt = typeof src == 'undefined' ? len : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
998 for (var i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
999 if (typeof src == 'undefined' || isSourcesEqual(sources[i], src))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1000 fetchEventSource(sources[i], fetchID);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1001 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1002 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1003
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1004
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1005
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1006 function fetchEventSource(source, fetchID) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1007 _fetchEventSource(source, function(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1008 if (fetchID == currentFetchID) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1009 if (events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1010
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1011 if (options.eventDataTransform) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1012 events = $.map(events, options.eventDataTransform);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1013 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1014 if (source.eventDataTransform) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1015 events = $.map(events, source.eventDataTransform);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1016 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1017 // TODO: this technique is not ideal for static array event sources.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1018 // For arrays, we'll want to process all events right in the beginning, then never again.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1019
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1020 for (var i=0; i<events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1021 events[i].source = source;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1022 normalizeEvent(events[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1023 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1024 cache = cache.concat(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1025 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1026 pendingSourceCnt--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1027 if (!pendingSourceCnt) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1028 reportEvents(cache);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1029 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1030 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1031 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1032 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1033
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1034
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1035 function _fetchEventSource(source, callback) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1036 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1037 var fetchers = fc.sourceFetchers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1038 var res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1039 for (i=0; i<fetchers.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1040 res = fetchers[i](source, rangeStart, rangeEnd, callback);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1041 if (res === true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1042 // the fetcher is in charge. made its own async request
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1043 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1044 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1045 else if (typeof res == 'object') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1046 // the fetcher returned a new source. process it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1047 _fetchEventSource(res, callback);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1048 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1049 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1050 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1051 var events = source.events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1052 if (events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1053 if ($.isFunction(events)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1054 pushLoading();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1055 events(cloneDate(rangeStart), cloneDate(rangeEnd), function(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1056 callback(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1057 popLoading();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1058 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1059 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1060 else if ($.isArray(events)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1061 callback(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1062 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1063 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1064 callback();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1065 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1066 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1067 var url = source.url;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1068 if (url) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1069 var success = source.success;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1070 var error = source.error;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1071 var complete = source.complete;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1072
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1073 // retrieve any outbound GET/POST $.ajax data from the options
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1074 var customData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1075 if ($.isFunction(source.data)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1076 // supplied as a function that returns a key/value object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1077 customData = source.data();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1078 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1079 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1080 // supplied as a straight key/value object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1081 customData = source.data;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1082 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1083
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1084 // use a copy of the custom data so we can modify the parameters
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1085 // and not affect the passed-in object.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1086 var data = $.extend({}, customData || {});
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1087
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1088 var startParam = firstDefined(source.startParam, options.startParam);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1089 var endParam = firstDefined(source.endParam, options.endParam);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1090 if (startParam) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1091 data[startParam] = Math.round(+rangeStart / 1000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1092 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1093 if (endParam) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1094 data[endParam] = Math.round(+rangeEnd / 1000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1095 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1096
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1097 pushLoading();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1098 $.ajax($.extend({}, ajaxDefaults, source, {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1099 data: data,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1100 success: function(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1101 events = events || [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1102 var res = applyAll(success, this, arguments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1103 if ($.isArray(res)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1104 events = res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1105 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1106 callback(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1107 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1108 error: function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1109 applyAll(error, this, arguments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1110 callback();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1111 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1112 complete: function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1113 applyAll(complete, this, arguments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1114 popLoading();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1115 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1116 }));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1117 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1118 callback();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1119 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1120 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1121 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1122
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1123
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1124
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1125 /* Sources
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1126 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1127
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1128
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1129 function addEventSource(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1130 source = _addEventSource(source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1131 if (source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1132 pendingSourceCnt++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1133 fetchEventSource(source, currentFetchID); // will eventually call reportEvents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1134 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1135 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1136
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1137
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1138 function _addEventSource(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1139 if ($.isFunction(source) || $.isArray(source)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1140 source = { events: source };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1141 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1142 else if (typeof source == 'string') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1143 source = { url: source };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1144 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1145 if (typeof source == 'object') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1146 normalizeSource(source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1147 sources.push(source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1148 return source;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1149 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1150 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1151
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1152
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1153 function removeEventSource(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1154 sources = $.grep(sources, function(src) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1155 return !isSourcesEqual(src, source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1156 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1157 // remove all client events from that source
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1158 cache = $.grep(cache, function(e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1159 return !isSourcesEqual(e.source, source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1160 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1161 reportEvents(cache);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1162 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1163
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1164
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1165 function removeEventSources() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1166 sources = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1167 removeEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1168 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1169
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1170
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1171
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1172 /* Manipulation
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1173 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1174
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1175
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1176 function updateEvent(event) { // update an existing event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1177 var i, len = cache.length, e,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1178 defaultEventEnd = getView().defaultEventEnd, // getView???
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1179 startDelta = event.start - event._start,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1180 endDelta = event.end ?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1181 (event.end - (event._end || defaultEventEnd(event))) // event._end would be null if event.end
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1182 : 0; // was null and event was just resized
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1183 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1184 e = cache[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1185 if (e._id == event._id && e != event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1186 e.start = new Date(+e.start + startDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1187 if (event.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1188 if (e.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1189 e.end = new Date(+e.end + endDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1190 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1191 e.end = new Date(+defaultEventEnd(e) + endDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1192 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1193 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1194 e.end = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1195 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1196 e.title = event.title;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1197 e.url = event.url;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1198 e.allDay = event.allDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1199 e.className = event.className;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1200 e.editable = event.editable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1201 e.color = event.color;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1202 e.backgroundColor = event.backgroundColor;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1203 e.borderColor = event.borderColor;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1204 e.textColor = event.textColor;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1205 normalizeEvent(e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1206 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1207 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1208 normalizeEvent(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1209 reportEvents(cache);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1210 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1211
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1212
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1213 function renderEvent(event, stick) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1214 normalizeEvent(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1215 if (!event.source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1216 if (stick) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1217 stickySource.events.push(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1218 event.source = stickySource;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1219 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1220 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1221 // always push event to cache (issue #1112:)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1222 cache.push(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1223 reportEvents(cache);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1225
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1226
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1227 function removeEvents(filter) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1228 if (!filter) { // remove all
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1229 cache = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1230 // clear all array sources
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1231 for (var i=0; i<sources.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1232 if ($.isArray(sources[i].events)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1233 sources[i].events = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1234 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1235 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1236 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1237 if (!$.isFunction(filter)) { // an event ID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1238 var id = filter + '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1239 filter = function(e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1240 return e._id == id;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1241 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1242 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1243 cache = $.grep(cache, filter, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1244 // remove events from array sources
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1245 for (var i=0; i<sources.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1246 if ($.isArray(sources[i].events)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1247 sources[i].events = $.grep(sources[i].events, filter, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1248 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1249 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1250 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1251 reportEvents(cache);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1252 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1253
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1254
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1255 function clientEvents(filter) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1256 if ($.isFunction(filter)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1257 return $.grep(cache, filter);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1258 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1259 else if (filter) { // an event ID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1260 filter += '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1261 return $.grep(cache, function(e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1262 return e._id == filter;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1263 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1264 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1265 return cache; // else, return all
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1266 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1267
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1268
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1269
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1270 /* Loading State
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1271 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1273
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1274 function pushLoading() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1275 if (!loadingLevel++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1276 trigger('loading', null, true, getView());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1277 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1278 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1279
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1280
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1281 function popLoading() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1282 if (!--loadingLevel) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1283 trigger('loading', null, false, getView());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1284 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1285 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1286
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1287
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1288
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1289 /* Event Normalization
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1290 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1291
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1292
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1293 function normalizeEvent(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1294 var source = event.source || {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1295 var ignoreTimezone = firstDefined(source.ignoreTimezone, options.ignoreTimezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1296 event._id = event._id || (event.id === undefined ? '_fc' + eventGUID++ : event.id + '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1297 if (event.date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1298 if (!event.start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1299 event.start = event.date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1300 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1301 delete event.date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1302 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1303 event._start = cloneDate(event.start = parseDate(event.start, ignoreTimezone));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1304 event.end = parseDate(event.end, ignoreTimezone);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1305 if (event.end && event.end <= event.start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1306 event.end = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1307 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1308 event._end = event.end ? cloneDate(event.end) : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1309 if (event.allDay === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1310 event.allDay = firstDefined(source.allDayDefault, options.allDayDefault);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1311 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1312 if (event.className) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1313 if (typeof event.className == 'string') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1314 event.className = event.className.split(/\s+/);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1315 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1316 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1317 event.className = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1318 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1319 // TODO: if there is no start date, return false to indicate an invalid event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1320 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1321
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1322
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1323
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1324 /* Utils
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1325 ------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1326
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1327
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1328 function normalizeSource(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1329 if (source.className) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1330 // TODO: repeat code, same code for event classNames
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1331 if (typeof source.className == 'string') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1332 source.className = source.className.split(/\s+/);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1333 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1334 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1335 source.className = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1336 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1337 var normalizers = fc.sourceNormalizers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1338 for (var i=0; i<normalizers.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1339 normalizers[i](source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1340 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1341 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1343
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1344 function isSourcesEqual(source1, source2) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1345 return source1 && source2 && getSourcePrimitive(source1) == getSourcePrimitive(source2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1346 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1347
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1348
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1349 function getSourcePrimitive(source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1350 return ((typeof source == 'object') ? (source.events || source.url) : '') || source;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1351 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1353
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1354 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1355
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1356 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1358
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1359 fc.addDays = addDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1360 fc.cloneDate = cloneDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1361 fc.parseDate = parseDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1362 fc.parseISO8601 = parseISO8601;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1363 fc.parseTime = parseTime;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1364 fc.formatDate = formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1365 fc.formatDates = formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1366
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1367
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1368
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1369 /* Date Math
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1370 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1371
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1372 var dayIDs = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1373 DAY_MS = 86400000,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1374 HOUR_MS = 3600000,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1375 MINUTE_MS = 60000;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1376
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1377
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1378 function addYears(d, n, keepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1379 d.setFullYear(d.getFullYear() + n);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1380 if (!keepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1381 clearTime(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1382 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1383 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1384 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1385
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1386
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1387 function addMonths(d, n, keepTime) { // prevents day overflow/underflow
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1388 if (+d) { // prevent infinite looping on invalid dates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1389 var m = d.getMonth() + n,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1390 check = cloneDate(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1391 check.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1392 check.setMonth(m);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1393 d.setMonth(m);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1394 if (!keepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1395 clearTime(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1396 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1397 while (d.getMonth() != check.getMonth()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1398 d.setDate(d.getDate() + (d < check ? 1 : -1));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1399 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1400 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1401 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1402 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1403
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1404
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1405 function addDays(d, n, keepTime) { // deals with daylight savings
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1406 if (+d) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1407 var dd = d.getDate() + n,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1408 check = cloneDate(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1409 check.setHours(9); // set to middle of day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1410 check.setDate(dd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1411 d.setDate(dd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1412 if (!keepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1413 clearTime(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1414 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1415 fixDate(d, check);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1416 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1417 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1418 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1419
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1420
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1421 function fixDate(d, check) { // force d to be on check's YMD, for daylight savings purposes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1422 if (+d) { // prevent infinite looping on invalid dates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1423 while (d.getDate() != check.getDate()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1424 d.setTime(+d + (d < check ? 1 : -1) * HOUR_MS);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1425 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1426 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1427 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1428
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1429
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1430 function addMinutes(d, n) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1431 d.setMinutes(d.getMinutes() + n);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1432 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1433 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1434
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1435
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1436 function clearTime(d) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1437 d.setHours(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1438 d.setMinutes(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1439 d.setSeconds(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1440 d.setMilliseconds(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1441 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1442 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1443
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1444
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1445 function cloneDate(d, dontKeepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1446 if (dontKeepTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1447 return clearTime(new Date(+d));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1448 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1449 return new Date(+d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1450 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1451
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1452
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1453 function zeroDate() { // returns a Date with time 00:00:00 and dateOfMonth=1
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1454 var i=0, d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1455 do {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1456 d = new Date(1970, i++, 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1457 } while (d.getHours()); // != 0
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1458 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1459 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1460
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1461
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1462 function dayDiff(d1, d2) { // d1 - d2
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1463 return Math.round((cloneDate(d1, true) - cloneDate(d2, true)) / DAY_MS);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1464 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1465
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1466
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1467 function setYMD(date, y, m, d) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1468 if (y !== undefined && y != date.getFullYear()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1469 date.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1470 date.setMonth(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1471 date.setFullYear(y);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1472 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1473 if (m !== undefined && m != date.getMonth()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1474 date.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1475 date.setMonth(m);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1476 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1477 if (d !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1478 date.setDate(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1479 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1480 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1481
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1482
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1483
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1484 /* Date Parsing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1485 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1486
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1487
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1488 function parseDate(s, ignoreTimezone) { // ignoreTimezone defaults to true
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1489 if (typeof s == 'object') { // already a Date object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1490 return s;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1491 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1492 if (typeof s == 'number') { // a UNIX timestamp
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1493 return new Date(s * 1000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1494 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1495 if (typeof s == 'string') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1496 if (s.match(/^\d+(\.\d+)?$/)) { // a UNIX timestamp
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1497 return new Date(parseFloat(s) * 1000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1498 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1499 if (ignoreTimezone === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1500 ignoreTimezone = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1501 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1502 return parseISO8601(s, ignoreTimezone) || (s ? new Date(s) : null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1503 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1504 // TODO: never return invalid dates (like from new Date(<string>)), return null instead
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1505 return null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1506 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1507
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1508
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1509 function parseISO8601(s, ignoreTimezone) { // ignoreTimezone defaults to false
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1510 // derived from http://delete.me.uk/2005/03/iso8601.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1511 // TODO: for a know glitch/feature, read tests/issue_206_parseDate_dst.html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1512 var m = s.match(/^([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T ]([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2})(:?([0-9]{2}))?))?)?)?)?$/);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1513 if (!m) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1514 return null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1516 var date = new Date(m[1], 0, 2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1517 if (ignoreTimezone || !m[13]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1518 var check = new Date(m[1], 0, 2, 9, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1519 if (m[3]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1520 date.setMonth(m[3] - 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1521 check.setMonth(m[3] - 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1522 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1523 if (m[5]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1524 date.setDate(m[5]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1525 check.setDate(m[5]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1526 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1527 fixDate(date, check);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1528 if (m[7]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1529 date.setHours(m[7]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1530 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1531 if (m[8]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1532 date.setMinutes(m[8]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1533 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1534 if (m[10]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1535 date.setSeconds(m[10]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1536 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1537 if (m[12]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1538 date.setMilliseconds(Number("0." + m[12]) * 1000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1539 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1540 fixDate(date, check);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1541 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1542 date.setUTCFullYear(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1543 m[1],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1544 m[3] ? m[3] - 1 : 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1545 m[5] || 1
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1546 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1547 date.setUTCHours(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1548 m[7] || 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1549 m[8] || 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1550 m[10] || 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1551 m[12] ? Number("0." + m[12]) * 1000 : 0
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1552 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1553 if (m[14]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1554 var offset = Number(m[16]) * 60 + (m[18] ? Number(m[18]) : 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1555 offset *= m[15] == '-' ? 1 : -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1556 date = new Date(+date + (offset * 60 * 1000));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1557 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1558 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1559 return date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1560 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1561
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1562
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1563 function parseTime(s) { // returns minutes since start of day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1564 if (typeof s == 'number') { // an hour
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1565 return s * 60;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1566 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1567 if (typeof s == 'object') { // a Date object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1568 return s.getHours() * 60 + s.getMinutes();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1569 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1570 var m = s.match(/(\d+)(?::(\d+))?\s*(\w+)?/);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1571 if (m) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1572 var h = parseInt(m[1], 10);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1573 if (m[3]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1574 h %= 12;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1575 if (m[3].toLowerCase().charAt(0) == 'p') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1576 h += 12;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1577 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1578 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1579 return h * 60 + (m[2] ? parseInt(m[2], 10) : 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1580 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1581 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1582
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1583
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1584
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1585 /* Date Formatting
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1586 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1587 // TODO: use same function formatDate(date, [date2], format, [options])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1588
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1589
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1590 function formatDate(date, format, options) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1591 return formatDates(date, null, format, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1592 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1593
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1594
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1595 function formatDates(date1, date2, format, options) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1596 options = options || defaults;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1597 var date = date1,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1598 otherDate = date2,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1599 i, len = format.length, c,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1600 i2, formatter,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1601 res = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1602 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1603 c = format.charAt(i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1604 if (c == "'") {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1605 for (i2=i+1; i2<len; i2++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1606 if (format.charAt(i2) == "'") {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1607 if (date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1608 if (i2 == i+1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1609 res += "'";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1610 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1611 res += format.substring(i+1, i2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1612 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1613 i = i2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1614 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1615 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1616 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1617 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1618 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1619 else if (c == '(') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1620 for (i2=i+1; i2<len; i2++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1621 if (format.charAt(i2) == ')') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1622 var subres = formatDate(date, format.substring(i+1, i2), options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1623 if (parseInt(subres.replace(/\D/, ''), 10)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1624 res += subres;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1625 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1626 i = i2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1627 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1628 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1629 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1630 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1631 else if (c == '[') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1632 for (i2=i+1; i2<len; i2++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1633 if (format.charAt(i2) == ']') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1634 var subformat = format.substring(i+1, i2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1635 var subres = formatDate(date, subformat, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1636 if (subres != formatDate(otherDate, subformat, options)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1637 res += subres;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1638 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1639 i = i2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1640 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1641 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1642 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1643 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1644 else if (c == '{') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1645 date = date2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1646 otherDate = date1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1647 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1648 else if (c == '}') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1649 date = date1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1650 otherDate = date2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1651 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1652 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1653 for (i2=len; i2>i; i2--) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1654 if (formatter = dateFormatters[format.substring(i, i2)]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1655 if (date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1656 res += formatter(date, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1657 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1658 i = i2 - 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1659 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1660 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1661 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1662 if (i2 == i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1663 if (date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1664 res += c;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1665 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1666 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1667 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1668 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1669 return res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1670 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1671
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1672
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1673 var dateFormatters = {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1674 s : function(d) { return d.getSeconds() },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1675 ss : function(d) { return zeroPad(d.getSeconds()) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1676 m : function(d) { return d.getMinutes() },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1677 mm : function(d) { return zeroPad(d.getMinutes()) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1678 h : function(d) { return d.getHours() % 12 || 12 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1679 hh : function(d) { return zeroPad(d.getHours() % 12 || 12) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1680 H : function(d) { return d.getHours() },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1681 HH : function(d) { return zeroPad(d.getHours()) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1682 d : function(d) { return d.getDate() },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1683 dd : function(d) { return zeroPad(d.getDate()) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1684 ddd : function(d,o) { return o.dayNamesShort[d.getDay()] },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1685 dddd: function(d,o) { return o.dayNames[d.getDay()] },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1686 M : function(d) { return d.getMonth() + 1 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1687 MM : function(d) { return zeroPad(d.getMonth() + 1) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1688 MMM : function(d,o) { return o.monthNamesShort[d.getMonth()] },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1689 MMMM: function(d,o) { return o.monthNames[d.getMonth()] },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1690 yy : function(d) { return (d.getFullYear()+'').substring(2) },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1691 yyyy: function(d) { return d.getFullYear() },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1692 t : function(d) { return d.getHours() < 12 ? 'a' : 'p' },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1693 tt : function(d) { return d.getHours() < 12 ? 'am' : 'pm' },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1694 T : function(d) { return d.getHours() < 12 ? 'A' : 'P' },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1695 TT : function(d) { return d.getHours() < 12 ? 'AM' : 'PM' },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1696 u : function(d) { return formatDate(d, "yyyy-MM-dd'T'HH:mm:ss'Z'") },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1697 S : function(d) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1698 var date = d.getDate();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1699 if (date > 10 && date < 20) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1700 return 'th';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1701 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1702 return ['st', 'nd', 'rd'][date%10-1] || 'th';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1703 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1704 w : function(d, o) { // local
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1705 return o.weekNumberCalculation(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1706 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1707 W : function(d) { // ISO
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1708 return iso8601Week(d);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1709 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1710 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1711 fc.dateFormatters = dateFormatters;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1712
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1713
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1714 /* thanks jQuery UI (https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1715 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1716 * Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1717 * `date` - the date to get the week for
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1718 * `number` - the number of the week within the year that contains this date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1719 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1720 function iso8601Week(date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1721 var time;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1722 var checkDate = new Date(date.getTime());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1723
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1724 // Find Thursday of this week starting on Monday
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1725 checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1726
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1727 time = checkDate.getTime();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1728 checkDate.setMonth(0); // Compare with Jan 1
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1729 checkDate.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1730 return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1731 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1732
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1733 // Determine the week of the year based on the ISO 8601 definition.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1734 // copied from jquery UI Datepicker
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1735 var iso8601Week = function(date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1736 var checkDate = cloneDate(date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1737 // Find Thursday of this week starting on Monday
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1738 checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1739 var time = checkDate.getTime();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1740 checkDate.setMonth(0); // Compare with Jan 1
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1741 checkDate.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1742 return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1743 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1744
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1745
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1746 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1747
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1748 fc.applyAll = applyAll;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1749
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1750
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1751 /* Event Date Math
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1752 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1753
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1754
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1755 function exclEndDay(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1756 if (event.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1757 return _exclEndDay(event.end, event.allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1758 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1759 return addDays(cloneDate(event.start), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1760 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1761 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1762
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1763
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1764 function _exclEndDay(end, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1765 end = cloneDate(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1766 return allDay || end.getHours() || end.getMinutes() ? addDays(end, 1) : clearTime(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1767 // why don't we check for seconds/ms too?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1768 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1770
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1771
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1772 /* Event Element Binding
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1773 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1774
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1775
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1776 function lazySegBind(container, segs, bindHandlers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1777 container.unbind('mouseover focusin').bind('mouseover focusin', function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1778 var parent=ev.target, e,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1779 i, seg;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1780 while (parent != this) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1781 e = parent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1782 parent = parent.parentNode;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1783 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1784 if ((i = e._fci) !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1785 e._fci = undefined;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1786 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1787 bindHandlers(seg.event, seg.element, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1788 $(ev.target).trigger(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1789 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1790 ev.stopPropagation();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1791 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1792 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1793
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1794
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1795
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1796 /* Element Dimensions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1797 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1798
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1799
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1800 function setOuterWidth(element, width, includeMargins) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1801 for (var i=0, e; i<element.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1802 e = $(element[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1803 e.width(Math.max(0, width - hsides(e, includeMargins)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1804 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1805 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1806
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1807
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1808 function setOuterHeight(element, height, includeMargins) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1809 for (var i=0, e; i<element.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1810 e = $(element[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1811 e.height(Math.max(0, height - vsides(e, includeMargins)));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1812 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1813 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1814
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1815
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1816 function hsides(element, includeMargins) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1817 return hpadding(element) + hborders(element) + (includeMargins ? hmargins(element) : 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1818 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1819
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1820
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1821 function hpadding(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1822 return (parseFloat($.css(element[0], 'paddingLeft', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1823 (parseFloat($.css(element[0], 'paddingRight', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1824 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1825
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1826
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1827 function hmargins(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1828 return (parseFloat($.css(element[0], 'marginLeft', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1829 (parseFloat($.css(element[0], 'marginRight', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1830 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1831
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1832
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1833 function hborders(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1834 return (parseFloat($.css(element[0], 'borderLeftWidth', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1835 (parseFloat($.css(element[0], 'borderRightWidth', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1836 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1837
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1838
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1839 function vsides(element, includeMargins) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1840 return vpadding(element) + vborders(element) + (includeMargins ? vmargins(element) : 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1841 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1842
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1843
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1844 function vpadding(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1845 return (parseFloat($.css(element[0], 'paddingTop', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1846 (parseFloat($.css(element[0], 'paddingBottom', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1847 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1848
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1849
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1850 function vmargins(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1851 return (parseFloat($.css(element[0], 'marginTop', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1852 (parseFloat($.css(element[0], 'marginBottom', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1853 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1854
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1855
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1856 function vborders(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1857 return (parseFloat($.css(element[0], 'borderTopWidth', true)) || 0) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1858 (parseFloat($.css(element[0], 'borderBottomWidth', true)) || 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1859 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1860
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1861
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1862
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1863 /* Misc Utils
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1864 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1865
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1866
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1867 //TODO: arraySlice
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1868 //TODO: isFunction, grep ?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1869
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1870
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1871 function noop() { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1872
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1873
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1874 function dateCompare(a, b) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1875 return a - b;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1876 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1877
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1878
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1879 function arrayMax(a) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1880 return Math.max.apply(Math, a);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1881 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1882
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1883
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1884 function zeroPad(n) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1885 return (n < 10 ? '0' : '') + n;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1886 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1887
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1888
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1889 function smartProperty(obj, name) { // get a camel-cased/namespaced property of an object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1890 if (obj[name] !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1891 return obj[name];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1892 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1893 var parts = name.split(/(?=[A-Z])/),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1894 i=parts.length-1, res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1895 for (; i>=0; i--) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1896 res = obj[parts[i].toLowerCase()];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1897 if (res !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1898 return res;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1899 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1900 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1901 return obj[''];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1902 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1903
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1904
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1905 function htmlEscape(s) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1906 return s.replace(/&/g, '&amp;')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1907 .replace(/</g, '&lt;')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1908 .replace(/>/g, '&gt;')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1909 .replace(/'/g, '&#039;')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1910 .replace(/"/g, '&quot;')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1911 .replace(/\n/g, '<br />');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1912 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1913
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1914
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1915 function disableTextSelection(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1916 element
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1917 .attr('unselectable', 'on')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1918 .css('MozUserSelect', 'none')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1919 .bind('selectstart.ui', function() { return false; });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1920 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1921
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1922
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1923 /*
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1924 function enableTextSelection(element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1925 element
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1926 .attr('unselectable', 'off')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1927 .css('MozUserSelect', '')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1928 .unbind('selectstart.ui');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1929 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1930 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1931
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1932
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1933 function markFirstLast(e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1934 e.children()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1935 .removeClass('fc-first fc-last')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1936 .filter(':first-child')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1937 .addClass('fc-first')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1938 .end()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1939 .filter(':last-child')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1940 .addClass('fc-last');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1941 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1942
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1943
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1944 function setDayID(cell, date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1945 cell.each(function(i, _cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1946 _cell.className = _cell.className.replace(/^fc-\w*/, 'fc-' + dayIDs[date.getDay()]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1947 // TODO: make a way that doesn't rely on order of classes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1948 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1949 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1950
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1951
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1952 function getSkinCss(event, opt) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1953 var source = event.source || {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1954 var eventColor = event.color;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1955 var sourceColor = source.color;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1956 var optionColor = opt('eventColor');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1957 var backgroundColor =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1958 event.backgroundColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1959 eventColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1960 source.backgroundColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1961 sourceColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1962 opt('eventBackgroundColor') ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1963 optionColor;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1964 var borderColor =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1965 event.borderColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1966 eventColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1967 source.borderColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1968 sourceColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1969 opt('eventBorderColor') ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1970 optionColor;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1971 var textColor =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1972 event.textColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1973 source.textColor ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1974 opt('eventTextColor');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1975 var statements = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1976 if (backgroundColor) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1977 statements.push('background-color:' + backgroundColor);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1978 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1979 if (borderColor) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1980 statements.push('border-color:' + borderColor);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1981 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1982 if (textColor) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1983 statements.push('color:' + textColor);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1984 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1985 return statements.join(';');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1986 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1987
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1988
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1989 function applyAll(functions, thisObj, args) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1990 if ($.isFunction(functions)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1991 functions = [ functions ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1992 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1993 if (functions) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1994 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1995 var ret;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1996 for (i=0; i<functions.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1997 ret = functions[i].apply(thisObj, args) || ret;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1998 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1999 return ret;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2000 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2001 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2002
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2003
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2004 function firstDefined() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2005 for (var i=0; i<arguments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2006 if (arguments[i] !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2007 return arguments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2008 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2009 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2010 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2011
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2012
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2013 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2014
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2015 fcViews.month = MonthView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2016
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2017 function MonthView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2018 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2019
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2020
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2021 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2022 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2023
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2024
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2025 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2026 BasicView.call(t, element, calendar, 'month');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2027 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2028 var renderBasic = t.renderBasic;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2029 var skipHiddenDays = t.skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2030 var getCellsPerWeek = t.getCellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2031 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2032
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2033
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2034 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2035
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2036 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2037 addMonths(date, delta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2038 date.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2039 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2040
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2041 var firstDay = opt('firstDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2042
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2043 var start = cloneDate(date, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2044 start.setDate(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2045
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2046 var end = addMonths(cloneDate(start), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2047
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2048 var visStart = cloneDate(start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2049 addDays(visStart, -((visStart.getDay() - firstDay + 7) % 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2050 skipHiddenDays(visStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2051
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2052 var visEnd = cloneDate(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2053 addDays(visEnd, (7 - visEnd.getDay() + firstDay) % 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2054 skipHiddenDays(visEnd, -1, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2055
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2056 var colCnt = getCellsPerWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2057 var rowCnt = Math.round(dayDiff(visEnd, visStart) / 7); // should be no need for Math.round
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2058
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2059 if (opt('weekMode') == 'fixed') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2060 addDays(visEnd, (6 - rowCnt) * 7); // add weeks to make up for it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2061 rowCnt = 6;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2062 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2063
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2064 t.title = formatDate(start, opt('titleFormat'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2065
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2066 t.start = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2067 t.end = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2068 t.visStart = visStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2069 t.visEnd = visEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2070
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2071 renderBasic(rowCnt, colCnt, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2072 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2073
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2074
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2075 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2076
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2077 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2078
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2079 fcViews.basicWeek = BasicWeekView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2080
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2081 function BasicWeekView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2082 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2083
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2084
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2085 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2086 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2087
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2088
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2089 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2090 BasicView.call(t, element, calendar, 'basicWeek');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2091 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2092 var renderBasic = t.renderBasic;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2093 var skipHiddenDays = t.skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2094 var getCellsPerWeek = t.getCellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2095 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2096
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2097
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2098 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2099
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2100 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2101 addDays(date, delta * 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2102 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2104 var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2105 var end = addDays(cloneDate(start), 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2106
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2107 var visStart = cloneDate(start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2108 skipHiddenDays(visStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2109
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2110 var visEnd = cloneDate(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2111 skipHiddenDays(visEnd, -1, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2112
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2113 var colCnt = getCellsPerWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2114
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2115 t.start = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2116 t.end = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2117 t.visStart = visStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2118 t.visEnd = visEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2119
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2120 t.title = formatDates(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2121 visStart,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2122 addDays(cloneDate(visEnd), -1),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2123 opt('titleFormat')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2124 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2125
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2126 renderBasic(1, colCnt, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2127 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2128
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2129
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2130 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2131
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2132 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2133
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2134 fcViews.basicDay = BasicDayView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2135
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2136
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2137 function BasicDayView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2138 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2139
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2140
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2141 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2142 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2143
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2144
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2145 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2146 BasicView.call(t, element, calendar, 'basicDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2147 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2148 var renderBasic = t.renderBasic;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2149 var skipHiddenDays = t.skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2150 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2151
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2152
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2153 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2154
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2155 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2156 addDays(date, delta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2157 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2158 skipHiddenDays(date, delta < 0 ? -1 : 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2159
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2160 var start = cloneDate(date, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2161 var end = addDays(cloneDate(start), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2162
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2163 t.title = formatDate(date, opt('titleFormat'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2164
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2165 t.start = t.visStart = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2166 t.end = t.visEnd = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2167
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2168 renderBasic(1, 1, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2169 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2170
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2171
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2172 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2173
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2174 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2175
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2176 setDefaults({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2177 weekMode: 'fixed'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2178 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2179
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2180
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2181 function BasicView(element, calendar, viewName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2182 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2183
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2184
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2185 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2186 t.renderBasic = renderBasic;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2187 t.setHeight = setHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2188 t.setWidth = setWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2189 t.renderDayOverlay = renderDayOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2190 t.defaultSelectionEnd = defaultSelectionEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2191 t.renderSelection = renderSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2192 t.clearSelection = clearSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2193 t.reportDayClick = reportDayClick; // for selection (kinda hacky)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2194 t.dragStart = dragStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2195 t.dragStop = dragStop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2196 t.defaultEventEnd = defaultEventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2197 t.getHoverListener = function() { return hoverListener };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2198 t.colLeft = colLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2199 t.colRight = colRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2200 t.colContentLeft = colContentLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2201 t.colContentRight = colContentRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2202 t.getIsCellAllDay = function() { return true };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2203 t.allDayRow = allDayRow;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2204 t.getRowCnt = function() { return rowCnt };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2205 t.getColCnt = function() { return colCnt };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2206 t.getColWidth = function() { return colWidth };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2207 t.getDaySegmentContainer = function() { return daySegmentContainer };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2208
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2209
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2210 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2211 View.call(t, element, calendar, viewName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2212 OverlayManager.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2213 SelectionManager.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2214 BasicEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2215 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2216 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2217 var renderOverlay = t.renderOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2218 var clearOverlays = t.clearOverlays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2219 var daySelectionMousedown = t.daySelectionMousedown;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2220 var cellToDate = t.cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2221 var dateToCell = t.dateToCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2222 var rangeToSegments = t.rangeToSegments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2223 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2224
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2225
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2226 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2227
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2228 var table;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2229 var head;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2230 var headCells;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2231 var body;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2232 var bodyRows;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2233 var bodyCells;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2234 var bodyFirstCells;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2235 var firstRowCellInners;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2236 var firstRowCellContentInners;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2237 var daySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2238
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2239 var viewWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2240 var viewHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2241 var colWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2242 var weekNumberWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2243
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2244 var rowCnt, colCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2245 var showNumbers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2246 var coordinateGrid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2247 var hoverListener;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2248 var colPositions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2249 var colContentPositions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2250
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2251 var tm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2252 var colFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2253 var showWeekNumbers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2254 var weekNumberTitle;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2255 var weekNumberFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2256
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2257
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2258
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2259 /* Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2260 ------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2261
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2262
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2263 disableTextSelection(element.addClass('fc-grid'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2264
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2265
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2266 function renderBasic(_rowCnt, _colCnt, _showNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2267 rowCnt = _rowCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2268 colCnt = _colCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2269 showNumbers = _showNumbers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2270 updateOptions();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2271
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2272 if (!body) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2273 buildEventContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2274 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2275
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2276 buildTable();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2277 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2278
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2279
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2280 function updateOptions() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2281 tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2282 colFormat = opt('columnFormat');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2283
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2284 // week # options. (TODO: bad, logic also in other views)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2285 showWeekNumbers = opt('weekNumbers');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2286 weekNumberTitle = opt('weekNumberTitle');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2287 if (opt('weekNumberCalculation') != 'iso') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2288 weekNumberFormat = "w";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2289 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2290 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2291 weekNumberFormat = "W";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2292 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2293 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2294
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2295
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2296 function buildEventContainer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2297 daySegmentContainer =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2298 $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2299 .appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2300 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2301
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2302
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2303 function buildTable() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2304 var html = buildTableHTML();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2305
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2306 if (table) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2307 table.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2308 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2309 table = $(html).appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2310
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2311 head = table.find('thead');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2312 headCells = head.find('.fc-day-header');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2313 body = table.find('tbody');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2314 bodyRows = body.find('tr');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2315 bodyCells = body.find('.fc-day');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2316 bodyFirstCells = bodyRows.find('td:first-child');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2317
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2318 firstRowCellInners = bodyRows.eq(0).find('.fc-day > div');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2319 firstRowCellContentInners = bodyRows.eq(0).find('.fc-day-content > div');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2320
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2321 markFirstLast(head.add(head.find('tr'))); // marks first+last tr/th's
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2322 markFirstLast(bodyRows); // marks first+last td's
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2323 bodyRows.eq(0).addClass('fc-first');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2324 bodyRows.filter(':last').addClass('fc-last');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2325
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2326 bodyCells.each(function(i, _cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2327 var date = cellToDate(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2328 Math.floor(i / colCnt),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2329 i % colCnt
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2330 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2331 trigger('dayRender', t, date, $(_cell));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2332 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2333
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2334 dayBind(bodyCells);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2335 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2336
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2337
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2338
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2339 /* HTML Building
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2340 -----------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2341
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2343 function buildTableHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2344 var html =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2345 "<table class='fc-border-separate' style='width:100%' cellspacing='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2346 buildHeadHTML() +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2347 buildBodyHTML() +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2348 "</table>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2349
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2350 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2351 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2353
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2354 function buildHeadHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2355 var headerClass = tm + "-widget-header";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2356 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2357 var col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2358 var date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2359
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2360 html += "<thead><tr>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2361
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2362 if (showWeekNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2363 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2364 "<th class='fc-week-number " + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2365 htmlEscape(weekNumberTitle) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2366 "</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2367 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2368
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2369 for (col=0; col<colCnt; col++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2370 date = cellToDate(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2371 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2372 "<th class='fc-day-header fc-" + dayIDs[date.getDay()] + " " + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2373 htmlEscape(formatDate(date, colFormat)) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2374 "</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2375 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2376
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2377 html += "</tr></thead>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2378
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2379 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2380 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2381
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2382
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2383 function buildBodyHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2384 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2385 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2386 var row;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2387 var col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2388 var date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2389
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2390 html += "<tbody>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2391
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2392 for (row=0; row<rowCnt; row++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2393
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2394 html += "<tr class='fc-week'>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2395
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2396 if (showWeekNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2397 date = cellToDate(row, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2398 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2399 "<td class='fc-week-number " + contentClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2400 "<div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2401 htmlEscape(formatDate(date, weekNumberFormat)) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2402 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2403 "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2404 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2405
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2406 for (col=0; col<colCnt; col++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2407 date = cellToDate(row, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2408 html += buildCellHTML(date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2409 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2410
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2411 html += "</tr>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2412 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2413
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2414 html += "</tbody>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2415
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2416 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2417 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2418
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2419
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2420 function buildCellHTML(date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2421 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2422 var month = t.start.getMonth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2423 var today = clearTime(new Date());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2424 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2425 var classNames = [
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2426 'fc-day',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2427 'fc-' + dayIDs[date.getDay()],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2428 contentClass
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2429 ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2430
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2431 if (date.getMonth() != month) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2432 classNames.push('fc-other-month');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2433 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2434 if (+date == +today) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2435 classNames.push(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2436 'fc-today',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2437 tm + '-state-highlight'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2438 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2439 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2440 else if (date < today) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2441 classNames.push('fc-past');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2442 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2443 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2444 classNames.push('fc-future');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2445 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2446
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2447 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2448 "<td" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2449 " class='" + classNames.join(' ') + "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2450 " data-date='" + formatDate(date, 'yyyy-MM-dd') + "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2451 ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2452 "<div>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2453
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2454 if (showNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2455 html += "<div class='fc-day-number'>" + date.getDate() + "</div>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2456 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2457
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2458 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2459 "<div class='fc-day-content'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2460 "<div style='position:relative'>&nbsp;</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2461 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2462 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2463 "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2464
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2465 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2466 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2467
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2468
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2469
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2470 /* Dimensions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2471 -----------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2472
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2473
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2474 function setHeight(height) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2475 viewHeight = height;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2476
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2477 var bodyHeight = viewHeight - head.height();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2478 var rowHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2479 var rowHeightLast;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2480 var cell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2481
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2482 if (opt('weekMode') == 'variable') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2483 rowHeight = rowHeightLast = Math.floor(bodyHeight / (rowCnt==1 ? 2 : 6));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2484 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2485 rowHeight = Math.floor(bodyHeight / rowCnt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2486 rowHeightLast = bodyHeight - rowHeight * (rowCnt-1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2487 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2488
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2489 bodyFirstCells.each(function(i, _cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2490 if (i < rowCnt) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2491 cell = $(_cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2492 cell.find('> div').css(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2493 'min-height',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2494 (i==rowCnt-1 ? rowHeightLast : rowHeight) - vsides(cell)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2495 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2496 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2497 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2498
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2499 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2500
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2501
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2502 function setWidth(width) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2503 viewWidth = width;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2504 colPositions.clear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2505 colContentPositions.clear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2506
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2507 weekNumberWidth = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2508 if (showWeekNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2509 weekNumberWidth = head.find('th.fc-week-number').outerWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2510 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2511
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2512 colWidth = Math.floor((viewWidth - weekNumberWidth) / colCnt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2513 setOuterWidth(headCells.slice(0, -1), colWidth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2514 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2515
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2516
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2517
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2518 /* Day clicking and binding
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2519 -----------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2520
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2521
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2522 function dayBind(days) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2523 days.click(dayClick)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2524 .mousedown(daySelectionMousedown);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2525 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2526
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2528 function dayClick(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2529 if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2530 var date = parseISO8601($(this).data('date'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2531 trigger('dayClick', this, date, true, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2532 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2533 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2534
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2535
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2536
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2537 /* Semi-transparent Overlay Helpers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2538 ------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2539 // TODO: should be consolidated with AgendaView's methods
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2540
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2541
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2542 function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2543
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2544 if (refreshCoordinateGrid) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2545 coordinateGrid.build();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2546 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2547
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2548 var segments = rangeToSegments(overlayStart, overlayEnd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2549
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2550 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2551 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2552 dayBind(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2553 renderCellOverlay(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2554 segment.row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2555 segment.leftCol,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2556 segment.row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2557 segment.rightCol
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2558 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2559 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2560 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2561 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2562
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2563
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2564 function renderCellOverlay(row0, col0, row1, col1) { // row1,col1 is inclusive
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2565 var rect = coordinateGrid.rect(row0, col0, row1, col1, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2566 return renderOverlay(rect, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2567 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2568
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2569
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2570
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2571 /* Selection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2572 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2573
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2574
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2575 function defaultSelectionEnd(startDate, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2576 return cloneDate(startDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2577 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2578
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2579
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2580 function renderSelection(startDate, endDate, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2581 renderDayOverlay(startDate, addDays(cloneDate(endDate), 1), true); // rebuild every time???
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2582 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2583
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2584
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2585 function clearSelection() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2586 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2587 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2588
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2589
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2590 function reportDayClick(date, allDay, ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2591 var cell = dateToCell(date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2592 var _element = bodyCells[cell.row*colCnt + cell.col];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2593 trigger('dayClick', _element, date, allDay, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2594 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2595
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2596
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2597
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2598 /* External Dragging
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2599 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2600
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2601
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2602 function dragStart(_dragElement, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2603 hoverListener.start(function(cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2604 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2605 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2606 renderCellOverlay(cell.row, cell.col, cell.row, cell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2607 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2608 }, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2609 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2610
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2611
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2612 function dragStop(_dragElement, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2613 var cell = hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2614 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2615 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2616 var d = cellToDate(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2617 trigger('drop', _dragElement, d, true, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2618 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2619 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2620
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2621
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2622
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2623 /* Utilities
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2624 --------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2625
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2626
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2627 function defaultEventEnd(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2628 return cloneDate(event.start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2629 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2630
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2631
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2632 coordinateGrid = new CoordinateGrid(function(rows, cols) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2633 var e, n, p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2634 headCells.each(function(i, _e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2635 e = $(_e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2636 n = e.offset().left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2637 if (i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2638 p[1] = n;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2639 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2640 p = [n];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2641 cols[i] = p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2642 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2643 p[1] = n + e.outerWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2644 bodyRows.each(function(i, _e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2645 if (i < rowCnt) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2646 e = $(_e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2647 n = e.offset().top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2648 if (i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2649 p[1] = n;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2650 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2651 p = [n];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2652 rows[i] = p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2653 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2654 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2655 p[1] = n + e.outerHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2656 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2657
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2658
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2659 hoverListener = new HoverListener(coordinateGrid);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2660
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2661 colPositions = new HorizontalPositionCache(function(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2662 return firstRowCellInners.eq(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2663 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2664
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2665 colContentPositions = new HorizontalPositionCache(function(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2666 return firstRowCellContentInners.eq(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2667 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2668
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2669
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2670 function colLeft(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2671 return colPositions.left(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2672 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2673
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2674
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2675 function colRight(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2676 return colPositions.right(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2677 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2678
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2679
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2680 function colContentLeft(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2681 return colContentPositions.left(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2682 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2683
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2684
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2685 function colContentRight(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2686 return colContentPositions.right(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2689
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2690 function allDayRow(i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2691 return bodyRows.eq(i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2692 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2693
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2694 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2695
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2696 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2697
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2698 function BasicEventRenderer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2699 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2700
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2701
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2702 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2703 t.renderEvents = renderEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2704 t.clearEvents = clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2706
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2707 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2708 DayEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2710
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2711 function renderEvents(events, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2712 t.renderDayEvents(events, modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2713 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2714
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2715
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2716 function clearEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2717 t.getDaySegmentContainer().empty();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2718 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2719
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2720
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2721 // TODO: have this class (and AgendaEventRenderer) be responsible for creating the event container div
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2722
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2723 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2724
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2725 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2726
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2727 fcViews.agendaWeek = AgendaWeekView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2728
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2729 function AgendaWeekView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2730 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2731
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2732
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2733 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2734 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2735
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2736
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2737 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2738 AgendaView.call(t, element, calendar, 'agendaWeek');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2739 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2740 var renderAgenda = t.renderAgenda;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2741 var skipHiddenDays = t.skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2742 var getCellsPerWeek = t.getCellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2743 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2744
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2745
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2746 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2747
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2748 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2749 addDays(date, delta * 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2750 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2751
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2752 var start = addDays(cloneDate(date), -((date.getDay() - opt('firstDay') + 7) % 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2753 var end = addDays(cloneDate(start), 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2754
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2755 var visStart = cloneDate(start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2756 skipHiddenDays(visStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2757
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2758 var visEnd = cloneDate(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2759 skipHiddenDays(visEnd, -1, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2760
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2761 var colCnt = getCellsPerWeek();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2762
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2763 t.title = formatDates(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2764 visStart,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2765 addDays(cloneDate(visEnd), -1),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2766 opt('titleFormat')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2767 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2768
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2769 t.start = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2770 t.end = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2771 t.visStart = visStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2772 t.visEnd = visEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2773
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2774 renderAgenda(colCnt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2775 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2776
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2777 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2778
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2779 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2780
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2781 fcViews.agendaDay = AgendaDayView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2782
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2783
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2784 function AgendaDayView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2785 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2786
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2787
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2788 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2789 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2790
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2791
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2792 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2793 AgendaView.call(t, element, calendar, 'agendaDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2794 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2795 var renderAgenda = t.renderAgenda;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2796 var skipHiddenDays = t.skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2797 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2798
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2799
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2800 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2801
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2802 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2803 addDays(date, delta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2804 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2805 skipHiddenDays(date, delta < 0 ? -1 : 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2806
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2807 var start = cloneDate(date, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2808 var end = addDays(cloneDate(start), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2809
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2810 t.title = formatDate(date, opt('titleFormat'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2811
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2812 t.start = t.visStart = start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2813 t.end = t.visEnd = end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2814
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2815 renderAgenda(1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2816 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2817
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2818
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2819 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2820
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2821 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2822
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2823 setDefaults({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2824 allDaySlot: true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2825 allDayText: 'all-day',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2826 firstHour: 6,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2827 slotMinutes: 30,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2828 defaultEventMinutes: 120,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2829 axisFormat: 'h(:mm)tt',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2830 timeFormat: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2831 agenda: 'h:mm{ - h:mm}'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2832 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2833 dragOpacity: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2834 agenda: .5
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2835 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2836 minTime: 0,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2837 maxTime: 24,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2838 slotEventOverlap: true
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2839 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2840
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2841
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2842 // TODO: make it work in quirks mode (event corners, all-day height)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2843 // TODO: test liquid width, especially in IE6
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2844
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2845
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2846 function AgendaView(element, calendar, viewName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2847 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2848
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2849
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2850 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2851 t.renderAgenda = renderAgenda;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2852 t.setWidth = setWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2853 t.setHeight = setHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2854 t.afterRender = afterRender;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2855 t.defaultEventEnd = defaultEventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2856 t.timePosition = timePosition;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2857 t.getIsCellAllDay = getIsCellAllDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2858 t.allDayRow = getAllDayRow;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2859 t.getCoordinateGrid = function() { return coordinateGrid }; // specifically for AgendaEventRenderer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2860 t.getHoverListener = function() { return hoverListener };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2861 t.colLeft = colLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2862 t.colRight = colRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2863 t.colContentLeft = colContentLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2864 t.colContentRight = colContentRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2865 t.getDaySegmentContainer = function() { return daySegmentContainer };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2866 t.getSlotSegmentContainer = function() { return slotSegmentContainer };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2867 t.getMinMinute = function() { return minMinute };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2868 t.getMaxMinute = function() { return maxMinute };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2869 t.getSlotContainer = function() { return slotContainer };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2870 t.getRowCnt = function() { return 1 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2871 t.getColCnt = function() { return colCnt };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2872 t.getColWidth = function() { return colWidth };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2873 t.getSnapHeight = function() { return snapHeight };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2874 t.getSnapMinutes = function() { return snapMinutes };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2875 t.defaultSelectionEnd = defaultSelectionEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2876 t.renderDayOverlay = renderDayOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2877 t.renderSelection = renderSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2878 t.clearSelection = clearSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2879 t.reportDayClick = reportDayClick; // selection mousedown hack
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2880 t.dragStart = dragStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2881 t.dragStop = dragStop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2882
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2883
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2884 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2885 View.call(t, element, calendar, viewName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2886 OverlayManager.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2887 SelectionManager.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2888 AgendaEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2889 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2890 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2891 var renderOverlay = t.renderOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2892 var clearOverlays = t.clearOverlays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2893 var reportSelection = t.reportSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2894 var unselect = t.unselect;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2895 var daySelectionMousedown = t.daySelectionMousedown;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2896 var slotSegHtml = t.slotSegHtml;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2897 var cellToDate = t.cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2898 var dateToCell = t.dateToCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2899 var rangeToSegments = t.rangeToSegments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2900 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2901
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2902
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2903 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2904
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2905 var dayTable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2906 var dayHead;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2907 var dayHeadCells;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2908 var dayBody;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2909 var dayBodyCells;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2910 var dayBodyCellInners;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2911 var dayBodyCellContentInners;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2912 var dayBodyFirstCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2913 var dayBodyFirstCellStretcher;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2914 var slotLayer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2915 var daySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2916 var allDayTable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2917 var allDayRow;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2918 var slotScroller;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2919 var slotContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2920 var slotSegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2921 var slotTable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2922 var selectionHelper;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2923
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2924 var viewWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2925 var viewHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2926 var axisWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2927 var colWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2928 var gutterWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2929 var slotHeight; // TODO: what if slotHeight changes? (see issue 650)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2930
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2931 var snapMinutes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2932 var snapRatio; // ratio of number of "selection" slots to normal slots. (ex: 1, 2, 4)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2933 var snapHeight; // holds the pixel hight of a "selection" slot
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2934
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2935 var colCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2936 var slotCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2937 var coordinateGrid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2938 var hoverListener;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2939 var colPositions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2940 var colContentPositions;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2941 var slotTopCache = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2942
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2943 var tm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2944 var rtl;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2945 var minMinute, maxMinute;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2946 var colFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2947 var showWeekNumbers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2948 var weekNumberTitle;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2949 var weekNumberFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2950
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2951
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2952
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2953 /* Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2954 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2955
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2956
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2957 disableTextSelection(element.addClass('fc-agenda'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2958
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2959
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2960 function renderAgenda(c) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2961 colCnt = c;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2962 updateOptions();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2963
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2964 if (!dayTable) { // first time rendering?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2965 buildSkeleton(); // builds day table, slot area, events containers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2966 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2967 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2968 buildDayTable(); // rebuilds day table
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2969 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2970 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2971
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2972
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2973 function updateOptions() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2974
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2975 tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2976 rtl = opt('isRTL')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2977 minMinute = parseTime(opt('minTime'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2978 maxMinute = parseTime(opt('maxTime'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2979 colFormat = opt('columnFormat');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2980
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2981 // week # options. (TODO: bad, logic also in other views)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2982 showWeekNumbers = opt('weekNumbers');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2983 weekNumberTitle = opt('weekNumberTitle');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2984 if (opt('weekNumberCalculation') != 'iso') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2985 weekNumberFormat = "w";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2986 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2987 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2988 weekNumberFormat = "W";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2989 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2990
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2991 snapMinutes = opt('snapMinutes') || opt('slotMinutes');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2992 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2993
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2994
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2995
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2996 /* Build DOM
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2997 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2998
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2999
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3000 function buildSkeleton() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3001 var headerClass = tm + "-widget-header";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3002 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3003 var s;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3004 var d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3005 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3006 var maxd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3007 var minutes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3008 var slotNormal = opt('slotMinutes') % 15 == 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3009
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3010 buildDayTable();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3011
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3012 slotLayer =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3013 $("<div style='position:absolute;z-index:2;left:0;width:100%'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3014 .appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3015
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3016 if (opt('allDaySlot')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3017
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3018 daySegmentContainer =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3019 $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3020 .appendTo(slotLayer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3021
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3022 s =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3023 "<table style='width:100%' class='fc-agenda-allday' cellspacing='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3024 "<tr>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3025 "<th class='" + headerClass + " fc-agenda-axis'>" + opt('allDayText') + "</th>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3026 "<td>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3027 "<div class='fc-day-content'><div style='position:relative'/></div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3028 "</td>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3029 "<th class='" + headerClass + " fc-agenda-gutter'>&nbsp;</th>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3030 "</tr>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3031 "</table>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3032 allDayTable = $(s).appendTo(slotLayer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3033 allDayRow = allDayTable.find('tr');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3034
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3035 dayBind(allDayRow.find('td'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3036
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3037 slotLayer.append(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3038 "<div class='fc-agenda-divider " + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3039 "<div class='fc-agenda-divider-inner'/>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3040 "</div>"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3041 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3042
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3043 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3044
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3045 daySegmentContainer = $([]); // in jQuery 1.4, we can just do $()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3046
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3047 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3048
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3049 slotScroller =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3050 $("<div style='position:absolute;width:100%;overflow-x:hidden;overflow-y:auto'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3051 .appendTo(slotLayer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3052
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3053 slotContainer =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3054 $("<div style='position:relative;width:100%;overflow:hidden'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3055 .appendTo(slotScroller);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3056
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3057 slotSegmentContainer =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3058 $("<div class='fc-event-container' style='position:absolute;z-index:8;top:0;left:0'/>")
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3059 .appendTo(slotContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3060
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3061 s =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3062 "<table class='fc-agenda-slots' style='width:100%' cellspacing='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3063 "<tbody>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3064 d = zeroDate();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3065 maxd = addMinutes(cloneDate(d), maxMinute);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3066 addMinutes(d, minMinute);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3067 slotCnt = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3068 for (i=0; d < maxd; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3069 minutes = d.getMinutes();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3070 s +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3071 "<tr class='fc-slot" + i + ' ' + (!minutes ? '' : 'fc-minor') + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3072 "<th class='fc-agenda-axis " + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3073 ((!slotNormal || !minutes) ? formatDate(d, opt('axisFormat')) : '&nbsp;') +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3074 "</th>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3075 "<td class='" + contentClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3076 "<div style='position:relative'>&nbsp;</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3077 "</td>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3078 "</tr>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3079 addMinutes(d, opt('slotMinutes'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3080 slotCnt++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3081 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3082 s +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3083 "</tbody>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3084 "</table>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3085 slotTable = $(s).appendTo(slotContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3086
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3087 slotBind(slotTable.find('td'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3088 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3089
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3090
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3091
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3092 /* Build Day Table
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3093 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3094
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3095
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3096 function buildDayTable() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3097 var html = buildDayTableHTML();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3098
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3099 if (dayTable) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3100 dayTable.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3101 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3102 dayTable = $(html).appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3104 dayHead = dayTable.find('thead');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3105 dayHeadCells = dayHead.find('th').slice(1, -1); // exclude gutter
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3106 dayBody = dayTable.find('tbody');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3107 dayBodyCells = dayBody.find('td').slice(0, -1); // exclude gutter
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3108 dayBodyCellInners = dayBodyCells.find('> div');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3109 dayBodyCellContentInners = dayBodyCells.find('.fc-day-content > div');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3110
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3111 dayBodyFirstCell = dayBodyCells.eq(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3112 dayBodyFirstCellStretcher = dayBodyCellInners.eq(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3113
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3114 markFirstLast(dayHead.add(dayHead.find('tr')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3115 markFirstLast(dayBody.add(dayBody.find('tr')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3116
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3117 // TODO: now that we rebuild the cells every time, we should call dayRender
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3118 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3119
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3120
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3121 function buildDayTableHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3122 var html =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3123 "<table style='width:100%' class='fc-agenda-days fc-border-separate' cellspacing='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3124 buildDayTableHeadHTML() +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3125 buildDayTableBodyHTML() +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3126 "</table>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3127
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3128 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3129 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3130
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3131
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3132 function buildDayTableHeadHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3133 var headerClass = tm + "-widget-header";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3134 var date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3135 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3136 var weekText;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3137 var col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3138
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3139 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3140 "<thead>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3141 "<tr>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3142
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3143 if (showWeekNumbers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3144 date = cellToDate(0, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3145 weekText = formatDate(date, weekNumberFormat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3146 if (rtl) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3147 weekText += weekNumberTitle;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3148 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3149 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3150 weekText = weekNumberTitle + weekText;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3151 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3152 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3153 "<th class='fc-agenda-axis fc-week-number " + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3154 htmlEscape(weekText) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3155 "</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3156 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3157 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3158 html += "<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3159 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3160
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3161 for (col=0; col<colCnt; col++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3162 date = cellToDate(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3163 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3164 "<th class='fc-" + dayIDs[date.getDay()] + " fc-col" + col + ' ' + headerClass + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3165 htmlEscape(formatDate(date, colFormat)) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3166 "</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3167 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3168
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3169 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3170 "<th class='fc-agenda-gutter " + headerClass + "'>&nbsp;</th>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3171 "</tr>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3172 "</thead>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3173
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3174 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3175 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3176
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3177
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3178 function buildDayTableBodyHTML() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3179 var headerClass = tm + "-widget-header"; // TODO: make these when updateOptions() called
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3180 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3181 var date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3182 var today = clearTime(new Date());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3183 var col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3184 var cellsHTML;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3185 var cellHTML;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3186 var classNames;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3187 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3188
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3189 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3190 "<tbody>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3191 "<tr>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3192 "<th class='fc-agenda-axis " + headerClass + "'>&nbsp;</th>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3193
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3194 cellsHTML = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3195
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3196 for (col=0; col<colCnt; col++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3197
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3198 date = cellToDate(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3199
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3200 classNames = [
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3201 'fc-col' + col,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3202 'fc-' + dayIDs[date.getDay()],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3203 contentClass
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3204 ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3205 if (+date == +today) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3206 classNames.push(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3207 tm + '-state-highlight',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3208 'fc-today'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3209 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3210 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3211 else if (date < today) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3212 classNames.push('fc-past');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3213 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3214 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3215 classNames.push('fc-future');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3216 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3217
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3218 cellHTML =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3219 "<td class='" + classNames.join(' ') + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3220 "<div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3221 "<div class='fc-day-content'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3222 "<div style='position:relative'>&nbsp;</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3223 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3224 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3225 "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3226
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3227 cellsHTML += cellHTML;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3228 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3229
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3230 html += cellsHTML;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3231 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3232 "<td class='fc-agenda-gutter " + contentClass + "'>&nbsp;</td>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3233 "</tr>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3234 "</tbody>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3235
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3236 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3237 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3238
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3239
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3240 // TODO: data-date on the cells
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3241
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3242
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3243
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3244 /* Dimensions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3245 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3247
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3248 function setHeight(height) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3249 if (height === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3250 height = viewHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3251 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3252 viewHeight = height;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3253 slotTopCache = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3254
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3255 var headHeight = dayBody.position().top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3256 var allDayHeight = slotScroller.position().top; // including divider
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3257 var bodyHeight = Math.min( // total body height, including borders
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3258 height - headHeight, // when scrollbars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3259 slotTable.height() + allDayHeight + 1 // when no scrollbars. +1 for bottom border
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3260 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3261
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3262 dayBodyFirstCellStretcher
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3263 .height(bodyHeight - vsides(dayBodyFirstCell));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3264
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3265 slotLayer.css('top', headHeight);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3266
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3267 slotScroller.height(bodyHeight - allDayHeight - 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3268
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3269 // the stylesheet guarantees that the first row has no border.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3270 // this allows .height() to work well cross-browser.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3271 slotHeight = slotTable.find('tr:first').height() + 1; // +1 for bottom border
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3273 snapRatio = opt('slotMinutes') / snapMinutes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3274 snapHeight = slotHeight / snapRatio;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3275 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3276
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3277
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3278 function setWidth(width) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3279 viewWidth = width;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3280 colPositions.clear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3281 colContentPositions.clear();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3282
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3283 var axisFirstCells = dayHead.find('th:first');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3284 if (allDayTable) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3285 axisFirstCells = axisFirstCells.add(allDayTable.find('th:first'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3286 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3287 axisFirstCells = axisFirstCells.add(slotTable.find('th:first'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3288
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3289 axisWidth = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3290 setOuterWidth(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3291 axisFirstCells
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3292 .width('')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3293 .each(function(i, _cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3294 axisWidth = Math.max(axisWidth, $(_cell).outerWidth());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3295 }),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3296 axisWidth
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3297 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3298
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3299 var gutterCells = dayTable.find('.fc-agenda-gutter');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3300 if (allDayTable) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3301 gutterCells = gutterCells.add(allDayTable.find('th.fc-agenda-gutter'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3302 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3303
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3304 var slotTableWidth = slotScroller[0].clientWidth; // needs to be done after axisWidth (for IE7)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3305
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3306 gutterWidth = slotScroller.width() - slotTableWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3307 if (gutterWidth) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3308 setOuterWidth(gutterCells, gutterWidth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3309 gutterCells
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3310 .show()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3311 .prev()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3312 .removeClass('fc-last');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3313 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3314 gutterCells
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3315 .hide()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3316 .prev()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3317 .addClass('fc-last');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3318 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3319
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3320 colWidth = Math.floor((slotTableWidth - axisWidth) / colCnt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3321 setOuterWidth(dayHeadCells.slice(0, -1), colWidth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3322 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3323
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3324
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3325
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3326 /* Scrolling
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3327 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3328
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3329
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3330 function resetScroll() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3331 var d0 = zeroDate();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3332 var scrollDate = cloneDate(d0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3333 scrollDate.setHours(opt('firstHour'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3334 var top = timePosition(d0, scrollDate) + 1; // +1 for the border
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3335 function scroll() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3336 slotScroller.scrollTop(top);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3337 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3338 scroll();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3339 setTimeout(scroll, 0); // overrides any previous scroll state made by the browser
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3340 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3341
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3343 function afterRender() { // after the view has been freshly rendered and sized
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3344 resetScroll();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3345 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3346
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3347
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3348
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3349 /* Slot/Day clicking and binding
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3350 -----------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3351
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3353 function dayBind(cells) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3354 cells.click(slotClick)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3355 .mousedown(daySelectionMousedown);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3356 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3358
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3359 function slotBind(cells) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3360 cells.click(slotClick)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3361 .mousedown(slotSelectionMousedown);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3362 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3363
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3364
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3365 function slotClick(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3366 if (!opt('selectable')) { // if selectable, SelectionManager will worry about dayClick
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3367 var col = Math.min(colCnt-1, Math.floor((ev.pageX - dayTable.offset().left - axisWidth) / colWidth));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3368 var date = cellToDate(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3369 var rowMatch = this.parentNode.className.match(/fc-slot(\d+)/); // TODO: maybe use data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3370 if (rowMatch) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3371 var mins = parseInt(rowMatch[1]) * opt('slotMinutes');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3372 var hours = Math.floor(mins/60);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3373 date.setHours(hours);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3374 date.setMinutes(mins%60 + minMinute);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3375 trigger('dayClick', dayBodyCells[col], date, false, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3376 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3377 trigger('dayClick', dayBodyCells[col], date, true, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3378 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3379 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3380 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3381
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3382
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3383
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3384 /* Semi-transparent Overlay Helpers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3385 -----------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3386 // TODO: should be consolidated with BasicView's methods
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3387
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3388
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3389 function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3390
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3391 if (refreshCoordinateGrid) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3392 coordinateGrid.build();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3393 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3394
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3395 var segments = rangeToSegments(overlayStart, overlayEnd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3396
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3397 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3398 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3399 dayBind(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3400 renderCellOverlay(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3401 segment.row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3402 segment.leftCol,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3403 segment.row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3404 segment.rightCol
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3405 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3406 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3407 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3408 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3409
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3410
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3411 function renderCellOverlay(row0, col0, row1, col1) { // only for all-day?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3412 var rect = coordinateGrid.rect(row0, col0, row1, col1, slotLayer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3413 return renderOverlay(rect, slotLayer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3414 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3415
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3416
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3417 function renderSlotOverlay(overlayStart, overlayEnd) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3418 for (var i=0; i<colCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3419 var dayStart = cellToDate(0, i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3420 var dayEnd = addDays(cloneDate(dayStart), 1);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3421 var stretchStart = new Date(Math.max(dayStart, overlayStart));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3422 var stretchEnd = new Date(Math.min(dayEnd, overlayEnd));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3423 if (stretchStart < stretchEnd) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3424 var rect = coordinateGrid.rect(0, i, 0, i, slotContainer); // only use it for horizontal coords
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3425 var top = timePosition(dayStart, stretchStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3426 var bottom = timePosition(dayStart, stretchEnd);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3427 rect.top = top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3428 rect.height = bottom - top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3429 slotBind(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3430 renderOverlay(rect, slotContainer)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3431 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3432 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3433 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3434 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3435
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3436
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3437
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3438 /* Coordinate Utilities
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3439 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3440
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3441
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3442 coordinateGrid = new CoordinateGrid(function(rows, cols) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3443 var e, n, p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3444 dayHeadCells.each(function(i, _e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3445 e = $(_e);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3446 n = e.offset().left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3447 if (i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3448 p[1] = n;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3449 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3450 p = [n];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3451 cols[i] = p;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3452 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3453 p[1] = n + e.outerWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3454 if (opt('allDaySlot')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3455 e = allDayRow;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3456 n = e.offset().top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3457 rows[0] = [n, n+e.outerHeight()];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3458 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3459 var slotTableTop = slotContainer.offset().top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3460 var slotScrollerTop = slotScroller.offset().top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3461 var slotScrollerBottom = slotScrollerTop + slotScroller.outerHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3462 function constrain(n) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3463 return Math.max(slotScrollerTop, Math.min(slotScrollerBottom, n));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3464 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3465 for (var i=0; i<slotCnt*snapRatio; i++) { // adapt slot count to increased/decreased selection slot count
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3466 rows.push([
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3467 constrain(slotTableTop + snapHeight*i),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3468 constrain(slotTableTop + snapHeight*(i+1))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3469 ]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3470 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3471 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3472
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3473
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3474 hoverListener = new HoverListener(coordinateGrid);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3475
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3476 colPositions = new HorizontalPositionCache(function(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3477 return dayBodyCellInners.eq(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3478 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3479
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3480 colContentPositions = new HorizontalPositionCache(function(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3481 return dayBodyCellContentInners.eq(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3482 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3483
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3484
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3485 function colLeft(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3486 return colPositions.left(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3487 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3488
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3489
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3490 function colContentLeft(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3491 return colContentPositions.left(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3492 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3493
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3494
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3495 function colRight(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3496 return colPositions.right(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3497 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3498
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3499
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3500 function colContentRight(col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3501 return colContentPositions.right(col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3502 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3503
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3504
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3505 function getIsCellAllDay(cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3506 return opt('allDaySlot') && !cell.row;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3507 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3508
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3509
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3510 function realCellToDate(cell) { // ugh "real" ... but blame it on our abuse of the "cell" system
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3511 var d = cellToDate(0, cell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3512 var slotIndex = cell.row;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3513 if (opt('allDaySlot')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3514 slotIndex--;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3516 if (slotIndex >= 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3517 addMinutes(d, minMinute + slotIndex * snapMinutes);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3518 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3519 return d;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3520 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3521
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3522
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3523 // get the Y coordinate of the given time on the given day (both Date objects)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3524 function timePosition(day, time) { // both date objects. day holds 00:00 of current day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3525 day = cloneDate(day, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3526 if (time < addMinutes(cloneDate(day), minMinute)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3527 return 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3528 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3529 if (time >= addMinutes(cloneDate(day), maxMinute)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3530 return slotTable.height();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3531 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3532 var slotMinutes = opt('slotMinutes'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3533 minutes = time.getHours()*60 + time.getMinutes() - minMinute,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3534 slotI = Math.floor(minutes / slotMinutes),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3535 slotTop = slotTopCache[slotI];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3536 if (slotTop === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3537 slotTop = slotTopCache[slotI] =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3538 slotTable.find('tr').eq(slotI).find('td div')[0].offsetTop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3539 // .eq() is faster than ":eq()" selector
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3540 // [0].offsetTop is faster than .position().top (do we really need this optimization?)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3541 // a better optimization would be to cache all these divs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3542 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3543 return Math.max(0, Math.round(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3544 slotTop - 1 + slotHeight * ((minutes % slotMinutes) / slotMinutes)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3545 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3546 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3547
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3548
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3549 function getAllDayRow(index) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3550 return allDayRow;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3551 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3552
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3553
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3554 function defaultEventEnd(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3555 var start = cloneDate(event.start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3556 if (event.allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3557 return start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3558 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3559 return addMinutes(start, opt('defaultEventMinutes'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3560 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3561
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3562
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3563
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3564 /* Selection
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3565 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3566
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3567
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3568 function defaultSelectionEnd(startDate, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3569 if (allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3570 return cloneDate(startDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3571 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3572 return addMinutes(cloneDate(startDate), opt('slotMinutes'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3573 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3574
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3575
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3576 function renderSelection(startDate, endDate, allDay) { // only for all-day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3577 if (allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3578 if (opt('allDaySlot')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3579 renderDayOverlay(startDate, addDays(cloneDate(endDate), 1), true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3580 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3581 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3582 renderSlotSelection(startDate, endDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3583 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3584 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3585
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3586
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3587 function renderSlotSelection(startDate, endDate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3588 var helperOption = opt('selectHelper');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3589 coordinateGrid.build();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3590 if (helperOption) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3591 var col = dateToCell(startDate).col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3592 if (col >= 0 && col < colCnt) { // only works when times are on same day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3593 var rect = coordinateGrid.rect(0, col, 0, col, slotContainer); // only for horizontal coords
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3594 var top = timePosition(startDate, startDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3595 var bottom = timePosition(startDate, endDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3596 if (bottom > top) { // protect against selections that are entirely before or after visible range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3597 rect.top = top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3598 rect.height = bottom - top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3599 rect.left += 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3600 rect.width -= 5;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3601 if ($.isFunction(helperOption)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3602 var helperRes = helperOption(startDate, endDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3603 if (helperRes) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3604 rect.position = 'absolute';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3605 selectionHelper = $(helperRes)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3606 .css(rect)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3607 .appendTo(slotContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3608 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3609 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3610 rect.isStart = true; // conside rect a "seg" now
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3611 rect.isEnd = true; //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3612 selectionHelper = $(slotSegHtml(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3613 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3614 title: '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3615 start: startDate,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3616 end: endDate,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3617 className: ['fc-select-helper'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3618 editable: false
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3619 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3620 rect
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3621 ));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3622 selectionHelper.css('opacity', opt('dragOpacity'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3623 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3624 if (selectionHelper) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3625 slotBind(selectionHelper);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3626 slotContainer.append(selectionHelper);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3627 setOuterWidth(selectionHelper, rect.width, true); // needs to be after appended
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3628 setOuterHeight(selectionHelper, rect.height, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3629 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3630 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3631 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3632 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3633 renderSlotOverlay(startDate, endDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3634 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3635 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3636
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3637
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3638 function clearSelection() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3639 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3640 if (selectionHelper) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3641 selectionHelper.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3642 selectionHelper = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3643 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3644 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3645
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3646
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3647 function slotSelectionMousedown(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3648 if (ev.which == 1 && opt('selectable')) { // ev.which==1 means left mouse button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3649 unselect(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3650 var dates, helperOption = opt('selectHelper');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3651 hoverListener.start(function(cell, origCell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3652 clearSelection();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3653 if (cell && (cell.col == origCell.col || !helperOption) && !getIsCellAllDay(cell)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3654 var d1 = realCellToDate(origCell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3655 var d2 = realCellToDate(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3656 dates = [
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3657 d1,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3658 addMinutes(cloneDate(d1), snapMinutes), // calculate minutes depending on selection slot minutes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3659 d2,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3660 addMinutes(cloneDate(d2), snapMinutes)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3661 ].sort(dateCompare);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3662 renderSlotSelection(dates[0], dates[3]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3663 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3664 dates = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3665 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3666 }, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3667 $(document).one('mouseup', function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3668 hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3669 if (dates) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3670 if (+dates[0] == +dates[1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3671 reportDayClick(dates[0], false, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3672 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3673 reportSelection(dates[0], dates[3], false, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3674 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3675 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3676 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3677 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3678
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3679
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3680 function reportDayClick(date, allDay, ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3681 trigger('dayClick', dayBodyCells[dateToCell(date).col], date, allDay, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3682 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3683
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3684
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3685
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3686 /* External Dragging
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3687 --------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3689
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3690 function dragStart(_dragElement, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3691 hoverListener.start(function(cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3692 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3693 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3694 if (getIsCellAllDay(cell)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3695 renderCellOverlay(cell.row, cell.col, cell.row, cell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3696 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3697 var d1 = realCellToDate(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3698 var d2 = addMinutes(cloneDate(d1), opt('defaultEventMinutes'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3699 renderSlotOverlay(d1, d2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3700 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3701 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3702 }, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3703 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3706 function dragStop(_dragElement, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3707 var cell = hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3708 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3709 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3710 trigger('drop', _dragElement, realCellToDate(cell), getIsCellAllDay(cell), ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3711 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3712 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3713
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3714
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3715 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3716
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3717 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3718
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3719 function AgendaEventRenderer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3720 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3721
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3722
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3723 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3724 t.renderEvents = renderEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3725 t.clearEvents = clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3726 t.slotSegHtml = slotSegHtml;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3727
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3728
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3729 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3730 DayEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3731 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3732 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3733 var isEventDraggable = t.isEventDraggable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3734 var isEventResizable = t.isEventResizable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3735 var eventEnd = t.eventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3736 var eventElementHandlers = t.eventElementHandlers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3737 var setHeight = t.setHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3738 var getDaySegmentContainer = t.getDaySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3739 var getSlotSegmentContainer = t.getSlotSegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3740 var getHoverListener = t.getHoverListener;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3741 var getMaxMinute = t.getMaxMinute;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3742 var getMinMinute = t.getMinMinute;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3743 var timePosition = t.timePosition;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3744 var getIsCellAllDay = t.getIsCellAllDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3745 var colContentLeft = t.colContentLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3746 var colContentRight = t.colContentRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3747 var cellToDate = t.cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3748 var getColCnt = t.getColCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3749 var getColWidth = t.getColWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3750 var getSnapHeight = t.getSnapHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3751 var getSnapMinutes = t.getSnapMinutes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3752 var getSlotContainer = t.getSlotContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3753 var reportEventElement = t.reportEventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3754 var showEvents = t.showEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3755 var hideEvents = t.hideEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3756 var eventDrop = t.eventDrop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3757 var eventResize = t.eventResize;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3758 var renderDayOverlay = t.renderDayOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3759 var clearOverlays = t.clearOverlays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3760 var renderDayEvents = t.renderDayEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3761 var calendar = t.calendar;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3762 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3763 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3764 var timeLineInterval;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3765
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3766
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3767 // overrides
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3768 t.draggableDayEvent = draggableDayEvent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3770
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3771 /* Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3772 ----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3773
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3774
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3775 function renderEvents(events, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3776 var i, len=events.length,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3777 dayEvents=[],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3778 slotEvents=[];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3779 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3780 if (events[i].allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3781 dayEvents.push(events[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3782 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3783 slotEvents.push(events[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3784 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3785 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3786
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3787 if (opt('allDaySlot')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3788 renderDayEvents(dayEvents, modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3789 setHeight(); // no params means set to viewHeight
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3790 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3791
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3792 renderSlotSegs(compileSlotSegs(slotEvents), modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3793
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3794 if (opt('currentTimeIndicator')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3795 window.clearInterval(timeLineInterval);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3796 timeLineInterval = window.setInterval(setTimeIndicator, 30000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3797 setTimeIndicator();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3798 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3799 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3800
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3801
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3802 function clearEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3803 getDaySegmentContainer().empty();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3804 getSlotSegmentContainer().empty();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3805 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3806
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3807
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3808 function compileSlotSegs(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3809 var colCnt = getColCnt(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3810 minMinute = getMinMinute(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3811 maxMinute = getMaxMinute(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3812 d,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3813 visEventEnds = $.map(events, slotEventEnd),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3814 i,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3815 j, seg,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3816 colSegs,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3817 segs = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3818
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3819 for (i=0; i<colCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3820
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3821 d = cellToDate(0, i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3822 addMinutes(d, minMinute);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3823
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3824 colSegs = sliceSegs(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3825 events,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3826 visEventEnds,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3827 d,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3828 addMinutes(cloneDate(d), maxMinute-minMinute)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3829 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3830
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3831 colSegs = placeSlotSegs(colSegs); // returns a new order
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3832
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3833 for (j=0; j<colSegs.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3834 seg = colSegs[j];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3835 seg.col = i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3836 segs.push(seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3837 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3838 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3839
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3840 return segs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3841 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3842
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3843
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3844 function sliceSegs(events, visEventEnds, start, end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3845 var segs = [],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3846 i, len=events.length, event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3847 eventStart, eventEnd,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3848 segStart, segEnd,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3849 isStart, isEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3850 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3851 event = events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3852 eventStart = event.start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3853 eventEnd = visEventEnds[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3854 if (eventEnd > start && eventStart < end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3855 if (eventStart < start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3856 segStart = cloneDate(start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3857 isStart = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3858 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3859 segStart = eventStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3860 isStart = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3861 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3862 if (eventEnd > end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3863 segEnd = cloneDate(end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3864 isEnd = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3865 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3866 segEnd = eventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3867 isEnd = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3868 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3869 segs.push({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3870 event: event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3871 start: segStart,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3872 end: segEnd,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3873 isStart: isStart,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3874 isEnd: isEnd
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3875 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3876 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3877 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3878 return segs.sort(compareSlotSegs);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3879 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3880
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3881
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3882 function slotEventEnd(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3883 if (event.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3884 return cloneDate(event.end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3885 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3886 return addMinutes(cloneDate(event.start), opt('defaultEventMinutes'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3887 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3888 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3889
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3890
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3891 // renders events in the 'time slots' at the bottom
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3892 // TODO: when we refactor this, when user returns `false` eventRender, don't have empty space
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3893 // TODO: refactor will include using pixels to detect collisions instead of dates (handy for seg cmp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3894
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3895 function renderSlotSegs(segs, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3896
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3897 var i, segCnt=segs.length, seg,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3898 event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3899 top,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3900 bottom,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3901 columnLeft,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3902 columnRight,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3903 columnWidth,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3904 width,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3905 left,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3906 right,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3907 html = '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3908 eventElements,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3909 eventElement,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3910 triggerRes,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3911 contentElement,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3912 height,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3913 slotSegmentContainer = getSlotSegmentContainer(),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3914 isRTL = opt('isRTL'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3915 colCnt = getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3916
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3917 // calculate position/dimensions, create html
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3918 for (i=0; i<segCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3919 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3920 event = seg.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3921 top = timePosition(seg.start, seg.start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3922 bottom = timePosition(seg.start, seg.end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3923 columnLeft = colContentLeft(seg.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3924 columnRight = colContentRight(seg.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3925 columnWidth = columnRight - columnLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3926
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3927 // shave off space on right near scrollbars (2.5%)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3928 // TODO: move this to CSS somehow
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3929 columnRight -= columnWidth * .025;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3930 columnWidth = columnRight - columnLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3931
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3932 width = columnWidth * (seg.forwardCoord - seg.backwardCoord);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3933
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3934 // bruederli@kolabsys.com: always disable slotEventOverlap in single day view
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3935 if (opt('slotEventOverlap') && colCnt > 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3936 // double the width while making sure resize handle is visible
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3937 // (assumed to be 20px wide)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3938 width = Math.max(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3939 (width - (20/2)) * 2,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3940 width // narrow columns will want to make the segment smaller than
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3941 // the natural width. don't allow it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3942 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3943 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3944
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3945 if (isRTL) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3946 right = columnRight - seg.backwardCoord * columnWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3947 left = right - width;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3948 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3949 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3950 left = columnLeft + seg.backwardCoord * columnWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3951 right = left + width;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3952 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3953
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3954 // make sure horizontal coordinates are in bounds
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3955 left = Math.max(left, columnLeft);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3956 right = Math.min(right, columnRight);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3957 width = right - left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3958
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3959 seg.top = top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3960 seg.left = left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3961 seg.outerWidth = width;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3962 seg.outerHeight = bottom - top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3963 html += slotSegHtml(event, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3964 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3965
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3966 slotSegmentContainer[0].innerHTML = html; // faster than html()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3967 eventElements = slotSegmentContainer.children();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3968
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3969 // retrieve elements, run through eventRender callback, bind event handlers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3970 for (i=0; i<segCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3971 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3972 event = seg.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3973 eventElement = $(eventElements[i]); // faster than eq()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3974 triggerRes = trigger('eventRender', event, event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3975 if (triggerRes === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3976 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3977 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3978 if (triggerRes && triggerRes !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3979 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3980 eventElement = $(triggerRes)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3981 .css({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3982 position: 'absolute',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3983 top: seg.top,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3984 left: seg.left
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3985 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3986 .appendTo(slotSegmentContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3987 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3988 seg.element = eventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3989 if (event._id === modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3990 bindSlotSeg(event, eventElement, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3991 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3992 eventElement[0]._fci = i; // for lazySegBind
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3993 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3994 reportEventElement(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3995 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3996 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3997
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3998 lazySegBind(slotSegmentContainer, segs, bindSlotSeg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3999
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4000 // record event sides and title positions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4001 for (i=0; i<segCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4002 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4003 if (eventElement = seg.element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4004 seg.vsides = vsides(eventElement, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4005 seg.hsides = hsides(eventElement, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4006 contentElement = eventElement.find('.fc-event-content');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4007 if (contentElement.length) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4008 seg.contentTop = contentElement[0].offsetTop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4009 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4010 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4011 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4012
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4013 // set all positions/dimensions at once
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4014 for (i=0; i<segCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4015 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4016 if (eventElement = seg.element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4017 eventElement[0].style.width = Math.max(0, seg.outerWidth - seg.hsides) + 'px';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4018 height = Math.max(0, seg.outerHeight - seg.vsides);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4019 eventElement[0].style.height = height + 'px';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4020 event = seg.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4021 if (seg.contentTop !== undefined && height - seg.contentTop < 10) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4022 // not enough room for title, put it in the time (TODO: maybe make both display:inline instead)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4023 eventElement.find('div.fc-event-time')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4024 .text(formatDate(event.start, opt('timeFormat')) + ' - ' + event.title);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4025 eventElement.find('div.fc-event-title')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4026 .remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4027 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4028 trigger('eventAfterRender', event, event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4029 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4030 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4031
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4032 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4033
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4034
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4035 function slotSegHtml(event, seg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4036 var html = "<";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4037 var url = event.url;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4038 var skinCss = getSkinCss(event, opt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4039 var skinCssAttr = (skinCss ? " style='" + skinCss + "'" : '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4040 var classes = ['fc-event', 'fc-event-skin', 'fc-event-vert'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4041 if (isEventDraggable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4042 classes.push('fc-event-draggable');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4043 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4044 if (seg.isStart) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4045 classes.push('fc-event-start');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4046 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4047 if (seg.isEnd) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4048 classes.push('fc-event-end');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4049 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4050 classes = classes.concat(event.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4051 if (event.source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4052 classes = classes.concat(event.source.className || []);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4053 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4054 if (url) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4055 html += "a href='" + htmlEscape(event.url) + "'";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4056 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4057 html += "div";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4058 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4059 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4060 " class='" + classes.join(' ') + "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4061 " style=" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4062 "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4063 "position:absolute;" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4064 "top:" + seg.top + "px;" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4065 "left:" + seg.left + "px;" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4066 skinCss +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4067 "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4068 " tabindex='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4069 "<div class='fc-event-inner fc-event-skin'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4070 "<div class='fc-event-head fc-event-skin'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4071 "<div class='fc-event-time'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4072 htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4073 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4074 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4075 "<div class='fc-event-content'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4076 "<div class='fc-event-title'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4077 htmlEscape(event.title || '') +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4078 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4079 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4080 "<div class='fc-event-bg'></div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4081 "</div>"; // close inner
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4082 if (seg.isEnd && isEventResizable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4083 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4084 "<div class='ui-resizable-handle ui-resizable-s' role='presentation'>=</div>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4085 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4086 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4087 "</" + (url ? "a" : "div") + ">";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4088 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4089 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4090
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4091
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4092 function bindSlotSeg(event, eventElement, seg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4093 var timeElement = eventElement.find('div.fc-event-time');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4094 if (isEventDraggable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4095 draggableSlotEvent(event, eventElement, timeElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4096 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4097 if (seg.isEnd && isEventResizable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4098 resizableSlotEvent(event, eventElement, timeElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4099 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4100 eventElementHandlers(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4101 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4102
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4104 // draw a horizontal line indicating the current time (#143)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4105 function setTimeIndicator()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4106 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4107 var container = getSlotContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4108 var timeline = container.children('.fc-timeline');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4109 if (timeline.length == 0) { // if timeline isn't there, add it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4110 timeline = $('<hr>').addClass('fc-timeline').appendTo(container);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4111 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4112
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4113 var cur_time = new Date();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4114 if (t.visStart < cur_time && t.visEnd > cur_time) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4115 timeline.show();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4116 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4117 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4118 timeline.hide();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4119 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4120 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4121
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4122 var secs = (cur_time.getHours() * 60 * 60) + (cur_time.getMinutes() * 60) + cur_time.getSeconds();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4123 var percents = secs / 86400; // 24 * 60 * 60 = 86400, # of seconds in a day
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4124
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4125 timeline.css('top', Math.floor(container.height() * percents - 1) + 'px');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4126
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4127 if (t.name == 'agendaWeek') { // week view, don't want the timeline to go the whole way across
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4128 var daycol = $('.fc-today', t.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4129 var left = daycol.position().left + 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4130 var width = daycol.width();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4131 timeline.css({ left: left + 'px', width: width + 'px' });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4132 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4133 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4134
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4135
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4136 /* Dragging
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4137 -----------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4138
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4139
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4140 // when event starts out FULL-DAY
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4141 // overrides DayEventRenderer's version because it needs to account for dragging elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4142 // to and from the slot area.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4143
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4144 function draggableDayEvent(event, eventElement, seg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4145 var isStart = seg.isStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4146 var origWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4147 var revert;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4148 var allDay = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4149 var dayDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4150 var hoverListener = getHoverListener();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4151 var colWidth = getColWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4152 var snapHeight = getSnapHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4153 var snapMinutes = getSnapMinutes();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4154 var minMinute = getMinMinute();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4155 eventElement.draggable({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4156 opacity: opt('dragOpacity', 'month'), // use whatever the month view was using
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4157 revertDuration: opt('dragRevertDuration'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4158 start: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4159 trigger('eventDragStart', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4160 hideEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4161 origWidth = eventElement.width();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4162 hoverListener.start(function(cell, origCell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4163 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4164 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4165 revert = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4166 var origDate = cellToDate(0, origCell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4167 var date = cellToDate(0, cell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4168 dayDelta = dayDiff(date, origDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4169 if (!cell.row) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4170 // on full-days
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4171 renderDayOverlay(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4172 addDays(cloneDate(event.start), dayDelta),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4173 addDays(exclEndDay(event), dayDelta)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4174 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4175 resetElement();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4176 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4177 // mouse is over bottom slots
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4178 if (isStart) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4179 if (allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4180 // convert event to temporary slot-event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4181 eventElement.width(colWidth - 10); // don't use entire width
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4182 setOuterHeight(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4183 eventElement,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4184 snapHeight * Math.round(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4185 (event.end ? ((event.end - event.start) / MINUTE_MS) : opt('defaultEventMinutes')) /
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4186 snapMinutes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4187 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4188 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4189 eventElement.draggable('option', 'grid', [colWidth, 1]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4190 allDay = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4191 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4192 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4193 revert = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4194 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4195 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4196 revert = revert || (allDay && !dayDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4197 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4198 resetElement();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4199 revert = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4200 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4201 eventElement.draggable('option', 'revert', revert);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4202 }, ev, 'drag');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4203 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4204 stop: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4205 hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4206 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4207 trigger('eventDragStop', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4208 if (revert) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4209 // hasn't moved or is out of bounds (draggable has already reverted)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4210 resetElement();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4211 eventElement.css('filter', ''); // clear IE opacity side-effects
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4212 showEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4213 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4214 // changed!
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4215 var minuteDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4216 if (!allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4217 minuteDelta = Math.round((eventElement.offset().top - getSlotContainer().offset().top) / snapHeight)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4218 * snapMinutes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4219 + minMinute
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4220 - (event.start.getHours() * 60 + event.start.getMinutes());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4221 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4222 eventDrop(this, event, dayDelta, minuteDelta, allDay, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4223 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4224 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4225 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4226 function resetElement() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4227 if (!allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4228 eventElement
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4229 .width(origWidth)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4230 .height('')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4231 .draggable('option', 'grid', null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4232 allDay = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4233 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4234 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4235 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4236
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4237
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4238 // when event starts out IN TIMESLOTS
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4239
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4240 function draggableSlotEvent(event, eventElement, timeElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4241 var coordinateGrid = t.getCoordinateGrid();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4242 var colCnt = getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4243 var colWidth = getColWidth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4244 var snapHeight = getSnapHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4245 var snapMinutes = getSnapMinutes();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4247 // states
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4248 var origPosition; // original position of the element, not the mouse
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4249 var origCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4250 var isInBounds, prevIsInBounds;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4251 var isAllDay, prevIsAllDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4252 var colDelta, prevColDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4253 var dayDelta; // derived from colDelta
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4254 var minuteDelta, prevMinuteDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4255
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4256 eventElement.draggable({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4257 scroll: false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4258 grid: [ colWidth, snapHeight ],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4259 axis: colCnt==1 ? 'y' : false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4260 opacity: opt('dragOpacity'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4261 revertDuration: opt('dragRevertDuration'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4262 start: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4263
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4264 trigger('eventDragStart', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4265 hideEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4266
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4267 coordinateGrid.build();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4268
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4269 // initialize states
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4270 origPosition = eventElement.position();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4271 origCell = coordinateGrid.cell(ev.pageX, ev.pageY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4272 isInBounds = prevIsInBounds = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4273 isAllDay = prevIsAllDay = getIsCellAllDay(origCell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4274 colDelta = prevColDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4275 dayDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4276 minuteDelta = prevMinuteDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4277
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4278 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4279 drag: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4280
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4281 // NOTE: this `cell` value is only useful for determining in-bounds and all-day.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4282 // Bad for anything else due to the discrepancy between the mouse position and the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4283 // element position while snapping. (problem revealed in PR #55)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4284 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4285 // PS- the problem exists for draggableDayEvent() when dragging an all-day event to a slot event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4286 // We should overhaul the dragging system and stop relying on jQuery UI.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4287 var cell = coordinateGrid.cell(ev.pageX, ev.pageY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4288
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4289 // update states
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4290 isInBounds = !!cell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4291 if (isInBounds) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4292 isAllDay = getIsCellAllDay(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4293
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4294 // calculate column delta
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4295 colDelta = Math.round((ui.position.left - origPosition.left) / colWidth);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4296 if (colDelta != prevColDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4297 // calculate the day delta based off of the original clicked column and the column delta
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4298 var origDate = cellToDate(0, origCell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4299 var col = origCell.col + colDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4300 col = Math.max(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4301 col = Math.min(colCnt-1, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4302 var date = cellToDate(0, col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4303 dayDelta = dayDiff(date, origDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4304 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4305
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4306 // calculate minute delta (only if over slots)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4307 if (!isAllDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4308 minuteDelta = Math.round((ui.position.top - origPosition.top) / snapHeight) * snapMinutes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4309 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4310 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4311
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4312 // any state changes?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4313 if (
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4314 isInBounds != prevIsInBounds ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4315 isAllDay != prevIsAllDay ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4316 colDelta != prevColDelta ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4317 minuteDelta != prevMinuteDelta
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4318 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4319
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4320 updateUI();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4321
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4322 // update previous states for next time
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4323 prevIsInBounds = isInBounds;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4324 prevIsAllDay = isAllDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4325 prevColDelta = colDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4326 prevMinuteDelta = minuteDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4327 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4328
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4329 // if out-of-bounds, revert when done, and vice versa.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4330 eventElement.draggable('option', 'revert', !isInBounds);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4331
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4332 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4333 stop: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4334
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4335 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4336 trigger('eventDragStop', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4337
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4338 if (isInBounds && (isAllDay || dayDelta || minuteDelta)) { // changed!
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4339 eventDrop(this, event, dayDelta, isAllDay ? 0 : minuteDelta, isAllDay, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4340 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4341 else { // either no change or out-of-bounds (draggable has already reverted)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4343 // reset states for next time, and for updateUI()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4344 isInBounds = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4345 isAllDay = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4346 colDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4347 dayDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4348 minuteDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4349
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4350 updateUI();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4351 eventElement.css('filter', ''); // clear IE opacity side-effects
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4353 // sometimes fast drags make event revert to wrong position, so reset.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4354 // also, if we dragged the element out of the area because of snapping,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4355 // but the *mouse* is still in bounds, we need to reset the position.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4356 eventElement.css(origPosition);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4358 showEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4359 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4360 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4361 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4362
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4363 function updateUI() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4364 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4365 if (isInBounds) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4366 if (isAllDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4367 timeElement.hide();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4368 eventElement.draggable('option', 'grid', null); // disable grid snapping
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4369 renderDayOverlay(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4370 addDays(cloneDate(event.start), dayDelta),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4371 addDays(exclEndDay(event), dayDelta)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4372 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4373 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4374 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4375 updateTimeText(minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4376 timeElement.css('display', ''); // show() was causing display=inline
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4377 eventElement.draggable('option', 'grid', [colWidth, snapHeight]); // re-enable grid snapping
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4378 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4379 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4380 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4381
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4382 function updateTimeText(minuteDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4383 var newStart = addMinutes(cloneDate(event.start), minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4384 var newEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4385 if (event.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4386 newEnd = addMinutes(cloneDate(event.end), minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4387 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4388 timeElement.text(formatDates(newStart, newEnd, opt('timeFormat')));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4389 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4390
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4391 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4392
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4393
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4394
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4395 /* Resizing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4396 --------------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4397
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4398
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4399 function resizableSlotEvent(event, eventElement, timeElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4400 var snapDelta, prevSnapDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4401 var snapHeight = getSnapHeight();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4402 var snapMinutes = getSnapMinutes();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4403 eventElement.resizable({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4404 handles: {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4405 s: '.ui-resizable-handle'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4406 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4407 grid: snapHeight,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4408 start: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4409 snapDelta = prevSnapDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4410 hideEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4411 trigger('eventResizeStart', this, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4412 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4413 resize: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4414 // don't rely on ui.size.height, doesn't take grid into account
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4415 snapDelta = Math.round((Math.max(snapHeight, eventElement.height()) - ui.originalSize.height) / snapHeight);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4416 if (snapDelta != prevSnapDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4417 timeElement.text(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4418 formatDates(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4419 event.start,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4420 (!snapDelta && !event.end) ? null : // no change, so don't display time range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4421 addMinutes(eventEnd(event), snapMinutes*snapDelta),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4422 opt('timeFormat')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4423 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4424 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4425 prevSnapDelta = snapDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4426 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4427 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4428 stop: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4429 trigger('eventResizeStop', this, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4430 if (snapDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4431 eventResize(this, event, 0, snapMinutes*snapDelta, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4432 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4433 showEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4434 // BUG: if event was really short, need to put title back in span
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4435 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4436 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4437 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4438 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4439
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4440
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4441 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4442
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4443
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4444
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4445 /* Agenda Event Segment Utilities
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4446 -----------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4447
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4448
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4449 // Sets the seg.backwardCoord and seg.forwardCoord on each segment and returns a new
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4450 // list in the order they should be placed into the DOM (an implicit z-index).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4451 function placeSlotSegs(segs) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4452 var levels = buildSlotSegLevels(segs);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4453 var level0 = levels[0];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4454 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4455
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4456 computeForwardSlotSegs(levels);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4457
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4458 if (level0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4459
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4460 for (i=0; i<level0.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4461 computeSlotSegPressures(level0[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4462 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4463
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4464 for (i=0; i<level0.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4465 computeSlotSegCoords(level0[i], 0, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4466 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4467 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4468
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4469 return flattenSlotSegLevels(levels);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4470 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4471
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4472
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4473 // Builds an array of segments "levels". The first level will be the leftmost tier of segments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4474 // if the calendar is left-to-right, or the rightmost if the calendar is right-to-left.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4475 function buildSlotSegLevels(segs) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4476 var levels = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4477 var i, seg;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4478 var j;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4479
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4480 for (i=0; i<segs.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4481 seg = segs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4482
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4483 // go through all the levels and stop on the first level where there are no collisions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4484 for (j=0; j<levels.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4485 if (!computeSlotSegCollisions(seg, levels[j]).length) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4486 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4487 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4488 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4489
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4490 (levels[j] || (levels[j] = [])).push(seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4491 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4492
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4493 return levels;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4494 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4495
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4496
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4497 // For every segment, figure out the other segments that are in subsequent
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4498 // levels that also occupy the same vertical space. Accumulate in seg.forwardSegs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4499 function computeForwardSlotSegs(levels) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4500 var i, level;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4501 var j, seg;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4502 var k;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4503
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4504 for (i=0; i<levels.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4505 level = levels[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4506
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4507 for (j=0; j<level.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4508 seg = level[j];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4509
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4510 seg.forwardSegs = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4511 for (k=i+1; k<levels.length; k++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4512 computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4513 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4514 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4515 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4516 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4517
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4518
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4519 // Figure out which path forward (via seg.forwardSegs) results in the longest path until
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4520 // the furthest edge is reached. The number of segments in this path will be seg.forwardPressure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4521 function computeSlotSegPressures(seg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4522 var forwardSegs = seg.forwardSegs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4523 var forwardPressure = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4524 var i, forwardSeg;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4525
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4526 if (seg.forwardPressure === undefined) { // not already computed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4528 for (i=0; i<forwardSegs.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4529 forwardSeg = forwardSegs[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4530
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4531 // figure out the child's maximum forward path
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4532 computeSlotSegPressures(forwardSeg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4533
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4534 // either use the existing maximum, or use the child's forward pressure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4535 // plus one (for the forwardSeg itself)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4536 forwardPressure = Math.max(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4537 forwardPressure,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4538 1 + forwardSeg.forwardPressure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4539 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4540 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4541
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4542 seg.forwardPressure = forwardPressure;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4543 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4544 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4545
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4546
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4547 // Calculate seg.forwardCoord and seg.backwardCoord for the segment, where both values range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4548 // from 0 to 1. If the calendar is left-to-right, the seg.backwardCoord maps to "left" and
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4549 // seg.forwardCoord maps to "right" (via percentage). Vice-versa if the calendar is right-to-left.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4550 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4551 // The segment might be part of a "series", which means consecutive segments with the same pressure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4552 // who's width is unknown until an edge has been hit. `seriesBackwardPressure` is the number of
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4553 // segments behind this one in the current series, and `seriesBackwardCoord` is the starting
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4554 // coordinate of the first segment in the series.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4555 function computeSlotSegCoords(seg, seriesBackwardPressure, seriesBackwardCoord) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4556 var forwardSegs = seg.forwardSegs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4557 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4558
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4559 if (seg.forwardCoord === undefined) { // not already computed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4560
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4561 if (!forwardSegs.length) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4562
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4563 // if there are no forward segments, this segment should butt up against the edge
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4564 seg.forwardCoord = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4565 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4566 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4567
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4568 // sort highest pressure first
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4569 forwardSegs.sort(compareForwardSlotSegs);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4570
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4571 // this segment's forwardCoord will be calculated from the backwardCoord of the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4572 // highest-pressure forward segment.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4573 computeSlotSegCoords(forwardSegs[0], seriesBackwardPressure + 1, seriesBackwardCoord);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4574 seg.forwardCoord = forwardSegs[0].backwardCoord;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4575 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4576
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4577 // calculate the backwardCoord from the forwardCoord. consider the series
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4578 seg.backwardCoord = seg.forwardCoord -
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4579 (seg.forwardCoord - seriesBackwardCoord) / // available width for series
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4580 (seriesBackwardPressure + 1); // # of segments in the series
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4581
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4582 // use this segment's coordinates to computed the coordinates of the less-pressurized
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4583 // forward segments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4584 for (i=0; i<forwardSegs.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4585 computeSlotSegCoords(forwardSegs[i], 0, seg.forwardCoord);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4586 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4587 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4588 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4589
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4590
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4591 // Outputs a flat array of segments, from lowest to highest level
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4592 function flattenSlotSegLevels(levels) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4593 var segs = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4594 var i, level;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4595 var j;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4596
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4597 for (i=0; i<levels.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4598 level = levels[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4599
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4600 for (j=0; j<level.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4601 segs.push(level[j]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4602 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4603 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4604
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4605 return segs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4606 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4607
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4608
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4609 // Find all the segments in `otherSegs` that vertically collide with `seg`.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4610 // Append into an optionally-supplied `results` array and return.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4611 function computeSlotSegCollisions(seg, otherSegs, results) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4612 results = results || [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4613
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4614 for (var i=0; i<otherSegs.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4615 if (isSlotSegCollision(seg, otherSegs[i])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4616 results.push(otherSegs[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4617 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4618 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4619
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4620 return results;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4621 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4622
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4623
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4624 // Do these segments occupy the same vertical space?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4625 function isSlotSegCollision(seg1, seg2) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4626 return seg1.end > seg2.start && seg1.start < seg2.end;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4627 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4628
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4629
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4630 // A cmp function for determining which forward segment to rely on more when computing coordinates.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4631 function compareForwardSlotSegs(seg1, seg2) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4632 // put higher-pressure first
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4633 return seg2.forwardPressure - seg1.forwardPressure ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4634 // put segments that are closer to initial edge first (and favor ones with no coords yet)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4635 (seg1.backwardCoord || 0) - (seg2.backwardCoord || 0) ||
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4636 // do normal sorting...
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4637 compareSlotSegs(seg1, seg2);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4638 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4639
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4640
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4641 // A cmp function for determining which segment should be closer to the initial edge
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4642 // (the left edge on a left-to-right calendar).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4643 function compareSlotSegs(seg1, seg2) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4644 return seg1.start - seg2.start || // earlier start time goes first
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4645 (seg2.end - seg2.start) - (seg1.end - seg1.start) || // tie? longer-duration goes first
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4646 (seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4647 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4648
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4649
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4650 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4651
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4652 /* Additional view: list (by bruederli@kolabsys.com)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4653 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4654
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4655 fcViews.list = ListView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4656
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4657
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4658 function ListView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4659 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4660
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4661 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4662 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4663 t.select = dummy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4664 t.unselect = dummy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4665 t.reportSelection = dummy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4666 t.getDaySegmentContainer = function(){ return body; };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4667
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4668 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4669 View.call(t, element, calendar, 'list');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4670 ListEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4671 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4672 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4673 var clearEvents = t.clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4674 var reportEventClear = t.reportEventClear;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4675 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4676 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4677
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4678 // overrides
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4679 t.setWidth = setWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4680 t.setHeight = setHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4681
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4682 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4683 var body;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4684 var firstDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4685 var nwe;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4686 var tm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4687 var colFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4688
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4689
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4690 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4691 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4692 addDays(date, opt('listPage') * delta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4693 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4694 t.start = t.visStart = cloneDate(date, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4695 t.end = addDays(cloneDate(t.start), opt('listPage'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4696 t.visEnd = addDays(cloneDate(t.start), opt('listRange'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4697 addMinutes(t.visEnd, -1); // set end to 23:59
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4698 t.title = formatDates(date, t.visEnd, opt('titleFormat'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4699
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4700 updateOptions();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4701
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4702 if (!body) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4703 buildSkeleton();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4704 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4705 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4706 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4707 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4708
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4710 function updateOptions() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4711 firstDay = opt('firstDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4712 nwe = opt('weekends') ? 0 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4713 tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4714 colFormat = opt('columnFormat', 'day');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4715 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4716
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4717
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4718 function buildSkeleton() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4719 body = $('<div>').addClass('fc-list-content').appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4720 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4721
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4722 function setHeight(height, dateChanged) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4723 if (!opt('listNoHeight'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4724 body.css('height', (height-1)+'px').css('overflow', 'auto');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4725 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4726
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4727 function setWidth(width) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4728 // nothing to be done here
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4729 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4730
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4731 function dummy() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4732 // Stub.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4733 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4734
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4735 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4736
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4737 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4738
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4739 /* Additional view renderer: list (by bruederli@kolabsys.com)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4740 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4741
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4742 function ListEventRenderer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4743 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4744
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4745 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4746 t.renderEvents = renderEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4747 t.renderEventTime = renderEventTime;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4748 t.compileDaySegs = compileSegs; // for DayEventRenderer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4749 t.clearEvents = clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4750 t.lazySegBind = lazySegBind;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4751 t.sortCmp = sortCmp;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4752
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4753 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4754 DayEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4755 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4756 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4757 var reportEventElement = t.reportEventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4758 var eventElementHandlers = t.eventElementHandlers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4759 var showEvents = t.showEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4760 var hideEvents = t.hideEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4761 var getListContainer = t.getDaySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4762 var calendar = t.calendar;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4763 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4764 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4765
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4766
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4767 /* Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4768 --------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4770 function clearEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4771 getListContainer().empty();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4772 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4773
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4774 function renderEvents(events, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4775 events.sort(sortCmp);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4776 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4777 renderSegs(compileSegs(events), modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4778 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4779
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4780 function compileSegs(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4781 var segs = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4782 var colFormat = opt('titleFormat', 'day');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4783 var firstDay = opt('firstDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4784 var segmode = opt('listSections');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4785 var event, i, dd, wd, md, seg, segHash, curSegHash, segDate, curSeg = -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4786 var today = clearTime(new Date());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4787 var weekstart = addDays(cloneDate(today), -((today.getDay() - firstDay + 7) % 7));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4788
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4789 for (i=0; i < events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4790 event = events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4791
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4792 // skip events out of range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4793 if ((event.end || event.start) < t.start || event.start > t.visEnd)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4794 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4795
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4796 // define sections of this event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4797 // create smart sections such as today, tomorrow, this week, next week, next month, ect.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4798 segDate = cloneDate(event.start < t.start && event.end > t.start ? t.start : event.start, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4799 dd = dayDiff(segDate, today);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4800 wd = Math.floor(dayDiff(segDate, weekstart) / 7);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4801 md = segDate.getMonth() + ((segDate.getYear() - today.getYear()) * 12) - today.getMonth();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4802
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4803 // build section title
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4804 if (segmode == 'smart') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4805 if (dd < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4806 segHash = opt('listTexts', 'past');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4807 } else if (dd == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4808 segHash = opt('listTexts', 'today');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4809 } else if (dd == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4810 segHash = opt('listTexts', 'tomorrow');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4811 } else if (wd == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4812 segHash = opt('listTexts', 'thisWeek');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4813 } else if (wd == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4814 segHash = opt('listTexts', 'nextWeek');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4815 } else if (md == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4816 segHash = opt('listTexts', 'thisMonth');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4817 } else if (md == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4818 segHash = opt('listTexts', 'nextMonth');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4819 } else if (md > 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4820 segHash = opt('listTexts', 'future');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4821 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4822 } else if (segmode == 'month') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4823 segHash = formatDate(segDate, 'MMMM yyyy');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4824 } else if (segmode == 'week') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4825 segHash = opt('listTexts', 'week') + formatDate(segDate, ' W');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4826 } else if (segmode == 'day') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4827 segHash = formatDate(segDate, colFormat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4828 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4829 segHash = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4830 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4831
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4832 // start new segment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4833 if (segHash != curSegHash) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4834 segs[++curSeg] = { events: [], start: segDate, title: segHash, daydiff: dd, weekdiff: wd, monthdiff: md };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4835 curSegHash = segHash;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4836 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4837
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4838 segs[curSeg].events.push(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4839 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4840
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4841 return segs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4842 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4843
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4844 function sortCmp(a, b) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4845 var sd = a.start.getTime() - b.start.getTime();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4846 return sd || (a.end ? a.end.getTime() : 0) - (b.end ? b.end.getTime() : 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4847 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4848
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4849 function renderSegs(segs, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4850 var tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4851 var headerClass = tm + "-widget-header";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4852 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4853 var i, j, seg, event, times, s, skinCss, skinCssAttr, classes, segContainer, eventElement, eventElements, triggerRes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4854
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4855 for (j=0; j < segs.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4856 seg = segs[j];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4857
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4858 if (seg.title) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4859 $('<div class="fc-list-header ' + headerClass + '">' + htmlEscape(seg.title) + '</div>').appendTo(getListContainer());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4860 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4861 segContainer = $('<div>').addClass('fc-list-section ' + contentClass).appendTo(getListContainer());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4862 s = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4863
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4864 for (i=0; i < seg.events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4865 event = seg.events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4866 times = renderEventTime(event, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4867 skinCss = getSkinCss(event, opt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4868 skinCssAttr = (skinCss ? " style='" + skinCss + "'" : '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4869 classes = ['fc-event', 'fc-event-skin', 'fc-event-vert', 'fc-corner-top', 'fc-corner-bottom'].concat(event.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4870 if (event.source && event.source.className) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4871 classes = classes.concat(event.source.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4872 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4873
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4874 s +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4875 "<div class='" + classes.join(' ') + "'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4876 "<div class='fc-event-inner fc-event-skin'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4877 "<div class='fc-event-head fc-event-skin'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4878 "<div class='fc-event-time'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4879 (times[0] ? '<span class="fc-col-date">' + times[0] + '</span> ' : '') +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4880 (times[1] ? '<span class="fc-col-time">' + times[1] + '</span>' : '') +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4881 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4882 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4883 "<div class='fc-event-content'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4884 "<div class='fc-event-title'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4885 htmlEscape(event.title) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4886 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4887 "</div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4888 "<div class='fc-event-bg'></div>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4889 "</div>" + // close inner
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4890 "</div>"; // close outer
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4891 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4892
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4893 segContainer[0].innerHTML = s;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4894 eventElements = segContainer.children();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4895
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4896 // retrieve elements, run through eventRender callback, bind event handlers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4897 for (i=0; i < seg.events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4898 event = seg.events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4899 eventElement = $(eventElements[i]); // faster than eq()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4900 triggerRes = trigger('eventRender', event, event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4901 if (triggerRes === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4902 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4903 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4904 if (triggerRes && triggerRes !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4905 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4906 eventElement = $(triggerRes).appendTo(segContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4907 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4908 if (event._id === modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4909 eventElementHandlers(event, eventElement, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4910 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4911 eventElement[0]._fci = i; // for lazySegBind
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4912 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4913 reportEventElement(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4914 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4915 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4916
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4917 lazySegBind(segContainer, seg, eventElementHandlers);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4918 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4919
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4920 markFirstLast(getListContainer());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4921 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4922
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4923 // event time/date range to display
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4924 function renderEventTime(event, seg) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4925 var timeFormat = opt('timeFormat');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4926 var dateFormat = opt('columnFormat');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4927 var segmode = opt('listSections');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4928 var duration = event.end ? event.end.getTime() - event.start.getTime() : 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4929 var datestr = '', timestr = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4930
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4931 if (segmode == 'smart') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4932 if (event.start < seg.start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4933 datestr = opt('listTexts', 'until') + ' ' + formatDate(event.end, (event.allDay || event.end.getDate() != seg.start.getDate()) ? dateFormat : timeFormat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4934 } else if (duration > DAY_MS) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4935 datestr = formatDates(event.start, event.end, dateFormat + '{ - ' + dateFormat + '}');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4936 } else if (seg.daydiff == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4937 datestr = opt('listTexts', 'today');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4938 } else if (seg.daydiff == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4939 datestr = opt('listTexts', 'tomorrow');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4940 } else if (seg.weekdiff == 0 || seg.weekdiff == 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4941 datestr = formatDate(event.start, 'dddd');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4942 } else if (seg.daydiff > 1 || seg.daydiff < 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4943 datestr = formatDate(event.start, dateFormat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4944 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4945 } else if (segmode != 'day') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4946 datestr = formatDates(event.start, event.end, dateFormat + (duration > DAY_MS ? '{ - ' + dateFormat + '}' : ''));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4947 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4948
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4949 if (!datestr && event.allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4950 timestr = opt('allDayText');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4951 } else if ((duration < DAY_MS || !datestr) && !event.allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4952 timestr = formatDates(event.start, event.end, timeFormat);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4953 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4954
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4955 return [datestr, timestr];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4956 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4957
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4958 function lazySegBind(container, seg, bindHandlers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4959 container.unbind('mouseover focusin').bind('mouseover focusin', function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4960 var parent = ev.target, e = parent, i, event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4961 while (parent != this) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4962 e = parent;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4963 parent = parent.parentNode;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4964 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4965 if ((i = e._fci) !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4966 e._fci = undefined;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4967 event = seg.events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4968 bindHandlers(event, container.children().eq(i), seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4969 $(ev.target).trigger(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4970 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4971 ev.stopPropagation();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4972 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4973 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4974
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4975 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4976
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4977
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4978 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4979
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4980 /* Additional view: table (by bruederli@kolabsys.com)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4981 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4982
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4983 fcViews.table = TableView;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4984
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4985
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4986 function TableView(element, calendar) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4987 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4988
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4989 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4990 t.render = render;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4991 t.select = dummy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4992 t.unselect = dummy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4993 t.getDaySegmentContainer = function(){ return table; };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4994
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4995 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4996 View.call(t, element, calendar, 'table');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4997 TableEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4998 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4999 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5000 var clearEvents = t.clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5001 var reportEventClear = t.reportEventClear;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5002 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5003 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5004
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5005 // overrides
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5006 t.setWidth = setWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5007 t.setHeight = setHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5008
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5009 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5010 var div;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5011 var table;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5012 var firstDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5013 var nwe;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5014 var tm;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5015 var colFormat;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5016
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5017
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5018 function render(date, delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5019 if (delta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5020 addDays(date, opt('listPage') * delta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5021 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5022 t.start = t.visStart = cloneDate(date, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5023 t.end = addDays(cloneDate(t.start), opt('listPage'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5024 t.visEnd = addDays(cloneDate(t.start), opt('listRange'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5025 addMinutes(t.visEnd, -1); // set end to 23:59
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5026 t.title = (t.visEnd.getTime() - t.visStart.getTime() < DAY_MS) ? formatDate(date, opt('titleFormat')) : formatDates(date, t.visEnd, opt('titleFormat'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5027
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5028 updateOptions();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5029
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5030 if (!table) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5031 buildSkeleton();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5032 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5033 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5034 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5035 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5036
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5037
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5038 function updateOptions() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5039 firstDay = opt('firstDay');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5040 nwe = opt('weekends') ? 0 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5041 tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5042 colFormat = opt('columnFormat');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5043 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5044
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5045
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5046 function buildSkeleton() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5047 var tableCols = opt('tableCols');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5048 var s =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5049 "<table class='fc-border-separate' style='width:100%' cellspacing='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5050 "<colgroup>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5051 for (var c=0; c < tableCols.length; c++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5052 s += "<col class='fc-event-" + tableCols[c] + "' />";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5053 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5054 s += "</colgroup>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5055 "</table>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5056 div = $('<div>').addClass('fc-list-content').appendTo(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5057 table = $(s).appendTo(div);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5058 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5059
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5060 function setHeight(height, dateChanged) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5061 if (!opt('listNoHeight'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5062 div.css('height', (height-1)+'px').css('overflow', 'auto');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5063 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5064
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5065 function setWidth(width) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5066 // nothing to be done here
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5067 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5068
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5069 function dummy() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5070 // Stub.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5071 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5072
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5073 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5074
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5075 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5076
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5077 /* Additional view renderer: table (by bruederli@kolabsys.com)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5078 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5079
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5080 function TableEventRenderer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5081 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5082
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5083 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5084 ListEventRenderer.call(t);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5085 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5086 var sortCmp = t.sortCmp;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5087 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5088 var compileSegs = t.compileDaySegs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5089 var reportEventElement = t.reportEventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5090 var eventElementHandlers = t.eventElementHandlers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5091 var renderEventTime = t.renderEventTime;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5092 var showEvents = t.showEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5093 var hideEvents = t.hideEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5094 var getListContainer = t.getDaySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5095 var lazySegBind = t.lazySegBind;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5096 var calendar = t.calendar;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5097 var formatDate = calendar.formatDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5098 var formatDates = calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5099
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5100 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5101 t.renderEvents = renderEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5102 t.clearEvents = clearEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5103
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5104
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5105 /* Rendering
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5106 --------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5107
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5108 function clearEvents() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5109 getListContainer().children('tbody').remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5110 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5111
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5112 function renderEvents(events, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5113 events.sort(sortCmp);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5114 clearEvents();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5115 renderSegs(compileSegs(events), modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5116 getListContainer().removeClass('fc-list-smart fc-list-day fc-list-month fc-list-week').addClass('fc-list-' + opt('listSections'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5117 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5118
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5119 function renderSegs(segs, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5120 var tm = opt('theme') ? 'ui' : 'fc';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5121 var table = getListContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5122 var headerClass = tm + "-widget-header";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5123 var contentClass = tm + "-widget-content";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5124 var tableCols = opt('tableCols');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5125 var timecol = $.inArray('time', tableCols) >= 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5126 var i, j, seg, event, times, s, skinCss, skinCssAttr, skinClasses, rowClasses, segContainer, eventElements, eventElement, triggerRes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5127
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5128 for (j=0; j < segs.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5129 seg = segs[j];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5130
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5131 if (seg.title) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5132 $('<tbody class="fc-list-header"><tr><td class="fc-list-header ' + headerClass + '" colspan="' + tableCols.length + '">' + htmlEscape(seg.title) + '</td></tr></tbody>').appendTo(table);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5133 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5134 segContainer = $('<tbody>').addClass('fc-list-section ' + contentClass).appendTo(table);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5135 s = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5136
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5137 for (i=0; i < seg.events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5138 event = seg.events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5139 times = renderEventTime(event, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5140 skinCss = getSkinCss(event, opt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5141 skinCssAttr = (skinCss ? " style='" + skinCss + "'" : '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5142 skinClasses = ['fc-event-skin', 'fc-corner-left', 'fc-corner-right', 'fc-corner-top', 'fc-corner-bottom'].concat(event.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5143 if (event.source && event.source.className) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5144 skinClasses = skinClasses.concat(event.source.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5145 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5146 rowClasses = ['fc-event', 'fc-event-row', 'fc-'+dayIDs[event.start.getDay()]].concat(event.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5147 if (seg.daydiff == 0) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5148 rowClasses.push('fc-today');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5149 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5150
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5151 s += "<tr class='" + rowClasses.join(' ') + "' tabindex='0'>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5152 for (var col, c=0; c < tableCols.length; c++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5153 col = tableCols[c];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5154 if (col == 'handle') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5155 s += "<td class='fc-event-handle'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5156 "<div class='" + skinClasses.join(' ') + "'" + skinCssAttr + ">" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5157 "<span class='fc-event-inner'></span>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5158 "</div></td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5159 } else if (col == 'date') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5160 s += "<td class='fc-event-date' colspan='" + (times[1] || !timecol ? 1 : 2) + "'>" + htmlEscape(times[0]) + "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5161 } else if (col == 'time') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5162 if (times[1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5163 s += "<td class='fc-event-time'>" + htmlEscape(times[1]) + "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5164 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5165 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5166 s += "<td class='fc-event-" + col + "'>" + (event[col] ? htmlEscape(event[col]) : '&nbsp;') + "</td>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5167 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5168 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5169 s += "</tr>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5170
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5171 // IE doesn't like innerHTML on tbody elements so we insert every row individually
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5172 if (document.all) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5173 $(s).appendTo(segContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5174 s = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5175 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5176 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5177
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5178 if (!document.all)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5179 segContainer[0].innerHTML = s;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5180
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5181 eventElements = segContainer.children();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5182
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5183 // retrieve elements, run through eventRender callback, bind event handlers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5184 for (i=0; i < seg.events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5185 event = seg.events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5186 eventElement = $(eventElements[i]); // faster than eq()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5187 triggerRes = trigger('eventRender', event, event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5188 if (triggerRes === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5189 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5190 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5191 if (triggerRes && triggerRes !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5192 eventElement.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5193 eventElement = $(triggerRes).appendTo(segContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5194 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5195 if (event._id === modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5196 eventElementHandlers(event, eventElement, seg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5197 } else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5198 eventElement[0]._fci = i; // for lazySegBind
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5199 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5200 reportEventElement(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5201 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5202 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5203
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5204 lazySegBind(segContainer, seg, eventElementHandlers);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5205 markFirstLast(segContainer);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5206 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5207
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5208 //markFirstLast(table);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5209 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5210
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5211 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5212 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5213
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5214
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5215 function View(element, calendar, viewName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5216 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5217
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5218
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5219 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5220 t.element = element;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5221 t.calendar = calendar;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5222 t.name = viewName;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5223 t.opt = opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5224 t.trigger = trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5225 t.isEventDraggable = isEventDraggable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5226 t.isEventResizable = isEventResizable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5227 t.setEventData = setEventData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5228 t.clearEventData = clearEventData;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5229 t.eventEnd = eventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5230 t.reportEventElement = reportEventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5231 t.triggerEventDestroy = triggerEventDestroy;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5232 t.eventElementHandlers = eventElementHandlers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5233 t.showEvents = showEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5234 t.hideEvents = hideEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5235 t.eventDrop = eventDrop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5236 t.eventResize = eventResize;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5237 // t.title
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5238 // t.start, t.end
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5239 // t.visStart, t.visEnd
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5240
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5241
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5242 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5243 var defaultEventEnd = t.defaultEventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5244 var normalizeEvent = calendar.normalizeEvent; // in EventManager
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5245 var reportEventChange = calendar.reportEventChange;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5246
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5247
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5248 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5249 var eventsByID = {}; // eventID mapped to array of events (there can be multiple b/c of repeating events)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5250 var eventElementsByID = {}; // eventID mapped to array of jQuery elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5251 var eventElementCouples = []; // array of objects, { event, element } // TODO: unify with segment system
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5252 var options = calendar.options;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5253
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5254
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5255
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5256 function opt(name, viewNameOverride) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5257 var v = options[name];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5258 if ($.isPlainObject(v)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5259 return smartProperty(v, viewNameOverride || viewName);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5260 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5261 return v;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5262 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5263
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5264
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5265 function trigger(name, thisObj) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5266 return calendar.trigger.apply(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5267 calendar,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5268 [name, thisObj || t].concat(Array.prototype.slice.call(arguments, 2), [t])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5269 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5270 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5271
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5272
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5273
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5274 /* Event Editable Boolean Calculations
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5275 ------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5276
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5277
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5278 function isEventDraggable(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5279 var source = event.source || {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5280 return firstDefined(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5281 event.startEditable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5282 source.startEditable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5283 opt('eventStartEditable'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5284 event.editable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5285 source.editable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5286 opt('editable')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5287 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5288 && !opt('disableDragging'); // deprecated
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5289 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5290
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5291
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5292 function isEventResizable(event) { // but also need to make sure the seg.isEnd == true
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5293 var source = event.source || {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5294 return firstDefined(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5295 event.durationEditable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5296 source.durationEditable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5297 opt('eventDurationEditable'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5298 event.editable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5299 source.editable,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5300 opt('editable')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5301 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5302 && !opt('disableResizing'); // deprecated
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5303 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5304
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5305
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5306
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5307 /* Event Data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5308 ------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5309
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5310
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5311 function setEventData(events) { // events are already normalized at this point
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5312 eventsByID = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5313 var i, len=events.length, event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5314 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5315 event = events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5316 if (eventsByID[event._id]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5317 eventsByID[event._id].push(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5318 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5319 eventsByID[event._id] = [event];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5320 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5321 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5322 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5323
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5324
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5325 function clearEventData() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5326 eventsByID = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5327 eventElementsByID = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5328 eventElementCouples = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5329 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5330
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5331
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5332 // returns a Date object for an event's end
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5333 function eventEnd(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5334 return event.end ? cloneDate(event.end) : defaultEventEnd(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5335 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5336
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5337
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5338
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5339 /* Event Elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5340 ------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5341
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5343 // report when view creates an element for an event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5344 function reportEventElement(event, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5345 eventElementCouples.push({ event: event, element: element });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5346 if (eventElementsByID[event._id]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5347 eventElementsByID[event._id].push(element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5348 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5349 eventElementsByID[event._id] = [element];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5350 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5351 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5352
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5353
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5354 function triggerEventDestroy() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5355 $.each(eventElementCouples, function(i, couple) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5356 t.trigger('eventDestroy', couple.event, couple.event, couple.element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5357 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5358 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5359
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5360
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5361 // attaches eventClick, eventMouseover, eventMouseout
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5362 function eventElementHandlers(event, eventElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5363 eventElement
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5364 .click(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5365 if (!eventElement.hasClass('ui-draggable-dragging') &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5366 !eventElement.hasClass('ui-resizable-resizing')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5367 return trigger('eventClick', this, event, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5368 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5369 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5370 .hover(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5371 function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5372 trigger('eventMouseover', this, event, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5373 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5374 function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5375 trigger('eventMouseout', this, event, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5376 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5377 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5378 .keypress(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5379 if (ev.keyCode == 13)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5380 $(this).trigger('click', { pointerType:'keyboard' });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5381 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5382 // TODO: don't fire eventMouseover/eventMouseout *while* dragging is occuring (on subject element)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5383 // TODO: same for resizing
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5384 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5385
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5386
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5387 function showEvents(event, exceptElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5388 eachEventElement(event, exceptElement, 'show');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5389 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5390
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5391
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5392 function hideEvents(event, exceptElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5393 eachEventElement(event, exceptElement, 'hide');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5394 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5395
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5396
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5397 function eachEventElement(event, exceptElement, funcName) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5398 // NOTE: there may be multiple events per ID (repeating events)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5399 // and multiple segments per event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5400 var elements = eventElementsByID[event._id],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5401 i, len = elements.length;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5402 for (i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5403 if (!exceptElement || elements[i][0] != exceptElement[0]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5404 elements[i][funcName]();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5405 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5406 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5407 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5408
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5409
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5410
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5411 /* Event Modification Reporting
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5412 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5413
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5414
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5415 function eventDrop(e, event, dayDelta, minuteDelta, allDay, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5416 var oldAllDay = event.allDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5417 var eventId = event._id;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5418 moveEvents(eventsByID[eventId], dayDelta, minuteDelta, allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5419 trigger(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5420 'eventDrop',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5421 e,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5422 event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5423 dayDelta,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5424 minuteDelta,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5425 allDay,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5426 function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5427 // TODO: investigate cases where this inverse technique might not work
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5428 moveEvents(eventsByID[eventId], -dayDelta, -minuteDelta, oldAllDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5429 reportEventChange(eventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5430 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5431 ev,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5432 ui
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5433 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5434 reportEventChange(eventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5435 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5436
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5437
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5438 function eventResize(e, event, dayDelta, minuteDelta, ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5439 var eventId = event._id;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5440 elongateEvents(eventsByID[eventId], dayDelta, minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5441 trigger(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5442 'eventResize',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5443 e,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5444 event,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5445 dayDelta,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5446 minuteDelta,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5447 function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5448 // TODO: investigate cases where this inverse technique might not work
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5449 elongateEvents(eventsByID[eventId], -dayDelta, -minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5450 reportEventChange(eventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5451 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5452 ev,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5453 ui
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5454 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5455 reportEventChange(eventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5456 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5457
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5458
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5459
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5460 /* Event Modification Math
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5461 ---------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5462
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5463
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5464 function moveEvents(events, dayDelta, minuteDelta, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5465 minuteDelta = minuteDelta || 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5466 for (var e, len=events.length, i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5467 e = events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5468 if (allDay !== undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5469 e.allDay = allDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5470 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5471 addMinutes(addDays(e.start, dayDelta, true), minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5472 if (e.end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5473 e.end = addMinutes(addDays(e.end, dayDelta, true), minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5474 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5475 normalizeEvent(e, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5476 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5477 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5478
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5479
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5480 function elongateEvents(events, dayDelta, minuteDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5481 minuteDelta = minuteDelta || 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5482 for (var e, len=events.length, i=0; i<len; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5483 e = events[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5484 e.end = addMinutes(addDays(eventEnd(e), dayDelta, true), minuteDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5485 normalizeEvent(e, options);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5486 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5487 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5488
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5489
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5490
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5491 // ====================================================================================================
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5492 // Utilities for day "cells"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5493 // ====================================================================================================
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5494 // The "basic" views are completely made up of day cells.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5495 // The "agenda" views have day cells at the top "all day" slot.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5496 // This was the obvious common place to put these utilities, but they should be abstracted out into
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5497 // a more meaningful class (like DayEventRenderer).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5498 // ====================================================================================================
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5499
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5500
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5501 // For determining how a given "cell" translates into a "date":
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5502 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5503 // 1. Convert the "cell" (row and column) into a "cell offset" (the # of the cell, cronologically from the first).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5504 // Keep in mind that column indices are inverted with isRTL. This is taken into account.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5505 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5506 // 2. Convert the "cell offset" to a "day offset" (the # of days since the first visible day in the view).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5507 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5508 // 3. Convert the "day offset" into a "date" (a JavaScript Date object).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5509 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5510 // The reverse transformation happens when transforming a date into a cell.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5511
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5512
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5513 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5514 t.isHiddenDay = isHiddenDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5515 t.skipHiddenDays = skipHiddenDays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5516 t.getCellsPerWeek = getCellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5517 t.dateToCell = dateToCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5518 t.dateToDayOffset = dateToDayOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5519 t.dayOffsetToCellOffset = dayOffsetToCellOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5520 t.cellOffsetToCell = cellOffsetToCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5521 t.cellToDate = cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5522 t.cellToCellOffset = cellToCellOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5523 t.cellOffsetToDayOffset = cellOffsetToDayOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5524 t.dayOffsetToDate = dayOffsetToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5525 t.rangeToSegments = rangeToSegments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5526
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5528 // internals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5529 var hiddenDays = opt('hiddenDays') || []; // array of day-of-week indices that are hidden
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5530 var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5531 var cellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5532 var dayToCellMap = []; // hash from dayIndex -> cellIndex, for one week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5533 var cellToDayMap = []; // hash from cellIndex -> dayIndex, for one week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5534 var isRTL = opt('isRTL');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5535
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5536
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5537 // initialize important internal variables
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5538 (function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5539
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5540 if (opt('weekends') === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5541 hiddenDays.push(0, 6); // 0=sunday, 6=saturday
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5542 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5543
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5544 // Loop through a hypothetical week and determine which
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5545 // days-of-week are hidden. Record in both hashes (one is the reverse of the other).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5546 for (var dayIndex=0, cellIndex=0; dayIndex<7; dayIndex++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5547 dayToCellMap[dayIndex] = cellIndex;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5548 isHiddenDayHash[dayIndex] = $.inArray(dayIndex, hiddenDays) != -1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5549 if (!isHiddenDayHash[dayIndex]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5550 cellToDayMap[cellIndex] = dayIndex;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5551 cellIndex++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5552 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5553 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5554
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5555 cellsPerWeek = cellIndex;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5556 if (!cellsPerWeek) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5557 throw 'invalid hiddenDays'; // all days were hidden? bad.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5558 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5559
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5560 })();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5561
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5562
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5563 // Is the current day hidden?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5564 // `day` is a day-of-week index (0-6), or a Date object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5565 function isHiddenDay(day) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5566 if (typeof day == 'object') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5567 day = day.getDay();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5568 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5569 return isHiddenDayHash[day];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5570 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5571
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5572
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5573 function getCellsPerWeek() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5574 return cellsPerWeek;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5575 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5576
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5577
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5578 // Keep incrementing the current day until it is no longer a hidden day.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5579 // If the initial value of `date` is not a hidden day, don't do anything.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5580 // Pass `isExclusive` as `true` if you are dealing with an end date.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5581 // `inc` defaults to `1` (increment one day forward each time)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5582 function skipHiddenDays(date, inc, isExclusive) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5583 inc = inc || 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5584 while (
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5585 isHiddenDayHash[ ( date.getDay() + (isExclusive ? inc : 0) + 7 ) % 7 ]
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5586 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5587 addDays(date, inc);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5588 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5589 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5590
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5591
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5592 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5593 // TRANSFORMATIONS: cell -> cell offset -> day offset -> date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5594 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5595
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5596 // cell -> date (combines all transformations)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5597 // Possible arguments:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5598 // - row, col
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5599 // - { row:#, col: # }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5600 function cellToDate() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5601 var cellOffset = cellToCellOffset.apply(null, arguments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5602 var dayOffset = cellOffsetToDayOffset(cellOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5603 var date = dayOffsetToDate(dayOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5604 return date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5605 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5606
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5607 // cell -> cell offset
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5608 // Possible arguments:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5609 // - row, col
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5610 // - { row:#, col:# }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5611 function cellToCellOffset(row, col) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5612 var colCnt = t.getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5613
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5614 // rtl variables. wish we could pre-populate these. but where?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5615 var dis = isRTL ? -1 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5616 var dit = isRTL ? colCnt - 1 : 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5617
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5618 if (typeof row == 'object') {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5619 col = row.col;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5620 row = row.row;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5621 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5622 var cellOffset = row * colCnt + (col * dis + dit); // column, adjusted for RTL (dis & dit)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5623
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5624 return cellOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5625 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5626
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5627 // cell offset -> day offset
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5628 function cellOffsetToDayOffset(cellOffset) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5629 var day0 = t.visStart.getDay(); // first date's day of week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5630 cellOffset += dayToCellMap[day0]; // normlize cellOffset to beginning-of-week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5631 return Math.floor(cellOffset / cellsPerWeek) * 7 // # of days from full weeks
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5632 + cellToDayMap[ // # of days from partial last week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5633 (cellOffset % cellsPerWeek + cellsPerWeek) % cellsPerWeek // crazy math to handle negative cellOffsets
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5634 ]
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5635 - day0; // adjustment for beginning-of-week normalization
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5636 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5637
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5638 // day offset -> date (JavaScript Date object)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5639 function dayOffsetToDate(dayOffset) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5640 var date = cloneDate(t.visStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5641 addDays(date, dayOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5642 return date;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5643 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5644
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5645
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5646 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5647 // TRANSFORMATIONS: date -> day offset -> cell offset -> cell
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5648 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5649
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5650 // date -> cell (combines all transformations)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5651 function dateToCell(date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5652 var dayOffset = dateToDayOffset(date);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5653 var cellOffset = dayOffsetToCellOffset(dayOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5654 var cell = cellOffsetToCell(cellOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5655 return cell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5656 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5657
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5658 // date -> day offset
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5659 function dateToDayOffset(date) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5660 return dayDiff(date, t.visStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5661 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5662
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5663 // day offset -> cell offset
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5664 function dayOffsetToCellOffset(dayOffset) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5665 var day0 = t.visStart.getDay(); // first date's day of week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5666 dayOffset += day0; // normalize dayOffset to beginning-of-week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5667 return Math.floor(dayOffset / 7) * cellsPerWeek // # of cells from full weeks
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5668 + dayToCellMap[ // # of cells from partial last week
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5669 (dayOffset % 7 + 7) % 7 // crazy math to handle negative dayOffsets
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5670 ]
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5671 - dayToCellMap[day0]; // adjustment for beginning-of-week normalization
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5672 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5673
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5674 // cell offset -> cell (object with row & col keys)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5675 function cellOffsetToCell(cellOffset) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5676 var colCnt = t.getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5677
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5678 // rtl variables. wish we could pre-populate these. but where?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5679 var dis = isRTL ? -1 : 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5680 var dit = isRTL ? colCnt - 1 : 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5681
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5682 var row = Math.floor(cellOffset / colCnt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5683 var col = ((cellOffset % colCnt + colCnt) % colCnt) * dis + dit; // column, adjusted for RTL (dis & dit)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5684 return {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5685 row: row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5686 col: col
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5687 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5688 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5689
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5690
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5691 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5692 // Converts a date range into an array of segment objects.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5693 // "Segments" are horizontal stretches of time, sliced up by row.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5694 // A segment object has the following properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5695 // - row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5696 // - cols
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5697 // - isStart
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5698 // - isEnd
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5699 //
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5700 function rangeToSegments(startDate, endDate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5701 var rowCnt = t.getRowCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5702 var colCnt = t.getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5703 var segments = []; // array of segments to return
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5704
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5705 // day offset for given date range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5706 var rangeDayOffsetStart = dateToDayOffset(startDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5707 var rangeDayOffsetEnd = dateToDayOffset(endDate); // exclusive
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5708
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5709 // first and last cell offset for the given date range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5710 // "last" implies inclusivity
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5711 var rangeCellOffsetFirst = dayOffsetToCellOffset(rangeDayOffsetStart);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5712 var rangeCellOffsetLast = dayOffsetToCellOffset(rangeDayOffsetEnd) - 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5713
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5714 // loop through all the rows in the view
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5715 for (var row=0; row<rowCnt; row++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5716
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5717 // first and last cell offset for the row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5718 var rowCellOffsetFirst = row * colCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5719 var rowCellOffsetLast = rowCellOffsetFirst + colCnt - 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5720
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5721 // get the segment's cell offsets by constraining the range's cell offsets to the bounds of the row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5722 var segmentCellOffsetFirst = Math.max(rangeCellOffsetFirst, rowCellOffsetFirst);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5723 var segmentCellOffsetLast = Math.min(rangeCellOffsetLast, rowCellOffsetLast);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5724
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5725 // make sure segment's offsets are valid and in view
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5726 if (segmentCellOffsetFirst <= segmentCellOffsetLast) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5727
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5728 // translate to cells
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5729 var segmentCellFirst = cellOffsetToCell(segmentCellOffsetFirst);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5730 var segmentCellLast = cellOffsetToCell(segmentCellOffsetLast);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5731
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5732 // view might be RTL, so order by leftmost column
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5733 var cols = [ segmentCellFirst.col, segmentCellLast.col ].sort();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5734
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5735 // Determine if segment's first/last cell is the beginning/end of the date range.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5736 // We need to compare "day offset" because "cell offsets" are often ambiguous and
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5737 // can translate to multiple days, and an edge case reveals itself when we the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5738 // range's first cell is hidden (we don't want isStart to be true).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5739 var isStart = cellOffsetToDayOffset(segmentCellOffsetFirst) == rangeDayOffsetStart;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5740 var isEnd = cellOffsetToDayOffset(segmentCellOffsetLast) + 1 == rangeDayOffsetEnd; // +1 for comparing exclusively
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5741
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5742 segments.push({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5743 row: row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5744 leftCol: cols[0],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5745 rightCol: cols[1],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5746 isStart: isStart,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5747 isEnd: isEnd
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5748 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5749 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5750 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5751
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5752 return segments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5753 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5754
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5755
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5756 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5757
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5758 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5759
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5760 function DayEventRenderer() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5761 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5762
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5763
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5764 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5765 t.renderDayEvents = renderDayEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5766 t.draggableDayEvent = draggableDayEvent; // made public so that subclasses can override
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5767 t.resizableDayEvent = resizableDayEvent; // "
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5768
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5769
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5770 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5771 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5772 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5773 var isEventDraggable = t.isEventDraggable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5774 var isEventResizable = t.isEventResizable;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5775 var eventEnd = t.eventEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5776 var reportEventElement = t.reportEventElement;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5777 var eventElementHandlers = t.eventElementHandlers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5778 var showEvents = t.showEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5779 var hideEvents = t.hideEvents;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5780 var eventDrop = t.eventDrop;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5781 var eventResize = t.eventResize;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5782 var getRowCnt = t.getRowCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5783 var getColCnt = t.getColCnt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5784 var getColWidth = t.getColWidth;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5785 var allDayRow = t.allDayRow; // TODO: rename
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5786 var colLeft = t.colLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5787 var colRight = t.colRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5788 var colContentLeft = t.colContentLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5789 var colContentRight = t.colContentRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5790 var dateToCell = t.dateToCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5791 var getDaySegmentContainer = t.getDaySegmentContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5792 var formatDates = t.calendar.formatDates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5793 var renderDayOverlay = t.renderDayOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5794 var clearOverlays = t.clearOverlays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5795 var clearSelection = t.clearSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5796 var getHoverListener = t.getHoverListener;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5797 var rangeToSegments = t.rangeToSegments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5798 var cellToDate = t.cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5799 var cellToCellOffset = t.cellToCellOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5800 var cellOffsetToDayOffset = t.cellOffsetToDayOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5801 var dateToDayOffset = t.dateToDayOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5802 var dayOffsetToCellOffset = t.dayOffsetToCellOffset;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5803
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5804
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5805 // Render `events` onto the calendar, attach mouse event handlers, and call the `eventAfterRender` callback for each.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5806 // Mouse event will be lazily applied, except if the event has an ID of `modifiedEventId`.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5807 // Can only be called when the event container is empty (because it wipes out all innerHTML).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5808 function renderDayEvents(events, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5809
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5810 // do the actual rendering. Receive the intermediate "segment" data structures.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5811 var segments = _renderDayEvents(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5812 events,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5813 false, // don't append event elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5814 true // set the heights of the rows
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5815 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5816
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5817 // report the elements to the View, for general drag/resize utilities
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5818 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5819 reportEventElement(segment.event, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5820 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5821
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5822 // attach mouse handlers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5823 attachHandlers(segments, modifiedEventId);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5824
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5825 // call `eventAfterRender` callback for each event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5826 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5827 trigger('eventAfterRender', segment.event, segment.event, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5828 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5829 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5830
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5831
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5832 // Render an event on the calendar, but don't report them anywhere, and don't attach mouse handlers.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5833 // Append this event element to the event container, which might already be populated with events.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5834 // If an event's segment will have row equal to `adjustRow`, then explicitly set its top coordinate to `adjustTop`.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5835 // This hack is used to maintain continuity when user is manually resizing an event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5836 // Returns an array of DOM elements for the event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5837 function renderTempDayEvent(event, adjustRow, adjustTop) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5838
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5839 // actually render the event. `true` for appending element to container.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5840 // Recieve the intermediate "segment" data structures.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5841 var segments = _renderDayEvents(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5842 [ event ],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5843 true, // append event elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5844 false // don't set the heights of the rows
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5845 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5846
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5847 var elements = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5848
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5849 // Adjust certain elements' top coordinates
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5850 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5851 if (segment.row === adjustRow) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5852 element.css('top', adjustTop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5853 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5854 elements.push(element[0]); // accumulate DOM nodes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5855 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5856
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5857 return elements;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5858 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5859
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5860
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5861 // Render events onto the calendar. Only responsible for the VISUAL aspect.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5862 // Not responsible for attaching handlers or calling callbacks.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5863 // Set `doAppend` to `true` for rendering elements without clearing the existing container.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5864 // Set `doRowHeights` to allow setting the height of each row, to compensate for vertical event overflow.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5865 function _renderDayEvents(events, doAppend, doRowHeights) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5866
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5867 // where the DOM nodes will eventually end up
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5868 var finalContainer = getDaySegmentContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5869
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5870 // the container where the initial HTML will be rendered.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5871 // If `doAppend`==true, uses a temporary container.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5872 var renderContainer = doAppend ? $("<div/>") : finalContainer;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5873
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5874 var segments = buildSegments(events);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5875 var html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5876 var elements;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5877
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5878 // calculate the desired `left` and `width` properties on each segment object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5879 calculateHorizontals(segments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5880
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5881 // build the HTML string. relies on `left` property
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5882 html = buildHTML(segments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5883
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5884 // render the HTML. innerHTML is considerably faster than jQuery's .html()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5885 renderContainer[0].innerHTML = html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5886
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5887 // retrieve the individual elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5888 elements = renderContainer.children();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5889
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5890 // if we were appending, and thus using a temporary container,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5891 // re-attach elements to the real container.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5892 if (doAppend) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5893 finalContainer.append(elements);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5894 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5895
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5896 // assigns each element to `segment.event`, after filtering them through user callbacks
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5897 resolveElements(segments, elements);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5898
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5899 // Calculate the left and right padding+margin for each element.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5900 // We need this for setting each element's desired outer width, because of the W3C box model.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5901 // It's important we do this in a separate pass from acually setting the width on the DOM elements
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5902 // because alternating reading/writing dimensions causes reflow for every iteration.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5903 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5904 segment.hsides = hsides(element, true); // include margins = `true`
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5905 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5906
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5907 // Set the width of each element
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5908 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5909 element.width(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5910 Math.max(0, segment.outerWidth - segment.hsides)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5911 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5912 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5913
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5914 // Grab each element's outerHeight (setVerticals uses this).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5915 // To get an accurate reading, it's important to have each element's width explicitly set already.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5916 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5917 segment.outerHeight = element.outerHeight(true); // include margins = `true`
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5918 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5919
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5920 // Set the top coordinate on each element (requires segment.outerHeight)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5921 setVerticals(segments, doRowHeights);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5922
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5923 return segments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5924 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5925
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5926
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5927 // Generate an array of "segments" for all events.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5928 function buildSegments(events) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5929 var segments = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5930 for (var i=0; i<events.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5931 var eventSegments = buildSegmentsForEvent(events[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5932 segments.push.apply(segments, eventSegments); // append an array to an array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5933 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5934 return segments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5935 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5936
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5937
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5938 // Generate an array of segments for a single event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5939 // A "segment" is the same data structure that View.rangeToSegments produces,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5940 // with the addition of the `event` property being set to reference the original event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5941 function buildSegmentsForEvent(event) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5942 var startDate = event.start;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5943 var endDate = exclEndDay(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5944 var segments = rangeToSegments(startDate, endDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5945 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5946 segments[i].event = event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5947 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5948 return segments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5949 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5950
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5951
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5952 // Sets the `left` and `outerWidth` property of each segment.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5953 // These values are the desired dimensions for the eventual DOM elements.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5954 function calculateHorizontals(segments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5955 var isRTL = opt('isRTL');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5956 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5957 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5958
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5959 // Determine functions used for calulating the elements left/right coordinates,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5960 // depending on whether the view is RTL or not.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5961 // NOTE:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5962 // colLeft/colRight returns the coordinate butting up the edge of the cell.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5963 // colContentLeft/colContentRight is indented a little bit from the edge.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5964 var leftFunc = (isRTL ? segment.isEnd : segment.isStart) ? colContentLeft : colLeft;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5965 var rightFunc = (isRTL ? segment.isStart : segment.isEnd) ? colContentRight : colRight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5966
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5967 var left = leftFunc(segment.leftCol);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5968 var right = rightFunc(segment.rightCol);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5969 segment.left = left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5970 segment.outerWidth = right - left;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5971 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5972 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5973
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5974
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5975 // Build a concatenated HTML string for an array of segments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5976 function buildHTML(segments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5977 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5978 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5979 html += buildHTMLForSegment(segments[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5980 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5981 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5982 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5983
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5984
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5985 // Build an HTML string for a single segment.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5986 // Relies on the following properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5987 // - `segment.event` (from `buildSegmentsForEvent`)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5988 // - `segment.left` (from `calculateHorizontals`)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5989 function buildHTMLForSegment(segment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5990 var html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5991 var isRTL = opt('isRTL');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5992 var event = segment.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5993 var url = event.url;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5994
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5995 // generate the list of CSS classNames
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5996 var classNames = [ 'fc-event', 'fc-event-skin', 'fc-event-hori' ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5997 if (isEventDraggable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5998 classNames.push('fc-event-draggable');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5999 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6000 if (segment.isStart) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6001 classNames.push('fc-event-start');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6002 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6003 if (segment.isEnd) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6004 classNames.push('fc-event-end');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6005 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6006 // use the event's configured classNames
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6007 // guaranteed to be an array via `normalizeEvent`
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6008 classNames = classNames.concat(event.className);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6009 if (event.source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6010 // use the event's source's classNames, if specified
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6011 classNames = classNames.concat(event.source.className || []);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6012 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6013
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6014 // generate a semicolon delimited CSS string for any of the "skin" properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6015 // of the event object (`backgroundColor`, `borderColor` and such)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6016 var skinCss = getSkinCss(event, opt);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6017
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6018 if (url) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6019 html += "<a href='" + htmlEscape(url) + "'";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6020 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6021 html += "<div";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6022 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6023 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6024 " class='" + classNames.join(' ') + "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6025 " style=" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6026 "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6027 "position:absolute;" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6028 "left:" + segment.left + "px;" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6029 skinCss +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6030 "'" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6031 " tabindex='0'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6032 "<div class='fc-event-inner'>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6033 if (!event.allDay && segment.isStart) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6034 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6035 "<span class='fc-event-time'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6036 htmlEscape(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6037 formatDates(event.start, event.end, opt('timeFormat'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6038 ) +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6039 "</span>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6040 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6041 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6042 "<span class='fc-event-title'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6043 htmlEscape(event.title || '') +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6044 "</span>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6045 "</div>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6046 if (segment.isEnd && isEventResizable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6047 html +=
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6048 "<div class='ui-resizable-handle ui-resizable-" + (isRTL ? 'w' : 'e') + "'>" +
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6049 "&nbsp;&nbsp;&nbsp;" + // makes hit area a lot better for IE6/7
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6050 "</div>";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6051 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6052 html += "</" + (url ? "a" : "div") + ">";
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6053
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6054 // TODO:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6055 // When these elements are initially rendered, they will be briefly visibile on the screen,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6056 // even though their widths/heights are not set.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6057 // SOLUTION: initially set them as visibility:hidden ?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6058
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6059 return html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6060 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6061
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6062
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6063 // Associate each segment (an object) with an element (a jQuery object),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6064 // by setting each `segment.element`.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6065 // Run each element through the `eventRender` filter, which allows developers to
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6066 // modify an existing element, supply a new one, or cancel rendering.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6067 function resolveElements(segments, elements) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6068 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6069 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6070 var event = segment.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6071 var element = elements.eq(i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6072
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6073 // call the trigger with the original element
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6074 var triggerRes = trigger('eventRender', event, event, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6075
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6076 if (triggerRes === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6077 // if `false`, remove the event from the DOM and don't assign it to `segment.event`
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6078 element.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6079 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6080 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6081 if (triggerRes && triggerRes !== true) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6082 // the trigger returned a new element, but not `true` (which means keep the existing element)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6083
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6084 // re-assign the important CSS dimension properties that were already assigned in `buildHTMLForSegment`
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6085 triggerRes = $(triggerRes)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6086 .css({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6087 position: 'absolute',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6088 left: segment.left
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6089 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6090
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6091 element.replaceWith(triggerRes);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6092 element = triggerRes;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6093 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6094
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6095 segment.element = element;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6096 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6097 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6098 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6099
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6100
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6101
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6102 /* Top-coordinate Methods
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6103 -------------------------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6104
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6105
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6106 // Sets the "top" CSS property for each element.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6107 // If `doRowHeights` is `true`, also sets each row's first cell to an explicit height,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6108 // so that if elements vertically overflow, the cell expands vertically to compensate.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6109 function setVerticals(segments, doRowHeights) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6110 var overflowLinks = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6111 var rowContentHeights = calculateVerticals(segments, overflowLinks); // also sets segment.top
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6112 var rowContentElements = getRowContentElements(); // returns 1 inner div per row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6113 var rowContentTops = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6114
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6115 // Set each row's height by setting height of first inner div
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6116 if (doRowHeights) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6117 for (var i=0; i<rowContentElements.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6118 rowContentElements[i].height(rowContentHeights[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6119 if (overflowLinks[i])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6120 renderOverflowLinks(overflowLinks[i], rowContentElements[i]);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6121 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6122 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6123
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6124 // Get each row's top, relative to the views's origin.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6125 // Important to do this after setting each row's height.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6126 for (var i=0; i<rowContentElements.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6127 rowContentTops.push(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6128 rowContentElements[i].position().top
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6129 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6130 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6131
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6132 // Set each segment element's CSS "top" property.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6133 // Each segment object has a "top" property, which is relative to the row's top, but...
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6134 segmentElementEach(segments, function(segment, element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6135 if (!segment.overflow) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6136 element.css(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6137 'top',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6138 rowContentTops[segment.row] + segment.top // ...now, relative to views's origin
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6139 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6140 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6141 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6142 element.hide();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6143 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6144 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6145 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6146
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6147
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6148 // Calculate the "top" coordinate for each segment, relative to the "top" of the row.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6149 // Also, return an array that contains the "content" height for each row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6150 // (the height displaced by the vertically stacked events in the row).
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6151 // Requires segments to have their `outerHeight` property already set.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6152 function calculateVerticals(segments, overflowLinks) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6153 var rowCnt = getRowCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6154 var colCnt = getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6155 var rowContentHeights = []; // content height for each row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6156 var segmentRows = buildSegmentRows(segments); // an array of segment arrays, one for each row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6157 var maxHeight = opt('maxHeight');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6158 var top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6159
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6160 for (var rowI=0; rowI<rowCnt; rowI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6161 var segmentRow = segmentRows[rowI];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6162
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6163 // an array of running total heights for each column.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6164 // initialize with all zeros.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6165 overflowLinks[rowI] = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6166 var colHeights = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6167 var overflows = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6168 for (var colI=0; colI<colCnt; colI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6169 colHeights.push(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6170 overflows.push(0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6171 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6172
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6173 // loop through every segment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6174 for (var segmentI=0; segmentI<segmentRow.length; segmentI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6175 var segment = segmentRow[segmentI];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6176
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6177 // find the segment's top coordinate by looking at the max height
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6178 // of all the columns the segment will be in.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6179 top = arrayMax(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6180 colHeights.slice(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6181 segment.leftCol,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6182 segment.rightCol + 1 // make exclusive for slice
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6183 )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6184 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6185
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6186 if (maxHeight && top + segment.outerHeight > maxHeight) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6187 segment.overflow = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6188 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6189 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6190 segment.top = top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6191 top += segment.outerHeight;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6192 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6193
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6194 // adjust the columns to account for the segment's height
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6195 for (var colI=segment.leftCol; colI<=segment.rightCol; colI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6196 if (overflows[colI]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6197 segment.overflow = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6198 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6199 if (segment.overflow) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6200 if (segment.isStart && !overflowLinks[rowI][colI])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6201 overflowLinks[rowI][colI] = { seg:segment, top:top, date:cloneDate(segment.event.start, true), count:0 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6202 if (overflowLinks[rowI][colI])
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6203 overflowLinks[rowI][colI].count++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6204 overflows[colI]++;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6205 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6206 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6207 colHeights[colI] = top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6208 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6209 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6210 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6211
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6212 // the tallest column in the row should be the "content height"
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6213 rowContentHeights.push(arrayMax(colHeights));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6214 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6215
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6216 return rowContentHeights;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6217 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6218
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6219
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6220 // Build an array of segment arrays, each representing the segments that will
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6221 // be in a row of the grid, sorted by which event should be closest to the top.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6222 function buildSegmentRows(segments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6223 var rowCnt = getRowCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6224 var segmentRows = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6225 var segmentI;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6226 var segment;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6227 var rowI;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6228
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6229 // group segments by row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6230 for (segmentI=0; segmentI<segments.length; segmentI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6231 segment = segments[segmentI];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6232 rowI = segment.row;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6233 if (segment.element) { // was rendered?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6234 if (segmentRows[rowI]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6235 // already other segments. append to array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6236 segmentRows[rowI].push(segment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6237 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6238 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6239 // first segment in row. create new array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6240 segmentRows[rowI] = [ segment ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6241 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6242 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6243 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6244
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6245 // sort each row
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6246 for (rowI=0; rowI<rowCnt; rowI++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6247 segmentRows[rowI] = sortSegmentRow(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6248 segmentRows[rowI] || [] // guarantee an array, even if no segments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6249 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6250 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6251
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6252 return segmentRows;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6253 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6254
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6255
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6256 // Sort an array of segments according to which segment should appear closest to the top
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6257 function sortSegmentRow(segments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6258 var sortedSegments = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6259
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6260 // build the subrow array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6261 var subrows = buildSegmentSubrows(segments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6262
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6263 // flatten it
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6264 for (var i=0; i<subrows.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6265 sortedSegments.push.apply(sortedSegments, subrows[i]); // append an array to an array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6266 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6267
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6268 return sortedSegments;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6269 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6270
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6271
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6272 // Take an array of segments, which are all assumed to be in the same row,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6273 // and sort into subrows.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6274 function buildSegmentSubrows(segments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6275
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6276 // Give preference to elements with certain criteria, so they have
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6277 // a chance to be closer to the top.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6278 segments.sort(compareDaySegments);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6279
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6280 var subrows = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6281 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6282 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6283
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6284 // loop through subrows, starting with the topmost, until the segment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6285 // doesn't collide with other segments.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6286 for (var j=0; j<subrows.length; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6287 if (!isDaySegmentCollision(segment, subrows[j])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6288 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6289 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6290 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6291 // `j` now holds the desired subrow index
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6292 if (subrows[j]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6293 subrows[j].push(segment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6294 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6295 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6296 subrows[j] = [ segment ];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6297 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6298 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6299
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6300 return subrows;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6301 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6302
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6303
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6304 // Return an array of jQuery objects for the placeholder content containers of each row.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6305 // The content containers don't actually contain anything, but their dimensions should match
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6306 // the events that are overlaid on top.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6307 function getRowContentElements() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6308 var i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6309 var rowCnt = getRowCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6310 var rowDivs = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6311 for (i=0; i<rowCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6312 rowDivs[i] = allDayRow(i)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6313 .find('div.fc-day-content > div');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6314 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6315 return rowDivs;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6316 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6317
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6318
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6319 function renderOverflowLinks(overflowLinks, rowDiv) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6320 var container = getDaySegmentContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6321 var colCnt = getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6322 var element, triggerRes, link;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6323 for (var j=0; j<colCnt; j++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6324 if ((link = overflowLinks[j])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6325 if (link.count > 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6326 element = $('<a>').addClass('fc-more-link').html('+'+link.count).appendTo(container);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6327 element[0].style.position = 'absolute';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6328 element[0].style.left = link.seg.left + 'px';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6329 element[0].style.top = (link.top + rowDiv[0].offsetTop) + 'px';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6330 triggerRes = trigger('overflowRender', link, { count:link.count, date:link.date }, element);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6331 if (triggerRes === false)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6332 element.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6333 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6334 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6335 link.seg.top = link.top;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6336 link.seg.overflow = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6337 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6338 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6339 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6340 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6341
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6342
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6343 /* Mouse Handlers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6344 ---------------------------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6345 // TODO: better documentation!
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6346
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6347
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6348 function attachHandlers(segments, modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6349 var segmentContainer = getDaySegmentContainer();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6350
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6351 segmentElementEach(segments, function(segment, element, i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6352 var event = segment.event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6353 if (event._id === modifiedEventId) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6354 bindDaySeg(event, element, segment);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6355 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6356 element[0]._fci = i; // for lazySegBind
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6357 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6358 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6359
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6360 lazySegBind(segmentContainer, segments, bindDaySeg);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6361 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6362
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6363
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6364 function bindDaySeg(event, eventElement, segment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6365
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6366 if (isEventDraggable(event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6367 t.draggableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6368 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6369
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6370 if (
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6371 segment.isEnd && // only allow resizing on the final segment for an event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6372 isEventResizable(event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6373 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6374 t.resizableDayEvent(event, eventElement, segment); // use `t` so subclasses can override
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6375 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6376
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6377 // attach all other handlers.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6378 // needs to be after, because resizableDayEvent might stopImmediatePropagation on click
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6379 eventElementHandlers(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6380 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6381
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6382
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6383 function draggableDayEvent(event, eventElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6384 var hoverListener = getHoverListener();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6385 var dayDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6386 eventElement.draggable({
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6387 delay: 50,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6388 opacity: opt('dragOpacity'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6389 revertDuration: opt('dragRevertDuration'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6390 start: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6391 trigger('eventDragStart', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6392 hideEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6393 hoverListener.start(function(cell, origCell, rowDelta, colDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6394 eventElement.draggable('option', 'revert', !cell || !rowDelta && !colDelta);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6395 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6396 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6397 var origDate = cellToDate(origCell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6398 var date = cellToDate(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6399 dayDelta = dayDiff(date, origDate);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6400 renderDayOverlay(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6401 addDays(cloneDate(event.start), dayDelta),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6402 addDays(exclEndDay(event), dayDelta)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6403 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6404 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6405 dayDelta = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6406 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6407 }, ev, 'drag');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6408 },
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6409 stop: function(ev, ui) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6410 hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6411 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6412 trigger('eventDragStop', eventElement, event, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6413 if (dayDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6414 eventDrop(this, event, dayDelta, 0, event.allDay, ev, ui);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6415 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6416 eventElement.css('filter', ''); // clear IE opacity side-effects
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6417 showEvents(event, eventElement);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6418 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6419 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6420 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6421 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6422
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6423
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6424 function resizableDayEvent(event, element, segment) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6425 var isRTL = opt('isRTL');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6426 var direction = isRTL ? 'w' : 'e';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6427 var handle = element.find('.ui-resizable-' + direction); // TODO: stop using this class because we aren't using jqui for this
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6428 var isResizing = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6429
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6430 // TODO: look into using jquery-ui mouse widget for this stuff
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6431 disableTextSelection(element); // prevent native <a> selection for IE
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6432 element
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6433 .mousedown(function(ev) { // prevent native <a> selection for others
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6434 ev.preventDefault();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6435 })
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6436 .click(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6437 if (isResizing) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6438 ev.preventDefault(); // prevent link from being visited (only method that worked in IE6)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6439 ev.stopImmediatePropagation(); // prevent fullcalendar eventClick handler from being called
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6440 // (eventElementHandlers needs to be bound after resizableDayEvent)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6441 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6442 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6443
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6444 handle.mousedown(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6445 if (ev.which != 1) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6446 return; // needs to be left mouse button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6447 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6448 isResizing = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6449 var hoverListener = getHoverListener();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6450 var rowCnt = getRowCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6451 var colCnt = getColCnt();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6452 var elementTop = element.css('top');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6453 var dayDelta;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6454 var helpers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6455 var eventCopy = $.extend({}, event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6456 var minCellOffset = dayOffsetToCellOffset( dateToDayOffset(event.start) );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6457 clearSelection();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6458 $('body')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6459 .css('cursor', direction + '-resize')
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6460 .one('mouseup', mouseup);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6461 trigger('eventResizeStart', this, event, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6462 hoverListener.start(function(cell, origCell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6463 if (cell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6464
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6465 var origCellOffset = cellToCellOffset(origCell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6466 var cellOffset = cellToCellOffset(cell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6467
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6468 // don't let resizing move earlier than start date cell
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6469 cellOffset = Math.max(cellOffset, minCellOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6470
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6471 dayDelta =
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6472 cellOffsetToDayOffset(cellOffset) -
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6473 cellOffsetToDayOffset(origCellOffset);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6474
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6475 if (dayDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6476 eventCopy.end = addDays(eventEnd(event), dayDelta, true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6477 var oldHelpers = helpers;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6478
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6479 helpers = renderTempDayEvent(eventCopy, segment.row, elementTop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6480 helpers = $(helpers); // turn array into a jQuery object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6481
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6482 helpers.find('*').css('cursor', direction + '-resize');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6483 if (oldHelpers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6484 oldHelpers.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6485 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6486
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6487 hideEvents(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6488 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6489 else {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6490 if (helpers) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6491 showEvents(event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6492 helpers.remove();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6493 helpers = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6494 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6495 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6496 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6497 renderDayOverlay( // coordinate grid already rebuilt with hoverListener.start()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6498 event.start,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6499 addDays( exclEndDay(event), dayDelta )
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6500 // TODO: instead of calling renderDayOverlay() with dates,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6501 // call _renderDayOverlay (or whatever) with cell offsets.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6502 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6503 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6504 }, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6505
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6506 function mouseup(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6507 trigger('eventResizeStop', this, event, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6508 $('body').css('cursor', '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6509 hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6510 clearOverlays();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6511 if (dayDelta) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6512 eventResize(this, event, dayDelta, 0, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6513 // event redraw will clear helpers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6514 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6515 // otherwise, the drag handler already restored the old events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6516
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6517 setTimeout(function() { // make this happen after the element's click event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6518 isResizing = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6519 },0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6520 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6521 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6522 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6523
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6524
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6525 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6526
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6527
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6528
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6529 /* Generalized Segment Utilities
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6530 -------------------------------------------------------------------------------------------------*/
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6531
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6532
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6533 function isDaySegmentCollision(segment, otherSegments) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6534 for (var i=0; i<otherSegments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6535 var otherSegment = otherSegments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6536 if (
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6537 otherSegment.leftCol <= segment.rightCol &&
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6538 otherSegment.rightCol >= segment.leftCol
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6539 ) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6540 return true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6541 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6542 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6543 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6544 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6545
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6546
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6547 function segmentElementEach(segments, callback) { // TODO: use in AgendaView?
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6548 for (var i=0; i<segments.length; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6549 var segment = segments[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6550 var element = segment.element;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6551 if (element) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6552 callback(segment, element, i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6553 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6554 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6555 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6556
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6557
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6558 // A cmp function for determining which segments should appear higher up
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6559 function compareDaySegments(a, b) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6560 return (b.rightCol - b.leftCol) - (a.rightCol - a.leftCol) || // put wider events first
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6561 b.event.allDay - a.event.allDay || // if tie, put all-day events first (booleans cast to 0/1)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6562 a.event.start - b.event.start || // if a tie, sort by event start date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6563 (a.event.title || '').localeCompare(b.event.title) // if a tie, sort by event title
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6564 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6565
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6566
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6567 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6568
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6569 //BUG: unselect needs to be triggered when events are dragged+dropped
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6570
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6571 function SelectionManager() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6572 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6573
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6574
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6575 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6576 t.select = select;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6577 t.unselect = unselect;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6578 t.reportSelection = reportSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6579 t.daySelectionMousedown = daySelectionMousedown;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6580
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6581
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6582 // imports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6583 var opt = t.opt;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6584 var trigger = t.trigger;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6585 var defaultSelectionEnd = t.defaultSelectionEnd;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6586 var renderSelection = t.renderSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6587 var clearSelection = t.clearSelection;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6588
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6589
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6590 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6591 var selected = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6592
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6593
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6594
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6595 // unselectAuto
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6596 if (opt('selectable') && opt('unselectAuto')) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6597 $(document).mousedown(function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6598 var ignore = opt('unselectCancel');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6599 if (ignore) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6600 if ($(ev.target).parents(ignore).length) { // could be optimized to stop after first match
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6601 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6602 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6603 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6604 unselect(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6605 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6606 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6607
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6608
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6609 function select(startDate, endDate, allDay) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6610 unselect();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6611 if (!endDate) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6612 endDate = defaultSelectionEnd(startDate, allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6613 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6614 renderSelection(startDate, endDate, allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6615 reportSelection(startDate, endDate, allDay);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6616 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6617
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6618
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6619 function unselect(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6620 if (selected) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6621 selected = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6622 clearSelection();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6623 trigger('unselect', null, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6624 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6625 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6626
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6627
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6628 function reportSelection(startDate, endDate, allDay, ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6629 selected = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6630 trigger('select', null, startDate, endDate, allDay, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6631 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6632
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6633
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6634 function daySelectionMousedown(ev) { // not really a generic manager method, oh well
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6635 var cellToDate = t.cellToDate;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6636 var getIsCellAllDay = t.getIsCellAllDay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6637 var hoverListener = t.getHoverListener();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6638 var reportDayClick = t.reportDayClick; // this is hacky and sort of weird
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6639 if (ev.which == 1 && opt('selectable')) { // which==1 means left mouse button
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6640 unselect(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6641 var _mousedownElement = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6642 var dates;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6643 hoverListener.start(function(cell, origCell) { // TODO: maybe put cellToDate/getIsCellAllDay info in cell
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6644 clearSelection();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6645 if (cell && getIsCellAllDay(cell)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6646 dates = [ cellToDate(origCell), cellToDate(cell) ].sort(dateCompare);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6647 renderSelection(dates[0], dates[1], true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6648 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6649 dates = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6650 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6651 }, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6652 $(document).one('mouseup', function(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6653 hoverListener.stop();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6654 if (dates) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6655 if (+dates[0] == +dates[1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6656 reportDayClick(dates[0], true, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6657 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6658 reportSelection(dates[0], dates[1], true, ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6659 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6660 });
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6661 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6662 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6663
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6664
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6665 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6666
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6667 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6668
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6669 function OverlayManager() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6670 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6671
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6672
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6673 // exports
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6674 t.renderOverlay = renderOverlay;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6675 t.clearOverlays = clearOverlays;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6676
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6677
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6678 // locals
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6679 var usedOverlays = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6680 var unusedOverlays = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6681
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6682
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6683 function renderOverlay(rect, parent) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6684 var e = unusedOverlays.shift();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6685 if (!e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6686 e = $("<div class='fc-cell-overlay' style='position:absolute;z-index:3'/>");
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6687 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6688 if (e[0].parentNode != parent[0]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6689 e.appendTo(parent);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6690 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6691 usedOverlays.push(e.css(rect).show());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6692 return e;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6693 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6694
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6695
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6696 function clearOverlays() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6697 var e;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6698 while (e = usedOverlays.shift()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6699 unusedOverlays.push(e.hide().unbind());
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6700 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6701 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6702
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6703
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6704 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6705
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6706 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6707
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6708 function CoordinateGrid(buildFunc) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6709
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6710 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6711 var rows;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6712 var cols;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6713
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6714
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6715 t.build = function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6716 rows = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6717 cols = [];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6718 buildFunc(rows, cols);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6719 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6720
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6721
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6722 t.cell = function(x, y) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6723 var rowCnt = rows.length;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6724 var colCnt = cols.length;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6725 var i, r=-1, c=-1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6726 for (i=0; i<rowCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6727 if (y >= rows[i][0] && y < rows[i][1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6728 r = i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6729 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6730 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6731 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6732 for (i=0; i<colCnt; i++) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6733 if (x >= cols[i][0] && x < cols[i][1]) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6734 c = i;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6735 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6736 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6737 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6738 return (r>=0 && c>=0) ? { row:r, col:c } : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6739 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6740
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6741
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6742 t.rect = function(row0, col0, row1, col1, originElement) { // row1,col1 is inclusive
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6743 var origin = originElement.offset();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6744 return {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6745 top: rows[row0][0] - origin.top,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6746 left: cols[col0][0] - origin.left,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6747 width: cols[col1][1] - cols[col0][0],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6748 height: rows[row1][1] - rows[row0][0]
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6749 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6750 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6751
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6752 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6753
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6754 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6755
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6756 function HoverListener(coordinateGrid) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6757
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6758
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6759 var t = this;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6760 var bindType;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6761 var change;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6762 var firstCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6763 var cell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6764
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6765
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6766 t.start = function(_change, ev, _bindType) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6767 change = _change;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6768 firstCell = cell = null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6769 coordinateGrid.build();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6770 mouse(ev);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6771 bindType = _bindType || 'mousemove';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6772 $(document).bind(bindType, mouse);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6773 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6774
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6775
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6776 function mouse(ev) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6777 _fixUIEvent(ev); // see below
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6778 var newCell = coordinateGrid.cell(ev.pageX, ev.pageY);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6779 if (!newCell != !cell || newCell && (newCell.row != cell.row || newCell.col != cell.col)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6780 if (newCell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6781 if (!firstCell) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6782 firstCell = newCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6783 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6784 change(newCell, firstCell, newCell.row-firstCell.row, newCell.col-firstCell.col);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6785 }else{
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6786 change(newCell, firstCell);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6787 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6788 cell = newCell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6789 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6790 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6791
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6792
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6793 t.stop = function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6794 $(document).unbind(bindType, mouse);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6795 return cell;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6796 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6797
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6798
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6799 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6800
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6801
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6802
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6803 // this fix was only necessary for jQuery UI 1.8.16 (and jQuery 1.7 or 1.7.1)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6804 // upgrading to jQuery UI 1.8.17 (and using either jQuery 1.7 or 1.7.1) fixed the problem
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6805 // but keep this in here for 1.8.16 users
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6806 // and maybe remove it down the line
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6807
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6808 function _fixUIEvent(event) { // for issue 1168
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6809 if (event.pageX === undefined) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6810 event.pageX = event.originalEvent.pageX;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6811 event.pageY = event.originalEvent.pageY;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6812 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6813 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6814 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6815
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6816 function HorizontalPositionCache(getElement) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6817
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6818 var t = this,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6819 elements = {},
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6820 lefts = {},
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6821 rights = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6822
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6823 function e(i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6824 return elements[i] = elements[i] || getElement(i);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6825 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6826
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6827 t.left = function(i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6828 return lefts[i] = lefts[i] === undefined ? e(i).position().left : lefts[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6829 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6830
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6831 t.right = function(i) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6832 return rights[i] = rights[i] === undefined ? t.left(i) + e(i).width() : rights[i];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6833 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6834
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6835 t.clear = function() {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6836 elements = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6837 lefts = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6838 rights = {};
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6839 };
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6840
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6841 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6842
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6843 ;;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6844
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6845 })(jQuery);