Added some JavaScript-Code to the date selector which handles clicks on the "Today" button

This commit is contained in:
Andreas Stöckel 2010-05-18 09:17:54 +00:00
parent 7ab47224c9
commit 95891c869f
2 changed files with 50 additions and 0 deletions

View File

@ -180,6 +180,43 @@ function dateChanged(calendar) {
window.location = "'.$url.'&date=" + calendar.date.print("%Y%m%d"); window.location = "'.$url.'&date=" + calendar.date.print("%Y%m%d");
} }
}; };
function todayClicked(calendar) {
var parts = window.location.search.split("&");
var newsearch = "";
var hasdate = false;
/* Assemble the new search string, if the "date" property is found, replace its value
with the current date */
for (i = 0; i < parts.length; i++)
{
var split = parts[i].split("=");
if (split[0] && split[0] == "date") {
split[1] = "'.date('Ymd').'";
hasdate = true;
}
if (split[1])
newsearch += split[0] + "=" + split[1];
else
newsearch += split[0];
if (i < parts.length - 1)
newsearch += "&"
}
/* If the date property hasn\'t been found, add it to the search string */
if (!hasdate) {
if (parts.length == 0)
newsearch = "?";
else
newsearch += "&";
newsearch += "date='.date('Ymd').'";
}
window.location.search = newsearch;
}
'.($weekUrl ? ' '.($weekUrl ? '
function weekClicked(calendar,weekstart) { function weekClicked(calendar,weekstart) {
window.location = "'.$weekUrl.'&date=" + weekstart.print("%Y%m%d"); window.location = "'.$weekUrl.'&date=" + weekstart.print("%Y%m%d");
@ -198,6 +235,7 @@ function monthClicked(calendar,monthstart) {
flatWeekTTip : "'.addslashes($weekTTip).'"' : '').($monthUrl ? ', flatWeekTTip : "'.addslashes($weekTTip).'"' : '').($monthUrl ? ',
flatMonthCallback : monthClicked' : '').($monthTTip ? ', flatMonthCallback : monthClicked' : '').($monthTTip ? ',
flatMonthTTip : "'.addslashes($monthTTip).'"' : '').($date ? ', flatMonthTTip : "'.addslashes($monthTTip).'"' : '').($date ? ',
flatTodayCallback : todayClicked,
date : "'.$date.'" date : "'.$date.'"
' : '').' ' : '').'
} }

View File

@ -693,6 +693,7 @@ Calendar.cellClick = function(el, ev) {
return; return;
case 0: case 0:
// TODAY will bring us here // TODAY will bring us here
cal.callTodayHandler();
if ((typeof cal.getDateStatus == "function") && cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) { if ((typeof cal.getDateStatus == "function") && cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) {
// remember, "date" was previously set to new // remember, "date" was previously set to new
// Date() if TODAY was clicked; thus, it // Date() if TODAY was clicked; thus, it
@ -1251,6 +1252,17 @@ Calendar.prototype.callMonthHandler = function () {
} }
}; };
/** Calls the today-clicked user handler (selectedHandler) */
Calendar.prototype.hasTodayHandler = function () {
return this.params && this.params.flat && this.params.flatTodayCallback;
}
Calendar.prototype.callTodayHandler = function () {
if (this.hasTodayHandler()) {
this.params.flatTodayCallback(this);
}
}
/** Calls the second user handler (closeHandler). */ /** Calls the second user handler (closeHandler). */
Calendar.prototype.callCloseHandler = function () { Calendar.prototype.callCloseHandler = function () {
if (this.onClose) { if (this.onClose) {