Author: pyaschenko
Date: 2007-11-26 10:06:19 -0500 (Mon, 26 Nov 2007)
New Revision: 4261
Modified:
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
Log:
RF-1414
Modified:
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js
===================================================================
---
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-11-26
14:22:43 UTC (rev 4260)
+++
trunk/ui/calendar/src/main/resources/org/richfaces/renderkit/html/scripts/calendar.js 2007-11-26
15:06:19 UTC (rev 4261)
@@ -254,125 +254,123 @@
* Date:
* d - 1-31
* dd+ - 01-31 */
-Object.extend(Date, {
- getDefaultMonthNames: function(shortNames)
- {
- return (shortNames
- ?
['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
- :
['January','February','March','April','May','June','July','August','September','October','November','December']);
- },
+Richfaces.Calendar.getDefaultMonthNames = function(shortNames)
+{
+ return (shortNames
+ ?
['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
+ :
['January','February','March','April','May','June','July','August','September','October','November','December']);
+};
+
+Richfaces.Calendar.parseDate = function(dateString, pattern, monthNames,
monthNamesShort)
+{
+ if (!monthNames) monthNames = Richfaces.Calendar.getDefaultMonthNames();
+ if (!monthNamesShort) monthNamesShort = Richfaces.Calendar.getDefaultMonthNames(true);
- parseDate: function(dateString, pattern, monthNames, monthNamesShort)
- {
- if (!monthNames) monthNames = Date.getDefaultMonthNames();
- if (!monthNamesShort) monthNamesShort = Date.getDefaultMonthNames(true);
-
- var counter=1;
- var y,m,d;
- var a,h,min;
- var shortLabel=false;
-
- pattern = pattern.replace(/([.*+?^<>=!:${}()|[\]\/\\])/g, '\\$1');
- pattern = pattern.replace(/(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
- function($1) {
- switch ($1) {
- case 'y' :
- case 'yy' : y=counter; counter++; return '(\\d{2})';
- case 'MM' : m=counter; counter++; return '(\\d{2})';
- case 'M' : m=counter; counter++; return '(\\d{1,2})';
- case 'd' : d=counter; counter++; return '(\\d{1,2})';
- case 'MMM': m=counter; counter++; shortLabel=true; return
'('+monthNamesShort.join('|')+')';
- case 'a' : a=counter; counter++; return '(AM|am|PM|pm)?';
- case 'HH' :
- case 'hh' : h=counter; counter++; return '(\\d{2})?';
- case 'H' :
- case 'h' : h=counter; counter++; return '(\\d{1,2})?';
- case 'mm' : min=counter; counter++; return '(\\d{2})?';
- }
- // y+,M+,d+
- var ch = $1.charAt(0);
- if (ch=='y') {y=counter; counter++; return '(\\d{4})'};
- if (ch=='M') {m=counter; counter++; return
'('+monthNames.join('|')+')'};
- if (ch=='d') {d=counter; counter++; return '(\\d{2})'};
+ var counter=1;
+ var y,m,d;
+ var a,h,min;
+ var shortLabel=false;
+
+ pattern = pattern.replace(/([.*+?^<>=!:${}()|[\]\/\\])/g, '\\$1');
+ pattern = pattern.replace(/(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
+ function($1) {
+ switch ($1) {
+ case 'y' :
+ case 'yy' : y=counter; counter++; return '(\\d{2})';
+ case 'MM' : m=counter; counter++; return '(\\d{2})';
+ case 'M' : m=counter; counter++; return '(\\d{1,2})';
+ case 'd' : d=counter; counter++; return '(\\d{1,2})';
+ case 'MMM': m=counter; counter++; shortLabel=true; return
'('+monthNamesShort.join('|')+')';
+ case 'a' : a=counter; counter++; return '(AM|am|PM|pm)?';
+ case 'HH' :
+ case 'hh' : h=counter; counter++; return '(\\d{2})?';
+ case 'H' :
+ case 'h' : h=counter; counter++; return '(\\d{1,2})?';
+ case 'mm' : min=counter; counter++; return '(\\d{2})?';
}
- );
-
- var re = new RegExp(pattern,'i');
- var match = dateString.match(re);
- if (match!=null)
- {
- var yy = parseInt(match[y],10); if (isNaN(yy)) return null; else if (yy<70)
yy+=2000; else if (yy<100) yy+=1900;
- var mm = parseInt(match[m],10); if (isNaN(mm)) mm =
Richfaces.Calendar.getMonthByLabel(match[m], shortLabel ? monthNamesShort : monthNames);
else if (--mm<0 || mm>11) return null;
- var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>daysInMonth(yy, mm))
return null;
+ // y+,M+,d+
+ var ch = $1.charAt(0);
+ if (ch=='y') {y=counter; counter++; return '(\\d{4})'};
+ if (ch=='M') {m=counter; counter++; return
'('+monthNames.join('|')+')'};
+ if (ch=='d') {d=counter; counter++; return '(\\d{2})'};
+ }
+ );
+
+ var re = new RegExp(pattern,'i');
+ var match = dateString.match(re);
+ if (match!=null)
+ {
+ var yy = parseInt(match[y],10); if (isNaN(yy)) return null; else if (yy<70)
yy+=2000; else if (yy<100) yy+=1900;
+ var mm = parseInt(match[m],10); if (isNaN(mm)) mm =
Richfaces.Calendar.getMonthByLabel(match[m], shortLabel ? monthNamesShort : monthNames);
else if (--mm<0 || mm>11) return null;
+ var dd = parseInt(match[d],10); if (isNaN(dd) || dd<1 || dd>daysInMonth(yy, mm))
return null;
- // time parsing
- if (min!=undefined && h!=undefined)
- {
- var hh,mmin,aa;
- mmin = parseInt(match[min],10); if (isNaN(mmin) || mmin<0 || mmin>59) return
null;
- hh = parseInt(match[h],10); if (isNaN(hh)) return null;
- if (a!=undefined)
+ // time parsing
+ if (min!=undefined && h!=undefined)
+ {
+ var hh,mmin,aa;
+ mmin = parseInt(match[min],10); if (isNaN(mmin) || mmin<0 || mmin>59) return
null;
+ hh = parseInt(match[h],10); if (isNaN(hh)) return null;
+ if (a!=undefined)
+ {
+ aa = match[a].toLowerCase();
+ if ((aa!='am' && aa!='pm') || hh<1 || hh>12) return
null;
+ if (aa=='pm')
{
- aa = match[a].toLowerCase();
- if ((aa!='am' && aa!='pm') || hh<1 || hh>12) return
null;
- if (aa=='pm')
- {
- if (hh!=12) hh+=11;
- } else if (hh==12) hh = 0;
- }
- else if (hh<0 || hh>23) return null;
+ if (hh!=12) hh+=11;
+ } else if (hh==12) hh = 0;
+ }
+ else if (hh<0 || hh>23) return null;
- return new Date(yy, mm, dd, hh, mmin, 0);
+ return new Date(yy, mm, dd, hh, mmin, 0);
+ }
+
+ return new Date(yy, mm, dd);
+ }
+ return null;
+};
+
+Richfaces.Calendar.formatDate = function(date, pattern, monthNames, monthNamesShort) {
+ if (!monthNames) monthNames = Richfaces.Calendar.getDefaultMonthNames();
+ if (!monthNamesShort) monthNamesShort = Richfaces.Calendar.getDefaultMonthNames(true);
+ var mm; var dd; var hh;
+ var result = pattern.replace(/(^|[^\\yMdHhm])(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
+ function($1,$2,$3) {
+ switch ($3) {
+ case 'y':
+ case 'yy': return $2+date.getYear().toString().slice(-2);
+ case 'M': return $2+(date.getMonth()+1);
+ case 'MM': return $2+((mm = date.getMonth()+1)<10 ?
'0'+mm : mm);
+ case 'MMM': return $2+monthNamesShort[date.getMonth()];
+ case 'd': return $2+date.getDate();
+ case 'a' : return $2+(date.getHours()<12 ? 'AM' :
'PM');
+ case 'HH' : return $2+((hh = date.getHours())<10 ? '0'+hh
: hh);
+ case 'H' : return $2+date.getHours();
+ case 'hh' : return $2+((hh = date.getHours())==0 ? '12' :
(hh<10 ? '0'+hh : (hh>12 ? hh-12 : hh)));
+ case 'h' : return $2+((hh = date.getHours())==0 ? '12' :
(hh>12 ? hh-12 : hh));
+ case 'mm' : return $2+((min = date.getMinutes())<10 ?
'0'+min : min);
}
-
- return new Date(yy, mm, dd);
+ // y+,M+,d+
+ var ch = $3.charAt(0);
+ if (ch=='y') return $2+date.getFullYear();
+ if (ch=='M') return $2+monthNames[date.getMonth()];
+ if (ch=='d') return $2+((dd = date.getDate())<10 ? '0'+dd : dd);
}
- return null;
- },
+ );
+ return Richfaces.Calendar.unescape(result);
+};
+
+Richfaces.Calendar.escape = function (str)
+{
+ return str.replace(/([yMdaHhm])/g,"\\$1");
+};
- escape : function (str)
- {
- return str.replace(/([yMdaHhm])/g,"\\$1");
- },
-
- unescape : function (str)
- {
- return str.replace(/\\([yMdaHhm])/g,"$1");
- }
-});
-Object.extend(Date.prototype, {
-
- format : function(pattern, monthNames, monthNamesShort) {
- if (!monthNames) monthNames = Date.getDefaultMonthNames();
- if (!monthNamesShort) monthNamesShort = Date.getDefaultMonthNames(true);
- var d = this; var mm; var dd; var hh;
- var result = pattern.replace(/(^|[^\\yMdHhm])(y+|M+|d+|a|H{1,2}|h{1,2}|m{2})/g,
- function($1,$2,$3) {
- switch ($3) {
- case 'y':
- case 'yy': return $2+d.getYear().toString().slice(-2);
- case 'M': return $2+(d.getMonth()+1);
- case 'MM': return $2+((mm = d.getMonth()+1)<10 ? '0'+mm
: mm);
- case 'MMM': return $2+monthNamesShort[d.getMonth()];
- case 'd': return $2+d.getDate();
- case 'a' : return $2+(d.getHours()<12 ? 'AM' :
'PM');
- case 'HH' : return $2+((hh = d.getHours())<10 ? '0'+hh :
hh);
- case 'H' : return $2+d.getHours();
- case 'hh' : return $2+((hh = d.getHours())==0 ? '12' :
(hh<10 ? '0'+hh : (hh>12 ? hh-12 : hh)));
- case 'h' : return $2+((hh = d.getHours())==0 ? '12' :
(hh>12 ? hh-12 : hh));
- case 'mm' : return $2+((min = d.getMinutes())<10 ?
'0'+min : min);
- }
- // y+,M+,d+
- var ch = $3.charAt(0);
- if (ch=='y') return $2+d.getFullYear();
- if (ch=='M') return $2+monthNames[d.getMonth()];
- if (ch=='d') return $2+((dd = d.getDate())<10 ? '0'+dd : dd);
- }
- );
- return Date.unescape(result);
- }
-});
+Richfaces.Calendar.unescape = function (str)
+{
+ return str.replace(/\\([yMdaHhm])/g,"$1");
+};
+
+
function isLeapYear(year) {
return new Date(year, 1, 29).getDate()==29;
}
@@ -554,7 +552,7 @@
}
var htmlTextHeader = (!this.params.popup ? '<input
id="'+this.INPUT_DATE_ID+'"
name="'+this.INPUT_DATE_ID+'" type="hidden"
style="display:none"
value="'+this.getSelectedDateString(this.params.datePattern)+'"/>\n'
: '') +
- '<input id="'+this.id+'InputCurrentDate"
name="'+this.id+'InputCurrentDate" type="hidden"
style="display:none"
value="'+this.getCurrentDate().format("MM/yyyy")+'"/>\n'
+
+ '<input id="'+this.id+'InputCurrentDate"
name="'+this.id+'InputCurrentDate" type="hidden"
style="display:none"
value="'+Richfaces.Calendar.formatDate(this.getCurrentDate(),"MM/yyyy")+'"/>\n'
+
(this.params.popup && Richfaces.browser.isIE6 ? '<iframe
src="javascript:\'\'" frameborder="0" scrolling="no"
id="' + this.IFRAME_ID + '" style="display:none; position:
absolute; width: 1px; height: 1px;
background-color:white;">'+'</iframe>\n' : '' )+
'<table id="'+this.id+'" border="0"
cellpadding="0" cellspacing="0" class="rich-calendar-exterior
rich-calendar-popup'+(this.params.className ? ' '+this.params.className :
'')+'"
style="'+popupStyles+this.params.style+'"><tbody>\n';
var colspan = (this.params.showWeeksBar ? "8" : "7");
@@ -913,7 +911,7 @@
getSelectedDateString: function(pattern) {
if (!this.selectedDate) return "";
if (!pattern) pattern = this.params.datePattern;
- return this.selectedDate.format(pattern, this.params.monthLabels,
this.params.monthLabelsShort);
+ return Richfaces.Calendar.formatDate(this.selectedDate, pattern,
this.params.monthLabels, this.params.monthLabelsShort);
},
getPrevYear: function() {
@@ -1440,7 +1438,7 @@
onUpdate: function()
{
- var formattedDate = this.getCurrentDate().format("MM/yyyy");
+ var formattedDate =
Richfaces.Calendar.formatDate(this.getCurrentDate(),"MM/yyyy");
$(this.id+'InputCurrentDate').value=formattedDate;
if (this.submitFunction)
@@ -1524,7 +1522,7 @@
var newSelectedDate;
if (date)
{
- if (typeof date=='string') date = Date.parseDate(date,this.params.datePattern,
this.params.monthLabels, this.params.monthLabelsShort);
+ if (typeof date=='string') date =
Richfaces.Calendar.parseDate(date,this.params.datePattern, this.params.monthLabels,
this.params.monthLabelsShort);
newSelectedDate = date;
}
else
@@ -1715,7 +1713,7 @@
if (!calendar.selectedDate || calendar.showApplyButton) return "";
- var text = calendar.selectedDate.format( (calendar.timeType ? calendar.datePattern :
calendar.params.datePattern), calendar.params.monthLabels,
calendar.params.monthLabelsShort);
+ var text = Richfaces.Calendar.formatDate(calendar.selectedDate,(calendar.timeType ?
calendar.datePattern : calendar.params.datePattern), calendar.params.monthLabels,
calendar.params.monthLabelsShort);
var markup = new E('div', {'class': 'rich-calendar-btn',
'style': 'white-space:nowrap', 'onclick':
"Richfaces.getComponent('calendar',this).showSelectedDate(); return
true;"}, [new ET(text)]);
@@ -1726,7 +1724,7 @@
if (!calendar.selectedDate || !calendar.timeType) return "";
- var text = calendar.selectedDate.format( calendar.timePattern,
calendar.params.monthLabels, calendar.params.monthLabelsShort);
+ var text = Richfaces.Calendar.formatDate(calendar.selectedDate, calendar.timePattern,
calendar.params.monthLabels, calendar.params.monthLabelsShort);
var markup = new E('div', {'class': 'rich-calendar-btn
rich-calendar-time', 'style': 'white-space:nowrap', 'onclick':
"Richfaces.getComponent('calendar',this).showTimeEditor(this);return
true;"}, [new ET(text)]);
@@ -1737,7 +1735,7 @@
CalendarView.previousYearControl = CalendarView.getControl("<<",
"prevYear");
CalendarView.nextMonthControl = CalendarView.getControl(">",
"nextMonth");
CalendarView.previousMonthControl = CalendarView.getControl("<",
"prevMonth");
-CalendarView.currentMonthControl = function (context) { return
context.calendar.getCurrentDate().format("MMMM, yyyy", context.monthLabels,
context.monthLabelsShort);};
+CalendarView.currentMonthControl = function (context) { return
Richfaces.Calendar.formatDate(context.calendar.getCurrentDate(), "MMMM, yyyy",
context.monthLabels, context.monthLabelsShort);};
CalendarView.todayControl = CalendarView.getControl("Today",
"today");
CalendarView.selectedDateControl = function (context) { return
CalendarView.getSelectedDateControl(context.calendar);};
CalendarView.timeControl = function (context) { return
CalendarView.getTimeControl(context.calendar);};