]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/form/_Spinner.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / form / _Spinner.js
1 if(!dojo._hasResource["dijit.form._Spinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit.form._Spinner"] = true;
3 dojo.provide("dijit.form._Spinner");
4
5 dojo.require("dijit.form.ValidationTextBox");
6
7 dojo.declare(
8         "dijit.form._Spinner",
9         dijit.form.RangeBoundTextBox,
10         {
11
12                 // summary: Mixin for validation widgets with a spinner
13                 // description: This class basically (conceptually) extends dijit.form.ValidationTextBox.
14                 //      It modifies the template to have up/down arrows, and provides related handling code.
15
16                 // defaultTimeout: Number
17                 //        number of milliseconds before a held key or button becomes typematic
18                 defaultTimeout: 500,
19
20                 // timeoutChangeRate: Number
21                 //        fraction of time used to change the typematic timer between events
22                 //        1.0 means that each typematic event fires at defaultTimeout intervals
23                 //        < 1.0 means that each typematic event fires at an increasing faster rate
24                 timeoutChangeRate: 0.90,
25
26                 // smallDelta: Number
27                 //        adjust the value by this much when spinning using the arrow keys/buttons
28                 smallDelta: 1,
29                 // largeDelta: Number
30                 //        adjust the value by this much when spinning using the PgUp/Dn keys
31                 largeDelta: 10,
32
33                 templateString:"<div class=\"dijit dijitReset dijitInlineTable dijitLeft\"\n\tid=\"widget_${id}\"\n\tdojoAttachEvent=\"onmouseenter:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse\" waiRole=\"presentation\"\n\t><div class=\"dijitInputLayoutContainer\"\n\t\t><div class=\"dijitReset dijitSpinnerButtonContainer\"\n\t\t\t>&nbsp;<div class=\"dijitReset dijitLeft dijitButtonNode dijitArrowButton dijitUpArrowButton\"\n\t\t\t\tdojoAttachPoint=\"upArrowNode\"\n\t\t\t\tdojoAttachEvent=\"onmouseenter:_onMouse,onmouseleave:_onMouse\"\n\t\t\t\tstateModifier=\"UpArrow\"\n\t\t\t\t><div class=\"dijitArrowButtonInner\">&thinsp;</div\n\t\t\t\t><div class=\"dijitArrowButtonChar\">&#9650;</div\n\t\t\t></div\n\t\t\t><div class=\"dijitReset dijitLeft dijitButtonNode dijitArrowButton dijitDownArrowButton\"\n\t\t\t\tdojoAttachPoint=\"downArrowNode\"\n\t\t\t\tdojoAttachEvent=\"onmouseenter:_onMouse,onmouseleave:_onMouse\"\n\t\t\t\tstateModifier=\"DownArrow\"\n\t\t\t\t><div class=\"dijitArrowButtonInner\">&thinsp;</div\n\t\t\t\t><div class=\"dijitArrowButtonChar\">&#9660;</div\n\t\t\t></div\n\t\t></div\n\t\t><div class=\"dijitReset dijitValidationIcon\"><br></div\n\t\t><div class=\"dijitReset dijitValidationIconText\">&Chi;</div\n\t\t><div class=\"dijitReset dijitInputField\"\n\t\t\t><input class='dijitReset' dojoAttachPoint=\"textbox,focusNode\" type=\"${type}\" dojoAttachEvent=\"onfocus:_update,onkeyup:_onkeyup,onkeypress:_onKeyPress\"\n\t\t\t\twaiRole=\"spinbutton\" autocomplete=\"off\" name=\"${name}\"\n\t\t/></div\n\t></div\n></div>\n",
34                 baseClass: "dijitSpinner",
35
36                 adjust: function(/* Object */ val, /*Number*/ delta){
37                         // summary: user replaceable function used to adjust a primitive value(Number/Date/...) by the delta amount specified
38                         // the val is adjusted in a way that makes sense to the object type
39                         return val;
40                 },
41
42                 _arrowState: function(/*Node*/ node, /*Boolean*/ pressed){
43                         this._active = pressed;
44                         this.stateModifier = node.getAttribute("stateModifier") || "";
45                         this._setStateClass();
46                 },
47
48                 _arrowPressed: function(/*Node*/ nodePressed, /*Number*/ direction){
49                         if(this.disabled || this.readOnly){ return; }
50                         this._arrowState(nodePressed, true);
51                         this.setValue(this.adjust(this.getValue(), direction*this.smallDelta), false);
52                         dijit.selectInputText(this.textbox, this.textbox.value.length);
53                 },
54
55                 _arrowReleased: function(/*Node*/ node){
56                         this._wheelTimer = null;
57                         if(this.disabled || this.readOnly){ return; }
58                         this._arrowState(node, false);
59                 },
60
61                 _typematicCallback: function(/*Number*/ count, /*DOMNode*/ node, /*Event*/ evt){
62                         if(node == this.textbox){ node = (evt.keyCode == dojo.keys.UP_ARROW) ? this.upArrowNode : this.downArrowNode; }
63                         if(count == -1){ this._arrowReleased(node); }
64                         else{ this._arrowPressed(node, (node == this.upArrowNode) ? 1 : -1); }
65                 },
66
67                 _wheelTimer: null,
68                 _mouseWheeled: function(/*Event*/ evt){
69                         dojo.stopEvent(evt);
70                         var scrollAmount = 0;
71                         if(typeof evt.wheelDelta == 'number'){ // IE
72                                 scrollAmount = evt.wheelDelta;
73                         }else if(typeof evt.detail == 'number'){ // Mozilla+Firefox
74                                 scrollAmount = -evt.detail;
75                         }
76                         var node, dir;
77                         if(scrollAmount > 0){
78                                 node = this.upArrowNode;
79                                 dir = +1;
80                         }else if(scrollAmount < 0){
81                                 node = this.downArrowNode;
82                                 dir = -1;
83                         }else{ return; }
84                         this._arrowPressed(node, dir);
85                         if(this._wheelTimer != null){
86                                 clearTimeout(this._wheelTimer);
87                         }
88                         var _this = this;
89                         this._wheelTimer = setTimeout(function(){_this._arrowReleased(node);}, 50);
90                 },
91
92                 postCreate: function(){
93                         this.inherited('postCreate', arguments);
94
95                         // extra listeners
96                         this.connect(this.textbox, dojo.isIE ? "onmousewheel" : 'DOMMouseScroll', "_mouseWheeled");
97                         this._connects.push(dijit.typematic.addListener(this.upArrowNode, this.textbox, {keyCode:dojo.keys.UP_ARROW,ctrlKey:false,altKey:false,shiftKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout));
98                         this._connects.push(dijit.typematic.addListener(this.downArrowNode, this.textbox, {keyCode:dojo.keys.DOWN_ARROW,ctrlKey:false,altKey:false,shiftKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout));
99                         if(dojo.isIE){
100                                 // When spinner is moved from hidden to visible, call _setStateClass to remind IE to render it. (#6123)
101                                 var _this = this;
102                                 this.connect(this.domNode, "onresize", 
103                                         function(){ setTimeout(dojo.hitch(_this,
104                                                 function(){
105                                                         // cause the IE expressions to rerun
106                                                         this.upArrowNode.style.behavior = '';
107                                                         this.downArrowNode.style.behavior = '';
108                                                         // cause IE to rerender
109                                                         this._setStateClass();
110                                                 }), 0);
111                                         }
112                                 );
113                         }
114                 }
115 });
116
117 }