Calendar = { } var DATE_FIELD = "p_pub_date_sort"; var DATE_RANGE = 0, SELECT_MONTH = 1, INPUT_RANGE = 2, SELECT_DATE = 3; var months = new Array(12); months[0] = "January"; months[1] = "February"; months[2] = "March"; months[3] = "April"; months[4] = "May"; months[5] = "June"; months[6] = "July"; months[7] = "August"; months[8] = "September"; months[9] = "October"; months[10] = "November"; months[11] = "December"; var hideCal = false; Calendar.onPageLoad = function() { if ((document.getElementById("date-selector-bar") != null) || (Common.getKeyValue(Common.getQueryString(), "eT") != "")) { Calendar.showDateSelectorBar(); //This event checks to see if background was clicked to hide calendar $("body").click(function(event) { if (event.target.id == '' && event.target.nodeName != 'A') { Calendar.hideCalendar(); } }); } if (document.getElementById('calendar-inline') != null) { Calendar.showCalendar(null, INPUT_RANGE, 0,0); } } /********* * The setDateRangeFilter function returns a querystring with the specified date filter added */ Calendar.setDateRangeFilter = function(startDate, endDate) { location.href = FilterHandler.updateRangeFilter(DATE_FIELD, 'BTWN', startDate + ' ' + endDate) + "&eT=DateRange"; } /********* * The setMonthFilter function returns a querystring with the specified month filter added */ Calendar.setMonthFilter = function(month, year) { //month = 1 + month; var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var startDate = Calendar.toEpochDate(year, month, 1); var endDate = Calendar.toEpochDate(year, month, monthDays[month]); location.href = FilterHandler.updateRangeFilter(DATE_FIELD, 'BTWN', startDate + ' ' + endDate) + "&eT=Month"; } /********* * The set30DayFilter function returns a querystring with the specified 30 day filter added */ Calendar.set30DayFilter = function() { var startDate = new Date(); var startDateString = Calendar.toEpochDate(startDate.getFullYear(), startDate.getMonth(), startDate.getDate()); var endDate = new Date(startDate.getTime() + (30*24*60*60*1000)); var endDateString = Calendar.toEpochDate(endDate.getFullYear(), endDate.getMonth(), endDate.getDate()); location.href = FilterHandler.updateRangeFilter(DATE_FIELD, 'BTWN', startDateString + ' ' + endDateString) + "&eT=30Day"; } /******** * The removeFilters function removes any applied date filters from the querystring */ Calendar.removeFilters = function() { var newString = FilterHandler.removeRangeFilter(); location.href = (newString == "" ? "?" : newString); } /********** * The showDateSelectorBar function uses the querystring parameter 'eT', and the current filter parameter * to display the appropriate display title */ var pageTab; var currTab, currLink; Calendar.showDateSelectorBar = function() { var type, range; type = Common.getKeyValue(Common.getQueryString(), "eT"); if (type != "") { var filter = unescape(Common.getKeyValue(Common.getQueryString(), "Nf")); filter = filter.split("|")[1]; range = filter.substring(filter.indexOf(" ")+1); } else { type = "All" } var title = document.getElementById("date-selector-title"); if (type == "All") { document.getElementById("date-selector-tab1").className = "search-tab-selected"; if (title != null ) title.innerHTML = "Displaying All events"; currTab = 1; currLink = document.getElementById("date-selector-tab1").innerHTML; } else if (type == "30Day") { document.getElementById("date-selector-tab2").className = "search-tab-selected"; if (title != null ) title.innerHTML = "Displaying events Upcoming this month"; currTab = 2; currLink = document.getElementById("date-selector-tab2").innerHTML; } else if (type == "Month") { var month = parseInt((range.split(" ")[0]).substring(4,6)); var year = range.split(" ")[0].substring(0,4); document.getElementById("date-selector-tab3").className = "search-tab-selected"; if (title != null ) title.innerHTML = "Displaying events for " + months[month-1] + " " + year + ""; currTab = 3; currLink = document.getElementById("date-selector-tab3").innerHTML; } else if (type == "DateRange") { var startDate = range.split(" ")[0]; var endDate = range.split(" ")[1]; document.getElementById("date-selector-tab4").className = "search-tab-selected"; if (title != null ) title.innerHTML = "Displaying events " + Calendar.fromEpochDate(startDate) + " to " + Calendar.fromEpochDate(endDate) + ""; currTab = 4; currLink = document.getElementById("date-selector-tab4").innerHTML; } pageTab = currTab; Calendar.roundDateSelectorTabs(); } Calendar.roundDateSelectorTabs = function() { var settings = { tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 0 }, br: { radius: 0 }, antiAlias: true } if (Common.getElementsByClassName(document, "*", "search-tab") != null) curvyCorners(settings, ".search-tab-selected"); } /********** * The showCalendar function displays the popup calendar element, with the specified * selection type (SELECT_MONTH or DATE_RANGE) and adds onclick events to hide calendar */ var selType = INPUT_RANGE; var cal = null; var calClick; Calendar.showCalendar = function(tabNo, selectionType, xPos, yPos) { var refObject; if (tabNo.length == 1) refObject = document.getElementById("date-selector-tab" + tabNo); else refObject = document.getElementById(tabNo); if (refObject != null) { xPos = - Common.getAbsoluteX(refObject.parentNode) + xPos; yPos = - Common.getAbsoluteY(refObject.parentNode) + yPos; selType = selectionType; if (cal != null) { cal.destroy(); cal = null; } var nav; if (selType == SELECT_MONTH) { Common.hidePopup(document.getElementById('calendar-popup')); var monthCal = document.getElementById("calendar-month"); var currMonth = new Date().getMonth(); var currYear = new Date().getFullYear(); var monthOptions = ""; document.getElementById("calendar-month-options").innerHTML = monthOptions; Common.showPopup(refObject, monthCal, xPos, yPos); /* cal = new YAHOO.widget.Calendar("cal", "calendar-popup", {navigator:true}); cal.render(); nav = cal.oNavigator; cal.hideNavEvent.subscribe(function() { //TODO: Need to check if Cancel button was clicked then ignore Calendar.executeSelection(cal); }, cal, true); var pgdate = cal.cfg.getProperty("pagedate"); nav.setYear(pgdate.getFullYear()); nav.setMonth(pgdate.getMonth()); nav.show(); calClick = true; document.getElementById("calendar-popup").onclick = function() { calClick = true; } Common.showPopup(refObject, document.getElementById('calendar-popup'), xPos, yPos); */ } else if (selType == DATE_RANGE) { if (document.getElementById('calendar-month') != null) Common.hidePopup(document.getElementById('calendar-month')); cal = new YAHOO.custom.IntervalCalendar("calendar-popup", {pages:1,close: true}); cal.selectEvent.subscribe(function() { if (cal.getInterval().length > 0) Calendar.executeSelection(cal); }, cal, true); cal.render(); calClick = true; document.getElementById("calendar-popup").onclick = function() { calClick = true; } Common.showPopup(refObject, document.getElementById('calendar-popup'), xPos, yPos); } else if (selType == SELECT_DATE) { //require future dates only var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var todayDate = month + "/" + day + "/" + year; cal = new YAHOO.custom.IntervalCalendar("calendar-popup", {pages:1, mindate: todayDate, close: true}); cal.selectEvent.subscribe(function() { if (cal.getInterval().length > 0) Calendar.executeSelection(cal); }, cal, true); cal.render(); calClick = true; document.getElementById("calendar-popup").onclick = function() { calClick = true; } Common.showPopup(refObject, document.getElementById('calendar-popup'), xPos, yPos); } else if (selType == INPUT_RANGE) { if (document.getElementById('calendar-popup').style.display == 'block') { Common.hidePopup(document.getElementById('calendar-popup')); } else { cal = new YAHOO.custom.IntervalCalendar("calendar-popup", {pages:1, close: true}); cal.selectEvent.subscribe(function() { Calendar.executeSelection(cal); }, cal, true); cal.render(); Common.showPopup(refObject, document.getElementById('calendar-popup'), xPos, yPos); } } } } /*********** * The hideCalendar function destroys the calendar object and hides the popup */ Calendar.hideCalendar = function() { //Warning: Do not place alerts here as it will create an infinite loop with the document.onfocus event if (cal != null) { cal.destroy(); cal = null; Common.hidePopup(document.getElementById('calendar-popup')); } } /********* * The executeSelection function parses the dates from the calender and sets the range filters * which triggers a page reload */ Calendar.executeSelection = function(cal) { if (selType == SELECT_MONTH) { Common.togglePopup(null, document.getElementById('calendar-month'), 0, 0); var monthYear = document.getElementById("months").options[document.getElementById("months").selectedIndex].value; var month = monthYear.split("/")[0]; var year = monthYear.split("/")[1]; Calendar.setMonthFilter(month-1, year); } else if (selType == SELECT_DATE) { var selection = cal.getInterval()[0]; document.getElementById("txtDate").value = zeroPad(selection.getDate() + "/" + (selection.getMonth()+1) + "/" +selection.getFullYear()); Common.togglePopup(null, document.getElementById('calendar-popup'), 0, 0); } else if (selType == DATE_RANGE) { var interval = cal.getInterval(); var startDate = Calendar.toEpochDate(interval[0].getFullYear(), interval[0].getMonth(), interval[0].getDate()); var endDate = Calendar.toEpochDate(interval[1].getFullYear(), interval[1].getMonth(), interval[1].getDate()); Common.togglePopup(null, document.getElementById('calendar-popup'), 0, 0); Calendar.setDateRangeFilter(startDate, endDate); } else if (selType == INPUT_RANGE) { var interval = cal.getInterval(); if (interval.length == 1) { //var startDate = Calendar.toEpochDate(interval[0].getFullYear(), interval[0].getMonth(), interval[0].getDate()); //document.getElementById("txtStart").value = startDate; document.getElementById("txtStartDay").value = zeroPad(interval[0].getDate()); document.getElementById("txtStartMonth").value = zeroPad(interval[0].getMonth()+1); document.getElementById("txtStartYear").value = interval[0].getFullYear(); } else if (interval.length == 2) { //var endDate = Calendar.toEpochDate(interval[1].getFullYear(), interval[1].getMonth(), interval[1].getDate()); //document.getElementById("txtEnd").value = endDate; document.getElementById("txtEndDay").value = zeroPad(interval[1].getDate()); document.getElementById("txtEndMonth").value = zeroPad(interval[1].getMonth()+1); document.getElementById("txtEndYear").value = interval[1].getFullYear(); Common.hidePopup(document.getElementById('calendar-popup')); } } } function zeroPad(val) { return (val < 10 ? '0' + val.toString() : val.toString()); } /******** * The toEpochDate function formats a year, month and day integer into an range-syntax string */ Calendar.toEpochDate = function(year, month, day){ var aYear = (year < 50 ? '20' + year.toString() : year.toString()); var aDay = (day < 10 ? '0' + day.toString() : day.toString()); var aMonth = 1 + month; aMonth = (aMonth < 10 ? '0' + aMonth.toString() : aMonth.toString()); return '' + aYear + aMonth + aDay; } /******** * The fromEpochDate function returns a display formatted date from an epoch string */ Calendar.fromEpochDate = function(epochString){ var dateString = months[parseInt(epochString.substring(4,6))-1] + " " + epochString.substring(6,8) + ", " + epochString.substring(0,4); return dateString; } /****************************************************************************** * IntervalCalendar is an extension of the CalendarGroup designed specifically * for the selection of an interval of dates. * * @namespace YAHOO.example.calendar * @module calendar * @since 2.5.2 * @requires yahoo, dom, event, calendar */ /** * IntervalCalendar is an extension of the CalendarGroup designed specifically * for the selection of an interval of dates, as opposed to a single date or * an arbitrary collection of dates. *
* Note: When using IntervalCalendar, dates should not be selected or * deselected using the 'selected' configuration property or any of the * CalendarGroup select/deselect methods. Doing so will corrupt the internal * state of the control. Instead, use the provided methods setInterval and * resetInterval. *
** Similarly, when handling select/deselect/etc. events, do not use the * dates passed in the arguments to attempt to keep track of the currently * selected interval. Instead, use getInterval. *
* * @namespace YAHOO.example.calendar * @class IntervalCalendar * @extends YAHOO.widget.CalendarGroup * @constructor * @param {String | HTMLElement} container The id of, or reference to, an HTML DIV element which will contain the control. * @param {Object} cfg optional The initial configuration options for the control. */ function IntervalCalendar(container, cfg) { /** * The interval state, which counts the number of interval endpoints that have * been selected (0 to 2). * * @private * @type Number */ this._iState = 0; // Must be a multi-select CalendarGroup cfg = cfg || {}; cfg.multi_select = true; // Call parent constructor IntervalCalendar.superclass.constructor.call(this, container, cfg); // Subscribe internal event handlers this.beforeSelectEvent.subscribe(this._intervalOnBeforeSelect, this, true); this.selectEvent.subscribe(this._intervalOnSelect, this, true); this.beforeDeselectEvent.subscribe(this._intervalOnBeforeDeselect, this, true); this.deselectEvent.subscribe(this._intervalOnDeselect, this, true); } /** * Default configuration parameters. * * @property IntervalCalendar._DEFAULT_CONFIG * @final * @static * @private * @type Object */ IntervalCalendar._DEFAULT_CONFIG = YAHOO.widget.CalendarGroup._DEFAULT_CONFIG; YAHOO.lang.extend(IntervalCalendar, YAHOO.widget.CalendarGroup, { /** * Returns a string representation of a date which takes into account * relevant localization settings and is suitable for use with * YAHOO.widget.CalendarGroup and YAHOO.widget.Calendar methods. * * @method _dateString * @private * @param {Date} d The JavaScript Date object of which to obtain a string representation. * @return {String} The string representation of the JavaScript Date object. */ _dateString : function(d) { var a = []; a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_MONTH_POSITION.key)-1] = (d.getMonth() + 1); a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_DAY_POSITION.key)-1] = d.getDate(); a[this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.MDY_YEAR_POSITION.key)-1] = d.getFullYear(); var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_FIELD_DELIMITER.key); return a.join(s); }, /** * Given a lower and upper date, returns a string representing the interval * of dates between and including them, which takes into account relevant * localization settings and is suitable for use with * YAHOO.widget.CalendarGroup and YAHOO.widget.Calendar methods. ** Note: No internal checking is done to ensure that the lower date * is in fact less than or equal to the upper date. *
* * @method _dateIntervalString * @private * @param {Date} l The lower date of the interval, as a JavaScript Date object. * @param {Date} u The upper date of the interval, as a JavaScript Date object. * @return {String} The string representing the interval of dates between and * including the lower and upper dates. */ _dateIntervalString : function(l, u) { var s = this.cfg.getProperty(IntervalCalendar._DEFAULT_CONFIG.DATE_RANGE_DELIMITER.key); return (this._dateString(l) + s + this._dateString(u)); }, /** * Returns the lower and upper dates of the currently selected interval, if an * interval is selected. * * @method getInterval * @return {Array} An empty array if no interval is selected; otherwise an array * consisting of two JavaScript Date objects, the first being the * lower date of the interval and the second being the upper date. */ getInterval : function() { // Get selected dates var dates = this.getSelectedDates(); if(dates.length > 1) { // Return lower and upper date in array var l = dates[0]; var u = dates[dates.length - 1]; return [l, u]; } else { // No dates selected, return empty array // return []; return [dates[0]]; } }, /** * Sets the currently selected interval by specifying the lower and upper * dates of the interval (in either order). ** Note: The render method must be called after setting the interval * for any changes to be seen. *
* * @method setInterval * @param {Date} d1 A JavaScript Date object. * @param {Date} d2 A JavaScript Date object. */ setInterval : function(d1, d2) { // Determine lower and upper dates var b = (d1 <= d2); var l = b ? d1 : d2; var u = b ? d2 : d1; // Update configuration this.cfg.setProperty('selected', this._dateIntervalString(l, u), false); this._iState = 2; }, /** * Resets the currently selected interval. ** Note: The render method must be called after resetting the interval * for any changes to be seen. *
* * @method resetInterval */ resetInterval : function() { // Update configuration this.cfg.setProperty('selected', [], false); this._iState = 0; }, /** * Handles beforeSelect event. * * @method _intervalOnBeforeSelect * @private */ _intervalOnBeforeSelect : function(t,a,o) { // Update interval state this._iState = (this._iState + 1) % 3; if(this._iState == 0) { // If starting over with upcoming selection, first deselect all this.deselectAll(); this._iState++; } }, /** * Handles selectEvent event. * * @method _intervalOnSelect * @private */ _intervalOnSelect : function(t,a,o) { // Get selected dates var dates = this.getSelectedDates(); if(dates.length > 1) { /* If more than one date is selected, ensure that the entire interval between and including them is selected */ var l = dates[0]; var u = dates[dates.length - 1]; this.cfg.setProperty('selected', this._dateIntervalString(l, u), false); } // Render changes this.render(); }, /** * Handles beforeDeselect event. * * @method _intervalOnBeforeDeselect * @private */ _intervalOnBeforeDeselect : function(t,a,o) { if(this._iState != 0) { /* If part of an interval is already selected, then swallow up this event because it is superfluous (see _intervalOnDeselect) */ return false; } }, /** * Handles deselectEvent event. * * @method _intervalOnDeselect * @private */ _intervalOnDeselect : function(t,a,o) { if(this._iState != 0) { // If part of an interval is already selected, then first deselect all this._iState = 0; this.deselectAll(); // Get individual date deselected and page containing it var d = a[0]; var date = YAHOO.widget.DateMath.getDate(d[0], d[1] - 1, d[2]); var page = this.getCalendarPage(date); if(page) { // Now (re)select the individual date page.beforeSelectEvent.fire(); this.cfg.setProperty('selected', this._dateString(date), false); page.selectEvent.fire([d]); } // Swallow up since we called deselectAll above return false; } } }); YAHOO.namespace("custom"); YAHOO.custom.IntervalCalendar = IntervalCalendar;