var fc = $.fullCalendar = {}; var views = fc.views = {}; /* Defaults -----------------------------------------------------------------------------*/ var defaults = { // display defaultView: 'month', aspectRatio: 1.35, header: { left: 'title', center: '', right: 'today prev,next' }, weekends: true, // editing //editable: false, //disableDragging: false, //disableResizing: false, allDayDefault: true, // event ajax startParam: 'start', endParam: 'end', cacheParam: '_', // time formats titleFormat: { month: 'MMMM yyyy', week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}", day: 'dddd, MMM d, yyyy' }, columnFormat: { month: 'ddd', week: 'ddd M/d', day: 'dddd M/d' }, timeFormat: { // for event elements '': 'h(:mm)t' // default }, // locale isRTL: false, firstDay: 0, monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'], monthNamesShort: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'], dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'], buttonText: { prev: ' ◄ ', next: ' ► ', prevYear: ' << ', nextYear: ' >> ', today: 'today', month: 'month', week: 'week', day: 'day' }, // jquery-ui theming theme: false, buttonIcons: { prev: 'circle-triangle-w', next: 'circle-triangle-e' } }; // right-to-left defaults var rtlDefaults = { header: { left: 'next,prev today', center: '', right: 'title' }, buttonText: { prev: ' ► ', next: ' ◄ ', prevYear: ' >> ', nextYear: ' << ' }, buttonIcons: { prev: 'circle-triangle-e', next: 'circle-triangle-w' } }; // function for adding/overriding defaults var setDefaults = fc.setDefaults = function(d) { $.extend(true, defaults, d); } /* .fullCalendar jQuery function -----------------------------------------------------------------------------*/ $.fn.fullCalendar = function(options) { // method calling if (typeof options == 'string') { var args = Array.prototype.slice.call(arguments, 1), res; this.each(function() { var r = $.data(this, 'fullCalendar')[options].apply(this, args); if (res == undefined) { res = r; } }); if (res != undefined) { return res; } return this; } // pluck the 'events' and 'eventSources' options var eventSources = options.eventSources || []; delete options.eventSources; if (options.events) { eventSources.push(options.events); delete options.events; } // first event source reserved for 'sticky' events eventSources.unshift([]); // initialize options options = $.extend(true, {}, defaults, (options.isRTL || options.isRTL==undefined && defaults.isRTL) ? rtlDefaults : {}, options ); var tm = options.theme ? 'ui' : 'fc'; // for making theme classes this.each(function() { /* Instance Initialization -----------------------------------------------------------------------------*/ // element var _element = this, element = $(this).addClass('fc'), elementWidth, content = $("
").appendTo(this), // relative for ie6 contentHeight; if (options.isRTL) { element.addClass('fc-rtl'); } if (options.theme) { element.addClass('ui-widget'); } // view managing var date = new Date(), viewName, view, // the current view viewInstances = {}; if (options.year != undefined && options.year != date.getFullYear()) { date.setDate(1); date.setMonth(0); date.setFullYear(options.year); } if (options.month != undefined && options.month != date.getMonth()) { date.setDate(1); date.setMonth(options.month); } if (options.date != undefined) { date.setDate(options.date); } /* View Rendering -----------------------------------------------------------------------------*/ function changeView(v) { if (v != viewName) { fixContentSize(); if (view) { if (view.eventsChanged) { eventsDirtyExcept(view); view.eventsChanged = false; } view.element.hide(); } if (viewInstances[v]) { (view = viewInstances[v]).element.show(); if (view.shown) { view.shown(); } }else{ view = viewInstances[v] = $.fullCalendar.views[v]( $("").appendTo(content), options); } if (header) { // update 'active' view button header.find('div.fc-button-' + viewName).removeClass(tm + '-state-active'); header.find('div.fc-button-' + v).addClass(tm + '-state-active'); } view.name = viewName = v; render(); unfixContentSize(); } } function render(inc, forceUpdateSize) { if ((elementWidth = _element.offsetWidth) !== 0) { // visible on the screen if (!contentHeight) { contentHeight = calculateContentHeight(); } if (inc || !view.date || +view.date != +date) { // !view.date means it hasn't been rendered yet fixContentSize(); view.render(date, inc || 0, contentHeight, function(callback) { // dont refetch if new view contains the same events (or a subset) if (!eventStart || view.visStart < eventStart || view.visEnd > eventEnd) { fetchEvents(callback); }else{ callback(events); // no refetching } }); unfixContentSize(); view.date = cloneDate(date); } else if (view.sizeDirty || forceUpdateSize) { view.updateSize(contentHeight); 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); // enable/disable 'today' button var today = new Date(); if (today >= view.start && today < view.end) { header.find('div.fc-button-today').addClass(tm + '-state-disabled'); }else{ header.find('div.fc-button-today').removeClass(tm + '-state-disabled'); } } view.sizeDirty = false; view.eventsDirty = false; view.trigger('viewDisplay', _element); } } // marks other views' events as dirty function eventsDirtyExcept(exceptView) { $.each(viewInstances, function() { if (this != exceptView) { this.eventsDirty = true; } }); } // called when any event objects have been added/removed/changed, rerenders function eventsChanged() { view.clearEvents(); view.renderEvents(events); eventsDirtyExcept(view); } // marks other views' sizes as dirty function sizesDirtyExcept(exceptView) { $.each(viewInstances, function() { if (this != exceptView) { this.sizeDirty = true; } }); } // called when we know the element size has changed function sizeChanged(fix) { contentHeight = calculateContentHeight(); if (fix) { fixContentSize(); } view.updateSize(contentHeight); if (fix) { unfixContentSize(); } sizesDirtyExcept(view); view.rerenderEvents(true); } // calculate what the height of the content should be function calculateContentHeight() { if (options.contentHeight) { return options.contentHeight; } else if (options.height) { return options.height - (header ? header.height() : 0) - horizontalSides(content); } return elementWidth / options.aspectRatio; } /* Event Sources and Fetching -----------------------------------------------------------------------------*/ var events = [], eventStart, eventEnd; // Fetch from ALL sources. Clear 'events' array and populate function fetchEvents(callback) { events = []; eventStart = cloneDate(view.visStart); eventEnd = cloneDate(view.visEnd); var queued = eventSources.length, sourceDone = function() { if (--queued == 0) { if (callback) { callback(events); } } }, i=0; for (; i