123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- if(!dojo._hasResource["dijit._TimePicker"]){
- dojo._hasResource["dijit._TimePicker"] = true;
- dojo.provide("dijit._TimePicker");
- dojo.require("dijit.form._FormWidget");
- dojo.require("dojo.date.locale");
- 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\" 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\" 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,
- setValue: function(/*Date*/ value){
-
-
-
-
- dojo.deprecated("dijit._TimePicker:setValue() is deprecated. Use set('value', ...) instead.", "", "2.0");
- this.set('value', value);
- },
- _setValueAttr: function(/*Date*/ date){
-
-
-
-
-
-
-
- this._set("value", date);
- this._showText();
- },
- _setFilterStringAttr: function(val){
-
-
- this._set("filterString", val);
- this._showText();
- },
- isDisabledDate: function(/*Date*/ dateObject, /*String?*/ locale){
-
-
-
-
- return false;
- },
- _getFilteredNodes: function(/*number*/ start, /*number*/ maxNum, /*Boolean*/ before, /*DOMnode*/ lastNode){
-
-
-
-
-
-
-
- var
- nodes = [],
- lastValue = lastNode ? lastNode.date : this._refDate,
- n,
- i = start,
- max = this._maxIncrement + Math.abs(i),
- chk = before ? -1 : 1,
- dec = before ? 1 : 0,
- inc = 1 - dec;
- do{
- i -= dec;
- n = this._createOption(i);
- if(n){
- if((before && n.date > lastValue) || (!before && n.date < lastValue)){
- break;
- }
- nodes[before ? "unshift" : "push"](n);
- lastValue = n.date;
- }
- i += inc;
- }while(nodes.length < maxNum && (i*chk) < max);
- return nodes;
- },
- _showText: function(){
-
-
-
-
- var fromIso = dojo.date.stamp.fromISOString;
- this.timeMenu.innerHTML = "";
- this._clickableIncrementDate=fromIso(this.clickableIncrement);
- this._visibleIncrementDate=fromIso(this.visibleIncrement);
- this._visibleRangeDate=fromIso(this.visibleRange);
-
- var
- sinceMidnight = function(/*Date*/ date){
- return date.getHours() * 60 * 60 + date.getMinutes() * 60 + date.getSeconds();
- },
- clickableIncrementSeconds = sinceMidnight(this._clickableIncrementDate),
- visibleIncrementSeconds = sinceMidnight(this._visibleIncrementDate),
- visibleRangeSeconds = sinceMidnight(this._visibleRangeDate),
-
- time = (this.value || this.currentFocus).getTime();
- this._refDate = new Date(time - time % (clickableIncrementSeconds*1000));
- this._refDate.setFullYear(1970,0,1);
-
- this._clickableIncrement = 1;
-
-
- this._totalIncrements = visibleRangeSeconds / clickableIncrementSeconds;
-
-
- this._visibleIncrement = visibleIncrementSeconds / clickableIncrementSeconds;
-
-
- this._maxIncrement = (60 * 60 * 24) / clickableIncrementSeconds;
- var
-
-
- count = Math.min(this._totalIncrements, 10),
- after = this._getFilteredNodes(0, (count >> 1) + 1, false),
- moreAfter = [],
- estBeforeLength = count - after.length,
- before = this._getFilteredNodes(0, estBeforeLength, true, after[0]);
- if(before.length < estBeforeLength && after.length > 0){
- moreAfter = this._getFilteredNodes(after.length, estBeforeLength - before.length, false, after[after.length-1]);
- }
- dojo.forEach(before.concat(after, moreAfter), function(n){this.timeMenu.appendChild(n);}, this);
- },
- constructor: function(){
- this.constraints = {};
- },
- postMixInProperties: function(){
- this.inherited(arguments);
- this._setConstraintsAttr(this.constraints);
- },
- _setConstraintsAttr: function(/* Object */ constraints){
-
- dojo.mixin(this, constraints);
-
- if(!constraints.locale){
- constraints.locale = this.lang;
- }
- },
- postCreate: function(){
-
- this.connect(this.timeMenu, dojo.isIE ? "onmousewheel" : 'DOMMouseScroll', "_mouseWheeled");
- this._connects.push(dijit.typematic.addMouseListener(this.upArrow, this, "_onArrowUp", 33, 250));
- this._connects.push(dijit.typematic.addMouseListener(this.downArrow, this, "_onArrowDown", 33, 250));
- this.inherited(arguments);
- },
- _buttonMouse: function(/*Event*/ e){
-
-
-
-
-
-
- dojo.toggleClass(e.currentTarget, e.currentTarget == this.upArrow ? "dijitUpArrowHover" : "dijitDownArrowHover",
- e.type == "mouseenter" || e.type == "mouseover");
- },
- _createOption: function(/*Number*/ index){
-
-
-
-
- var date = new Date(this._refDate);
- var incrementDate = this._clickableIncrementDate;
- date.setHours(date.getHours() + incrementDate.getHours() * index,
- date.getMinutes() + incrementDate.getMinutes() * index,
- date.getSeconds() + incrementDate.getSeconds() * index);
- if(this.constraints.selector == "time"){
- date.setFullYear(1970,0,1);
- }
- var dateString = dojo.date.locale.format(date, this.constraints);
- if(this.filterString && dateString.toLowerCase().indexOf(this.filterString) !== 0){
-
- return null;
- }
- var div = dojo.create("div", {"class": this.baseClass+"Item"});
- div.date = date;
- div.index = index;
- dojo.create('div',{
- "class": this.baseClass + "ItemInner",
- innerHTML: dateString
- }, div);
- if(index%this._visibleIncrement<1 && index%this._visibleIncrement>-1){
- dojo.addClass(div, this.baseClass+"Marker");
- }else if(!(index%this._clickableIncrement)){
- dojo.addClass(div, this.baseClass+"Tick");
- }
- if(this.isDisabledDate(date)){
-
- dojo.addClass(div, this.baseClass+"ItemDisabled");
- }
- if(this.value && !dojo.date.compare(this.value, date, this.constraints.selector)){
- div.selected = true;
- dojo.addClass(div, this.baseClass+"ItemSelected");
- if(dojo.hasClass(div, this.baseClass+"Marker")){
- dojo.addClass(div, this.baseClass+"MarkerSelected");
- }else{
- dojo.addClass(div, this.baseClass+"TickSelected");
- }
-
-
- this._highlightOption(div, true);
- }
- return div;
- },
- _onOptionSelected: function(/*Object*/ tgt){
-
-
-
-
- var tdate = tgt.target.date || tgt.target.parentNode.date;
- if(!tdate || this.isDisabledDate(tdate)){ return; }
- this._highlighted_option = null;
- this.set('value', tdate);
- this.onChange(tdate);
- },
- onChange: function(/*Date*/ time){
-
-
-
-
- },
- _highlightOption: function(/*node*/ node, /*Boolean*/ highlight){
-
-
-
-
- if(!node){return;}
- if(highlight){
- if(this._highlighted_option){
- this._highlightOption(this._highlighted_option, false);
- }
- this._highlighted_option = node;
- }else if(this._highlighted_option !== node){
- return;
- }else{
- this._highlighted_option = null;
- }
- dojo.toggleClass(node, this.baseClass+"ItemHover", highlight);
- if(dojo.hasClass(node, this.baseClass+"Marker")){
- dojo.toggleClass(node, this.baseClass+"MarkerHover", highlight);
- }else{
- dojo.toggleClass(node, this.baseClass+"TickHover", highlight);
- }
- },
- onmouseover: function(/*Event*/ e){
-
-
-
-
- this._keyboardSelected = null;
- var tgr = (e.target.parentNode === this.timeMenu) ? e.target : e.target.parentNode;
-
- if(!dojo.hasClass(tgr, this.baseClass+"Item")){return;}
- this._highlightOption(tgr, true);
- },
- onmouseout: function(/*Event*/ e){
-
-
-
-
- this._keyboardSelected = null;
- var tgr = (e.target.parentNode === this.timeMenu) ? e.target : e.target.parentNode;
- this._highlightOption(tgr, false);
- },
- _mouseWheeled: function(/*Event*/ e){
-
-
-
-
- this._keyboardSelected = null;
- dojo.stopEvent(e);
-
- var scrollAmount = (dojo.isIE ? e.wheelDelta : -e.detail);
- this[(scrollAmount>0 ? "_onArrowUp" : "_onArrowDown")]();
- },
- _onArrowUp: function(count){
-
-
-
-
-
-
- if(typeof count == "number" && count == -1){ return; }
- if(!this.timeMenu.childNodes.length){ return; }
- var index = this.timeMenu.childNodes[0].index;
- var divs = this._getFilteredNodes(index, 1, true, this.timeMenu.childNodes[0]);
- if(divs.length){
- this.timeMenu.removeChild(this.timeMenu.childNodes[this.timeMenu.childNodes.length - 1]);
- this.timeMenu.insertBefore(divs[0], this.timeMenu.childNodes[0]);
- }
- },
- _onArrowDown: function(count){
-
-
-
-
-
-
- if(typeof count == "number" && count == -1){ return; }
- if(!this.timeMenu.childNodes.length){ return; }
- var index = this.timeMenu.childNodes[this.timeMenu.childNodes.length - 1].index + 1;
- var divs = this._getFilteredNodes(index, 1, false, this.timeMenu.childNodes[this.timeMenu.childNodes.length - 1]);
- if(divs.length){
- this.timeMenu.removeChild(this.timeMenu.childNodes[0]);
- this.timeMenu.appendChild(divs[0]);
- }
- },
- handleKey: function(/*Event*/ e){
-
-
-
-
-
- var dk = dojo.keys;
- if(e.charOrCode == dk.DOWN_ARROW || e.charOrCode == dk.UP_ARROW){
- dojo.stopEvent(e);
-
- if(this._highlighted_option && !this._highlighted_option.parentNode){
- this._highlighted_option = null;
- }
- var timeMenu = this.timeMenu,
- tgt = this._highlighted_option || dojo.query("." + this.baseClass + "ItemSelected", timeMenu)[0];
- if(!tgt){
- tgt = timeMenu.childNodes[0];
- }else if(timeMenu.childNodes.length){
- if(e.charOrCode == dk.DOWN_ARROW && !tgt.nextSibling){
- this._onArrowDown();
- }else if(e.charOrCode == dk.UP_ARROW && !tgt.previousSibling){
- this._onArrowUp();
- }
- if(e.charOrCode == dk.DOWN_ARROW){
- tgt = tgt.nextSibling;
- }else{
- tgt = tgt.previousSibling;
- }
- }
- this._highlightOption(tgt, true);
- this._keyboardSelected = tgt;
- return false;
- }else if(e.charOrCode == dk.ENTER || e.charOrCode === dk.TAB){
-
- if(!this._keyboardSelected && e.charOrCode === dk.TAB){
- return true;
- }
-
- if(this._highlighted_option){
- this._onOptionSelected({target: this._highlighted_option});
- }
-
-
- return e.charOrCode === dk.TAB;
- }
- return undefined;
- }
- }
- );
- }
|