root / trunk / web / dojo / dijit / _TimePicker.js @ 12
History | View | Annotate | Download (8.75 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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._TimePicker"]){ |
||
9 | dojo._hasResource["dijit._TimePicker"]=true; |
||
10 | dojo.provide("dijit._TimePicker");
|
||
11 | dojo.require("dijit.form._FormWidget");
|
||
12 | dojo.require("dojo.date.locale");
|
||
13 | dojo.declare("dijit._TimePicker",[dijit._Widget,dijit._Templated],{templateString:dojo.cache("dijit","templates/TimePicker.html","<div id=\"widget_${id}\" class=\"dijitMenu\"\n ><div dojoAttachPoint=\"upArrow\" class=\"dijitButtonNode dijitUpArrowButton\" dojoAttachEvent=\"onmouseenter:_buttonMouse,onmouseleave:_buttonMouse\"\n\t\t><div class=\"dijitReset dijitInline dijitArrowButtonInner\" wairole=\"presentation\" role=\"presentation\"> </div\n\t\t><div class=\"dijitArrowButtonChar\">▲</div></div\n ><div dojoAttachPoint=\"timeMenu,focusNode\" dojoAttachEvent=\"onclick:_onOptionSelected,onmouseover,onmouseout\"></div\n ><div dojoAttachPoint=\"downArrow\" class=\"dijitButtonNode dijitDownArrowButton\" dojoAttachEvent=\"onmouseenter:_buttonMouse,onmouseleave:_buttonMouse\"\n\t\t><div class=\"dijitReset dijitInline dijitArrowButtonInner\" wairole=\"presentation\" role=\"presentation\"> </div\n\t\t><div class=\"dijitArrowButtonChar\">▼</div></div\n></div>\n"),baseClass:"dijitTimePicker",clickableIncrement:"T00:15:00",visibleIncrement:"T01:00:00",visibleRange:"T05:00:00",value:new Date(),_visibleIncrement:2,_clickableIncrement:1,_totalIncrements:10,constraints:{},serialize:dojo.date.stamp.toISOString,_filterString:"",setValue:function(_1){ |
||
14 | dojo.deprecated("dijit._TimePicker:setValue() is deprecated. Use set('value', ...) instead.","","2.0"); |
||
15 | this.set("value",_1); |
||
16 | },_setValueAttr:function(_2){ |
||
17 | this.value=_2;
|
||
18 | this._showText();
|
||
19 | },onOpen:function(_3){ |
||
20 | if(this._beenOpened&&this.domNode.parentNode){ |
||
21 | var p=dijit.byId(this.domNode.parentNode.dijitPopupParent); |
||
22 | if(p){
|
||
23 | var _4=p.get("displayedValue"); |
||
24 | if(_4&&!p.parse(_4,p.constraints)){
|
||
25 | this._filterString=_4;
|
||
26 | }else{
|
||
27 | this._filterString=""; |
||
28 | } |
||
29 | this._showText();
|
||
30 | } |
||
31 | } |
||
32 | this._beenOpened=true; |
||
33 | },isDisabledDate:function(_5,_6){ |
||
34 | return false; |
||
35 | },_getFilteredNodes:function(_7,_8,_9){ |
||
36 | var _a=[],n,i=_7,_b=this._maxIncrement+Math.abs(i),_c=_9?-1:1,_d=_9?1:0,_e=_9?0:1; |
||
37 | do{
|
||
38 | i=i-_d; |
||
39 | n=this._createOption(i);
|
||
40 | if(n){
|
||
41 | _a.push(n); |
||
42 | } |
||
43 | i=i+_e; |
||
44 | }while(_a.length<_8&&(i*_c)<_b);
|
||
45 | if(_9){
|
||
46 | _a.reverse(); |
||
47 | } |
||
48 | return _a;
|
||
49 | },_showText:function(){ |
||
50 | this.timeMenu.innerHTML=""; |
||
51 | var _f=dojo.date.stamp.fromISOString;
|
||
52 | this._clickableIncrementDate=_f(this.clickableIncrement); |
||
53 | this._visibleIncrementDate=_f(this.visibleIncrement); |
||
54 | this._visibleRangeDate=_f(this.visibleRange); |
||
55 | var _10=function(_11){ |
||
56 | return _11.getHours()*60*60+_11.getMinutes()*60+_11.getSeconds(); |
||
57 | }; |
||
58 | var _12=_10(this._clickableIncrementDate); |
||
59 | var _13=_10(this._visibleIncrementDate); |
||
60 | var _14=_10(this._visibleRangeDate); |
||
61 | var _15=this.value.getTime(); |
||
62 | this._refDate=new Date(_15-_15%(_13*1000)); |
||
63 | this._refDate.setFullYear(1970,0,1); |
||
64 | this._clickableIncrement=1; |
||
65 | this._totalIncrements=_14/_12;
|
||
66 | this._visibleIncrement=_13/_12;
|
||
67 | this._maxIncrement=(60*60*24)/_12; |
||
68 | var _16=this._getFilteredNodes(0,this._totalIncrements>>1,true); |
||
69 | var _17=this._getFilteredNodes(0,this._totalIncrements>>1,false); |
||
70 | if(_16.length<this._totalIncrements>>1){ |
||
71 | _16=_16.slice(_16.length/2);
|
||
72 | _17=_17.slice(0,_17.length/2); |
||
73 | } |
||
74 | dojo.forEach(_16.concat(_17),function(n){
|
||
75 | this.timeMenu.appendChild(n);
|
||
76 | },this);
|
||
77 | },postCreate:function(){ |
||
78 | if(this.constraints===dijit._TimePicker.prototype.constraints){ |
||
79 | this.constraints={};
|
||
80 | } |
||
81 | dojo.mixin(this,this.constraints); |
||
82 | if(!this.constraints.locale){ |
||
83 | this.constraints.locale=this.lang; |
||
84 | } |
||
85 | this.connect(this.timeMenu,dojo.isIE?"onmousewheel":"DOMMouseScroll","_mouseWheeled"); |
||
86 | var _18=this; |
||
87 | var _19=function(){ |
||
88 | _18._connects.push(dijit.typematic.addMouseListener.apply(null,arguments)); |
||
89 | }; |
||
90 | _19(this.upArrow,this,this._onArrowUp,1,50); |
||
91 | _19(this.downArrow,this,this._onArrowDown,1,50); |
||
92 | var _1a=function(cb){ |
||
93 | return function(cnt){ |
||
94 | if(cnt>0){ |
||
95 | cb.call(this,arguments); |
||
96 | } |
||
97 | }; |
||
98 | }; |
||
99 | var _1b=function(_1c,cb){ |
||
100 | return function(e){ |
||
101 | dojo.stopEvent(e); |
||
102 | dijit.typematic.trigger(e,this,_1c,_1a(cb),_1c,1,50); |
||
103 | }; |
||
104 | }; |
||
105 | this.connect(this.upArrow,"onmouseover",_1b(this.upArrow,this._onArrowUp)); |
||
106 | this.connect(this.downArrow,"onmouseover",_1b(this.downArrow,this._onArrowDown)); |
||
107 | this.inherited(arguments); |
||
108 | },_buttonMouse:function(e){ |
||
109 | dojo.toggleClass(e.currentTarget,e.currentTarget==this.upArrow?"dijitUpArrowHover":"dijitDownArrowHover",e.type=="mouseenter"||e.type=="mouseover"); |
||
110 | },_createOption:function(_1d){ |
||
111 | var _1e=new Date(this._refDate); |
||
112 | var _1f=this._clickableIncrementDate; |
||
113 | _1e.setHours(_1e.getHours()+_1f.getHours()*_1d,_1e.getMinutes()+_1f.getMinutes()*_1d,_1e.getSeconds()+_1f.getSeconds()*_1d); |
||
114 | if(this.constraints.selector=="time"){ |
||
115 | _1e.setFullYear(1970,0,1); |
||
116 | } |
||
117 | var _20=dojo.date.locale.format(_1e,this.constraints); |
||
118 | if(this._filterString&&_20.toLowerCase().indexOf(this._filterString)!==0){ |
||
119 | return null; |
||
120 | } |
||
121 | var div=dojo.create("div",{"class":this.baseClass+"Item"}); |
||
122 | div.date=_1e; |
||
123 | div.index=_1d; |
||
124 | dojo.create("div",{"class":this.baseClass+"ItemInner",innerHTML:_20},div); |
||
125 | if(_1d%this._visibleIncrement<1&&_1d%this._visibleIncrement>-1){ |
||
126 | dojo.addClass(div,this.baseClass+"Marker"); |
||
127 | }else{
|
||
128 | if(!(_1d%this._clickableIncrement)){ |
||
129 | dojo.addClass(div,this.baseClass+"Tick"); |
||
130 | } |
||
131 | } |
||
132 | if(this.isDisabledDate(_1e)){ |
||
133 | dojo.addClass(div,this.baseClass+"ItemDisabled"); |
||
134 | } |
||
135 | if(!dojo.date.compare(this.value,_1e,this.constraints.selector)){ |
||
136 | div.selected=true;
|
||
137 | dojo.addClass(div,this.baseClass+"ItemSelected"); |
||
138 | if(dojo.hasClass(div,this.baseClass+"Marker")){ |
||
139 | dojo.addClass(div,this.baseClass+"MarkerSelected"); |
||
140 | }else{
|
||
141 | dojo.addClass(div,this.baseClass+"TickSelected"); |
||
142 | } |
||
143 | } |
||
144 | return div;
|
||
145 | },_onOptionSelected:function(tgt){ |
||
146 | var _21=tgt.target.date||tgt.target.parentNode.date;
|
||
147 | if(!_21||this.isDisabledDate(_21)){ |
||
148 | return;
|
||
149 | } |
||
150 | this._highlighted_option=null; |
||
151 | this.set("value",_21); |
||
152 | this.onValueSelected(_21);
|
||
153 | },onValueSelected:function(_22){ |
||
154 | },_highlightOption:function(_23,_24){ |
||
155 | if(!_23){
|
||
156 | return;
|
||
157 | } |
||
158 | if(_24){
|
||
159 | if(this._highlighted_option){ |
||
160 | this._highlightOption(this._highlighted_option,false); |
||
161 | } |
||
162 | this._highlighted_option=_23;
|
||
163 | }else{
|
||
164 | if(this._highlighted_option!==_23){ |
||
165 | return;
|
||
166 | }else{
|
||
167 | this._highlighted_option=null; |
||
168 | } |
||
169 | } |
||
170 | dojo.toggleClass(_23,this.baseClass+"ItemHover",_24); |
||
171 | if(dojo.hasClass(_23,this.baseClass+"Marker")){ |
||
172 | dojo.toggleClass(_23,this.baseClass+"MarkerHover",_24); |
||
173 | }else{
|
||
174 | dojo.toggleClass(_23,this.baseClass+"TickHover",_24); |
||
175 | } |
||
176 | },onmouseover:function(e){ |
||
177 | this._keyboardSelected=null; |
||
178 | var tgr=(e.target.parentNode===this.timeMenu)?e.target:e.target.parentNode; |
||
179 | if(!dojo.hasClass(tgr,this.baseClass+"Item")){ |
||
180 | return;
|
||
181 | } |
||
182 | this._highlightOption(tgr,true); |
||
183 | },onmouseout:function(e){ |
||
184 | this._keyboardSelected=null; |
||
185 | var tgr=(e.target.parentNode===this.timeMenu)?e.target:e.target.parentNode; |
||
186 | this._highlightOption(tgr,false); |
||
187 | },_mouseWheeled:function(e){ |
||
188 | this._keyboardSelected=null; |
||
189 | dojo.stopEvent(e); |
||
190 | var _25=(dojo.isIE?e.wheelDelta:-e.detail);
|
||
191 | this[(_25>0?"_onArrowUp":"_onArrowDown")](); |
||
192 | },_onArrowUp:function(_26){ |
||
193 | if(typeof _26=="number"&&_26==-1){ |
||
194 | return;
|
||
195 | } |
||
196 | if(!this.timeMenu.childNodes.length){ |
||
197 | return;
|
||
198 | } |
||
199 | var _27=this.timeMenu.childNodes[0].index; |
||
200 | var _28=this._getFilteredNodes(_27,1,true); |
||
201 | if(_28.length){
|
||
202 | this.timeMenu.removeChild(this.timeMenu.childNodes[this.timeMenu.childNodes.length-1]); |
||
203 | this.timeMenu.insertBefore(_28[0],this.timeMenu.childNodes[0]); |
||
204 | } |
||
205 | },_onArrowDown:function(_29){ |
||
206 | if(typeof _29=="number"&&_29==-1){ |
||
207 | return;
|
||
208 | } |
||
209 | if(!this.timeMenu.childNodes.length){ |
||
210 | return;
|
||
211 | } |
||
212 | var _2a=this.timeMenu.childNodes[this.timeMenu.childNodes.length-1].index+1; |
||
213 | var _2b=this._getFilteredNodes(_2a,1,false); |
||
214 | if(_2b.length){
|
||
215 | this.timeMenu.removeChild(this.timeMenu.childNodes[0]); |
||
216 | this.timeMenu.appendChild(_2b[0]); |
||
217 | } |
||
218 | },handleKey:function(e){ |
||
219 | var dk=dojo.keys;
|
||
220 | if(e.keyChar||e.charOrCode===dk.BACKSPACE||e.charOrCode==dk.DELETE){
|
||
221 | setTimeout(dojo.hitch(this,function(){ |
||
222 | this._filterString=e.target.value.toLowerCase();
|
||
223 | this._showText();
|
||
224 | }),1);
|
||
225 | }else{
|
||
226 | if(e.charOrCode==dk.DOWN_ARROW||e.charOrCode==dk.UP_ARROW){
|
||
227 | dojo.stopEvent(e); |
||
228 | if(this._highlighted_option&&!this._highlighted_option.parentNode){ |
||
229 | this._highlighted_option=null; |
||
230 | } |
||
231 | var _2c=this.timeMenu,tgt=this._highlighted_option||dojo.query("."+this.baseClass+"ItemSelected",_2c)[0]; |
||
232 | if(!tgt){
|
||
233 | tgt=_2c.childNodes[0];
|
||
234 | }else{
|
||
235 | if(_2c.childNodes.length){
|
||
236 | if(e.charOrCode==dk.DOWN_ARROW&&!tgt.nextSibling){
|
||
237 | this._onArrowDown();
|
||
238 | }else{
|
||
239 | if(e.charOrCode==dk.UP_ARROW&&!tgt.previousSibling){
|
||
240 | this._onArrowUp();
|
||
241 | } |
||
242 | } |
||
243 | if(e.charOrCode==dk.DOWN_ARROW){
|
||
244 | tgt=tgt.nextSibling; |
||
245 | }else{
|
||
246 | tgt=tgt.previousSibling; |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | this._highlightOption(tgt,true); |
||
251 | this._keyboardSelected=tgt;
|
||
252 | }else{
|
||
253 | if(this._highlighted_option&&(e.charOrCode==dk.ENTER||e.charOrCode===dk.TAB)){ |
||
254 | if(!this._keyboardSelected&&e.charOrCode===dk.TAB){ |
||
255 | return;
|
||
256 | } |
||
257 | if(e.charOrCode==dk.ENTER){
|
||
258 | dojo.stopEvent(e); |
||
259 | } |
||
260 | this._onOptionSelected({target:this._highlighted_option}); |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | }}); |
||
265 | } |