Added gotoCurrent setting to show currently selected date instead of today

Fixed positioning for right-to-left languages
This commit is contained in:
Keith Wood 2008-07-06 05:31:06 +00:00
parent 8bbf22585b
commit ec94093f6e

View File

@ -80,6 +80,7 @@ function Datepicker() {
hideIfNoPrevNext: false, // True to hide next/previous month links hideIfNoPrevNext: false, // True to hide next/previous month links
// if not applicable, false to just disable them // if not applicable, false to just disable them
navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
gotoCurrent: false, // True of today link goes back to current selection instead
changeMonth: true, // True if month can be selected directly, false if only prev/next changeMonth: true, // True if month can be selected directly, false if only prev/next
changeYear: true, // True if year can be selected directly, false if only prev/next changeYear: true, // True if year can be selected directly, false if only prev/next
yearRange: '-10:+10', // Range of years to display in drop-down, yearRange: '-10:+10', // Range of years to display in drop-down,
@ -512,7 +513,7 @@ $.extend(Datepicker.prototype, {
var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
// reposition date picker horizontally if outside the browser window // reposition date picker horizontally if outside the browser window
if ((offset.left + inst.dpDiv.width() - scrollX) > browserWidth) if (this._get(inst, 'isRTL') || (offset.left + inst.dpDiv.width() - scrollX) > browserWidth)
offset.left = Math.max((isFixed ? 0 : scrollX), offset.left = Math.max((isFixed ? 0 : scrollX),
pos[0] + (inst.input ? inst.input.width() : 0) - (isFixed ? scrollX : 0) - inst.dpDiv.width() - pos[0] + (inst.input ? inst.input.width() : 0) - (isFixed ? scrollX : 0) - inst.dpDiv.width() -
(isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)); (isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0));
@ -607,10 +608,17 @@ $.extend(Datepicker.prototype, {
_gotoToday: function(id) { _gotoToday: function(id) {
var target = $(id); var target = $(id);
var inst = $.data(target[0], PROP_NAME); var inst = $.data(target[0], PROP_NAME);
if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
inst.selectedDay = inst.currentDay;
inst.drawMonth = inst.selectedMonth = inst.currentMonth;
inst.drawYear = inst.selectedYear = inst.currentYear;
}
else {
var date = new Date(); var date = new Date();
inst.selectedDay = date.getDate(); inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth(); inst.drawMonth = inst.selectedMonth = date.getMonth();
inst.drawYear = inst.selectedYear = date.getFullYear(); inst.drawYear = inst.selectedYear = date.getFullYear();
}
this._adjustDate(target); this._adjustDate(target);
this._notifyChange(inst); this._notifyChange(inst);
}, },
@ -1197,7 +1205,8 @@ $.extend(Datepicker.prototype, {
var html = (prompt ? '<div class="' + this._promptClass + '">' + prompt + '</div>' : '') + var html = (prompt ? '<div class="' + this._promptClass + '">' + prompt + '</div>' : '') +
(closeAtTop && !inst.inline ? controls : '') + (closeAtTop && !inst.inline ? controls : '') +
'<div class="ui-datepicker-links">' + (isRTL ? next : prev) + '<div class="ui-datepicker-links">' + (isRTL ? next : prev) +
(this._isInRange(inst, today) ? '<div class="ui-datepicker-current">' + (this._isInRange(inst, (this._get(inst, 'gotoCurrent') && inst.currentDay ?
currentDate : today)) ? '<div class="ui-datepicker-current">' +
'<a onclick="jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' + '<a onclick="jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' +
(showStatus ? this._addStatus(inst, this._get(inst, 'currentStatus') || '&#xa0;') : '') + '>' + (showStatus ? this._addStatus(inst, this._get(inst, 'currentStatus') || '&#xa0;') : '') + '>' +
currentText + '</a></div>' : '') + (isRTL ? prev : next) + '</div>'; currentText + '</a></div>' : '') + (isRTL ? prev : next) + '</div>';