From ec94093f6eceda0361425089152cb6fb4e34f990 Mon Sep 17 00:00:00 2001 From: Keith Wood Date: Sun, 6 Jul 2008 05:31:06 +0000 Subject: [PATCH] Added gotoCurrent setting to show currently selected date instead of today Fixed positioning for right-to-left languages --- ui/ui.datepicker.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index a14327ec4..d021e3839 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -80,6 +80,7 @@ function Datepicker() { hideIfNoPrevNext: false, // True to hide next/previous month links // if not applicable, false to just disable them 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 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, @@ -512,7 +513,7 @@ $.extend(Datepicker.prototype, { var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; // 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), pos[0] + (inst.input ? inst.input.width() : 0) - (isFixed ? scrollX : 0) - inst.dpDiv.width() - (isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)); @@ -607,10 +608,17 @@ $.extend(Datepicker.prototype, { _gotoToday: function(id) { var target = $(id); 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(); inst.selectedDay = date.getDate(); inst.drawMonth = inst.selectedMonth = date.getMonth(); inst.drawYear = inst.selectedYear = date.getFullYear(); + } this._adjustDate(target); this._notifyChange(inst); }, @@ -1197,7 +1205,8 @@ $.extend(Datepicker.prototype, { var html = (prompt ? '
' + prompt + '
' : '') + (closeAtTop && !inst.inline ? controls : '') + '