optimizations for month/basic views, groundwork for optimizations in agenda views

This commit is contained in:
Adam Shaw 2009-12-30 18:45:39 -08:00
parent 2d97e4f15d
commit 1667943d1c
8 changed files with 4729 additions and 166 deletions

View file

@ -21,7 +21,7 @@ setDefaults({
views.agendaWeek = function(element, options) { views.agendaWeek = function(element, options) {
return new Agenda(element, options, { return new Agenda(element, options, {
render: function(date, delta, height, fetchEvents) { render: function(date, delta, width, height, fetchEvents) {
if (delta) { if (delta) {
addDays(date, delta * 7); addDays(date, delta * 7);
} }
@ -41,14 +41,19 @@ views.agendaWeek = function(element, options) {
this.option('titleFormat'), this.option('titleFormat'),
options options
); );
this.renderAgenda(options.weekends ? 7 : 5, this.option('columnFormat'), height, fetchEvents); this.renderAgenda(
options.weekends ? 7 : 5,
this.option('columnFormat'),
width, height,
fetchEvents
);
} }
}); });
}; };
views.agendaDay = function(element, options) { views.agendaDay = function(element, options) {
return new Agenda(element, options, { return new Agenda(element, options, {
render: function(date, delta, height, fetchEvents) { render: function(date, delta, width, height, fetchEvents) {
if (delta) { if (delta) {
addDays(date, delta); addDays(date, delta);
if (!options.weekends) { if (!options.weekends) {
@ -58,7 +63,12 @@ views.agendaDay = function(element, options) {
this.title = formatDate(date, this.option('titleFormat'), options); this.title = formatDate(date, this.option('titleFormat'), options);
this.start = this.visStart = cloneDate(date, true); this.start = this.visStart = cloneDate(date, true);
this.end = this.visEnd = addDays(cloneDate(this.start), 1); this.end = this.visEnd = addDays(cloneDate(this.start), 1);
this.renderAgenda(1, this.option('columnFormat'), height, fetchEvents); this.renderAgenda(
1,
this.option('columnFormat'),
width, height,
fetchEvents
);
} }
}); });
}; };
@ -68,8 +78,8 @@ function Agenda(element, options, methods) {
var head, body, bodyContent, bodyTable, bg, var head, body, bodyContent, bodyTable, bg,
colCnt, colCnt,
axisWidth, colWidth, slotHeight, axisWidth, colWidth, slotHeight,
viewWidth, viewHeight,
cachedDaySegs=[], cachedSlotSegs=[], cachedDaySegs=[], cachedSlotSegs=[],
cachedHeight,
tm, firstDay, tm, firstDay,
nwe, // no weekends (int) nwe, // no weekends (int)
rtl, dis, dit, // day index sign / translate rtl, dis, dit, // day index sign / translate
@ -88,21 +98,6 @@ function Agenda(element, options, methods) {
return start; return start;
} }
return addMinutes(start, options.defaultEventMinutes); return addMinutes(start, options.defaultEventMinutes);
},
visEventEnd: function(event) {
if (event.allDay) {
if (event.end) {
var end = cloneDate(event.end);
return (event.allDay || end.getHours() || end.getMinutes()) ? addDays(end, 1) : end;
}else{
return addDays(cloneDate(event.start), 1);
}
}
if (event.end) {
return cloneDate(event.end);
}else{
return addMinutes(cloneDate(event.start), options.defaultEventMinutes);
}
} }
}); });
view.init(element, options); view.init(element, options);
@ -118,7 +113,7 @@ function Agenda(element, options, methods) {
element.disableSelection(); element.disableSelection();
} }
function renderAgenda(c, colFormat, height, fetchEvents) { function renderAgenda(c, colFormat, width, height, fetchEvents) {
colCnt = c; colCnt = c;
// update option-derived variables // update option-derived variables
@ -218,7 +213,7 @@ function Agenda(element, options, methods) {
}else{ // skeleton already built, just modify it }else{ // skeleton already built, just modify it
view.clearEvents(); clearEvents();
// redo column header text and class // redo column header text and class
head.find('tr:first th').slice(1, -1).each(function() { head.find('tr:first th').slice(1, -1).each(function() {
@ -253,7 +248,7 @@ function Agenda(element, options, methods) {
} }
updateSize(height); updateSize(width, height);
resetScroll(); resetScroll();
fetchEvents(renderEvents); fetchEvents(renderEvents);
@ -276,8 +271,9 @@ function Agenda(element, options, methods) {
} }
function updateSize(height) { function updateSize(width, height) {
cachedHeight = height; viewWidth = width;
viewHeight = height;
bodyTable.width(''); bodyTable.width('');
body.height(height - head.height()); body.height(height - head.height());
@ -342,10 +338,10 @@ function Agenda(element, options, methods) {
/* Event Rendering /* Event Rendering
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
var cachedEvents;
function renderEvents(events) { function renderEvents(events) {
view.reportEvents(events); view.reportEvents(cachedEvents = events);
var i, len=events.length, var i, len=events.length,
dayEvents=[], dayEvents=[],
slotEvents=[]; slotEvents=[];
@ -356,30 +352,33 @@ function Agenda(element, options, methods) {
slotEvents.push(events[i]); slotEvents.push(events[i]);
} }
} }
renderDaySegs(cachedDaySegs = stackSegs(view.sliceSegs(dayEvents, $.map(dayEvents, visEventEnd), view.visStart, view.visEnd)));
renderDaySegs(cachedDaySegs = stackSegs(view.sliceSegs(dayEvents, view.visStart, view.visEnd)));
renderSlotSegs(cachedSlotSegs = compileSlotSegs(slotEvents)); renderSlotSegs(cachedSlotSegs = compileSlotSegs(slotEvents));
} }
function rerenderEvents(skipCompile) { function rerenderEvents() {
view.clearEvents(); clearEvents();
if (skipCompile) { renderEvents(cachedEvents);
renderDaySegs(cachedDaySegs);
renderSlotSegs(cachedSlotSegs);
}else{
renderEvents(view.cachedEvents);
} }
function clearEvents() {
$.each(view.eventElements, function() { // TODO: move away from this, empty a container instead
this.remove();
});
view._clearEvents(); // only clears the hashes
} }
function compileSlotSegs(events) { function compileSlotSegs(events) {
var d = addMinutes(cloneDate(view.visStart), minMinute), var d = addMinutes(cloneDate(view.visStart), minMinute),
ends = $.map(events, visEventEnd),
levels, levels,
segCols = [], segCols = [],
i=0; i=0;
for (; i<colCnt; i++) { for (; i<colCnt; i++) {
levels = stackSegs(view.sliceSegs(events, d, addMinutes(cloneDate(d), maxMinute-minMinute))); levels = stackSegs(view.sliceSegs(events, ends, d, addMinutes(cloneDate(d), maxMinute-minMinute)));
countForwardSegs(levels); countForwardSegs(levels);
segCols.push(levels); segCols.push(levels);
addDays(d, 1, true); addDays(d, 1, true);
@ -476,7 +475,7 @@ function Agenda(element, options, methods) {
rowContentHeight += levelHeight; rowContentHeight += levelHeight;
} }
tdInner.height(rowContentHeight); tdInner.height(rowContentHeight);
updateSize(cachedHeight); // tdInner might have pushed the body down, so resize updateSize(viewWidth, viewHeight); // tdInner might have pushed the body down, so resize
} }
} }
@ -576,6 +575,23 @@ function Agenda(element, options, methods) {
} }
function visEventEnd(event) { // returns exclusive 'visible' end, for rendering
if (event.allDay) {
if (event.end) {
var end = cloneDate(event.end);
return (event.allDay || end.getHours() || end.getMinutes()) ? addDays(end, 1) : end;
}else{
return addDays(cloneDate(event.start), 1);
}
}
if (event.end) {
return cloneDate(event.end);
}else{
return addMinutes(cloneDate(event.start), options.defaultEventMinutes);
}
}
/* Event Dragging /* Event Dragging

View file

@ -8,7 +8,7 @@ setDefaults({
views.month = function(element, options) { views.month = function(element, options) {
return new Grid(element, options, { return new Grid(element, options, {
render: function(date, delta, height, fetchEvents) { render: function(date, delta, width, height, fetchEvents) {
if (delta) { if (delta) {
addMonths(date, delta); addMonths(date, delta);
date.setDate(1); date.setDate(1);
@ -44,7 +44,7 @@ views.month = function(element, options) {
rowCnt, options.weekends ? 7 : 5, rowCnt, options.weekends ? 7 : 5,
this.option('columnFormat'), this.option('columnFormat'),
true, true,
height, width, height,
fetchEvents fetchEvents
); );
} }
@ -53,7 +53,7 @@ views.month = function(element, options) {
views.basicWeek = function(element, options) { views.basicWeek = function(element, options) {
return new Grid(element, options, { return new Grid(element, options, {
render: function(date, delta, height, fetchEvents) { render: function(date, delta, width, height, fetchEvents) {
if (delta) { if (delta) {
addDays(date, delta * 7); addDays(date, delta * 7);
} }
@ -77,7 +77,7 @@ views.basicWeek = function(element, options) {
1, options.weekends ? 7 : 5, 1, options.weekends ? 7 : 5,
this.option('columnFormat'), this.option('columnFormat'),
false, false,
height, width, height,
fetchEvents fetchEvents
); );
} }
@ -86,7 +86,7 @@ views.basicWeek = function(element, options) {
views.basicDay = function(element, options) { views.basicDay = function(element, options) {
return new Grid(element, options, { return new Grid(element, options, {
render: function(date, delta, height, fetchEvents) { render: function(date, delta, width, height, fetchEvents) {
if (delta) { if (delta) {
addDays(date, delta); addDays(date, delta);
if (!options.weekends) { if (!options.weekends) {
@ -96,7 +96,13 @@ views.basicDay = function(element, options) {
this.title = formatDate(date, this.option('titleFormat'), options); this.title = formatDate(date, this.option('titleFormat'), options);
this.start = this.visStart = cloneDate(date, true); this.start = this.visStart = cloneDate(date, true);
this.end = this.visEnd = addDays(cloneDate(this.start), 1); this.end = this.visEnd = addDays(cloneDate(this.start), 1);
this.renderGrid(1, 1, this.option('columnFormat'), false, height, fetchEvents); this.renderGrid(
1, 1,
this.option('columnFormat'),
false,
width, height,
fetchEvents
);
} }
}); });
} }
@ -112,10 +118,16 @@ function Grid(element, options, methods) {
var tm, firstDay, var tm, firstDay,
nwe, // no weekends (int) nwe, // no weekends (int)
rtl, dis, dit, // day index sign / translate rtl, dis, dit, // day index sign / translate
viewWidth, viewHeight,
rowCnt, colCnt, rowCnt, colCnt,
colWidth, colWidth,
thead, tbody, thead, tbody,
cachedSegs=[], //... cachedEvents=[],
segments=[],
segmentContainer,
dayContentElements=[],
dayContentLefts=[],
dayContentRights=[], // ...
// initialize superclass // initialize superclass
view = $.extend(this, viewMethods, methods, { view = $.extend(this, viewMethods, methods, {
@ -125,14 +137,6 @@ function Grid(element, options, methods) {
updateSize: updateSize, updateSize: updateSize,
defaultEventEnd: function(event) { // calculates an end if event doesnt have one, mostly for resizing defaultEventEnd: function(event) { // calculates an end if event doesnt have one, mostly for resizing
return cloneDate(event.start); return cloneDate(event.start);
},
visEventEnd: function(event) { // returns exclusive 'visible' end, for rendering
if (event.end) {
var end = cloneDate(event.end);
return (event.allDay || end.getHours() || end.getMinutes()) ? addDays(end, 1) : end;
}else{
return addDays(cloneDate(event.start), 1);
}
} }
}); });
view.init(element, options); view.init(element, options);
@ -148,7 +152,7 @@ function Grid(element, options, methods) {
element.disableSelection(); element.disableSelection();
} }
function renderGrid(r, c, colFormat, showNumbers, height, fetchEvents) { function renderGrid(r, c, colFormat, showNumbers, width, height, fetchEvents) {
rowCnt = r; rowCnt = r;
colCnt = c; colCnt = c;
@ -211,9 +215,11 @@ function Grid(element, options, methods) {
tbody = $(s + "</tbody>").appendTo(table); tbody = $(s + "</tbody>").appendTo(table);
tbody.find('td').click(dayClick); tbody.find('td').click(dayClick);
segmentContainer = $("<div/>").appendTo(element);
}else{ // NOT first time, reuse as many cells as possible }else{ // NOT first time, reuse as many cells as possible
view.clearEvents(); clearEvents();
var prevRowCnt = tbody.find('tr').length; var prevRowCnt = tbody.find('tr').length;
if (rowCnt < prevRowCnt) { if (rowCnt < prevRowCnt) {
@ -296,7 +302,7 @@ function Grid(element, options, methods) {
} }
updateSize(height); updateSize(width, height);
fetchEvents(renderEvents); fetchEvents(renderEvents);
}; };
@ -312,10 +318,14 @@ function Grid(element, options, methods) {
} }
function updateSize(height) { function updateSize(width, height) { // does not render/position the events
viewWidth = width;
viewHeight = height;
dayContentLefts = [];
dayContentRights = [];
var leftTDs = tbody.find('tr td:first-child'), var leftTDs = tbody.find('tr td:first-child'),
tbodyHeight = height - thead.height(), tbodyHeight = viewHeight - thead.height(),
rowHeight1, rowHeight2; rowHeight1, rowHeight2;
if (options.weekMode == 'variable') { if (options.weekMode == 'variable') {
@ -345,30 +355,62 @@ function Grid(element, options, methods) {
setOuterWidth( setOuterWidth(
thead.find('th').slice(0, -1), thead.find('th').slice(0, -1),
colWidth = Math.floor(element.width() / colCnt) colWidth = Math.floor(viewWidth / colCnt)
); );
} }
/* cell/cell-content positioning calculating/caching
-----------------------------------------------------------------------------*/
function dayContentElement(dayOfWeek) {
if (dayContentElements[dayOfWeek] == undefined) {
dayContentElements[dayOfWeek] = tbody.find('td:eq(' + ((dayOfWeek - Math.max(firstDay,nwe)+colCnt) % colCnt) + ') div div');
}
return dayContentElements[dayOfWeek];
}
function dayContentLeft(dayOfWeek) {
if (dayContentLefts[dayOfWeek] == undefined) {
dayContentLefts[dayOfWeek] = dayContentElement(dayOfWeek).position().left;
}
return dayContentLefts[dayOfWeek];
}
function dayContentRight(dayOfWeek) {
if (dayContentRights[dayOfWeek] == undefined) {
dayContentRights[dayOfWeek] = dayContentLeft(dayOfWeek) + dayContentElement(dayOfWeek).width();
}
return dayContentRights[dayOfWeek];
}
/* Event Rendering /* Event Rendering
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
function renderEvents(events) { function renderEvents(events) {
view.reportEvents(events); view.reportEvents(cachedEvents = events);
renderSegs(cachedSegs = compileSegs(events)); renderSegs(segments = compileSegs(events));
} }
function rerenderEvents(skipCompile) { function rerenderEvents() {
view.clearEvents(); clearEvents();
if (skipCompile) { renderSegs(segments = compileSegs(cachedEvents));
renderSegs(cachedSegs);
}else{
renderEvents(view.cachedEvents);
} }
function clearEvents() {
view._clearEvents(); // only clears the hashes
segmentContainer.empty();
} }
@ -378,7 +420,7 @@ function Grid(element, options, methods) {
rows = [], rows = [],
i=0; i=0;
for (; i<rowCnt; i++) { for (; i<rowCnt; i++) {
rows.push(stackSegs(view.sliceSegs(events, d1, d2))); rows.push(stackSegs(view.sliceSegs(events, $.map(events, visEventEnd), d1, d2)));
addDays(d1, 7); addDays(d1, 7);
addDays(d2, 7); addDays(d2, 7);
} }
@ -386,7 +428,138 @@ function Grid(element, options, methods) {
} }
function renderSegs(segRows) { function renderSegs(segRows) {
//renderSegs2(segRows);
//return;
var html='',
i, len = segRows.length, levels,
tr, td,
innerDiv,
top,
rowContentHeight,
j, segs,
levelHeight,
k, seg,
event,
className,
left, right,
eventElement,
triggerRes,
l=0,
_eventElements,
eventLefts=[], eventRights=[],
eventHSides=[],
eventOuterHeights=[];
for (i=0; i<len; i++) {
levels = segRows[i];
for (j=0; j<levels.length; j++) {
segs = levels[j];
for (k=0; k<segs.length; k++) {
seg = segs[k];
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 ? 0 : dayContentLeft(seg.end.getDay()-1);
right = seg.isStart ? viewWidth : dayContentRight(seg.start.getDay());
}else{
if (seg.isStart) {
className += 'fc-corner-left ';
}
if (seg.isEnd) {
className += 'fc-corner-right ';
}
left = seg.isStart ? dayContentLeft(seg.start.getDay()) : 0;
right = seg.isEnd ? dayContentRight(seg.end.getDay()-1) : viewWidth;
}
eventLefts[l] = left;
eventRights[l] = right;
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>" +
"</div>";
l++;
}
}
}
segmentContainer.html(html);
_eventElements = segmentContainer[0].childNodes;
l = 0;
for (i=0; i<len; i++) {
levels = segRows[i];
for (j=0; j<levels.length; j++) {
segs = levels[j];
for (k=0; k<segs.length; k++) {
seg = segs[k];
event = seg.event;
eventElement = $(_eventElements[l]);
triggerRes = view.trigger('eventRender', event, event, eventElement);
if (triggerRes !== false) {
if (triggerRes && typeof triggerRes != 'boolean') {
eventElement = $(triggerRes).appendTo(segmentContainer);
}
eventOuterHeights[l] = eventElement.outerHeight(true);
eventHSides[l] = hsides(eventElement, true);
seg.element = eventElement;
bootstrapEventHandlers(event, seg, eventElement);
view.reportEventElement(event, eventElement);
}
l++;
}
}
}
l = 0;
for (i=0; i<len; i++) {
levels = segRows[i];
tr = tbody.find('tr:eq('+i+')');
td = tr.find('td:first');
innerDiv = td.find('div.fc-day-content div').css('position', 'relative');
top = safePosition(innerDiv, td, tr, tbody).top;
rowContentHeight = 0;
for (j=0; j<levels.length; j++) {
segs = levels[j];
levelHeight = 0;
for (k=0; k<segs.length; k++) {
seg = segs[k];
if (eventElement = seg.element) {
eventElement.css('top', top);
if (rtl && rtlLeftDiff == undefined) {
// bug in IE6 where offsets are miscalculated with direction:rtl
rtlLeftDiff = eventLefts[l] - eventElement.position().left;
if (rtlLeftDiff) {
eventElement.css('left', eventLefts[l] + rtlLeftDiff);
}
}
eventElement.width(eventRights[l] - eventLefts[l] - eventHSides[l]);
view.trigger('eventAfterRender', event, event, eventElement);
levelHeight = Math.max(levelHeight, eventOuterHeights[l]);
}
l++;
}
rowContentHeight += levelHeight;
top += levelHeight;
}
innerDiv.height(rowContentHeight);
}
}
/*
// the original function
function renderSegs2(segRows) {
var i, len = segRows.length, levels, var i, len = segRows.length, levels,
tr, td, tr, td,
innerDiv, innerDiv,
@ -397,47 +570,9 @@ function Grid(element, options, methods) {
k, seg, k, seg,
event, event,
className, className,
//startElm, endElm,
left, right, left, right,
eventElement, eventAnchor, eventElement, eventAnchor,
triggerRes; triggerRes;
function tbodyLeft() {
return 0;
}
var tbodyw;
function tbodyRight() {
if (tbodyw == undefined) {
tbodyw = tbody.width();
}
return tbodyw;
}
var dayContentElements = [];
function dayContentElement(dayOfWeek) {
if (dayContentElements[dayOfWeek] == undefined) {
dayContentElements[dayOfWeek] = tr.find('td:eq(' + ((dayOfWeek - Math.max(firstDay,nwe)+colCnt) % colCnt) + ') div div');
}
return dayContentElements[dayOfWeek];
}
var dayContentLefts = [];
function dayContentLeft(dayOfWeek) {
if (dayContentLefts[dayOfWeek] == undefined) {
dayContentLefts[dayOfWeek] = dayContentElement(dayOfWeek).position().left;
}
return dayContentLefts[dayOfWeek];
}
var dayContentRights = [];
function dayContentRight(dayOfWeek) {
if (dayContentRights[dayOfWeek] == undefined) {
dayContentRights[dayOfWeek] = dayContentLeft(dayOfWeek) + dayContentElement(dayOfWeek).width();
}
return dayContentRights[dayOfWeek];
}
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
levels = segRows[i]; levels = segRows[i];
tr = tbody.find('tr:eq('+i+')'); tr = tbody.find('tr:eq('+i+')');
@ -452,19 +587,9 @@ function Grid(element, options, methods) {
seg = segs[k]; seg = segs[k];
event = seg.event; event = seg.event;
className = 'fc-event fc-event-hori '; className = 'fc-event fc-event-hori ';
/*
startElm = seg.isStart ?
tr.find('td:eq('+((seg.start.getDay()-Math.max(firstDay,nwe)+colCnt)%colCnt)+') div div') :
tbody;
endElm = seg.isEnd ?
tr.find('td:eq('+((seg.end.getDay()-Math.max(firstDay,nwe)+colCnt-1)%colCnt)+') div div') :
tbody;
*/
if (rtl) { if (rtl) {
left = seg.isEnd ? tbodyLeft() : dayContentLeft(seg.end.getDay()-1); left = seg.isEnd ? 0 : dayContentLeft(seg.end.getDay()-1);
right = seg.isStart ? tbodyRight() : dayContentRight(seg.start.getDay()); right = seg.isStart ? viewWidth : dayContentRight(seg.start.getDay());
//left = endElm.position().left;
//right = startElm.position().left + startElm.width();
if (seg.isStart) { if (seg.isStart) {
className += 'fc-corner-right '; className += 'fc-corner-right ';
} }
@ -472,10 +597,8 @@ function Grid(element, options, methods) {
className += 'fc-corner-left '; className += 'fc-corner-left ';
} }
}else{ }else{
left = seg.isStart ? dayContentLeft(seg.start.getDay()) : tbodyLeft(); left = seg.isStart ? dayContentLeft(seg.start.getDay()) : 0;
right = seg.isEnd ? dayContentRight(seg.end.getDay()-1) : tbodyRight(); right = seg.isEnd ? dayContentRight(seg.end.getDay()-1) : viewWidth;
//left = startElm.position().left;
//right = endElm.position().left + endElm.width();
if (seg.isStart) { if (seg.isStart) {
className += 'fc-corner-left '; className += 'fc-corner-left ';
} }
@ -532,6 +655,37 @@ function Grid(element, options, methods) {
innerDiv.height(rowContentHeight); innerDiv.height(rowContentHeight);
} }
} }
*/
function visEventEnd(event) { // returns exclusive 'visible' end, for rendering
if (event.end) {
var end = cloneDate(event.end);
return (event.allDay || end.getHours() || end.getMinutes()) ? addDays(end, 1) : end;
}else{
return addDays(cloneDate(event.start), 1);
}
}
function bootstrapEventHandlers(event, seg, eventElement) {
var attached = false;
eventElement.mouseover(function(ev) {
if (!attached) {
view.eventElementHandlers(event, eventElement);
if (event.editable || event.editable == undefined && options.editable) {
draggableEvent(event, eventElement);
if (seg.isEnd) {
view.resizableDayEvent(event, eventElement, colWidth);
}
}
attached = true;
view.trigger('eventMouseover', this, event, ev);
}
});
}

4389
src/jquery/jquery-uncompressed.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -149,7 +149,9 @@ $.fn.fullCalendar = function(options) {
element = $(_element).addClass('fc'), element = $(_element).addClass('fc'),
elementWidth, elementWidth,
content = $("<div class='fc-content " + tm + "-widget-content' style='position:relative'/>").prependTo(_element), // relative for ie6 content = $("<div class='fc-content " + tm + "-widget-content' style='position:relative'/>").prependTo(_element), // relative for ie6
contentWidth,
contentHeight; contentHeight;
if (options.isRTL) { if (options.isRTL) {
element.addClass('fc-rtl'); element.addClass('fc-rtl');
} }
@ -214,11 +216,12 @@ $.fn.fullCalendar = function(options) {
function render(inc, forceUpdateSize) { function render(inc, forceUpdateSize) {
if ((elementWidth = _element.offsetWidth) !== 0) { // visible on the screen if ((elementWidth = _element.offsetWidth) !== 0) { // visible on the screen
if (!contentHeight) { if (!contentHeight) {
contentWidth = content.width();
contentHeight = calculateContentHeight(); contentHeight = calculateContentHeight();
} }
if (inc || !view.date || +view.date != +date) { // !view.date means it hasn't been rendered yet if (inc || !view.date || +view.date != +date) { // !view.date means it hasn't been rendered yet
fixContentSize(); fixContentSize();
view.render(date, inc || 0, contentHeight, function(callback) { view.render(date, inc || 0, contentWidth, contentHeight, function(callback) {
// dont refetch if new view contains the same events (or a subset) // dont refetch if new view contains the same events (or a subset)
if (!eventStart || view.visStart < eventStart || view.visEnd > eventEnd) { if (!eventStart || view.visStart < eventStart || view.visEnd > eventEnd) {
fetchEvents(callback); fetchEvents(callback);
@ -230,12 +233,14 @@ $.fn.fullCalendar = function(options) {
view.date = cloneDate(date); view.date = cloneDate(date);
} }
else if (view.sizeDirty || forceUpdateSize) { else if (view.sizeDirty || forceUpdateSize) {
view.updateSize(contentHeight); view.updateSize(contentWidth, contentHeight);
view.rerenderEvents(); view.rerenderEvents(); // TODO: could probably skip recompile??
} }
else if (view.eventsDirty) { else if (view.eventsDirty) {
// ensure events are rerendered if another view messed with them // ensure events are rerendered if another view messed with them
// pass in 'events' b/c event might have been added/removed // pass in 'events' b/c event might have been added/removed
// executed on a switchView
// TODO: should this be inclusive with sizeDirty and forceUpdateSize??
view.clearEvents(); view.clearEvents();
view.renderEvents(events); view.renderEvents(events);
} }
@ -257,7 +262,7 @@ $.fn.fullCalendar = function(options) {
} }
// marks other views' events as dirty // marks other views' events as dirty
function eventsDirtyExcept(exceptView) { function eventsDirtyExcept(exceptView) { // TODO: otherViewsEventsDirty
$.each(viewInstances, function() { $.each(viewInstances, function() {
if (this != exceptView) { if (this != exceptView) {
this.eventsDirty = true; this.eventsDirty = true;
@ -283,16 +288,17 @@ $.fn.fullCalendar = function(options) {
// called when we know the element size has changed // called when we know the element size has changed
function sizeChanged(fix) { function sizeChanged(fix) {
contentWidth = content.width();
contentHeight = calculateContentHeight(); contentHeight = calculateContentHeight();
if (fix) { if (fix) {
fixContentSize(); fixContentSize();
} }
view.updateSize(contentHeight); view.updateSize(contentWidth, contentHeight);
if (fix) { if (fix) {
unfixContentSize(); unfixContentSize();
} }
sizesDirtyExcept(view); sizesDirtyExcept(view);
view.rerenderEvents(true); view.rerenderEvents();
} }
// calculate what the height of the content should be // calculate what the height of the content should be
@ -301,9 +307,9 @@ $.fn.fullCalendar = function(options) {
return options.contentHeight; return options.contentHeight;
} }
else if (options.height) { else if (options.height) {
return options.height - (header ? header.height() : 0) - horizontalSides(content); return options.height - (header ? header.height() : 0) - horizontalSides(content); // TODO: shouldn't this be vertical sides??
} }
return elementWidth / Math.max(options.aspectRatio, .5); return Math.round(contentWidth / Math.max(options.aspectRatio, .5));
} }
@ -776,7 +782,7 @@ $.fn.fullCalendar = function(options) {
} }
} }
}; };
$(window).resize(windowResize); //$(window).resize(windowResize);
// let's begin... // let's begin...
@ -787,7 +793,7 @@ $.fn.fullCalendar = function(options) {
setTimeout(function() { setTimeout(function() {
render(); render();
content.hide().show(); // needed for IE 6 content.hide().show(); // needed for IE 6
view.rerenderEvents(); // needed for IE 7 view.rerenderEvents(); // needed for IE 7 // TODO: could probably skip recompile
}, 0); }, 0);
} }

View file

@ -296,42 +296,38 @@ var dateFormatters = {
/* Element Dimensions /* Element Dimensions
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
function setOuterWidth(element, width, includeMargins) { function setOuterWidth(element, width, includeMargins) { // TODO: probably eventually remove this
element.each(function() { element.each(function() {
var e = $(this); var e = $(this);
var w = width - horizontalSides(e); e.width(width - hsides(e, includeMargins));
if (includeMargins) {
w -= (parseInt(e.css('margin-left')) || 0) +
(parseInt(e.css('margin-right')) || 0);
}
e.width(w);
}); });
} }
function horizontalSides(e) { function hsides(e, includeMargins) {
return (parseInt(e.css('border-left-width')) || 0) + return (parseInt(e.css('border-left-width')) || 0) +
(parseInt(e.css('padding-left')) || 0) + (parseInt(e.css('padding-left')) || 0) +
(parseInt(e.css('padding-right')) || 0) + (parseInt(e.css('padding-right')) || 0) +
(parseInt(e.css('border-right-width')) || 0); (parseInt(e.css('border-right-width')) || 0) +
(includeMargins ?
(parseInt(e.css('margin-left')) || 0) + (parseInt(e.css('margin-right')) || 0)
: 0);
} }
function setOuterHeight(element, height, includeMargins) { function setOuterHeight(element, height, includeMargins) { // TODO: probably eventually remove this
element.each(function() { element.each(function() {
var e = $(this); var e = $(this);
var h = height - verticalSides(e); e.height(height - vsides(e, includeMargins));
if (includeMargins) {
h -= (parseInt(e.css('margin-top')) || 0) +
(parseInt(e.css('margin-bottom')) || 0);
}
e.height(h);
}); });
} }
function verticalSides(e) { function vsides(e, includeMargins) {
return (parseInt(e.css('border-top-width')) || 0) + return (parseInt(e.css('border-top-width')) || 0) +
(parseInt(e.css('padding-top')) || 0) + (parseInt(e.css('padding-top')) || 0) +
(parseInt(e.css('padding-bottom')) || 0) + (parseInt(e.css('padding-bottom')) || 0) +
(parseInt(e.css('border-bottom-width')) || 0); (parseInt(e.css('border-bottom-width')) || 0) +
(includeMargins ?
(parseInt(e.css('margin-top')) || 0) + (parseInt(e.css('margin-bottom')) || 0)
: 0);
} }
@ -432,7 +428,7 @@ function zeroPad(n) {
return (n < 10 ? '0' : '') + n; return (n < 10 ? '0' : '') + n;
} }
function smartProperty(obj, name) { // get a camel-cased/namespaced property function smartProperty(obj, name) { // get a camel-cased/namespaced property of an object
if (obj[name] != undefined) { if (obj[name] != undefined) {
return obj[name]; return obj[name];
} }
@ -447,4 +443,13 @@ function smartProperty(obj, name) { // get a camel-cased/namespaced property
return obj['']; return obj[''];
} }
function htmlEscape(s) {
return s
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#039;')
.replace(/"/g, '&quot;')
}

View file

@ -14,7 +14,6 @@ var viewMethods = {
* - visStart * - visStart
* - visEnd * - visEnd
* - defaultEventEnd(event) * - defaultEventEnd(event)
* - visEventEnd(event)
* - render(events) * - render(events)
* - rerenderEvents() * - rerenderEvents()
* *
@ -31,7 +30,6 @@ var viewMethods = {
init: function(element, options) { init: function(element, options) {
this.element = element; this.element = element;
this.options = options; this.options = options;
this.cachedEvents = [];
this.eventsByID = {}; this.eventsByID = {};
this.eventElements = []; this.eventElements = [];
this.eventElementsByID = {}; this.eventElementsByID = {};
@ -61,8 +59,7 @@ var viewMethods = {
reportEvents: function(events) { // events are already normalized at this point reportEvents: function(events) { // events are already normalized at this point
var i, len=events.length, event, var i, len=events.length, event,
eventsByID = this.eventsByID = {}, eventsByID = this.eventsByID = {};
cachedEvents = this.cachedEvents = [];
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
event = events[i]; event = events[i];
if (eventsByID[event._id]) { if (eventsByID[event._id]) {
@ -70,7 +67,6 @@ var viewMethods = {
}else{ }else{
eventsByID[event._id] = [event]; eventsByID[event._id] = [event];
} }
cachedEvents.push(event);
} }
}, },
@ -92,10 +88,7 @@ var viewMethods = {
// event element manipulation // event element manipulation
clearEvents: function() { // only remove ELEMENTS _clearEvents: function() { // only resets hashes
$.each(this.eventElements, function() {
this.remove();
});
this.eventElements = []; this.eventElements = [];
this.eventElementsByID = {}; this.eventElementsByID = {};
}, },
@ -273,7 +266,7 @@ var viewMethods = {
// event rendering utilities // event rendering utilities
sliceSegs: function(events, start, end) { sliceSegs: function(events, visEventEnds, start, end) {
var segs = [], var segs = [],
i, len=events.length, event, i, len=events.length, event,
eventStart, eventEnd, eventStart, eventEnd,
@ -282,7 +275,7 @@ var viewMethods = {
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
event = events[i]; event = events[i];
eventStart = event.start; eventStart = event.start;
eventEnd = this.visEventEnd(event); eventEnd = visEventEnds[i];
if (eventEnd > start && eventStart < end) { if (eventEnd > start && eventStart < end) {
if (eventStart < start) { if (eventStart < start) {
segStart = cloneDate(start); segStart = cloneDate(start);

View file

@ -63,7 +63,7 @@ else if (_build) {
includeJS('../build/fullcalendar/jquery/ui.resizable.js'); includeJS('../build/fullcalendar/jquery/ui.resizable.js');
} }
else { else {
includeJS('../src/jquery/jquery.js'); includeJS('../src/jquery/jquery-uncompressed.js');
includeJS('../src/jquery/ui.core.js'); includeJS('../src/jquery/ui.core.js');
includeJS('../src/jquery/ui.draggable.js'); includeJS('../src/jquery/ui.draggable.js');
includeJS('../src/jquery/ui.resizable.js'); includeJS('../src/jquery/ui.resizable.js');

View file

@ -19,7 +19,7 @@
center: 'title', center: 'title',
right: 'month,agendaWeek,basicWeek,agendaDay,basicDay' right: 'month,agendaWeek,basicWeek,agendaDay,basicDay'
}, },
//editable: true, editable: true,
events: 'many_events_json.txt' events: 'many_events_json.txt'
}); });