version 1.3.1

This commit is contained in:
Adam Shaw 2009-10-01 05:39:02 +00:00
parent ef2713aed0
commit 1cb53661fd
15 changed files with 200 additions and 76 deletions

View file

@ -1,4 +1,14 @@
version 1.3.1 (9/30/09)
- Important Bugfixes (please upgrade from 1.3!)
- When current date was late in the month, for long months, and prev/next buttons
were clicked in month-view, some months would be skipped/repeated
- In certain time zones, daylight savings time would cause certain days
to be misnumbered in month-view
- Subtle change in way week interval is chosen when switching from month to basicWeek/basicDay view
- Added 'allDayDefault' option
- Added 'changeView' and 'render' methods
version 1.3 (9/21/09) version 1.3 (9/21/09)
- different 'views': month/basicWeek/basicDay - different 'views': month/basicWeek/basicDay
- more flexible 'header' system for buttons - more flexible 'header' system for buttons

View file

@ -78,7 +78,7 @@
body { body {
margin-top: 40px; margin-top: 40px;
text-align: center; text-align: center;
font-size: 13px; font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
} }

View file

@ -49,7 +49,7 @@
body { body {
margin-top: 40px; margin-top: 40px;
text-align: center; text-align: center;
font-size: 13px; font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
} }

View file

@ -53,7 +53,7 @@
body { body {
margin-top: 40px; margin-top: 40px;
text-align: center; text-align: center;
font-size: 13px; font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
} }

View file

@ -83,7 +83,7 @@
body { body {
margin-top: 40px; margin-top: 40px;
text-align: center; text-align: center;
font-size: 13px; font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
text-align: left; text-align: left;
} }

View file

