2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
/* Grid-based Views: month, basicWeek, basicDay
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
setDefaults({
|
|
|
|
weekMode: 'fixed'
|
|
|
|
});
|
|
|
|
|
|
|
|
views.month = function(element, options) {
|
|
|
|
return new Grid(element, options, {
|
2010-02-16 07:32:43 +01:00
|
|
|
render: function(date, delta) {
|
2009-09-21 06:57:20 +02:00
|
|
|
if (delta) {
|
|
|
|
addMonths(date, delta);
|
2009-10-01 07:39:02 +02:00
|
|
|
date.setDate(1);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
2009-11-01 00:51:30 +01:00
|
|
|
// start/end
|
2009-09-21 06:57:20 +02:00
|
|
|
var start = this.start = cloneDate(date, true);
|
|
|
|
start.setDate(1);
|
2009-11-01 00:51:30 +01:00
|
|
|
this.end = addMonths(cloneDate(start), 1);
|
|
|
|
// visStart/visEnd
|
|
|
|
var visStart = this.visStart = cloneDate(start),
|
|
|
|
visEnd = this.visEnd = cloneDate(this.end),
|
|
|
|
nwe = options.weekends ? 0 : 1;
|
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(visStart);
|
|
|
|
skipWeekend(visEnd, -1, true);
|
|
|
|
}
|
|
|
|
addDays(visStart, -((visStart.getDay() - Math.max(options.firstDay, nwe) + 7) % 7));
|
|
|
|
addDays(visEnd, (7 - visEnd.getDay() + Math.max(options.firstDay, nwe)) % 7);
|
|
|
|
// row count
|
|
|
|
var rowCnt = Math.round((visEnd - visStart) / (DAY_MS * 7));
|
|
|
|
if (options.weekMode == 'fixed') {
|
|
|
|
addDays(visEnd, (6 - rowCnt) * 7);
|
|
|
|
rowCnt = 6;
|
|
|
|
}
|
|
|
|
// title
|
|
|
|
this.title = formatDate(
|
2009-09-21 06:57:20 +02:00
|
|
|
start,
|
2009-10-10 10:12:40 +02:00
|
|
|
this.option('titleFormat'),
|
2009-09-21 06:57:20 +02:00
|
|
|
options
|
|
|
|
);
|
2009-11-01 00:51:30 +01:00
|
|
|
// render
|
|
|
|
this.renderGrid(
|
|
|
|
rowCnt, options.weekends ? 7 : 5,
|
|
|
|
this.option('columnFormat'),
|
2010-02-16 07:32:43 +01:00
|
|
|
true
|
2009-11-01 00:51:30 +01:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
});
|
2010-03-14 02:06:13 +01:00
|
|
|
};
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
views.basicWeek = function(element, options) {
|
|
|
|
return new Grid(element, options, {
|
2010-02-16 07:32:43 +01:00
|
|
|
render: function(date, delta) {
|
2009-09-21 06:57:20 +02:00
|
|
|
if (delta) {
|
|
|
|
addDays(date, delta * 7);
|
|
|
|
}
|
2009-11-01 00:51:30 +01:00
|
|
|
var visStart = this.visStart = cloneDate(
|
|
|
|
this.start = addDays(cloneDate(date), -((date.getDay() - options.firstDay + 7) % 7))
|
|
|
|
),
|
|
|
|
visEnd = this.visEnd = cloneDate(
|
|
|
|
this.end = addDays(cloneDate(visStart), 7)
|
|
|
|
);
|
|
|
|
if (!options.weekends) {
|
|
|
|
skipWeekend(visStart);
|
|
|
|
skipWeekend(visEnd, -1, true);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
this.title = formatDates(
|
2009-11-01 00:51:30 +01:00
|
|
|
visStart,
|
|
|
|
addDays(cloneDate(visEnd), -1),
|
2009-10-10 10:12:40 +02:00
|
|
|
this.option('titleFormat'),
|
2009-09-21 06:57:20 +02:00
|
|
|
options
|
|
|
|
);
|
2009-11-01 00:51:30 +01:00
|
|
|
this.renderGrid(
|
|
|
|
1, options.weekends ? 7 : 5,
|
|
|
|
this.option('columnFormat'),
|
2010-02-16 07:32:43 +01:00
|
|
|
false
|
2009-11-01 00:51:30 +01:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
views.basicDay = function(element, options) {
|
|
|
|
return new Grid(element, options, {
|
2010-02-16 07:32:43 +01:00
|
|
|
render: function(date, delta) {
|
2009-09-21 06:57:20 +02:00
|
|
|
if (delta) {
|
|
|
|
addDays(date, delta);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (!options.weekends) {
|
|
|
|
skipWeekend(date, delta < 0 ? -1 : 1);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
2009-10-10 10:12:40 +02:00
|
|
|
this.title = formatDate(date, this.option('titleFormat'), options);
|
2009-09-21 06:57:20 +02:00
|
|
|
this.start = this.visStart = cloneDate(date, true);
|
|
|
|
this.end = this.visEnd = addDays(cloneDate(this.start), 1);
|
2009-12-31 03:45:39 +01:00
|
|
|
this.renderGrid(
|
|
|
|
1, 1,
|
|
|
|
this.option('columnFormat'),
|
2010-02-16 07:32:43 +01:00
|
|
|
false
|
2009-12-31 03:45:39 +01:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
});
|
2010-03-14 02:06:13 +01:00
|
|
|
};
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
// rendering bugs
|
|
|
|
|
2010-01-25 07:56:57 +01:00
|
|
|
var tdHeightBug;
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
function Grid(element, options, methods) {
|
|
|
|
|
|
|
|
var tm, firstDay,
|
2009-11-01 00:51:30 +01:00
|
|
|
nwe, // no weekends (int)
|
2009-09-21 06:57:20 +02:00
|
|
|
rtl, dis, dit, // day index sign / translate
|
2009-12-31 03:45:39 +01:00
|
|
|
viewWidth, viewHeight,
|
2009-09-21 06:57:20 +02:00
|
|
|
rowCnt, colCnt,
|
|
|
|
colWidth,
|
|
|
|
thead, tbody,
|
2009-12-31 03:45:39 +01:00
|
|
|
cachedEvents=[],
|
|
|
|
segmentContainer,
|
2010-01-25 07:56:57 +01:00
|
|
|
dayContentPositions = new HorizontalPositionCache(function(dayOfWeek) {
|
2010-03-14 02:06:13 +01:00
|
|
|
return tbody.find('td:eq(' + ((dayOfWeek - Math.max(firstDay,nwe)+colCnt) % colCnt) + ') div div');
|
2010-01-25 07:56:57 +01:00
|
|
|
}),
|
2010-05-23 02:30:16 +02:00
|
|
|
selectionManager,
|
2010-05-29 07:11:26 +02:00
|
|
|
selectionMatrix,
|
2010-01-20 04:49:15 +01:00
|
|
|
// ...
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
// initialize superclass
|
|
|
|
view = $.extend(this, viewMethods, methods, {
|
|
|
|
renderGrid: renderGrid,
|
|
|
|
renderEvents: renderEvents,
|
|
|
|
rerenderEvents: rerenderEvents,
|
2010-01-25 07:56:57 +01:00
|
|
|
clearEvents: clearEvents,
|
2010-02-16 07:32:43 +01:00
|
|
|
setHeight: setHeight,
|
|
|
|
setWidth: setWidth,
|
2009-09-21 06:57:20 +02:00
|
|
|
defaultEventEnd: function(event) { // calculates an end if event doesnt have one, mostly for resizing
|
|
|
|
return cloneDate(event.start);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
view.init(element, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Grid Rendering
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
2010-05-31 19:18:29 +02:00
|
|
|
disableTextSelection(element.addClass('fc-grid'));
|
|
|
|
|
2009-09-21 06:57:20 +02:00
|
|
|
|
2010-02-16 07:32:43 +01:00
|
|
|
function renderGrid(r, c, colFormat, showNumbers) {
|
2010-05-03 06:47:23 +02:00
|
|
|
|
2009-09-21 06:57:20 +02:00
|
|
|
rowCnt = r;
|
2010-05-23 02:30:16 +02:00
|
|
|
colCnt = c;
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
// update option-derived variables
|
2009-11-01 00:51:30 +01:00
|
|
|
tm = options.theme ? 'ui' : 'fc';
|
|
|
|
nwe = options.weekends ? 0 : 1;
|
2009-09-21 06:57:20 +02:00
|
|
|
firstDay = options.firstDay;
|
|
|
|
if (rtl = options.isRTL) {
|
|
|
|
dis = -1;
|
|
|
|
dit = colCnt - 1;
|
|
|
|
}else{
|
|
|
|
dis = 1;
|
|
|
|
dit = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:47:26 +02:00
|
|
|
var month = view.start.getMonth(),
|
|
|
|
today = clearTime(new Date()),
|
|
|
|
s, i, j, d = cloneDate(view.visStart);
|
|
|
|
|
2009-09-21 06:57:20 +02:00
|
|
|
if (!tbody) { // first time, build all cells from scratch
|
|
|
|
|
|
|
|
var table = $("<table/>").appendTo(element);
|
|
|
|
|
|
|
|
s = "<thead><tr>";
|
|
|
|
for (i=0; i<colCnt; i++) {
|
|
|
|
s += "<th class='fc-" +
|
|
|
|
dayIDs[d.getDay()] + ' ' + // needs to be first
|
|
|
|
tm + '-state-default' +
|
|
|
|
(i==dit ? ' fc-leftmost' : '') +
|
|
|
|
"'>" + formatDate(d, colFormat, options) + "</th>";
|
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
thead = $(s + "</tr></thead>").appendTo(table);
|
|
|
|
|
|
|
|
s = "<tbody>";
|
|
|
|
d = cloneDate(view.visStart);
|
|
|
|
for (i=0; i<rowCnt; i++) {
|
|
|
|
s += "<tr class='fc-week" + i + "'>";
|
|
|
|
for (j=0; j<colCnt; j++) {
|
|
|
|
s += "<td class='fc-" +
|
|
|
|
dayIDs[d.getDay()] + ' ' + // needs to be first
|
|
|
|
tm + '-state-default fc-day' + (i*colCnt+j) +
|
|
|
|
(j==dit ? ' fc-leftmost' : '') +
|
|
|
|
(rowCnt>1 && d.getMonth() != month ? ' fc-other-month' : '') +
|
|
|
|
(+d == +today ?
|
|
|
|
' fc-today '+tm+'-state-highlight' :
|
|
|
|
' fc-not-today') + "'>" +
|
|
|
|
(showNumbers ? "<div class='fc-day-number'>" + d.getDate() + "</div>" : '') +
|
2010-02-01 07:32:51 +01:00
|
|
|
"<div class='fc-day-content'><div style='position:relative'> </div></div></td>";
|
2009-09-21 06:57:20 +02:00
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
s += "</tr>";
|
|
|
|
}
|
|
|
|
tbody = $(s + "</tbody>").appendTo(table);
|
2010-05-23 02:30:16 +02:00
|
|
|
dayBind(tbody.find('td'));
|
2009-12-31 03:45:39 +01:00
|
|
|
|
2010-02-22 03:06:32 +01:00
|
|
|
segmentContainer = $("<div style='position:absolute;z-index:8;top:0;left:0'/>").appendTo(element);
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
}else{ // NOT first time, reuse as many cells as possible
|
|
|
|
|
2009-12-31 03:45:39 +01:00
|
|
|
clearEvents();
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
var prevRowCnt = tbody.find('tr').length;
|
|
|
|
if (rowCnt < prevRowCnt) {
|
|
|
|
tbody.find('tr:gt(' + (rowCnt-1) + ')').remove(); // remove extra rows
|
|
|
|
}
|
|
|
|
else if (rowCnt > prevRowCnt) { // needs to create new rows...
|
|
|
|
s = '';
|
|
|
|
for (i=prevRowCnt; i<rowCnt; i++) {
|
|
|
|
s += "<tr class='fc-week" + i + "'>";
|
|
|
|
for (j=0; j<colCnt; j++) {
|
|
|
|
s += "<td class='fc-" +
|
|
|
|
dayIDs[d.getDay()] + ' ' + // needs to be first
|
|
|
|
tm + '-state-default fc-new fc-day' + (i*colCnt+j) +
|
|
|
|
(j==dit ? ' fc-leftmost' : '') + "'>" +
|
|
|
|
(showNumbers ? "<div class='fc-day-number'></div>" : '') +
|
2010-02-01 07:32:51 +01:00
|
|
|
"<div class='fc-day-content'><div style='position:relative'> </div></div>" +
|
2009-09-21 06:57:20 +02:00
|
|
|
"</td>";
|
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
s += "</tr>";
|
|
|
|
}
|
|
|
|
tbody.append(s);
|
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
dayBind(tbody.find('td.fc-new').removeClass('fc-new'));
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
// re-label and re-class existing cells
|
|
|
|
d = cloneDate(view.visStart);
|
|
|
|
tbody.find('td').each(function() {
|
|
|
|
var td = $(this);
|
|
|
|
if (rowCnt > 1) {
|
|
|
|
if (d.getMonth() == month) {
|
|
|
|
td.removeClass('fc-other-month');
|
|
|
|
}else{
|
|
|
|
td.addClass('fc-other-month');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (+d == +today) {
|
|
|
|
td.removeClass('fc-not-today')
|
|
|
|
.addClass('fc-today')
|
|
|
|
.addClass(tm + '-state-highlight');
|
|
|
|
}else{
|
|
|
|
td.addClass('fc-not-today')
|
|
|
|
.removeClass('fc-today')
|
|
|
|
.removeClass(tm + '-state-highlight');
|
|
|
|
}
|
|
|
|
td.find('div.fc-day-number').text(d.getDate());
|
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (rowCnt == 1) { // more changes likely (week or day view)
|
|
|
|
|
|
|
|
// redo column header text and class
|
|
|
|
d = cloneDate(view.visStart);
|
|
|
|
thead.find('th').each(function() {
|
|
|
|
$(this).text(formatDate(d, colFormat, options));
|
|
|
|
this.className = this.className.replace(/^fc-\w+(?= )/, 'fc-' + dayIDs[d.getDay()]);
|
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// redo cell day-of-weeks
|
|
|
|
d = cloneDate(view.visStart);
|
|
|
|
tbody.find('td').each(function() {
|
|
|
|
this.className = this.className.replace(/^fc-\w+(?= )/, 'fc-' + dayIDs[d.getDay()]);
|
|
|
|
addDays(d, 1);
|
2009-11-01 00:51:30 +01:00
|
|
|
if (nwe) {
|
|
|
|
skipWeekend(d);
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-04-23 05:27:14 +02:00
|
|
|
|
2010-03-14 02:06:13 +01:00
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
|
2010-02-16 07:32:43 +01:00
|
|
|
|
|
|
|
function setHeight(height) {
|
2009-12-31 03:45:39 +01:00
|
|
|
viewHeight = height;
|
2009-11-29 09:12:36 +01:00
|
|
|
var leftTDs = tbody.find('tr td:first-child'),
|
2009-12-31 03:45:39 +01:00
|
|
|
tbodyHeight = viewHeight - thead.height(),
|
2009-09-21 06:57:20 +02:00
|
|
|
rowHeight1, rowHeight2;
|
|
|
|
if (options.weekMode == 'variable') {
|
|
|
|
rowHeight1 = rowHeight2 = Math.floor(tbodyHeight / (rowCnt==1 ? 2 : 6));
|
|
|
|
}else{
|
|
|
|
rowHeight1 = Math.floor(tbodyHeight / rowCnt);
|
|
|
|
rowHeight2 = tbodyHeight - rowHeight1*(rowCnt-1);
|
|
|
|
}
|
2010-03-14 02:06:13 +01:00
|
|
|
if (tdHeightBug === undefined) {
|
2009-09-21 06:57:20 +02:00
|
|
|
// bug in firefox where cell height includes padding
|
2009-10-13 06:22:40 +02:00
|
|
|
var tr = tbody.find('tr:first'),
|
|
|
|
td = tr.find('td:first');
|
2009-09-21 06:57:20 +02:00
|
|
|
td.height(rowHeight1);
|
|
|
|
tdHeightBug = rowHeight1 != td.height();
|
|
|
|
}
|
|
|
|
if (tdHeightBug) {
|
|
|
|
leftTDs.slice(0, -1).height(rowHeight1);
|
|
|
|
leftTDs.slice(-1).height(rowHeight2);
|
|
|
|
}else{
|
|
|
|
setOuterHeight(leftTDs.slice(0, -1), rowHeight1);
|
|
|
|
setOuterHeight(leftTDs.slice(-1), rowHeight2);
|
|
|
|
}
|
2010-02-16 07:32:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setWidth(width) {
|
|
|
|
viewWidth = width;
|
|
|
|
dayContentPositions.clear();
|
2009-09-21 12:11:08 +02:00
|
|
|
setOuterWidth(
|
|
|
|
thead.find('th').slice(0, -1),
|
2009-12-31 03:45:39 +01:00
|
|
|
colWidth = Math.floor(viewWidth / colCnt)
|
2009-09-21 12:11:08 +02:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
2009-12-31 03:45:39 +01:00
|
|
|
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Event Rendering
|
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
function renderEvents(events) {
|
2009-12-31 03:45:39 +01:00
|
|
|
view.reportEvents(cachedEvents = events);
|
2010-01-27 08:58:43 +01:00
|
|
|
renderSegs(compileSegs(events));
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 19:50:30 +01:00
|
|
|
function rerenderEvents(modifiedEventId) {
|
2009-12-31 03:45:39 +01:00
|
|
|
clearEvents();
|
2010-02-02 19:50:30 +01:00
|
|
|
renderSegs(compileSegs(cachedEvents), modifiedEventId);
|
2009-12-31 03:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clearEvents() {
|
|
|
|
view._clearEvents(); // only clears the hashes
|
|
|
|
segmentContainer.empty();
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function compileSegs(events) {
|
2009-10-10 10:12:40 +02:00
|
|
|
var d1 = cloneDate(view.visStart),
|
|
|
|
d2 = addDays(cloneDate(d1), colCnt),
|
2010-05-29 07:11:26 +02:00
|
|
|
visEventsEnds = $.map(events, exclEndDay),
|
2010-02-01 07:32:51 +01:00
|
|
|
i, row,
|
|
|
|
j, level,
|
|
|
|
k, seg,
|
|
|
|
segs=[];
|
|
|
|
for (i=0; i<rowCnt; i++) {
|
|
|
|
row = stackSegs(view.sliceSegs(events, visEventsEnds, d1, d2));
|
|
|
|
for (j=0; j<row.length; j++) {
|
|
|
|
level = row[j];
|
|
|
|
for (k=0; k<level.length; k++) {
|
|
|
|
seg = level[k];
|
|
|
|
seg.row = i;
|
|
|
|
seg.level = j;
|
|
|
|
segs.push(seg);
|
|
|
|
}
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
addDays(d1, 7);
|
|
|
|
addDays(d2, 7);
|
|
|
|
}
|
2010-02-01 07:32:51 +01:00
|
|
|
return segs;
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-02 19:50:30 +01:00
|
|
|
function renderSegs(segs, modifiedEventId) {
|
2010-01-25 07:56:57 +01:00
|
|
|
_renderDaySegs(
|
2010-02-01 07:32:51 +01:00
|
|
|
segs,
|
|
|
|
rowCnt,
|
2010-01-25 07:56:57 +01:00
|
|
|
view,
|
|
|
|
0,
|
|
|
|
viewWidth,
|
2010-02-01 07:32:51 +01:00
|
|
|
function(i) { return tbody.find('tr:eq('+i+')') },
|
2010-01-25 07:56:57 +01:00
|
|
|
dayContentPositions.left,
|
|
|
|
dayContentPositions.right,
|
|
|
|
segmentContainer,
|
2010-02-02 19:50:30 +01:00
|
|
|
bindSegHandlers,
|
|
|
|
modifiedEventId
|
2010-01-25 07:56:57 +01:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
2009-12-31 03:45:39 +01:00
|
|
|
|
|
|
|
|
2010-02-02 19:50:30 +01:00
|
|
|
function bindSegHandlers(event, eventElement, seg) {
|
|
|
|
view.eventElementHandlers(event, eventElement);
|
2010-03-14 02:06:13 +01:00
|
|
|
if (event.editable || event.editable === undefined && options.editable) {
|
2010-02-02 19:50:30 +01:00
|
|
|
draggableEvent(event, eventElement);
|
|
|
|
if (seg.isEnd) {
|
|
|
|
view.resizableDayEvent(event, eventElement, colWidth);
|
|
|
|
}
|
2010-01-27 08:58:43 +01:00
|
|
|
}
|
2009-12-31 03:45:39 +01:00
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-10 10:12:40 +02:00
|
|
|
/* Event Dragging
|
2009-09-21 06:57:20 +02:00
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
function draggableEvent(event, eventElement) {
|
|
|
|
if (!options.disableDragging && eventElement.draggable) {
|
2010-04-23 05:27:14 +02:00
|
|
|
var matrix,
|
|
|
|
dayDelta = 0;
|
2009-09-21 06:57:20 +02:00
|
|
|
eventElement.draggable({
|
2009-10-10 10:12:40 +02:00
|
|
|
zIndex: 9,
|
2009-09-21 12:11:08 +02:00
|
|
|
delay: 50,
|
2009-10-10 10:12:40 +02:00
|
|
|
opacity: view.option('dragOpacity'),
|
2009-09-21 06:57:20 +02:00
|
|
|
revertDuration: options.dragRevertDuration,
|
|
|
|
start: function(ev, ui) {
|
2009-10-12 08:35:33 +02:00
|
|
|
view.hideEvents(event, eventElement);
|
|
|
|
view.trigger('eventDragStart', eventElement, event, ev, ui);
|
2010-05-23 02:30:16 +02:00
|
|
|
matrix = buildDayMatrix(function(cell) {
|
2009-09-21 06:57:20 +02:00
|
|
|
eventElement.draggable('option', 'revert', !cell || !cell.rowDelta && !cell.colDelta);
|
2010-05-23 02:30:16 +02:00
|
|
|
clearOverlays();
|
2009-09-21 06:57:20 +02:00
|
|
|
if (cell) {
|
2010-04-23 05:27:14 +02:00
|
|
|
dayDelta = cell.rowDelta*7 + cell.colDelta*dis;
|
2010-05-23 02:30:16 +02:00
|
|
|
renderDayOverlays(
|
2010-04-23 05:27:14 +02:00
|
|
|
matrix,
|
2010-05-29 07:11:26 +02:00
|
|
|
addDays(cloneDate(event.start), dayDelta),
|
|
|
|
addDays(exclEndDay(event), dayDelta)
|
2010-04-23 05:27:14 +02:00
|
|
|
);
|
2009-09-21 06:57:20 +02:00
|
|
|
}else{
|
2010-04-23 05:27:14 +02:00
|
|
|
dayDelta = 0;
|
2009-09-21 06:57:20 +02:00
|
|
|
}
|
|
|
|
});
|
2010-05-23 02:30:16 +02:00
|
|
|
matrix.mouse(ev);
|
2009-09-21 06:57:20 +02:00
|
|
|
},
|
|
|
|
drag: function(ev) {
|
2010-05-23 02:30:16 +02:00
|
|
|
matrix.mouse(ev);
|
2009-09-21 06:57:20 +02:00
|
|
|
},
|
|
|
|
stop: function(ev, ui) {
|
2010-05-23 02:30:16 +02:00
|
|
|
clearOverlays();
|
2009-09-21 06:57:20 +02:00
|
|
|
view.trigger('eventDragStop', eventElement, event, ev, ui);
|
2010-04-23 05:27:14 +02:00
|
|
|
if (dayDelta) {
|
|
|
|
eventElement.find('a').removeAttr('href'); // prevents safari from visiting the link
|
|
|
|
view.eventDrop(this, event, dayDelta, 0, event.allDay, ev, ui);
|
|
|
|
}else{
|
2009-10-13 06:22:40 +02:00
|
|
|
if ($.browser.msie) {
|
|
|
|
eventElement.css('filter', ''); // clear IE opacity side-effects
|
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
view.showEvents(event, eventElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-23 05:27:14 +02:00
|
|
|
|
2010-05-23 02:30:16 +02:00
|
|
|
/* Day clicking and binding
|
2010-04-23 05:27:14 +02:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
|
2010-05-23 02:30:16 +02:00
|
|
|
function dayBind(days) {
|
2010-05-29 07:11:26 +02:00
|
|
|
days.click(dayClick)
|
|
|
|
.mousedown(selectionMousedown);
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function dayClick(ev) {
|
2010-05-29 07:11:26 +02:00
|
|
|
if (!view.option('selectable')) { // SelectionManager will worry about dayClick
|
|
|
|
var n = parseInt(this.className.match(/fc\-day(\d+)/)[1]),
|
|
|
|
date = addDays(
|
|
|
|
cloneDate(view.visStart),
|
|
|
|
Math.floor(n/colCnt) * 7 + n % colCnt
|
|
|
|
);
|
|
|
|
// TODO: what about weekends in middle of week?
|
|
|
|
view.trigger('dayClick', this, date, true, ev);
|
|
|
|
}
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-23 02:30:16 +02:00
|
|
|
/* Selecting
|
|
|
|
--------------------------------------------------------*/
|
2010-05-29 07:11:26 +02:00
|
|
|
|
|
|
|
selectionManager = new SelectionManager(
|
|
|
|
view,
|
|
|
|
unselect,
|
|
|
|
function(startDate, endDate, allDay) {
|
|
|
|
renderDayOverlays(
|
|
|
|
selectionMatrix,
|
|
|
|
startDate,
|
|
|
|
addDays(cloneDate(endDate), 1)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
clearOverlays
|
|
|
|
);
|
2010-04-23 05:27:14 +02:00
|
|
|
|
2010-05-29 07:11:26 +02:00
|
|
|
function selectionMousedown(ev) {
|
|
|
|
if (view.option('selectable')) {
|
2010-05-23 02:30:16 +02:00
|
|
|
selectionMatrix = buildDayMatrix(function(cell) {
|
|
|
|
if (cell) {
|
|
|
|
var d = cellDate(cell.row, cell.col);
|
|
|
|
selectionManager.drag(d, d, true);
|
|
|
|
}else{
|
|
|
|
selectionManager.drag();
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
});
|
|
|
|
documentDragHelp(
|
|
|
|
function(ev) {
|
|
|
|
selectionMatrix.mouse(ev);
|
|
|
|
},
|
|
|
|
function(ev) {
|
|
|
|
selectionManager.dragStop(ev);
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
);
|
|
|
|
selectionManager.dragStart(ev);
|
|
|
|
selectionMatrix.mouse(ev);
|
2010-05-31 19:18:29 +02:00
|
|
|
return false; // prevent auto-unselect and text selection
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:11:26 +02:00
|
|
|
documentUnselectAuto(view, unselect);
|
|
|
|
|
|
|
|
view.select = function(start, end, allDay) {
|
|
|
|
if (!end) {
|
|
|
|
end = cloneDate(start);
|
2010-05-23 02:30:16 +02:00
|
|
|
}
|
2010-05-29 07:11:26 +02:00
|
|
|
selectionMatrix = buildDayMatrix();
|
|
|
|
selectionManager.select(start, end, allDay);
|
2010-05-23 02:30:16 +02:00
|
|
|
};
|
2010-04-23 05:27:14 +02:00
|
|
|
|
2010-05-23 02:30:16 +02:00
|
|
|
function unselect() {
|
2010-05-29 07:11:26 +02:00
|
|
|
selectionManager.unselect();
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
view.unselect = unselect;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Semi-transparent Overlay Helpers
|
|
|
|
------------------------------------------------------*/
|
2010-05-29 07:11:26 +02:00
|
|
|
|
|
|
|
function renderDayOverlays(matrix, overlayStart, overlayEnd) { // overlayEnd is exclusive
|
|
|
|
var rowStart = cloneDate(view.visStart);
|
|
|
|
var rowEnd = addDays(cloneDate(rowStart), colCnt);
|
|
|
|
for (var i=0; i<rowCnt; i++) {
|
|
|
|
var stretchStart = new Date(Math.max(rowStart, overlayStart));
|
|
|
|
var stretchEnd = new Date(Math.min(rowEnd, overlayEnd));
|
|
|
|
if (stretchStart < stretchEnd) {
|
|
|
|
var colStart, colEnd;
|
|
|
|
if (rtl) {
|
|
|
|
colStart = dayDiff(stretchEnd, rowStart)*dis+dit+1;
|
|
|
|
colEnd = dayDiff(stretchStart, rowStart)*dis+dit+1;
|
|
|
|
}else{
|
|
|
|
colStart = dayDiff(stretchStart, rowStart);
|
|
|
|
colEnd = dayDiff(stretchEnd, rowStart);
|
|
|
|
}
|
|
|
|
var rect = matrix.rect(i, colStart, i+1, colEnd, element);
|
2010-05-23 02:30:16 +02:00
|
|
|
dayBind(
|
|
|
|
view.renderOverlay(rect, element)
|
|
|
|
);
|
|
|
|
}
|
2010-05-29 07:11:26 +02:00
|
|
|
addDays(rowStart, 7);
|
|
|
|
addDays(rowEnd, 7);
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
|
|
|
|
function clearOverlays() {
|
|
|
|
view.clearOverlays();
|
|
|
|
}
|
|
|
|
|
2010-04-23 05:27:14 +02:00
|
|
|
|
|
|
|
|
2010-05-29 07:11:26 +02:00
|
|
|
|
|
|
|
/* Utils
|
2010-05-23 02:30:16 +02:00
|
|
|
---------------------------------------------------*/
|
2010-05-29 07:11:26 +02:00
|
|
|
|
2010-05-23 02:30:16 +02:00
|
|
|
|
|
|
|
function buildDayMatrix(changeCallback) {
|
2010-04-23 05:27:14 +02:00
|
|
|
var tds = tbody.find('tr:first td');
|
|
|
|
if (rtl) {
|
|
|
|
tds = $(tds.get().reverse());
|
|
|
|
}
|
2010-05-29 07:11:26 +02:00
|
|
|
return new HoverMatrix(tbody.find('tr'), tds, changeCallback);
|
2010-04-23 05:27:14 +02:00
|
|
|
}
|
2010-05-23 02:30:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
function cellDate(r, c) { // convert r,c to date
|
|
|
|
return addDays(cloneDate(view.visStart), r*7 + c*dis+dit);
|
|
|
|
// TODO: what about weekends in middle of week?
|
|
|
|
}
|
2010-04-23 05:27:14 +02:00
|
|
|
|
2009-09-21 06:57:20 +02:00
|
|
|
|
2010-03-14 02:06:13 +01:00
|
|
|
}
|
2009-09-21 06:57:20 +02:00
|
|
|
|
2010-01-25 07:56:57 +01:00
|
|
|
|
2010-02-02 19:50:30 +01:00
|
|
|
function _renderDaySegs(segs, rowCnt, view, minLeft, maxLeft, getRow, dayContentLeft, dayContentRight, segmentContainer, bindSegHandlers, modifiedEventId) {
|
2010-01-25 07:56:57 +01:00
|
|
|
|
|
|
|
var options=view.options,
|
|
|
|
rtl=options.isRTL,
|
2010-02-01 07:32:51 +01:00
|
|
|
i, segCnt=segs.length, seg,
|
2010-01-25 07:56:57 +01:00
|
|
|
event,
|
|
|
|
className,
|
2010-02-01 07:32:51 +01:00
|
|
|
left, right,
|
2010-01-25 07:56:57 +01:00
|
|
|
html='',
|
2010-02-02 19:50:30 +01:00
|
|
|
eventElements,
|
2010-01-25 07:56:57 +01:00
|
|
|
eventElement,
|
|
|
|
triggerRes,
|
2010-02-01 07:32:51 +01:00
|
|
|
hsideCache={},
|
|
|
|
vmarginCache={},
|
|
|
|
key, val,
|
|
|
|
rowI, top, levelI, levelHeight,
|
|
|
|
rowDivs=[],
|
|
|
|
rowDivTops=[];
|
2010-01-25 07:56:57 +01:00
|
|
|
|
|
|
|
// calculate desired position/dimensions, create html
|
2010-02-01 07:32:51 +01:00
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
2010-01-25 07:56:57 +01:00
|
|
|
event = seg.event;
|
|
|
|
className = 'fc-event fc-event-hori ';
|
|
|
|
if (rtl) {
|
|
|
|
if (seg.isStart) {
|
|
|
|
className += 'fc-corner-right ';
|
|
|
|
}
|
|
|
|
if (seg.isEnd) {
|
|
|
|
className += 'fc-corner-left ';
|
|
|
|
}
|
|
|
|
left = seg.isEnd ? dayContentLeft(seg.end.getDay()-1) : minLeft;
|
|
|
|
right = seg.isStart ? dayContentRight(seg.start.getDay()) : maxLeft;
|
|
|
|
}else{
|
|
|
|
if (seg.isStart) {
|
|
|
|
className += 'fc-corner-left ';
|
|
|
|
}
|
|
|
|
if (seg.isEnd) {
|
|
|
|
className += 'fc-corner-right ';
|
|
|
|
}
|
|
|
|
left = seg.isStart ? dayContentLeft(seg.start.getDay()) : minLeft;
|
|
|
|
right = seg.isEnd ? dayContentRight(seg.end.getDay()-1) : maxLeft;
|
|
|
|
}
|
|
|
|
html +=
|
|
|
|
"<div class='" + className + event.className.join(' ') + "' style='position:absolute;z-index:8;left:"+left+"px'>" +
|
|
|
|
"<a" + (event.url ? " href='" + htmlEscape(event.url) + "'" : '') + ">" +
|
|
|
|
(!event.allDay && seg.isStart ?
|
|
|
|
"<span class='fc-event-time'>" +
|
|
|
|
htmlEscape(formatDates(event.start, event.end, view.option('timeFormat'), options)) +
|
|
|
|
"</span>"
|
|
|
|
:'') +
|
|
|
|
"<span class='fc-event-title'>" + htmlEscape(event.title) + "</span>" +
|
|
|
|
"</a>" +
|
2010-03-14 02:06:13 +01:00
|
|
|
((event.editable || event.editable === undefined && options.editable) && !options.disableResizing && $.fn.resizable ?
|
2010-02-02 19:50:30 +01:00
|
|
|
"<div class='ui-resizable-handle ui-resizable-" + (rtl ? 'w' : 'e') + "'></div>"
|
|
|
|
: '') +
|
2010-01-25 07:56:57 +01:00
|
|
|
"</div>";
|
2010-02-01 07:32:51 +01:00
|
|
|
seg.left = left;
|
|
|
|
seg.outerWidth = right - left;
|
|
|
|
}
|
2010-02-04 07:56:20 +01:00
|
|
|
segmentContainer[0].innerHTML = html; // faster than html()
|
2010-02-02 19:50:30 +01:00
|
|
|
eventElements = segmentContainer.children();
|
2010-01-25 07:56:57 +01:00
|
|
|
|
2010-02-01 07:32:51 +01:00
|
|
|
// retrieve elements, run through eventRender callback, bind handlers
|
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
2010-02-02 19:50:30 +01:00
|
|
|
eventElement = $(eventElements[i]); // faster than eq()
|
2010-01-25 07:56:57 +01:00
|
|
|
event = seg.event;
|
|
|
|
triggerRes = view.trigger('eventRender', event, event, eventElement);
|
|
|
|
if (triggerRes === false) {
|
|
|
|
eventElement.remove();
|
|
|
|
}else{
|
|
|
|
if (triggerRes && triggerRes !== true) {
|
|
|
|
eventElement.remove();
|
|
|
|
eventElement = $(triggerRes)
|
2010-01-27 08:58:43 +01:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2010-02-01 07:32:51 +01:00
|
|
|
left: seg.left
|
2010-01-27 08:58:43 +01:00
|
|
|
})
|
2010-01-25 07:56:57 +01:00
|
|
|
.appendTo(segmentContainer);
|
|
|
|
}
|
2010-02-01 07:32:51 +01:00
|
|
|
seg.element = eventElement;
|
2010-02-02 19:50:30 +01:00
|
|
|
if (event._id === modifiedEventId) {
|
|
|
|
bindSegHandlers(event, eventElement, seg);
|
|
|
|
}else{
|
|
|
|
eventElement[0]._fci = i; // for lazySegBind
|
|
|
|
}
|
2010-01-25 07:56:57 +01:00
|
|
|
view.reportEventElement(event, eventElement);
|
|
|
|
}
|
2010-02-01 07:32:51 +01:00
|
|
|
}
|
2010-01-25 07:56:57 +01:00
|
|
|
|
2010-02-02 19:50:30 +01:00
|
|
|
lazySegBind(segmentContainer, segs, bindSegHandlers);
|
|
|
|
|
2010-02-01 07:32:51 +01:00
|
|
|
// record event horizontal sides
|
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
|
|
|
if (eventElement = seg.element) {
|
|
|
|
val = hsideCache[key = seg.key = cssKey(eventElement[0])];
|
2010-03-14 02:06:13 +01:00
|
|
|
seg.hsides = val === undefined ? (hsideCache[key] = hsides(eventElement[0], true)) : val;
|
2010-02-01 07:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set event widths
|
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
|
|
|
if (eventElement = seg.element) {
|
|
|
|
eventElement[0].style.width = seg.outerWidth - seg.hsides + 'px';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// record event heights
|
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
|
|
|
if (eventElement = seg.element) {
|
|
|
|
val = vmarginCache[key = seg.key];
|
|
|
|
seg.outerHeight = eventElement[0].offsetHeight + (
|
2010-03-14 02:06:13 +01:00
|
|
|
val === undefined ? (vmarginCache[key] = vmargins(eventElement[0])) : val
|
2010-02-01 07:32:51 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set row heights, calculate event tops (in relation to row top)
|
|
|
|
for (i=0, rowI=0; rowI<rowCnt; rowI++) {
|
|
|
|
top = levelI = levelHeight = 0;
|
|
|
|
while (i<segCnt && (seg = segs[i]).row == rowI) {
|
|
|
|
if (seg.level != levelI) {
|
|
|
|
top += levelHeight;
|
|
|
|
levelHeight = 0;
|
|
|
|
levelI++;
|
2010-01-25 07:56:57 +01:00
|
|
|
}
|
2010-02-01 07:32:51 +01:00
|
|
|
levelHeight = Math.max(levelHeight, seg.outerHeight||0);
|
|
|
|
seg.top = top;
|
|
|
|
i++;
|
|
|
|
}
|
2010-02-04 07:56:20 +01:00
|
|
|
rowDivs[rowI] = getRow(rowI).find('td:first div.fc-day-content > div') // optimal selector?
|
2010-02-01 07:32:51 +01:00
|
|
|
.height(top + levelHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate row tops
|
|
|
|
for (rowI=0; rowI<rowCnt; rowI++) {
|
|
|
|
rowDivTops[rowI] = rowDivs[rowI][0].offsetTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set event tops
|
|
|
|
for (i=0; i<segCnt; i++) {
|
|
|
|
seg = segs[i];
|
|
|
|
if (eventElement = seg.element) {
|
|
|
|
eventElement[0].style.top = rowDivTops[seg.row] + seg.top + 'px';
|
|
|
|
event = seg.event;
|
|
|
|
view.trigger('eventAfterRender', event, event, eventElement);
|
2010-01-25 07:56:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-01 07:32:51 +01:00
|
|
|
|