]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/Calendar.js
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
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");
20 },_getValueAttr:function(){
21 var _2
=new this.dateClassObj(this.value
);
23 if(_2
.getDate()<this.value
.getDate()){
24 _2
=this.dateFuncObj
.add(_2
,"hour",1);
27 },_setValueAttr:function(_3
){
28 if(!this.value
||this.dateFuncObj
.compare(_3
,this.value
)){
29 _3
=new this.dateClassObj(_3
);
31 this.displayMonth
=new this.dateClassObj(_3
);
32 if(!this.isDisabledDate(_3
,this.lang
)){
34 this.onChange(this.get("value"));
36 dojo
.attr(this.domNode
,"aria-label",this.dateLocaleModule
.format(_3
,{selector
:"date",formatLength
:"full"}));
39 },_setText:function(_4
,_5
){
41 _4
.removeChild(_4
.firstChild
);
43 _4
.appendChild(dojo
.doc
.createTextNode(_5
));
44 },_populateGrid:function(){
45 var _6
=this.displayMonth
;
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
);
51 dojo
.query(".dijitCalendarDateTemplate",this.domNode
).forEach(function(_c
,i
){
53 var _d
=new this.dateClassObj(_6
),_e
,_f
="dijitCalendar",adj
=0;
69 _d
=this.dateFuncObj
.add(_d
,"month",adj
);
72 if(!this.dateFuncObj
.compare(_d
,_a
,"date")){
73 _f
="dijitCalendarCurrentDate "+_f
;
75 if(this._isSelectedDate(_d
,this.lang
)){
76 _f
="dijitCalendarSelectedDate "+_f
;
78 if(this.isDisabledDate(_d
,this.lang
)){
79 _f
="dijitCalendarDisabledDate "+_f
;
81 var _10
=this.getClassForDate(_d
,this.lang
);
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
);
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
]);
96 var y
=_6
.getFullYear()-1;
97 var d
=new this.dateClassObj();
98 dojo
.forEach(["previous","current","next"],function(_15
){
100 this._setText(this[_15
+"YearLabelNode"],this.dateLocaleModule
.format(d
,{selector
:"year",locale
:this.lang
}));
103 var _17=function(_18
,_19
,adj
){
104 _16
._connects
.push(dijit
.typematic
.addMouseListener(_16
[_18
],_16
,function(_1a
){
106 _16
._adjustDisplay(_19
,adj
);
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
)){
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));
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]);
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
);
150 this._setText(_25
,_24
[i
]);
152 dojo
.place(_25
.cloneNode(true),this.monthLabelSpacer
);
155 this.set("value",_23
);
156 },_onMenuHover:function(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
){
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";
170 dojo
.style(this.monthDropDown
,dim
);
171 this._popupHandler
=this.connect(document
,"onmouseup","_onMonthToggle");
173 this.disconnect(this._popupHandler
);
174 delete this._popupHandler
;
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
){
184 for(var _29
=evt
.target
;_29
&&!_29
.dijitDateValue
;_29
=_29
.parentNode
){
186 if(_29
&&!dojo
.hasClass(_29
,"dijitCalendarDisabledDate")){
187 this.set("value",_29
.dijitDateValue
);
188 this.onValueSelected(this.get("value"));
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
;
196 },_onDayMouseOut:function(evt
){
197 if(!this._currentNode
){
200 if(evt
.relatedTarget
&&evt
.relatedTarget
.parentNode
==this._currentNode
){
203 dojo
.removeClass(this._currentNode
,"dijitCalendarHoveredDate");
204 if(dojo
.hasClass(this._currentNode
,"dijitCalendarActiveDate")){
205 dojo
.removeClass(this._currentNode
,"dijitCalendarActiveDate");
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
;
214 },_onDayMouseUp:function(evt
){
215 var _2c
=evt
.target
.parentNode
;
216 if(_2c
&&_2c
.dijitDateValue
){
217 dojo
.removeClass(_2c
,"dijitCalendarActiveDate");
219 },_onKeyPress:function(evt
){
220 var dk
=dojo
.keys
,_2d
=-1,_2e
,_2f
=this.value
;
226 if(!this.isLeftToRight()){
238 _2e
=evt
.ctrlKey
?"year":"month";
241 _2f
=this.dateFuncObj
.add(_2f
,"month",1);
244 _2f
=new Date(_2f
).setDate(1);
247 this.onValueSelected(this.get("value"));
255 _2f
=this.dateFuncObj
.add(_2f
,_2e
,_2d
);
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
){