@ -221,10 +221,10 @@ table.fc-header {
.fc-event, .fc-event,
.fc-event a { .fc-event a {
color: #fff; border-style: solid;
border-style: solid; border-color: #36c; /* default BORDER color (probably the same as background-color) */
border-color: #36c; /* DEFAULT EVENT COLOR */ background-color: #36c; /* default BACKGROUND color */
background-color: #36c; /* */ color: #fff; /* default TEXT color */
} }
/* Use the 'className' CalEvent property and the following /* Use the 'className' CalEvent property and the following
@ -232,8 +232,9 @@ table.fc-header {
* *
* .my-event-class, * .my-event-class,
* .my-event-class a { * .my-event-class a {
* border-color: red; * border-color: black;
* background-color: red; * background-color: black;
* color: red;
* } * }
*/ */

View file

@ -11,6 +11,7 @@ views.month = function(element, options) {
render: function(date, delta, fetchEvents) { render: function(date, delta, fetchEvents) {
if (delta) { if (delta) {
addMonths(date, delta); addMonths(date, delta);
date.setDate(1);
} }
var start = this.start = cloneDate(date, true); var start = this.start = cloneDate(date, true);
start.setDate(1); start.setDate(1);

View file

@ -22,6 +22,8 @@ var defaults = {
//disableDragging: false, //disableDragging: false,
//disableResizing: false, //disableResizing: false,
allDayDefault: true,
// event ajax // event ajax
startParam: 'start', startParam: 'start',
endParam: 'end', endParam: 'end',
@ -163,7 +165,7 @@ $.fn.fullCalendar = function(options) {
/* View Rendering /* View Rendering
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
function switchView(v) { function changeView(v) {
if (v != viewName) { if (v != viewName) {
prevView = view; prevView = view;
if (viewInstances[v]) { if (viewInstances[v]) {
@ -193,45 +195,47 @@ $.fn.fullCalendar = function(options) {
} }
function render(inc) { function render(inc) {
if (inc || !view.date || +view.date != +date) { // !view.date means it hasn't been rendered yet if (_element.offsetWidth !== 0) { // visible on the screen
ignoreWindowResizes = true; if (inc || !view.date || +view.date != +date) { // !view.date means it hasn't been rendered yet
view.render(date, inc || 0, function(callback) { ignoreWindowResizes = true;
// dont refetch if new view contains the same events (or a subset) view.render(date, inc || 0, function(callback) {
if (!eventStart || view.visStart < eventStart || view.visEnd > eventEnd) { // dont refetch if new view contains the same events (or a subset)
fetchEvents(callback); if (!eventStart || view.visStart < eventStart || view.visEnd > eventEnd) {
}else{ fetchEvents(callback);
callback(events); // no refetching }else{
} callback(events); // no refetching
}); }
ignoreWindowResizes = false; });
view.date = cloneDate(date); ignoreWindowResizes = false;
if (header) { view.date = cloneDate(date);
// enable/disable 'today' button if (header) {
var today = new Date(); // enable/disable 'today' button
if (today >= view.start && today < view.end) { var today = new Date();
header.find('div.fc-button-today').addClass(tm + '-state-disabled'); if (today >= view.start && today < view.end) {
}else{ header.find('div.fc-button-today').addClass(tm + '-state-disabled');
header.find('div.fc-button-today').removeClass(tm + '-state-disabled'); }else{
header.find('div.fc-button-today').removeClass(tm + '-state-disabled');
}
} }
} }
else if (view.sizeDirty) {
view.updateSize();
view.rerenderEvents();
}
else if (view.eventsDirty) {
// ensure events are rerendered if another view messed with them
// pass in 'events' b/c event might have been added/removed
view.clearEvents();
view.renderEvents(events);
}
if (header) {
// update title text
header.find('h2.fc-header-title').html(view.title);
}
view.sizeDirty = false;
view.eventsDirty = false;
view.trigger('viewDisplay', _element);
} }
else if (view.sizeDirty) {
view.updateSize();
view.rerenderEvents();
}
else if (view.eventsDirty) {
// ensure events are rerendered if another view messed with them
// pass in 'events' b/c event might have been added/removed
view.clearEvents();
view.renderEvents(events);
}
if (header) {
// update title text
header.find('h2.fc-header-title').html(view.title);
}
view.sizeDirty = false;
view.eventsDirty = false;
view.trigger('viewDisplay', _element);
} }
// marks other views' events as dirty // marks other views' events as dirty
@ -292,7 +296,7 @@ $.fn.fullCalendar = function(options) {
reportEvents = function(a) { reportEvents = function(a) {
if (prevViewName == view.name && +prevDate == +date) { // protects from fast switching if (prevViewName == view.name && +prevDate == +date) { // protects from fast switching
for (var i=0; i<a.length; i++) { for (var i=0; i<a.length; i++) {
normalizeEvent(a[i]); normalizeEvent(a[i], options);
a[i].source = src; a[i].source = src;
} }
events = events.concat(a); events = events.concat(a);
@ -348,6 +352,9 @@ $.fn.fullCalendar = function(options) {
var publicMethods = { var publicMethods = {
render: render,
changeView: changeView,
// //
// Navigation // Navigation
// //
@ -419,15 +426,15 @@ $.fn.fullCalendar = function(options) {
e.allDay = event.allDay; e.allDay = event.allDay;
e.className = event.className; e.className = event.className;
e.editable = event.editable; e.editable = event.editable;
normalizeEvent(e); normalizeEvent(e, options);
} }
} }
normalizeEvent(event); normalizeEvent(event, options);
eventsChanged(); eventsChanged();
}, },
renderEvent: function(event, stick) { // render a new event renderEvent: function(event, stick) { // render a new event
normalizeEvent(event); normalizeEvent(event, options);
if (!event.source) { if (!event.source) {
if (stick) { if (stick) {
(event.source = eventSources[0]).push(event); (event.source = eventSources[0]).push(event);
@ -549,7 +556,7 @@ $.fn.fullCalendar = function(options) {
buttonClick = publicMethods[buttonNameShort]; buttonClick = publicMethods[buttonNameShort];
} }
else if (views[buttonName]) { else if (views[buttonName]) {
buttonClick = function() { switchView(buttonName) }; buttonClick = function() { changeView(buttonName) };
} }
if (buttonClick) { if (buttonClick) {
if (prevButton) { if (prevButton) {
@ -589,7 +596,7 @@ $.fn.fullCalendar = function(options) {
} }
else if (views[buttonName]) { else if (views[buttonName]) {
button.click(function() { button.click(function() {
switchView(buttonName); changeView(buttonName);
}); });
} }
if (prevButton) { if (prevButton) {
@ -620,7 +627,7 @@ $.fn.fullCalendar = function(options) {
resizeCnt = 0; resizeCnt = 0;
$(window).resize(function() { $(window).resize(function() {
if (!ignoreWindowResizes) { if (!ignoreWindowResizes && view.date) { // view.date means the view has been rendered
var rcnt = ++resizeCnt; // add a delay var rcnt = ++resizeCnt; // add a delay
setTimeout(function() { setTimeout(function() {
if (rcnt == resizeCnt) { if (rcnt == resizeCnt) {
@ -639,7 +646,7 @@ $.fn.fullCalendar = function(options) {
// let's begin... // let's begin...
switchView(options.defaultView); changeView(options.defaultView);
elementWidth = element.width(); elementWidth = element.width();
}); });
@ -655,7 +662,7 @@ $.fn.fullCalendar = function(options) {
var fakeID = 0; var fakeID = 0;
function normalizeEvent(event) { function normalizeEvent(event, options) {
event._id = event._id || (event.id == undefined ? '_fc' + fakeID++ : event.id + ''); event._id = event._id || (event.id == undefined ? '_fc' + fakeID++ : event.id + '');
if (event.date) { if (event.date) {
if (!event.start) { if (!event.start) {
@ -670,7 +677,7 @@ function normalizeEvent(event) {
} }
event._end = event.end ? cloneDate(event.end) : null; event._end = event.end ? cloneDate(event.end) : null;
if (event.allDay == undefined) { if (event.allDay == undefined) {
event.allDay = true; event.allDay = options.allDayDefault;
} }
} }

View file

@ -2,24 +2,45 @@
/* Date Math /* Date Math
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
var DAY_MS = 86400000; var DAY_MS = 86400000,
HOUR_MS = 3600000;
function addYears(d, n, keepTime) { function addYears(d, n, keepTime) {
d.setFullYear(d.getFullYear() + n); d.setFullYear(d.getFullYear() + n);
if (keepTime) return d; if (!keepTime) {
return clearTime(d); clearTime(d);
}
return d;
} }
function addMonths(d, n, keepTime) { function addMonths(d, n, keepTime) { // prevents day overflow/underflow
d.setMonth(d.getMonth() + n); var m = d.getMonth() + n,
if (keepTime) return d; check = cloneDate(d);
return clearTime(d); check.setDate(1);
check.setMonth(m);
d.setMonth(m);
if (!keepTime) {
clearTime(d);
}
while (d.getMonth() != check.getMonth()) {
d.setDate(d.getDate() + (d < check ? 1 : -1));
}
return d;
} }
function addDays(d, n, keepTime) { function addDays(d, n, keepTime) { // deals with daylight savings
d.setDate(d.getDate() + n); var dd = d.getDate() + n,
if (keepTime) return d; check = cloneDate(d);
return clearTime(d); check.setHours(12); // set to middle of day
check.setDate(dd);
d.setDate(dd);
if (!keepTime) {
clearTime(d);
}
while (d.getDate() != check.getDate()) {
d.setTime(+d + (d < check ? 1 : -1) * HOUR_MS);
}
return d;
} }
function addMinutes(d, n) { function addMinutes(d, n) {

View file

@ -131,7 +131,7 @@ var viewMethods = {
if (e.end) { if (e.end) {
e.end = addMinutes(addDays(e.end, days, true), minutes); e.end = addMinutes(addDays(e.end, days, true), minutes);
} }
normalizeEvent(e); normalizeEvent(e, this.options);
} }
this.eventsChanged = true; this.eventsChanged = true;
}, },
@ -143,7 +143,7 @@ var viewMethods = {
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
e = events[i]; e = events[i];
e.end = addMinutes(addDays(this.eventEnd(e), days, true), minutes); e.end = addMinutes(addDays(this.eventEnd(e), days, true), minutes);
normalizeEvent(e); normalizeEvent(e, this.options);
} }
this.eventsChanged = true; this.eventsChanged = true;
}, },

79
tests/basic.html Executable file
View file

@ -0,0 +1,79 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type='text/javascript' src='loader.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
var d = new Date();
var y = d.getFullYear();
var m = d.getMonth();
$('#calendar').fullCalendar({
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
events: [
{
id: 1,
title: "Long Event",
start: new Date(y, m, 6, 14, 0),
end: new Date(y, m, 11),
allDay: false
},
{
id: 2,
title: "Repeating Event",
start: new Date(y, m, 2),
allDay: true
},
{
id: 2,
title: "Repeating Event",
start: new Date(y, m, 9),
allDay: true
},
{
id: 3,
title: "Meeting",
start: new Date(y, m, 20, 9, 0),
allDay: false
},
{
id: 4,
title: "Click for Facebook",
start: new Date(y, m, 27, 16),
end: new Date(y, m, 29),
url: "http://facebook.com/",
allDay: false
}
]
});
});
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 13px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>

View file

@ -83,10 +83,7 @@ if (_build) {
includeJS('../src/gcal.js'); includeJS('../src/gcal.js');
} }
var _userAgent = navigator.userAgent.toLowerCase(); includeJS('firebug-lite/firebug-lite-compressed.js');
if (!/mozilla/.test(_userAgent) || /(compatible|webkit)/.test(_userAgent) || !window.console || !window.console.log) {
includeJS('firebug-lite/firebug-lite-compressed.js');
}
window.onload = function() { window.onload = function() {
$('body').append( $('body').append(

View file

@ -153,6 +153,12 @@
<button onclick="cal.fullCalendar('rerenderEvents')">rerender</button> <button onclick="cal.fullCalendar('rerenderEvents')">rerender</button>
<button onclick="cal.fullCalendar('refetchEvents')">refetch</button> <button onclick="cal.fullCalendar('refetchEvents')">refetch</button>
<br />
<button onclick="cal.fullCalendar('changeView', 'month')">change to month</button>
<button onclick="cal.fullCalendar('changeView', 'basicWeek')">change to basicWeek</button>
<button onclick="cal.fullCalendar('changeView', 'basicDay')">change to basicDay</button>
<button onclick="cal.fullCalendar('render')">render</button>
</p> </p>
<div id='loading' style='position:absolute;display:none'>loading...</div> <div id='loading' style='position:absolute;display:none'>loading...</div>

View file

@ -35,6 +35,8 @@
weekMode: 'variable', weekMode: 'variable',
//allDayDefault: false,
/* /*
titleFormat: { titleFormat: {
month: "'hey!'" month: "'hey!'"
@ -45,7 +47,7 @@
month: "dddd" month: "dddd"
}, },
timeFormat: "H(:mm)[T]{ - H(:mm)T}", timeFormat: "h(:mm)[T]{ - h(:mm)T}",
events: [ events: [
{ {

View file

@ -1 +1 @@
1.3 1.3.1