Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / form / RangeSlider.js @ 12

History | View | Annotate | Download (16.3 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["dojox.form.RangeSlider"]){
9
dojo._hasResource["dojox.form.RangeSlider"]=true;
10
dojo.provide("dojox.form.RangeSlider");
11
dojo.require("dijit.form.HorizontalSlider");
12
dojo.require("dijit.form.VerticalSlider");
13
dojo.require("dojox.fx");
14
(function(){
15
var _1=function(a,b){
16
return b-a;
17
},_2=function(a,b){
18
return a-b;
19
};
20
dojo.declare("dojox.form._RangeSliderMixin",null,{value:[0,100],postMixInProperties:function(){
21
this.inherited(arguments);
22
this.value=dojo.map(this.value,function(i){
23
return parseInt(i,10);
24
});
25
},postCreate:function(){
26
this.inherited(arguments);
27
this.value.sort(this._isReversed()?_1:_2);
28
var _3=this;
29
var _4=function(){
30
dijit.form._SliderMoverMax.apply(this,arguments);
31
this.widget=_3;
32
};
33
dojo.extend(_4,dijit.form._SliderMoverMax.prototype);
34
this._movableMax=new dojo.dnd.Moveable(this.sliderHandleMax,{mover:_4});
35
dijit.setWaiState(this.focusNodeMax,"valuemin",this.minimum);
36
dijit.setWaiState(this.focusNodeMax,"valuemax",this.maximum);
37
var _5=function(){
38
dijit.form._SliderBarMover.apply(this,arguments);
39
this.widget=_3;
40
};
41
dojo.extend(_5,dijit.form._SliderBarMover.prototype);
42
this._movableBar=new dojo.dnd.Moveable(this.progressBar,{mover:_5});
43
},destroy:function(){
44
this.inherited(arguments);
45
this._movableMax.destroy();
46
this._movableBar.destroy();
47
},_onKeyPress:function(e){
48
if(this.disabled||this.readOnly||e.altKey||e.ctrlKey){
49
return;
50
}
51
var _6=e.currentTarget,_7=false,_8=false,k=dojo.keys;
52
if(_6==this.sliderHandle){
53
_7=true;
54
}else{
55
if(_6==this.progressBar){
56
_8=_7=true;
57
}else{
58
if(_6==this.sliderHandleMax){
59
_8=true;
60
}
61
}
62
}
63
switch(e.keyCode){
64
case k.HOME:
65
this._setValueAttr(this.minimum,true,_8);
66
break;
67
case k.END:
68
this._setValueAttr(this.maximum,true,_8);
69
break;
70
case ((this._descending||this.isLeftToRight())?k.RIGHT_ARROW:k.LEFT_ARROW):
71
case (this._descending===false?k.DOWN_ARROW:k.UP_ARROW):
72
case (this._descending===false?k.PAGE_DOWN:k.PAGE_UP):
73
if(_7&&_8){
74
this._bumpValue([{"change":e.keyCode==k.PAGE_UP?this.pageIncrement:1,"useMaxValue":true},{"change":e.keyCode==k.PAGE_UP?this.pageIncrement:1,"useMaxValue":false}]);
75
}else{
76
if(_7){
77
this._bumpValue(e.keyCode==k.PAGE_UP?this.pageIncrement:1,true);
78
}else{
79
if(_8){
80
this._bumpValue(e.keyCode==k.PAGE_UP?this.pageIncrement:1);
81
}
82
}
83
}
84
break;
85
case ((this._descending||this.isLeftToRight())?k.LEFT_ARROW:k.RIGHT_ARROW):
86
case (this._descending===false?k.UP_ARROW:k.DOWN_ARROW):
87
case (this._descending===false?k.PAGE_UP:k.PAGE_DOWN):
88
if(_7&&_8){
89
this._bumpValue([{change:e.keyCode==k.PAGE_DOWN?-this.pageIncrement:-1,useMaxValue:false},{change:e.keyCode==k.PAGE_DOWN?-this.pageIncrement:-1,useMaxValue:true}]);
90
}else{
91
if(_7){
92
this._bumpValue(e.keyCode==k.PAGE_DOWN?-this.pageIncrement:-1);
93
}else{
94
if(_8){
95
this._bumpValue(e.keyCode==k.PAGE_DOWN?-this.pageIncrement:-1,true);
96
}
97
}
98
}
99
break;
100
default:
101
dijit.form._FormValueWidget.prototype._onKeyPress.apply(this,arguments);
102
this.inherited(arguments);
103
return;
104
}
105
dojo.stopEvent(e);
106
},_onHandleClickMax:function(e){
107
if(this.disabled||this.readOnly){
108
return;
109
}
110
if(!dojo.isIE){
111
dijit.focus(this.sliderHandleMax);
112
}
113
dojo.stopEvent(e);
114
},_onClkIncBumper:function(){
115
this._setValueAttr(this._descending===false?this.minimum:this.maximum,true,true);
116
},_bumpValue:function(_9,_a){
117
var _b=dojo.isArray(_9)?[this._getBumpValue(_9[0].change,_9[0].useMaxValue),this._getBumpValue(_9[1].change,_9[1].useMaxValue)]:this._getBumpValue(_9,_a);
118
this._setValueAttr(_b,true,!dojo.isArray(_9)&&((_9>0&&!_a)||(_a&&_9<0)));
119
},_getBumpValue:function(_c,_d){
120
var s=dojo.getComputedStyle(this.sliderBarContainer),c=dojo._getContentBox(this.sliderBarContainer,s),_e=this.discreteValues,_f=!_d?this.value[0]:this.value[1];
121
if(_e<=1||_e==Infinity){
122
_e=c[this._pixelCount];
123
}
124
_e--;
125
if((this._isReversed()&&_c<0)||(_c>0&&!this._isReversed())){
126
_f=!_d?this.value[1]:this.value[0];
127
}
128
var _10=(_f-this.minimum)*_e/(this.maximum-this.minimum)+_c;
129
if(_10<0){
130
_10=0;
131
}
132
if(_10>_e){
133
_10=_e;
134
}
135
return _10*(this.maximum-this.minimum)/_e+this.minimum;
136
},_onBarClick:function(e){
137
if(this.disabled||this.readOnly){
138
return;
139
}
140
if(!dojo.isIE){
141
dijit.focus(this.progressBar);
142
}
143
dojo.stopEvent(e);
144
},_onRemainingBarClick:function(e){
145
if(this.disabled||this.readOnly){
146
return;
147
}
148
if(!dojo.isIE){
149
dijit.focus(this.progressBar);
150
}
151
var _11=dojo.coords(this.sliderBarContainer,true),bar=dojo.coords(this.progressBar,true),_12=e[this._mousePixelCoord]-_11[this._startingPixelCoord],_13=bar[this._startingPixelCount],_14=_13+bar[this._pixelCount],_15=this._isReversed()?_12<=_13:_12>=_14,p=this._isReversed()?_11[this._pixelCount]-_12:_12;
152
this._setPixelValue(p,_11[this._pixelCount],true,_15);
153
dojo.stopEvent(e);
154
},_setPixelValue:function(_16,_17,_18,_19){
155
if(this.disabled||this.readOnly){
156
return;
157
}
158
var _1a=this._getValueByPixelValue(_16,_17);
159
this._setValueAttr(_1a,_18,_19);
160
},_getValueByPixelValue:function(_1b,_1c){
161
_1b=_1b<0?0:_1c<_1b?_1c:_1b;
162
var _1d=this.discreteValues;
163
if(_1d<=1||_1d==Infinity){
164
_1d=_1c;
165
}
166
_1d--;
167
var _1e=_1c/_1d;
168
var _1f=Math.round(_1b/_1e);
169
return (this.maximum-this.minimum)*_1f/_1d+this.minimum;
170
},_setValueAttr:function(_20,_21,_22){
171
var _23=this.value;
172
if(!dojo.isArray(_20)){
173
if(_22){
174
if(this._isReversed()){
175
_23[0]=_20;
176
}else{
177
_23[1]=_20;
178
}
179
}else{
180
if(this._isReversed()){
181
_23[1]=_20;
182
}else{
183
_23[0]=_20;
184
}
185
}
186
}else{
187
_23=_20;
188
}
189
this._lastValueReported="";
190
this.valueNode.value=this.value=_20=_23;
191
dijit.setWaiState(this.focusNode,"valuenow",_23[0]);
192
dijit.setWaiState(this.focusNodeMax,"valuenow",_23[1]);
193
this.value.sort(this._isReversed()?_1:_2);
194
dijit.form._FormValueWidget.prototype._setValueAttr.apply(this,arguments);
195
this._printSliderBar(_21,_22);
196
},_printSliderBar:function(_24,_25){
197
var _26=(this.value[0]-this.minimum)/(this.maximum-this.minimum);
198
var _27=(this.value[1]-this.minimum)/(this.maximum-this.minimum);
199
var _28=_26;
200
if(_26>_27){
201
_26=_27;
202
_27=_28;
203
}
204
var _29=this._isReversed()?((1-_26)*100):(_26*100);
205
var _2a=this._isReversed()?((1-_27)*100):(_27*100);
206
var _2b=this._isReversed()?((1-_27)*100):(_26*100);
207
if(_24&&this.slideDuration>0&&this.progressBar.style[this._progressPixelSize]){
208
var _2c=_25?_27:_26;
209
var _2d=this;
210
var _2e={};
211
var _2f=parseFloat(this.progressBar.style[this._handleOffsetCoord]);
212
var _30=this.slideDuration/10;
213
if(_30===0){
214
return;
215
}
216
if(_30<0){
217
_30=0-_30;
218
}
219
var _31={};
220
var _32={};
221
var _33={};
222
_31[this._handleOffsetCoord]={start:this.sliderHandle.style[this._handleOffsetCoord],end:_29,units:"%"};
223
_32[this._handleOffsetCoord]={start:this.sliderHandleMax.style[this._handleOffsetCoord],end:_2a,units:"%"};
224
_33[this._handleOffsetCoord]={start:this.progressBar.style[this._handleOffsetCoord],end:_2b,units:"%"};
225
_33[this._progressPixelSize]={start:this.progressBar.style[this._progressPixelSize],end:(_27-_26)*100,units:"%"};
226
var _34=dojo.animateProperty({node:this.sliderHandle,duration:_30,properties:_31});
227
var _35=dojo.animateProperty({node:this.sliderHandleMax,duration:_30,properties:_32});
228
var _36=dojo.animateProperty({node:this.progressBar,duration:_30,properties:_33});
229
var _37=dojo.fx.combine([_34,_35,_36]);
230
_37.play();
231
}else{
232
this.sliderHandle.style[this._handleOffsetCoord]=_29+"%";
233
this.sliderHandleMax.style[this._handleOffsetCoord]=_2a+"%";
234
this.progressBar.style[this._handleOffsetCoord]=_2b+"%";
235
this.progressBar.style[this._progressPixelSize]=((_27-_26)*100)+"%";
236
}
237
}});
238
dojo.declare("dijit.form._SliderMoverMax",dijit.form._SliderMover,{onMouseMove:function(e){
239
var _38=this.widget;
240
var _39=_38._abspos;
241
if(!_39){
242
_39=_38._abspos=dojo.coords(_38.sliderBarContainer,true);
243
_38._setPixelValue_=dojo.hitch(_38,"_setPixelValue");
244
_38._isReversed_=_38._isReversed();
245
}
246
var _3a=e[_38._mousePixelCoord]-_39[_38._startingPixelCoord];
247
_38._setPixelValue_(_38._isReversed_?(_39[_38._pixelCount]-_3a):_3a,_39[_38._pixelCount],false,true);
248
},destroy:function(e){
249
dojo.dnd.Mover.prototype.destroy.apply(this,arguments);
250
var _3b=this.widget;
251
_3b._abspos=null;
252
_3b._setValueAttr(_3b.value,true);
253
}});
254
dojo.declare("dijit.form._SliderBarMover",dojo.dnd.Mover,{onMouseMove:function(e){
255
var _3c=this.widget;
256
if(_3c.disabled||_3c.readOnly){
257
return;
258
}
259
var _3d=_3c._abspos;
260
var bar=_3c._bar;
261
var _3e=_3c._mouseOffset;
262
if(!_3d){
263
_3d=_3c._abspos=dojo.coords(_3c.sliderBarContainer,true);
264
_3c._setPixelValue_=dojo.hitch(_3c,"_setPixelValue");
265
_3c._getValueByPixelValue_=dojo.hitch(_3c,"_getValueByPixelValue");
266
_3c._isReversed_=_3c._isReversed();
267
}
268
if(!bar){
269
bar=_3c._bar=dojo.coords(_3c.progressBar,true);
270
}
271
if(!_3e){
272
_3e=_3c._mouseOffset=e[_3c._mousePixelCoord]-_3d[_3c._startingPixelCoord]-bar[_3c._startingPixelCount];
273
}
274
var _3f=e[_3c._mousePixelCoord]-_3d[_3c._startingPixelCoord]-_3e,_40=_3f+bar[_3c._pixelCount];
275
pixelValues=[_3f,_40];
276
pixelValues.sort(_2);
277
if(pixelValues[0]<=0){
278
pixelValues[0]=0;
279
pixelValues[1]=bar[_3c._pixelCount];
280
}
281
if(pixelValues[1]>=_3d[_3c._pixelCount]){
282
pixelValues[1]=_3d[_3c._pixelCount];
283
pixelValues[0]=_3d[_3c._pixelCount]-bar[_3c._pixelCount];
284
}
285
var _41=[_3c._getValueByPixelValue(_3c._isReversed_?(_3d[_3c._pixelCount]-pixelValues[0]):pixelValues[0],_3d[_3c._pixelCount]),_3c._getValueByPixelValue(_3c._isReversed_?(_3d[_3c._pixelCount]-pixelValues[1]):pixelValues[1],_3d[_3c._pixelCount])];
286
_3c._setValueAttr(_41,false,false);
287
},destroy:function(){
288
dojo.dnd.Mover.prototype.destroy.apply(this,arguments);
289
var _42=this.widget;
290
_42._abspos=null;
291
_42._bar=null;
292
_42._mouseOffset=null;
293
_42._setValueAttr(_42.value,true);
294
}});
295
dojo.declare("dojox.form.HorizontalRangeSlider",[dijit.form.HorizontalSlider,dojox.form._RangeSliderMixin],{templateString:dojo.cache("dojox.form","resources/HorizontalRangeSlider.html","<table class=\"dijit dijitReset dijitSlider dijitSliderH dojoxRangeSlider\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" rules=\"none\" dojoAttachEvent=\"onkeypress:_onKeyPress,onkeyup:_onKeyUp\"\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t\t><td dojoAttachPoint=\"topDecoration\" class=\"dijitReset dijitSliderDecoration dijitSliderDecorationT dijitSliderDecorationH\"></td\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitSliderButtonContainerH\"\n\t\t\t><div class=\"dijitSliderDecrementIconH\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"decrementButton\"><span class=\"dijitSliderButtonInner\">-</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><div class=\"dijitSliderBar dijitSliderBumper dijitSliderBumperH dijitSliderLeftBumper\" dojoAttachEvent=\"onmousedown:_onClkDecBumper\"></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><input dojoAttachPoint=\"valueNode\" type=\"hidden\" ${!nameAttrSetting}\n\t\t\t/><div waiRole=\"presentation\" class=\"dojoxRangeSliderBarContainer\" dojoAttachPoint=\"sliderBarContainer\"\n\t\t\t\t><div dojoAttachPoint=\"sliderHandle\" tabIndex=\"${tabIndex}\" class=\"dijitSliderMoveable dijitSliderMoveableH\" dojoAttachEvent=\"onmousedown:_onHandleClick\" waiRole=\"slider\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitSliderImageHandleH\"></div\n\t\t\t\t></div\n\t\t\t\t><div waiRole=\"presentation\" dojoAttachPoint=\"progressBar,focusNode\" class=\"dijitSliderBar dijitSliderBarH dijitSliderProgressBar dijitSliderProgressBarH\" dojoAttachEvent=\"onmousedown:_onBarClick\"></div\n\t\t\t\t><div dojoAttachPoint=\"sliderHandleMax,focusNodeMax\" tabIndex=\"${tabIndex}\" class=\"dijitSliderMoveable dijitSliderMoveableH\" dojoAttachEvent=\"onmousedown:_onHandleClickMax\" waiRole=\"sliderMax\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitSliderImageHandleH\"></div\n\t\t\t\t></div\n\t\t\t\t><div waiRole=\"presentation\" dojoAttachPoint=\"remainingBar\" class=\"dijitSliderBar dijitSliderBarH dijitSliderRemainingBar dijitSliderRemainingBarH\" dojoAttachEvent=\"onmousedown:_onRemainingBarClick\"></div\n\t\t\t></div\n\t\t></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><div class=\"dijitSliderBar dijitSliderBumper dijitSliderBumperH dijitSliderRightBumper\" dojoAttachEvent=\"onmousedown:_onClkIncBumper\"></div\n\t\t></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitSliderButtonContainerH\"\n\t\t\t><div class=\"dijitSliderIncrementIconH\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"incrementButton\"><span class=\"dijitSliderButtonInner\">+</span></div\n\t\t></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t\t><td dojoAttachPoint=\"containerNode,bottomDecoration\" class=\"dijitReset dijitSliderDecoration dijitSliderDecorationB dijitSliderDecorationH\"></td\n\t\t><td class=\"dijitReset\" colspan=\"2\"></td\n\t></tr\n></table>\n")});
296
dojo.declare("dojox.form.VerticalRangeSlider",[dijit.form.VerticalSlider,dojox.form._RangeSliderMixin],{templateString:dojo.cache("dojox.form","resources/VerticalRangeSlider.html","<table class=\"dijitReset dijitSlider dijitSliderV dojoxRangeSlider\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" rules=\"none\"\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitSliderButtonContainerV\"\n\t\t\t><div class=\"dijitSliderIncrementIconV\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"decrementButton\" dojoAttachEvent=\"onclick: increment\"><span class=\"dijitSliderButtonInner\">+</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><center><div class=\"dijitSliderBar dijitSliderBumper dijitSliderBumperV dijitSliderTopBumper\" dojoAttachEvent=\"onclick:_onClkIncBumper\"></div></center\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td dojoAttachPoint=\"leftDecoration\" class=\"dijitReset dijitSliderDecoration dijitSliderDecorationL dijitSliderDecorationV\" style=\"text-align:center;height:100%;\"></td\n\t\t><td class=\"dijitReset\" style=\"height:100%;\"\n\t\t\t><input dojoAttachPoint=\"valueNode\" type=\"hidden\" ${!nameAttrSetting}\n\t\t\t/><center waiRole=\"presentation\" style=\"position:relative;height:100%;\" dojoAttachPoint=\"sliderBarContainer\"\n\t\t\t\t><div waiRole=\"presentation\" dojoAttachPoint=\"remainingBar\" class=\"dijitSliderBar dijitSliderBarV dijitSliderRemainingBar dijitSliderRemainingBarV\" dojoAttachEvent=\"onmousedown:_onRemainingBarClick\"\n\t\t\t\t\t><div dojoAttachPoint=\"sliderHandle\" tabIndex=\"${tabIndex}\" class=\"dijitSliderMoveable dijitSliderMoveableV\" dojoAttachEvent=\"onkeypress:_onKeyPress,onmousedown:_onHandleClick\" style=\"vertical-align:top;\" waiRole=\"slider\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitSliderImageHandleV\"></div\n\t\t\t\t\t></div\n\t\t\t\t\t><div waiRole=\"presentation\" dojoAttachPoint=\"progressBar,focusNode\" tabIndex=\"${tabIndex}\" class=\"dijitSliderBar dijitSliderBarV dijitSliderProgressBar dijitSliderProgressBarV\" dojoAttachEvent=\"onkeypress:_onKeyPress,onmousedown:_onBarClick\"\n\t\t\t\t\t></div\n\t\t\t\t\t><div dojoAttachPoint=\"sliderHandleMax,focusNodeMax\" tabIndex=\"${tabIndex}\" class=\"dijitSliderMoveable dijitSliderMoveableV\" dojoAttachEvent=\"onkeypress:_onKeyPress,onmousedown:_onHandleClickMax\" style=\"vertical-align:top;\" waiRole=\"slider\" valuemin=\"${minimum}\" valuemax=\"${maximum}\"\n\t\t\t\t\t\t><div class=\"dijitSliderImageHandle dijitSliderImageHandleV\"></div\n\t\t\t\t\t></div\n\t\t\t\t></div\n\t\t\t></center\n\t\t></td\n\t\t><td dojoAttachPoint=\"containerNode,rightDecoration\" class=\"dijitReset dijitSliderDecoration dijitSliderDecorationR dijitSliderDecorationV\" style=\"text-align:center;height:100%;\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset\"\n\t\t\t><center><div class=\"dijitSliderBar dijitSliderBumper dijitSliderBumperV dijitSliderBottomBumper\" dojoAttachEvent=\"onclick:_onClkDecBumper\"></div></center\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset\"></td\n\t\t><td class=\"dijitReset dijitSliderButtonContainer dijitSliderButtonContainerV\"\n\t\t\t><div class=\"dijitSliderDecrementIconV\" tabIndex=\"-1\" style=\"display:none\" dojoAttachPoint=\"incrementButton\" dojoAttachEvent=\"onclick: decrement\"><span class=\"dijitSliderButtonInner\">-</span></div\n\t\t></td\n\t\t><td class=\"dijitReset\"></td\n\t></tr\n></table>\n")});
297
})();
298
}