diff options
Diffstat (limited to 'ui/ui.datepicker.js')
-rw-r--r-- | ui/ui.datepicker.js | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index dc54dd94d..99bc8ec93 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -139,13 +139,13 @@ function Datepicker() { $.extend(Datepicker.prototype, { /* Class name added to elements to indicate already configured with a date picker. */ markerClassName: 'hasDatepicker', - + /* Debug logging (if enabled). */ log: function () { if (this.debug) console.log.apply('', arguments); }, - + /* Override the default settings for all instances of the date picker. @param settings object - the new settings to use as defaults (anonymous object) @return the manager object */ @@ -153,7 +153,7 @@ $.extend(Datepicker.prototype, { extendRemove(this._defaults, settings || {}); return this; }, - + /* Attach the date picker to a jQuery selection. @param target element - the target input field or division or span @param settings object - the new settings to use for this date picker instance (anonymous) */ @@ -183,7 +183,7 @@ $.extend(Datepicker.prototype, { this._inlineDatepicker(target, inst); } }, - + /* Create a new instance object. */ _newInst: function(target, inline) { var id = target[0].id.replace(/([:\[\]\.])/g, '\\\\$1'); // escape jQuery meta chars @@ -194,7 +194,7 @@ $.extend(Datepicker.prototype, { dpDiv: (!inline ? this.dpDiv : // presentation div $('<div class="' + this._inlineClass + '"></div>'))}; }, - + /* Attach the date picker to an input field. */ _connectDatepicker: function(target, inst) { var input = $(target); @@ -233,7 +233,7 @@ $.extend(Datepicker.prototype, { }); $.data(target, PROP_NAME, inst); }, - + /* Attach an inline date picker to a div. */ _inlineDatepicker: function(target, inst) { var divSpan = $(target); @@ -250,7 +250,7 @@ $.extend(Datepicker.prototype, { this._updateDatepicker(inst); this._updateAlternate(inst); }, - + /* Pop-up the date picker in a "dialog" box. @param input element - ignored @param dateText string - the initial date to display (in the current format) @@ -274,7 +274,7 @@ $.extend(Datepicker.prototype, { } extendRemove(inst.settings, settings || {}); this._dialogInput.val(dateText); - + this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null); if (!this._pos) { var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; @@ -284,7 +284,7 @@ $.extend(Datepicker.prototype, { this._pos = // should use actual width/height below [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY]; } - + // move input on screen for focus, but hidden behind dialog this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px'); inst.settings.onSelect = onSelect; @@ -296,7 +296,7 @@ $.extend(Datepicker.prototype, { $.data(this._dialogInput[0], PROP_NAME, inst); return this; }, - + /* Detach a datepicker from its control. @param target element - the target input field or division or span */ _destroyDatepicker: function(target) { @@ -316,7 +316,7 @@ $.extend(Datepicker.prototype, { } else if (nodeName == 'div' || nodeName == 'span') $target.removeClass(this.markerClassName).empty(); }, - + /* Enable the date picker to a jQuery selection. @param target element - the target input field or division or span */ _enableDatepicker: function(target) { @@ -338,7 +338,7 @@ $.extend(Datepicker.prototype, { this._disabledInputs = $.map(this._disabledInputs, function(value) { return (value == target ? null : value); }); // delete entry }, - + /* Disable the date picker to a jQuery selection. @param target element - the target input field or division or span */ _disableDatepicker: function(target) { @@ -374,7 +374,7 @@ $.extend(Datepicker.prototype, { function(value) { return (value == target ? null : value); }); // delete entry this._disabledInputs[this._disabledInputs.length] = target; }, - + /* Is the first field in a jQuery collection disabled as a datepicker? @param target element - the target input field or division or span @return boolean - true if disabled, false if enabled */ @@ -387,7 +387,7 @@ $.extend(Datepicker.prototype, { } return false; }, - + /* Retrieve the instance data for the target control. @param target element - the target input field or division or span @return object - the associated instance data @@ -400,7 +400,7 @@ $.extend(Datepicker.prototype, { throw 'Missing instance data for this datepicker'; } }, - + /* Update the settings for a date picker attached to an input field or division. @param target element - the target input field or division or span @param name object - the new settings to update or @@ -429,12 +429,12 @@ $.extend(Datepicker.prototype, { this._updateDatepicker(inst); } }, - + // change method deprecated _changeDatepicker: function(target, name, value) { this._optionDatepicker(target, name, value); }, - + /* Redraw the date picker attached to an input field or division. @param target element - the target input field or division or span */ _refreshDatepicker: function(target) { @@ -443,7 +443,7 @@ $.extend(Datepicker.prototype, { this._updateDatepicker(inst); } }, - + /* Set the dates for a jQuery selection. @param target element - the target input field or division or span @param date Date - the new date @@ -456,7 +456,7 @@ $.extend(Datepicker.prototype, { this._updateAlternate(inst); } }, - + /* Get the date(s) for the first entry in a jQuery selection. @param target element - the target input field or division or span @return Date - the current date or @@ -467,7 +467,7 @@ $.extend(Datepicker.prototype, { this._setDateFromField(inst); return (inst ? this._getDate(inst) : null); }, - + /* Handle keystrokes. */ _doKeyDown: function(event) { var inst = $.datepicker._getInst(event.target); @@ -535,7 +535,7 @@ $.extend(Datepicker.prototype, { event.stopPropagation(); } }, - + /* Filter entered characters - based on date format. */ _doKeyPress: function(event) { var inst = $.datepicker._getInst(event.target); @@ -545,7 +545,7 @@ $.extend(Datepicker.prototype, { return event.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1); } }, - + /* Pop-up the date picker for a given input field. @param input element - the input field attached to the date picker or event - if triggered by focus */ @@ -610,7 +610,7 @@ $.extend(Datepicker.prototype, { $.datepicker._curInst = inst; } }, - + /* Generate the date picker content. */ _updateDatepicker: function(inst) { var dims = {width: inst.dpDiv.width() + 4, @@ -626,7 +626,7 @@ $.extend(Datepicker.prototype, { if (inst.input && inst.input[0].type != 'hidden' && inst == $.datepicker._curInst) $(inst.input[0]).focus(); }, - + /* Check positioning to remain on screen. */ _checkOffset: function(inst, offset, isFixed) { var pos = inst.input ? this._findPos(inst.input[0]) : null; @@ -652,7 +652,7 @@ $.extend(Datepicker.prototype, { offset.top -= (isFixed ? scrollY : 0); return offset; }, - + /* Find an object's position on the screen. */ _findPos: function(obj) { while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) { @@ -661,7 +661,7 @@ $.extend(Datepicker.prototype, { var position = $(obj).offset(); return [position.left, position.top]; }, - + /* Hide the date picker from view. @param input element - the input field attached to the date picker @param duration string - the duration over which to close the date picker */ @@ -706,13 +706,13 @@ $.extend(Datepicker.prototype, { } this._curInst = null; }, - + /* Tidy up after a dialog display. */ _tidyDialog: function(inst) { inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker'); $('.' + this._promptClass, inst.dpDiv).remove(); }, - + /* Close date picker if clicked elsewhere. */ _checkExternalClick: function(event) { if (!$.datepicker._curInst) @@ -724,7 +724,7 @@ $.extend(Datepicker.prototype, { $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI)) $.datepicker._hideDatepicker(null, ''); }, - + /* Adjust one of the date sub-fields. */ _adjustDate: function(id, offset, period) { var target = $(id); @@ -732,7 +732,7 @@ $.extend(Datepicker.prototype, { this._adjustInstDate(inst, offset, period); this._updateDatepicker(inst); }, - + /* Action for current link. */ _gotoToday: function(id) { var target = $(id); @@ -751,7 +751,7 @@ $.extend(Datepicker.prototype, { this._notifyChange(inst); this._adjustDate(target); }, - + /* Action for selecting a new month/year. */ _selectMonthYear: function(id, select, period) { var target = $(id); @@ -763,7 +763,7 @@ $.extend(Datepicker.prototype, { this._notifyChange(inst); this._adjustDate(target); }, - + /* Restore input focus after not changing month/year. */ _clickMonthYear: function(id) { var target = $(id); @@ -772,7 +772,7 @@ $.extend(Datepicker.prototype, { inst.input[0].focus(); inst._selectingMonthYear = !inst._selectingMonthYear; }, - + /* Action for changing the first week day. */ _changeFirstDay: function(id, day) { var target = $(id); @@ -780,7 +780,7 @@ $.extend(Datepicker.prototype, { inst.settings.firstDay = day; this._updateDatepicker(inst); }, - + /* Action for selecting a day. */ _selectDay: function(id, month, year, td) { if ($(td).hasClass(this._unselectableClass)) @@ -822,7 +822,7 @@ $.extend(Datepicker.prototype, { this._updateDatepicker(inst); } }, - + /* Erase the input field and hide the date picker. */ _clearDate: function(id) { var target = $(id); @@ -833,7 +833,7 @@ $.extend(Datepicker.prototype, { inst.endDay = inst.endMonth = inst.endYear = inst.rangeStart = null; this._selectDate(target, ''); }, - + /* Update the input field with the selected date. */ _selectDate: function(id, dateStr) { var target = $(id); @@ -860,7 +860,7 @@ $.extend(Datepicker.prototype, { this._lastInput = null; } }, - + /* Update any alternate field to synchronise with the main field. */ _updateAlternate: function(inst) { var altField = this._get(inst, 'altField'); @@ -875,7 +875,7 @@ $.extend(Datepicker.prototype, { $(altField).each(function() { $(this).val(dateStr); }); } }, - + /* Set as beforeShowDay function to prevent selection of weekends. @param date Date - the date to customise @return [boolean, string] - is this date selectable?, what is its CSS class? */ @@ -883,7 +883,7 @@ $.extend(Datepicker.prototype, { var day = date.getDay(); return [(day > 0 && day < 6), '']; }, - + /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition. @param date Date - the date to get the week for @return number - the number of the week within the year that contains this date */ @@ -903,7 +903,7 @@ $.extend(Datepicker.prototype, { } return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date }, - + /* Provide status text for a particular date. @param date the date to get the status for @param inst the current datepicker instance @@ -912,7 +912,7 @@ $.extend(Datepicker.prototype, { return $.datepicker.formatDate($.datepicker._get(inst, 'dateStatus'), date, $.datepicker._getFormatConfig(inst)); }, - + /* Parse a string value into a date object. See formatDate below for the possible formats. @@ -946,7 +946,7 @@ $.extend(Datepicker.prototype, { var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match); if (matches) iFormat++; - return matches; + return matches; }; // Extract a number from the string value var getNumber = function(match) { @@ -1050,7 +1050,7 @@ $.extend(Datepicker.prototype, { throw 'Invalid date'; // E.g. 31/02/* return date; }, - + /* Standard date formats. */ ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601) COOKIE: 'D, dd M yy', @@ -1063,7 +1063,7 @@ $.extend(Datepicker.prototype, { RSS: 'D, d M y', // RFC 822 TIMESTAMP: '@', W3C: 'yy-mm-dd', // ISO 8601 - + /* Format a date object into a string value. The format can be combinations of the following: d - day of month (no leading zero) @@ -1081,7 +1081,7 @@ $.extend(Datepicker.prototype, { @ - Unix timestamp (ms since 01/01/1970) '...' - literal text '' - single quote - + @param format string - the desired format of the date @param date Date - the date value to format @param settings Object - attributes include: @@ -1102,7 +1102,7 @@ $.extend(Datepicker.prototype, { var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match); if (matches) iFormat++; - return matches; + return matches; }; // Format a number, with leading zero if necessary var formatNumber = function(match, value, len) { @@ -1164,7 +1164,7 @@ $.extend(Datepicker.prototype, { } return output; }, - + /* Extract all possible characters from the date format. */ _possibleChars: function (format) { var chars = ''; @@ -1193,13 +1193,13 @@ $.extend(Datepicker.prototype, { } return chars; }, - + /* Get a setting value, defaulting if necessary. */ _get: function(inst, name) { return inst.settings[name] !== undefined ? inst.settings[name] : this._defaults[name]; }, - + /* Parse existing date and initialise date picker. */ _setDateFromField: function(inst) { var dateFormat = this._get(inst, 'dateFormat'); @@ -1229,7 +1229,7 @@ $.extend(Datepicker.prototype, { inst.currentYear = (dates[0] ? date.getFullYear() : 0); this._adjustInstDate(inst); }, - + /* Retrieve the default date shown on opening. */ _getDefaultDate: function(inst) { var date = this._determineDate(this._get(inst, 'defaultDate'), new Date()); @@ -1239,7 +1239,7 @@ $.extend(Datepicker.prototype, { date = (maxDate && date > maxDate ? maxDate : date); return date; }, - + /* A date may be specified as an exact value or a relative one. */ _determineDate: function(date, defaultDate) { var offsetNumeric = function(offset) { @@ -1327,7 +1327,7 @@ $.extend(Datepicker.prototype, { (!this._get(inst, 'rangeSelect') ? '' : this._get(inst, 'rangeSeparator') + this._formatDate(inst, inst.endDay, inst.endMonth, inst.endYear))); }, - + /* Retrieve the date(s) directly. */ _getDate: function(inst) { var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null : @@ -1340,7 +1340,7 @@ $.extend(Datepicker.prototype, { } else return startDate; }, - + /* Generate the HTML for the current state of the date picker. */ _generateHTML: function(inst) { var today = new Date(); @@ -1535,7 +1535,7 @@ $.extend(Datepicker.prototype, { inst._keyEvent = false; return html; }, - + /* Generate the month and year header. */ _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, selectedDate, secondary, showStatus, initStatus, monthNames) { @@ -1603,7 +1603,7 @@ $.extend(Datepicker.prototype, { html += '</div>'; // Close datepicker_header return html; }, - + /* Provide code to set and clear the status panel. */ _addStatus: function(showStatus, id, text, initStatus) { return (showStatus ? ' onmouseover="jQuery(\'#ui-datepicker-status-' + id + @@ -1611,7 +1611,7 @@ $.extend(Datepicker.prototype, { 'onmouseout="jQuery(\'#ui-datepicker-status-' + id + '\').html(\'' + initStatus + '\');"' : ''); }, - + /* Adjust one of the date sub-fields. */ _adjustInstDate: function(inst, offset, period) { var year = inst.drawYear + (period == 'Y' ? offset : 0); @@ -1630,7 +1630,7 @@ $.extend(Datepicker.prototype, { if (period == 'M' || period == 'Y') this._notifyChange(inst); }, - + /* Notify change of month/year. */ _notifyChange: function(inst) { var onChange = this._get(inst, 'onChangeMonthYear'); @@ -1638,30 +1638,30 @@ $.extend(Datepicker.prototype, { onChange.apply((inst.input ? inst.input[0] : null), [inst.selectedYear, inst.selectedMonth + 1, inst]); }, - + /* Determine the number of months to show. */ _getNumberOfMonths: function(inst) { var numMonths = this._get(inst, 'numberOfMonths'); return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths)); }, - + /* Determine the current maximum date - ensure no time components are set - may be overridden for a range. */ _getMinMaxDate: function(inst, minMax, checkRange) { var date = this._determineDate(this._get(inst, minMax + 'Date'), null); return (!checkRange || !inst.rangeStart ? date : (!date || inst.rangeStart > date ? inst.rangeStart : date)); }, - + /* Find the number of days in a given month. */ _getDaysInMonth: function(year, month) { return 32 - new Date(year, month, 32).getDate(); }, - + /* Find the day of the week of the first of a month. */ _getFirstDayOfMonth: function(year, month) { return new Date(year, month, 1).getDay(); }, - + /* Determines if we should allow a "next/prev" month display change. */ _canAdjustMonth: function(inst, offset, curYear, curMonth) { var numMonths = this._getNumberOfMonths(inst); @@ -1671,7 +1671,7 @@ $.extend(Datepicker.prototype, { date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth())); return this._isInRange(inst, date); }, - + /* Is the given date in the accepted range? */ _isInRange: function(inst, date) { // during range selection, use minimum of selected date and range start @@ -1682,7 +1682,7 @@ $.extend(Datepicker.prototype, { var maxDate = this._getMinMaxDate(inst, 'max'); return ((!minDate || date >= minDate) && (!maxDate || date <= maxDate)); }, - + /* Provide the configuration settings for formatting/parsing. */ _getFormatConfig: function(inst) { var shortYearCutoff = this._get(inst, 'shortYearCutoff'); @@ -1692,7 +1692,7 @@ $.extend(Datepicker.prototype, { dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'), monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')}; }, - + /* Format the given date for display. */ _formatDate: function(inst, day, month, year) { if (!day) { @@ -1727,14 +1727,14 @@ function isArray(a) { Object - settings for attaching new datepicker functionality @return jQuery object */ $.fn.datepicker = function(options){ - + /* Initialise the date picker. */ if (!$.datepicker.initialized) { $(document.body).append($.datepicker.dpDiv). mousedown($.datepicker._checkExternalClick); $.datepicker.initialized = true; } - + var otherArgs = Array.prototype.slice.call(arguments, 1); if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate')) return $.datepicker['_' + options + 'Datepicker']. |