From 92e482089b5f53ed3108e1fa63ced74d882e12f7 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Mon, 14 Sep 2009 10:28:23 +0000 Subject: [PATCH] modified docs, added all new tests --- docs/events-and-sources.txt | 24 +-- docs/methods.txt | 4 +- docs/triggered-actions.txt | 2 +- src/agenda.js | 16 ++ src/css/grid.css | 4 +- src/css/main.css | 36 +++-- src/gcal.js | 10 +- src/grid.js | 120 ++++++++------- src/main.js | 283 ++++++++++++++++++++--------------- src/util.js | 8 +- src/view.js | 47 ++---- test/actions.html | 134 ----------------- test/gcal.html | 115 ++++++++++++++ test/locale.html | 171 ++++++++++----------- test/methods.html | 260 ++++++++++++++++++-------------- test/new.html | 119 --------------- test/options.html | 208 ++++++++++++++------------ test/sources.html | 289 ++++++++++++++++++------------------ test/theming.html | 87 +++++++++++ test/triggers.html | 180 ++++++++++++++++++++++ 20 files changed, 1173 insertions(+), 944 deletions(-) delete mode 100644 test/actions.html create mode 100755 test/gcal.html delete mode 100755 test/new.html create mode 100755 test/theming.html create mode 100755 test/triggers.html diff --git a/docs/events-and-sources.txt b/docs/events-and-sources.txt index e971f19..c25f25a 100755 --- a/docs/events-and-sources.txt +++ b/docs/events-and-sources.txt @@ -77,6 +77,11 @@ CalEvent: **title**: String The text on an event's element + +**allDay**: Boolean (optional, defaults to ``true``) + Determines whether the start-date and end-date's times should be ignored. + If ``true``, times will be ignored. If ``false``, times will be considered, + displaying them on each event (like the text '3pm'). **date**: Date Alias for ``start`` @@ -91,18 +96,17 @@ CalEvent: **end**: Date (optional) A javascript Date object indicating the date/time an event ends. - If the event is an all-day event, specifies the inclusive last day - of the event. (This is different from previous versions of FullCalendar). + As with ``start``, IETF and ISO8601 strings can be used. - For example, an all-day event with start on *Nov 10* and end on *Nov 12* - would span *3 days*. + **If an event is all-day...** - As with ``start``, IETF and ISO8601 strings can be used with an - :ref:`Event Source `. - -**allDay**: Boolean (optional, defaults to ``true``) - Determines whether an event's time is displayed (such as 3pm). - ``false`` will show the time, ``true`` will not. + the end date is *inclusive*. This means an event with ``start`` *Nov 10* and + ``end`` *Nov 12* will span *3 days* on the calendar. + + **If an event is NOT all-day...** + + the end date is *exclusive*. This is only a gotcha when your ``end`` has time 00:00. + It means your event ends on midnight, and it will *not* span through the next day. **className**: String/Array (optional) A CSS class (or array of classes) that will be attached to this event's diff --git a/docs/methods.txt b/docs/methods.txt index 19c5c30..7179477 100755 --- a/docs/methods.txt +++ b/docs/methods.txt @@ -35,8 +35,8 @@ jQuery object: Renders a new event on the calendar. ``calEvent`` must have at least a ``title`` and a ``start``. - By default, the event will disappear once the user switches views - or clicks prev/next. However, specifying ``stick`` as ``true`` + By default, the event will disappear once the calendar refetches its event + sources (example: when prev/next is clicked). However, specifying ``stick`` as ``true`` will cause the event to be permanently fixed to the calendar. **removeEvents** - .fullCalendar('removeEvents', *[idOrFilter]*) diff --git a/docs/triggered-actions.txt b/docs/triggered-actions.txt index 49e368d..87434d5 100755 --- a/docs/triggered-actions.txt +++ b/docs/triggered-actions.txt @@ -78,7 +78,7 @@ always available (:ref:`more below `). ``this`` is set to the event's element -**eventResized**: function(*event, dayDelta, minuteDelta, jsEvent, ui, view*) +**eventResize**: function(*calEvent, dayDelta, minuteDelta, jsEvent, ui, view*) Triggered when an event is resized and *changed in duration*. ``dayDelta`` holds the number of days the event's end time was moved diff --git a/src/agenda.js b/src/agenda.js index d1b2529..9cdbf45 100755 --- a/src/agenda.js +++ b/src/agenda.js @@ -1,4 +1,20 @@ +function segAfters(levels) { // TODO: put in agenda.js + var i, j, k, level, seg, seg2; + for (i=levels.length-1; i>0; i--) { + level = levels[i]; + for (j=0; j").appendTo(element); - s = ''; + s = ""; for (i=0; i" + formatDate(d, colFormat, options) + ""; // TODO: optionize - //if (rtl) { - // s = s2 + s; - //}else{ - s += s2; - //} + "'>" + formatDate(d, colFormat, options) + ""; addDays(d, 1); } - thead = $("" + s + "").appendTo(table); + thead = $(s + "").appendTo(table); s = ""; d = cloneDate(view.visStart); for (i=0; i"; for (j=0; j" + (showNumbers ? "
" + d.getDate() + "
" : '') + "
 
"; - //if (rtl) { - // s2 = s3 + s2; - //}else{ - s2 += s3; - //} addDays(d, 1); } - s += "" + s2 + ""; + s += ""; } tbody = $(s + "").appendTo(table); tbody.find('td').click(dayClick); @@ -182,60 +172,67 @@ function Grid(element, options, methods) { if (rowCnt < prevRowCnt) { tbody.find('tr:gt(' + (rowCnt-1) + ')').remove(); // remove extra rows } - else if (rowCnt > prevRowCnt) { + else if (rowCnt > prevRowCnt) { // needs to create new rows... s = ''; for (i=prevRowCnt; i"; for (j=0; j" + (showNumbers ? "
" : '') + "
 
" + ""; - //if (rtl) { - // s2 = s3 + s2; - //}else{ - s2 += s3; - //} + addDays(d, 1); } - s += "" + s2 + ""; + s += ""; } tbody.append(s); } tbody.find('td.fc-new').removeClass('fc-new').click(dayClick); // re-label and re-class existing cells - tbody.find('tr').each(function() { - for (i=0; i 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'); + 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-not-today') - .removeClass('fc-today') - .removeClass(tm + '-state-highlight'); + td.addClass('fc-other-month'); } - td.find('div.fc-day-number').text(d.getDate()); - addDays(d, 1); } + 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); }); - if (colCnt == 1) { - var startDay = this.visStart.getDay(); - var td = tbody.find('td')[0]; - td.className = td.className.replace(/^fc-\w+(?= )/, 'fc-' + dayIDs[startDay]); - thead.find('th').text(formatDate(this.start, colFormat, options)); + if (rowCnt == 1) { // more likely changed (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); + }); + + // 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); + }); + } } @@ -297,7 +294,7 @@ function Grid(element, options, methods) { function renderEvents(events) { view.reportEvents(events); - renderSegs(cachedSegs = compileSegs(events)); // view.visibleEvents( + renderSegs(cachedSegs = compileSegs(events)); } @@ -388,10 +385,9 @@ function Grid(element, options, methods) { } eventElement = $("
") .append(eventAnchor = $("") - .append(event.hasTime ? + .append(event.allDay ? null : $("") - .html(formatDate(event.start, options.eventTimeFormat, options)) : - null) + .html(formatDates(event.start, event.end, options.timeFormat, options))) .append($("") .text(event.title))); if (event.url) { diff --git a/src/main.js b/src/main.js index 851b9a6..9a29957 100755 --- a/src/main.js +++ b/src/main.js @@ -12,9 +12,9 @@ var defaults = { defaultView: 'month', aspectRatio: 1.35, header: { - left: 'prev,next today', - center: 'title', - right: 'month,basicWeek,basicDay' + left: 'title', + center: '', + right: 'today prev,next' }, // event ajax @@ -23,7 +23,7 @@ var defaults = { cacheParam: '_', // time formats - eventTimeFormat: 'h(:mm)t', + timeFormat: 'h(:mm)t', // for events titleFormat: { month: 'MMMM yyyy', week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}", @@ -62,9 +62,9 @@ var defaults = { // right-to-left defaults var rtlDefaults = { header: { - left: 'basicDay,basicWeek,month', - center: 'title', - right: 'today next,prev' + left: 'next,prev today', + center: '', + right: 'title' }, buttonText: { prev: '►', @@ -254,7 +254,7 @@ $.fn.fullCalendar = function(options) { // Fetch from a particular source. Append to the 'events' array function fetchEventSource(src, callback) { var prevDate = cloneDate(date), - reportEvents = function(a, dontPopLoading) { + reportEvents = function(a) { if (+date == +prevDate) { for (var i=0; i

"); prevTitle = true; }else{ - var button, - icon = options.theme ? options.buttonIcons[buttonNameShort] : null, - text = options.buttonText[buttonNameShort]; - if (icon) { - button = $(""); + var buttonClick; + if (publicMethods[buttonNameShort]) { + buttonClick = publicMethods[buttonNameShort]; } - else if (text) { - button = $(""); + else if (views[buttonName]) { + buttonClick = function() { switchView(buttonName) }; } - if (button) { - button - .mousedown(function() { - button.addClass(tm + '-state-down'); - }) - .mouseup(function() { - button.removeClass(tm + '-state-down'); - }) - .hover(function() { - button.addClass(tm + '-state-hover'); - }, - function() { - button.removeClass(tm + '-state-hover') - .removeClass(tm + '-state-down'); - }) - .appendTo($("").appendTo(tr)); - if (publicMethods[buttonNameShort]) { - button.click(publicMethods[buttonNameShort]); + if (buttonClick) { + var button, + icon = options.theme ? options.buttonIcons[buttonNameShort] : null, + text = options.buttonText[buttonNameShort]; + if (icon) { + button = $("
" + + "
"); } - else if (views[buttonName]) { - button.click(function() { - switchView(buttonName); - }); + else if (text) { + button = $(""); } - if (j == 0 || prevTitle) { - button.addClass(tm + '-corner-left'); - }else{ - button.addClass(tm + '-no-left'); + if (button) { + button + .mousedown(function() { + button.addClass(tm + '-state-down'); + }) + .mouseup(function() { + button.removeClass(tm + '-state-down'); + }) + .hover( + function() { + button.addClass(tm + '-state-hover'); + }, + function() { + button.removeClass(tm + '-state-hover') + .removeClass(tm + '-state-down'); + } + ) + .appendTo($("").appendTo(tr)); + if (publicMethods[buttonNameShort]) { + button.click(publicMethods[buttonNameShort]); + } + else if (views[buttonName]) { + button.click(function() { + switchView(buttonName); + }); + } + if (j == 0 || prevTitle) { + button.addClass(tm + '-corner-left'); + }else{ + button.addClass(tm + '-no-left'); + } + prevTitle = false; } - prevTitle = false; } } }); @@ -572,6 +602,8 @@ $.fn.fullCalendar = function(options) { }); + return this; + }; @@ -583,7 +615,20 @@ var fakeID = 0; function normalizeEvent(event) { event._id = event._id || (typeof event.id == 'undefined' ? '_fc' + fakeID++ : event.id + ''); + if (event.date) { + if (!event.start) { + event.start = event.date; + } + delete event.date; + } event._start = cloneDate(event.start = parseDate(event.start)); event.end = parseDate(event.end); + if (event.end && event.end < event.start) { + event.end = cloneDate(event.start); + } + event._end = event.end ? cloneDate(event.end) : null; + if (typeof event.allDay == 'undefined') { + event.allDay = true; + } } diff --git a/src/util.js b/src/util.js index ff0f56d..89b3dc1 100755 --- a/src/util.js +++ b/src/util.js @@ -4,14 +4,14 @@ var DAY_MS = 86400000; -function addMonths(d, n, keepTime) { - d.setMonth(d.getMonth() + n); +function addYears(d, n, keepTime) { + d.setFullYear(d.getFullYear() + n); if (keepTime) return d; return clearTime(d); } -function addYears(d, n, keepTime) { - d.setFullYear(d.getFullYear() + n); +function addMonths(d, n, keepTime) { + d.setMonth(d.getMonth() + n); if (keepTime) return d; return clearTime(d); } diff --git a/src/view.js b/src/view.js index b52580c..641f8d2 100755 --- a/src/view.js +++ b/src/view.js @@ -8,7 +8,7 @@ var viewMethods = { // - end // - visStart // - visEnd - // - eventEnd(event) + // - defaultEventEnd(event) // - visEventEnd(event) // // - render @@ -26,6 +26,8 @@ var viewMethods = { + // trigger event handlers, always append view as last arg + trigger: function(name, thisObj) { if (this.options[name]) { return this.options[name].apply(thisObj || this, Array.prototype.slice.call(arguments, 2).concat([this])); @@ -34,6 +36,14 @@ var viewMethods = { + // + + eventEnd: function(event) { + return event.end || this.defaultEventEnd(event); + }, + + + // event/element creation reporting reportEvents: function(events) { @@ -64,21 +74,6 @@ var viewMethods = { - // get events within visStart and visEnd TODO: need this? move it somewhere else? - - visibleEvents: function(events) { - var res=[], i, len=events.length, event; - for (i=0; i this.visStart && event.start < this.visEnd) { - res.push(event); - } - } - return res; - }, - - - // event element manipulation clearEvents: function() { // just remove ELEMENTS @@ -115,7 +110,7 @@ var viewMethods = { var i, event2, events = this.eventsByID[event._id]; for (i=0; i0; i--) { - level = levels[i]; - for (j=0; j - - - - - - - - - - - - -
- - diff --git a/test/gcal.html b/test/gcal.html new file mode 100755 index 0000000..53034fc --- /dev/null +++ b/test/gcal.html @@ -0,0 +1,115 @@ + + + + + + + + +
+ + \ No newline at end of file diff --git a/test/locale.html b/test/locale.html index 71bf8bc..738b167 100644 --- a/test/locale.html +++ b/test/locale.html @@ -1,89 +1,82 @@ - - - - - - - - - - - - - -
- - + + + + + + + +
+ + \ No newline at end of file diff --git a/test/methods.html b/test/methods.html index 70d427e..9034ad5 100644 --- a/test/methods.html +++ b/test/methods.html @@ -1,110 +1,150 @@ - - - - - - - - - - - - - - - -
-
-
-
-
-
- -

-

-today   -prev   -next   -prevyear   -nextyear   -June 1986 -

-
- - + + + + + + + + +

+ + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + + + +

+
+ + \ No newline at end of file diff --git a/test/new.html b/test/new.html deleted file mode 100755 index 0ca1270..0000000 --- a/test/new.html +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - -
- \ No newline at end of file diff --git a/test/options.html b/test/options.html index 2024aa0..9f3c732 100644 --- a/test/options.html +++ b/test/options.html @@ -1,99 +1,109 @@ - - - - - - - - - - - - - - -
- - + + + + + + + +
+ + \ No newline at end of file diff --git a/test/sources.html b/test/sources.html index dc19406..3b1eca7 100644 --- a/test/sources.html +++ b/test/sources.html @@ -1,145 +1,144 @@ - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
-
-
-
- -
- - -
- - + + + + + + + + + +

+ +

+
+ + \ No newline at end of file diff --git a/test/theming.html b/test/theming.html new file mode 100755 index 0000000..86593d4 --- /dev/null +++ b/test/theming.html @@ -0,0 +1,87 @@ + + + + + + + + +
+ + \ No newline at end of file diff --git a/test/triggers.html b/test/triggers.html new file mode 100755 index 0000000..7ff112e --- /dev/null +++ b/test/triggers.html @@ -0,0 +1,180 @@ + + + + + + + +
+ + \ No newline at end of file