Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / Calendar.js @ 9

History | View | Annotate | Download (11.1 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dijit.Calendar"]){
9
dojo._hasResource["dijit.Calendar"]=true;
10
dojo.provide("dijit.Calendar");
11
dojo.require("dojo.cldr.supplemental");
12
dojo.require("dojo.date");
13
dojo.require("dojo.date.locale");
14
dojo.require("dijit._Widget");
15
dojo.require("dijit._Templated");
16
dojo.require("dijit._CssStateMixin");
17
dojo.declare("dijit.Calendar",[dijit._Widget,dijit._Templated,dijit._CssStateMixin],{templateString:dojo.cache("dijit","templates/Calendar.html","<table cellspacing=\"0\" cellpadding=\"0\" class=\"dijitCalendarContainer\" role=\"grid\" dojoAttachEvent=\"onkeypress: _onKeyPress\">\n\t<thead>\n\t\t<tr class=\"dijitReset dijitCalendarMonthContainer\" valign=\"top\">\n\t\t\t<th class='dijitReset dijitCalendarArrow' dojoAttachPoint=\"decrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarDecrease\" waiRole=\"presentation\"/>\n\t\t\t\t<span dojoAttachPoint=\"decreaseArrowNode\" class=\"dijitA11ySideArrow\">-</span>\n\t\t\t</th>\n\t\t\t<th class='dijitReset' colspan=\"5\">\n\t\t\t\t<div class=\"dijitVisible\">\n\t\t\t\t\t<div class=\"dijitPopup dijitMenu dijitMenuPassive dijitHidden\" dojoAttachPoint=\"monthDropDown\" dojoAttachEvent=\"onmouseup: _onMonthSelect, onmouseover: _onMenuHover, onmouseout: _onMenuHover\">\n\t\t\t\t\t\t<div class=\"dijitCalendarMonthLabelTemplate dijitCalendarMonthLabel\"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div dojoAttachPoint=\"monthLabelSpacer\" class=\"dijitSpacer\"></div>\n\t\t\t\t<div dojoAttachPoint=\"monthLabelNode\" class=\"dijitCalendarMonthLabel dijitInline dijitVisible\" dojoAttachEvent=\"onmousedown: _onMonthToggle\"></div>\n\t\t\t</th>\n\t\t\t<th class='dijitReset dijitCalendarArrow' dojoAttachPoint=\"incrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarIncrease\" waiRole=\"presentation\"/>\n\t\t\t\t<span dojoAttachPoint=\"increaseArrowNode\" class=\"dijitA11ySideArrow\">+</span>\n\t\t\t</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th class=\"dijitReset dijitCalendarDayLabelTemplate\" role=\"columnheader\"><span class=\"dijitCalendarDayLabel\"></span></th>\n\t\t</tr>\n\t</thead>\n\t<tbody dojoAttachEvent=\"onclick: _onDayClick, onmouseover: _onDayMouseOver, onmouseout: _onDayMouseOut, onmousedown: _onDayMouseDown, onmouseup: _onDayMouseUp\" class=\"dijitReset dijitCalendarBodyContainer\">\n\t\t<tr class=\"dijitReset dijitCalendarWeekTemplate\" role=\"row\">\n\t\t\t<td class=\"dijitReset dijitCalendarDateTemplate\" role=\"gridcell\"><span class=\"dijitCalendarDateLabel\"></span></td>\n\t\t</tr>\n\t</tbody>\n\t<tfoot class=\"dijitReset dijitCalendarYearContainer\">\n\t\t<tr>\n\t\t\t<td class='dijitReset' valign=\"top\" colspan=\"7\">\n\t\t\t\t<h3 class=\"dijitCalendarYearLabel\">\n\t\t\t\t\t<span dojoAttachPoint=\"previousYearLabelNode\" class=\"dijitInline dijitCalendarPreviousYear\"></span>\n\t\t\t\t\t<span dojoAttachPoint=\"currentYearLabelNode\" class=\"dijitInline dijitCalendarSelectedYear\"></span>\n\t\t\t\t\t<span dojoAttachPoint=\"nextYearLabelNode\" class=\"dijitInline dijitCalendarNextYear\"></span>\n\t\t\t\t</h3>\n\t\t\t</td>\n\t\t</tr>\n\t</tfoot>\n</table>\n"),value:new Date(),datePackage:"dojo.date",dayWidth:"narrow",tabIndex:"0",baseClass:"dijitCalendar",cssStateNodes:{"decrementMonth":"dijitCalendarArrow","incrementMonth":"dijitCalendarArrow","previousYearLabelNode":"dijitCalendarPreviousYear","nextYearLabelNode":"dijitCalendarNextYear"},attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{tabIndex:"domNode"}),setValue:function(_1){
18
dojo.deprecated("dijit.Calendar:setValue() is deprecated.  Use set('value', ...) instead.","","2.0");
19
this.set("value",_1);
20
},_getValueAttr:function(){
21
var _2=new this.dateClassObj(this.value);
22
_2.setHours(0,0,0,0);
23
if(_2.getDate()<this.value.getDate()){
24
_2=this.dateFuncObj.add(_2,"hour",1);
25
}
26
return _2;
27
},_setValueAttr:function(_3){
28
if(!this.value||this.dateFuncObj.compare(_3,this.value)){
29
_3=new this.dateClassObj(_3);
30
_3.setHours(1);
31
this.displayMonth=new this.dateClassObj(_3);
32
if(!this.isDisabledDate(_3,this.lang)){
33
this.value=_3;
34
this.onChange(this.get("value"));
35
}
36
dojo.attr(this.domNode,"aria-label",this.dateLocaleModule.format(_3,{selector:"date",formatLength:"full"}));
37
this._populateGrid();
38
}
39
},_setText:function(_4,_5){
40
while(_4.firstChild){
41
_4.removeChild(_4.firstChild);
42
}
43
_4.appendChild(dojo.doc.createTextNode(_5));
44
},_populateGrid:function(){
45
var _6=this.displayMonth;
46
_6.setDate(1);
47
var _7=_6.getDay(),_8=this.dateFuncObj.getDaysInMonth(_6),_9=this.dateFuncObj.getDaysInMonth(this.dateFuncObj.add(_6,"month",-1)),_a=new this.dateClassObj(),_b=dojo.cldr.supplemental.getFirstDayOfWeek(this.lang);
48
if(_b>_7){
49
_b-=7;
50
}
51
dojo.query(".dijitCalendarDateTemplate",this.domNode).forEach(function(_c,i){
52
i+=_b;
53
var _d=new this.dateClassObj(_6),_e,_f="dijitCalendar",adj=0;
54
if(i<_7){
55
_e=_9-_7+i+1;
56
adj=-1;
57
_f+="Previous";
58
}else{
59
if(i>=(_7+_8)){
60
_e=i-_7-_8+1;
61
adj=1;
62
_f+="Next";
63
}else{
64
_e=i-_7+1;
65
_f+="Current";
66
}
67
}
68
if(adj){
69
_d=this.dateFuncObj.add(_d,"month",adj);
70
}
71
_d.setDate(_e);
72
if(!this.dateFuncObj.compare(_d,_a,"date")){
73
_f="dijitCalendarCurrentDate "+_f;
74
}
75
if(this._isSelectedDate(_d,this.lang)){
76
_f="dijitCalendarSelectedDate "+_f;
77
}
78
if(this.isDisabledDate(_d,this.lang)){
79
_f="dijitCalendarDisabledDate "+_f;
80
}
81
var _10=this.getClassForDate(_d,this.lang);
82
if(_10){
83
_f=_10+" "+_f;
84
}
85
_c.className=_f+"Month dijitCalendarDateTemplate";
86
_c.dijitDateValue=_d.valueOf();
87
var _11=dojo.query(".dijitCalendarDateLabel",_c)[0],_12=_d.getDateLocalized?_d.getDateLocalized(this.lang):_d.getDate();
88
this._setText(_11,_12);
89
},this);
90
var _13=this.dateLocaleModule.getNames("months","wide","standAlone",this.lang,_6);
91
this._setText(this.monthLabelNode,_13[_6.getMonth()]);
92
dojo.query(".dijitCalendarMonthLabelTemplate",this.domNode).forEach(function(_14,i){
93
dojo.toggleClass(_14,"dijitHidden",!(i in _13));
94
this._setText(_14,_13[i]);
95
},this);
96
var y=_6.getFullYear()-1;
97
var d=new this.dateClassObj();
98
dojo.forEach(["previous","current","next"],function(_15){
99
d.setFullYear(y++);
100
this._setText(this[_15+"YearLabelNode"],this.dateLocaleModule.format(d,{selector:"year",locale:this.lang}));
101
},this);
102
var _16=this;
103
var _17=function(_18,_19,adj){
104
_16._connects.push(dijit.typematic.addMouseListener(_16[_18],_16,function(_1a){
105
if(_1a>=0){
106
_16._adjustDisplay(_19,adj);
107
}
108
},0.8,500));
109
};
110
_17("incrementMonth","month",1);
111
_17("decrementMonth","month",-1);
112
_17("nextYearLabelNode","year",1);
113
_17("previousYearLabelNode","year",-1);
114
},goToToday:function(){
115
this.set("value",new this.dateClassObj());
116
},constructor:function(_1b){
117
var _1c=(_1b.datePackage&&(_1b.datePackage!="dojo.date"))?_1b.datePackage+".Date":"Date";
118
this.dateClassObj=dojo.getObject(_1c,false);
119
this.datePackage=_1b.datePackage||this.datePackage;
120
this.dateFuncObj=dojo.getObject(this.datePackage,false);
121
this.dateLocaleModule=dojo.getObject(this.datePackage+".locale",false);
122
},postMixInProperties:function(){
123
if(isNaN(this.value)){
124
delete this.value;
125
}
126
this.inherited(arguments);
127
},postCreate:function(){
128
this.inherited(arguments);
129
dojo.setSelectable(this.domNode,false);
130
var _1d=dojo.hitch(this,function(_1e,n){
131
var _1f=dojo.query(_1e,this.domNode)[0];
132
for(var i=0;i<n;i++){
133
_1f.parentNode.appendChild(_1f.cloneNode(true));
134
}
135
});
136
_1d(".dijitCalendarDayLabelTemplate",6);
137
_1d(".dijitCalendarDateTemplate",6);
138
_1d(".dijitCalendarWeekTemplate",5);
139
var _20=this.dateLocaleModule.getNames("days",this.dayWidth,"standAlone",this.lang);
140
var _21=dojo.cldr.supplemental.getFirstDayOfWeek(this.lang);
141
dojo.query(".dijitCalendarDayLabel",this.domNode).forEach(function(_22,i){
142
this._setText(_22,_20[(i+_21)%7]);
143
},this);
144
var _23=new this.dateClassObj(this.value);
145
var _24=this.dateLocaleModule.getNames("months","wide","standAlone",this.lang,_23);
146
_1d(".dijitCalendarMonthLabelTemplate",_24.length-1);
147
dojo.query(".dijitCalendarMonthLabelTemplate",this.domNode).forEach(function(_25,i){
148
dojo.attr(_25,"month",i);
149
if(i in _24){
150
this._setText(_25,_24[i]);
151
}
152
dojo.place(_25.cloneNode(true),this.monthLabelSpacer);
153
},this);
154
this.value=null;
155
this.set("value",_23);
156
},_onMenuHover:function(e){
157
dojo.stopEvent(e);
158
dojo.toggleClass(e.target,"dijitMenuItemHover");
159
},_adjustDisplay:function(_26,_27){
160
this.displayMonth=this.dateFuncObj.add(this.displayMonth,_26,_27);
161
this._populateGrid();
162
},_onMonthToggle:function(evt){
163
dojo.stopEvent(evt);
164
if(evt.type=="mousedown"){
165
var _28=dojo.position(this.monthLabelNode);
166
var dim={width:_28.w+"px",top:-this.displayMonth.getMonth()*_28.h+"px"};
167
if((dojo.isIE&&dojo.isQuirks)||dojo.isIE<7){
168
dim.left=-_28.w/2+"px";
169
}
170
dojo.style(this.monthDropDown,dim);
171
this._popupHandler=this.connect(document,"onmouseup","_onMonthToggle");
172
}else{
173
this.disconnect(this._popupHandler);
174
delete this._popupHandler;
175
}
176
dojo.toggleClass(this.monthDropDown,"dijitHidden");
177
dojo.toggleClass(this.monthLabelNode,"dijitVisible");
178
},_onMonthSelect:function(evt){
179
this._onMonthToggle(evt);
180
this.displayMonth.setMonth(dojo.attr(evt.target,"month"));
181
this._populateGrid();
182
},_onDayClick:function(evt){
183
dojo.stopEvent(evt);
184
for(var _29=evt.target;_29&&!_29.dijitDateValue;_29=_29.parentNode){
185
}
186
if(_29&&!dojo.hasClass(_29,"dijitCalendarDisabledDate")){
187
this.set("value",_29.dijitDateValue);
188
this.onValueSelected(this.get("value"));
189
}
190
},_onDayMouseOver:function(evt){
191
var _2a=dojo.hasClass(evt.target,"dijitCalendarDateLabel")?evt.target.parentNode:evt.target;
192
if(_2a&&(_2a.dijitDateValue||_2a==this.previousYearLabelNode||_2a==this.nextYearLabelNode)){
193
dojo.addClass(_2a,"dijitCalendarHoveredDate");
194
this._currentNode=_2a;
195
}
196
},_onDayMouseOut:function(evt){
197
if(!this._currentNode){
198
return;
199
}
200
if(evt.relatedTarget&&evt.relatedTarget.parentNode==this._currentNode){
201
return;
202
}
203
dojo.removeClass(this._currentNode,"dijitCalendarHoveredDate");
204
if(dojo.hasClass(this._currentNode,"dijitCalendarActiveDate")){
205
dojo.removeClass(this._currentNode,"dijitCalendarActiveDate");
206
}
207
this._currentNode=null;
208
},_onDayMouseDown:function(evt){
209
var _2b=evt.target.parentNode;
210
if(_2b&&_2b.dijitDateValue){
211
dojo.addClass(_2b,"dijitCalendarActiveDate");
212
this._currentNode=_2b;
213
}
214
},_onDayMouseUp:function(evt){
215
var _2c=evt.target.parentNode;
216
if(_2c&&_2c.dijitDateValue){
217
dojo.removeClass(_2c,"dijitCalendarActiveDate");
218
}
219
},_onKeyPress:function(evt){
220
var dk=dojo.keys,_2d=-1,_2e,_2f=this.value;
221
switch(evt.keyCode){
222
case dk.RIGHT_ARROW:
223
_2d=1;
224
case dk.LEFT_ARROW:
225
_2e="day";
226
if(!this.isLeftToRight()){
227
_2d*=-1;
228
}
229
break;
230
case dk.DOWN_ARROW:
231
_2d=1;
232
case dk.UP_ARROW:
233
_2e="week";
234
break;
235
case dk.PAGE_DOWN:
236
_2d=1;
237
case dk.PAGE_UP:
238
_2e=evt.ctrlKey?"year":"month";
239
break;
240
case dk.END:
241
_2f=this.dateFuncObj.add(_2f,"month",1);
242
_2e="day";
243
case dk.HOME:
244
_2f=new Date(_2f).setDate(1);
245
break;
246
case dk.ENTER:
247
this.onValueSelected(this.get("value"));
248
break;
249
case dk.ESCAPE:
250
default:
251
return;
252
}
253
dojo.stopEvent(evt);
254
if(_2e){
255
_2f=this.dateFuncObj.add(_2f,_2e,_2d);
256
}
257
this.set("value",_2f);
258
},onValueSelected:function(_30){
259
},onChange:function(_31){
260
},_isSelectedDate:function(_32,_33){
261
return !this.dateFuncObj.compare(_32,this.value,"date");
262
},isDisabledDate:function(_34,_35){
263
},getClassForDate:function(_36,_37){
264
}});
265
}