//============================================================================== // // Purpose: Date-picker. // //============================================================================== // Title: Timestamp picker // Description: See the demo at url // URL: http://www.geocities.com/tspicker/ // Version: 1.0.a (Date selector only) // Date: 12-12-2001 (mm-dd-yyyy) // Author: Denis Gritcyuk ; // Notes: Permission given to use this script in any kind of applications if // header lines are left unchanged. Feel free to contact the author // for feature requests and/or donations /* eslint no-redeclare: "off", no-unused-vars: "off", eqeqeq: "off", no-useless-assignment: "off", no-eval: "off", no-alert: "off", no-global-assign: "off", no-unreachable: "off" */ /*global JSON // ConsoleLogging.js ConsoleLogging asyncShowPicker doPositionPicker g_objPicker g_objPickerRelativePos g_showPickerTimer g_workDaysOfTheWeekBitmask getCanonicalDateString getCookie getLocalDateString hidePicker oPopup pageIncludeRoot parseDateString setCookie trim */ var tableWidth = ''; var prefix = ''; function getWeekStart() { return getCookie("MJTPopupWeekStart"); } function saveWeekStart(weekStart_) { var expiration = new Date(new Date().getFullYear() + 5, 0, 1); setCookie("MJTPopupWeekStart", weekStart_, expiration); } /*global g_dateChangeRedirectUrl getDateForUrlParam */ function redirectToDateChangeRedirectUrlAfterAddingEffectiveDateOf(dateStr) { window.location = g_dateChangeRedirectUrl + "&effdate=" + getDateForUrlParam(dateStr); } function deriveOnclickTextFor(params_) { var onclickText; if (params_.functionName) { onclickText = params_.functionName + "('" + getLocalDateString(params_.date) + "');"; } else { onclickText = params_.prefix + params_.str_target + ".value='" + getLocalDateString(params_.date) + "';" + "if(" + params_.prefix + params_.str_target + ".onchange){" + params_.prefix + params_.str_target + ".onchange()" + "}" + params_.prefix + "oPopup.hide();" + "try{setFocus(" + params_.prefix + params_.str_target + ");}catch(e){}"; } return onclickText; } function getTodayClassesIfApplicable(today_, currentDay_) { if(today_ === undefined || currentDay_ === undefined) { return ''; } //show today icon if(today_.getDate() === currentDay_.getDate() && today_.getMonth() === currentDay_.getMonth() && today_.getFullYear() === currentDay_.getFullYear()) { return ' datePickerTodayIcon'; } else { return ''; } return ''; } function isWithinRange(currentDay_, startDateRange_, endDateRange_) { //highlight the selected range if applicable if(startDateRange_ && startDateRange_ !== 'undefined' && endDateRange_ && endDateRange_ !== 'undefined') { if(currentDay_ >= Date.parse(startDateRange_) && currentDay_ <= Date.parse(endDateRange_)) { return true; } } return false; } //Find the working day by looking at the bitmask //0 is a non working day function isWorkingDay(day_, workdaysOfWeekBitMask_) { var dayBitMask = (1 << (day_ - 1)); var day = dayBitMask & workdaysOfWeekBitMask_; return Boolean(day); } //this function finds an element with id='pickerPopUp' and fills its innerHtml with a monthly calendar that includes the value of the parameter str_datetime. //the html this function generates contains many elements that have onclick attributes that re-call this function with different str_datetime values. //this allows the user to "navigate" through the months of the calendar. //the html this function generates also contain many elements that allow the user to select a date. These elements have onclick attributes as follows: // 1) when an onclickFunctionName is provided, the onclick attribute calls the onclickFunctionName with the selected date as the only argument. // 2) when an onclickFunctionName is not provided and a str_target has been provided, the onclick attribute does the following: // 2a) sets str_target.value to the selected date // 2b) sets focus to str_target // 2c) if str_target has an onchange method, its called. function show_calendar( str_target, str_datetime, relativePosition, n_weekstart, selectedDate, onclickFunctionName, startRange, endRange, hideTodayButton_) { ConsoleLogging.logBlockOpen('show_calendar()'); ConsoleLogging.logObject({ what: 'Showing picker', hideTodayButton_: ConsoleLogging.undefinedStringIfUndefined( hideTodayButton_) }); if (!relativePosition) { relativePosition = ''; } if (onclickFunctionName === undefined) { onclickFunctionName = ''; } // Don't show popup if textbox is disabled if (str_target && eval(prefix + str_target + ".disabled")) { ConsoleLogging.logBlockClose('disabled-textbox'); return; } // Show in div on page oPopup = document.getElementById('pickerPopUp'); oPopup.hide = hidePicker; if (!oPopup) { ConsoleLogging.logBlockClose('no-popup'); return; } var arr_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; var dt_today = new Date(); // day week starts from (normally 0 or 1) if (typeof n_weekstart === 'undefined' || n_weekstart === null || n_weekstart === '') { n_weekstart = getWeekStart(); } else { n_weekstart = parseInt(n_weekstart, 10); if (!isNaN(n_weekstart)) { saveWeekStart(n_weekstart); } } n_weekstart = parseInt(n_weekstart, 10); if (isNaN(n_weekstart)) { n_weekstart = 1; // default to start on Monday } str_datetime = trim(str_datetime); var dt_datetime = str_datetime === null || str_datetime === "" || str_datetime === "**Multi**" ? new Date() : parseDateString(str_datetime); if (!dt_datetime) { alert("Invalid date format: " + str_datetime); dt_datetime = new Date(); } var dt_selectedDate = selectedDate === null || selectedDate === "" ? dt_datetime : parseDateString(selectedDate); if (!dt_selectedDate) { dt_selectedDate = dt_datetime; } var dt_prev_month = new Date(dt_datetime); dt_prev_month.setDate(1); dt_prev_month.setMonth(dt_datetime.getMonth() - 1); var dt_next_month = new Date(dt_datetime); dt_next_month.setDate(1); dt_next_month.setMonth(dt_datetime.getMonth() + 1); var dt_firstday = new Date(dt_datetime); dt_firstday.setDate(1); dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - n_weekstart) % 7); var dt_lastday = new Date(dt_next_month); dt_lastday.setDate(0); var cellSpacing = '0'; var cellPadding = '6'; // html generation // print calendar header var str_buffer = "" + "" + "\n\n
\n" + "" + "" + "\n" + "\n" + "\n" + "\n"; var dt_current_day = new Date(dt_firstday); // print weekdays titles str_buffer += "\n"; for (var n = 0; n < 7; n++) { if (n === 0) { str_buffer += "\n"; for (var weekCount = 0; weekCount < 7; weekCount++) { // print row header str_buffer += "\n"; for (var n_current_wday = 0; n_current_wday < 7; n_current_wday++) { var strCellDayClasses = ''; var isWorkDay; if(typeof g_workDaysOfTheWeekBitmask !== 'undefined' && g_workDaysOfTheWeekBitmask > 0) { isWorkDay = isWorkingDay(dt_current_day.getDay(), g_workDaysOfTheWeekBitmask); } else { isWorkDay = !(dt_current_day.getDay() === 0 || dt_current_day.getDay() === 6); } if (dt_current_day.getDate() === dt_selectedDate.getDate() && dt_current_day.getMonth() === dt_selectedDate.getMonth() && dt_current_day.getFullYear() === dt_selectedDate.getFullYear()) { // print selected date strCellDayClasses = ' selectedDay'; if (!isWorkDay) { strCellDayClasses += ' weekendDay'; } } else if (!isWorkDay) { // non working days strCellDayClasses = ' weekendDay'; } else { // print working days of current month strCellDayClasses = ' workingDay'; } if (dt_current_day.getMonth() === dt_datetime.getMonth()) { // print days of current month strCellDayClasses += ' currentMonth'; } else { // print days of other months strCellDayClasses += ' otherMonth'; } var strCellClasses = 'calPopDayCell '; var strTodayClasses = getTodayClassesIfApplicable(dt_today, dt_current_day); if (isWorkDay && isWithinRange(dt_current_day, startRange, endRange)) { strCellDayClasses += ' datePickerSelectedRange'; strCellClasses += ' datePickerSelectedRangeCell'; } var cellOnclickText = deriveOnclickTextFor({ date: dt_current_day, functionName: onclickFunctionName, prefix: prefix, str_target: str_target }); str_buffer += " \n"; dt_current_day.setDate(dt_current_day.getDate() + 1); } // print row footer str_buffer += "\n"; } // print today link if(hideTodayButton_) { str_buffer += "" + "" + "\n"; //show a blank row because it looks nice and doesn't mess up the styling str_buffer += ""; } else { str_buffer += "" + "" + "\n"; } // print calendar footer str_buffer += "
"; var UNICODE_LEFT_FONT_AWESOME = 61523, UNICODE_RIGHT_FONT_AWESOME = 61524; str_buffer += "&#" + UNICODE_LEFT_FONT_AWESOME + ";"; str_buffer += "" + arr_months[dt_datetime.getMonth()] + " " + dt_datetime.getFullYear() + "" + "&#" + UNICODE_RIGHT_FONT_AWESOME + ";" + "
"; } else { str_buffer += "\n"; } // print calendar table str_buffer += "
" + "
" + dt_current_day.getDate() + "
" + "
" + "" + "Go to Today" + "" + "
" + "" + "Today" + "" + "
\n" + "
\n"; oPopup.className = 'dialogDiv calPopDialog'; oPopup.innerHTML = str_buffer; if (relativePosition !== '') { g_objPickerRelativePos = eval(relativePosition); } else { g_objPickerRelativePos = eval(str_target); } g_objPicker = null; doPositionPicker(); g_showPickerTimer = setTimeout(asyncShowPicker, 1); ConsoleLogging.logBlockClose(); }