1
1
Framework . Components . registerComponent ( "range" , {
2
2
3
- getValue : function ( ) {
4
- return this . values ;
3
+ getValue : function ( full ) {
4
+ return ! full && this . singleMode ? this . values [ 1 ] : this . values ;
5
5
} ,
6
6
7
7
getMinimum : function ( ) {
@@ -14,17 +14,22 @@ Framework.Components.registerComponent("range", {
14
14
15
15
setMinimum : function ( min ) {
16
16
this . min = min ;
17
+ this . values [ 0 ] = Math . min ( this . values [ 0 ] , this . min ) ;
17
18
this . updateValues ( ) ;
18
19
} ,
19
20
20
21
setMaximum : function ( max ) {
21
22
this . max = max ;
23
+ this . values [ 1 ] = Math . max ( this . values [ 1 ] , this . max ) ;
22
24
this . updateValues ( ) ;
23
25
} ,
24
26
25
27
setValue : function ( val ) {
28
+ if ( ! Object . isArray ( val ) )
29
+ val = [ this . min , val * 1 ] ;
30
+
26
31
if ( this . oldValues [ 0 ] == val [ 0 ] && this . oldValues [ 1 ] == val [ 1 ] ) {
27
- this . updateLayout ( ) ;
32
+ this . updateLayout ( this . getElement ( ) ) ;
28
33
return ; // No update
29
34
}
30
35
@@ -33,19 +38,30 @@ Framework.Components.registerComponent("range", {
33
38
this . updateValues ( ) ;
34
39
} ,
35
40
36
- updateLayout : function ( ) {
37
- var el = this . getElement ( ) ;
38
- var width = el . measure ( "width" ) - ( this . knobSize * 2 ) ;
41
+ updateLayout : function ( el ) {
42
+ var width ;
43
+ if ( this . singleMode ) {
44
+ width = el . measure ( "width" ) - this . knobSize ;
45
+ } else {
46
+ width = el . measure ( "width" ) - ( this . knobSize * 2 ) ;
47
+ }
39
48
var minPerc = ( ( this . values [ 0 ] - this . min ) / this . valMod ) ;
40
49
var maxPerc = ( ( this . values [ 1 ] - this . min ) / this . valMod ) ;
41
50
this . minKnob . slideTo ( {
42
51
"left" : ( minPerc * width ) + "px"
43
52
} ) ;
44
- this . maxKnob . slideTo ( {
45
- "left" : ( this . knobSize + ( maxPerc * width ) ) + "px"
46
- } ) ;
47
- var left = minPerc * width ;
48
- var right = ( maxPerc * width ) + this . knobSize ;
53
+ if ( this . singleMode )
54
+ this . maxKnob . slideTo ( {
55
+ "left" : ( maxPerc * width ) + "px"
56
+ } ) ;
57
+ else
58
+ this . maxKnob . slideTo ( {
59
+ "left" : ( this . knobSize + ( maxPerc * width ) ) + "px"
60
+ } ) ;
61
+ var left = this . singleMode ? 0 : minPerc * width ;
62
+ var right = ( maxPerc * width ) ;
63
+ if ( ! this . singleMode )
64
+ right += this . knobSize ;
49
65
this . bar . slideTo ( {
50
66
"left" : left + "px"
51
67
} ) ;
@@ -72,9 +88,25 @@ Framework.Components.registerComponent("range", {
72
88
this . tick = el . readAttribute ( "tick" ) * 1 || 1 ;
73
89
this . valMod = this . max - this . min ;
74
90
91
+ this . singleMode = el . hasAttribute ( "single" ) ;
92
+ if ( this . singleMode )
93
+ this . minKnob . hide ( ) ;
94
+ else
95
+ this . minKnob . show ( ) ;
96
+
97
+ this . disabled = el . hasAttribute ( "disabled" ) ;
98
+ if ( this . disabled )
99
+ el . addClassName ( "disabled" ) ;
100
+ else
101
+ el . removeClassName ( "disabled" ) ;
102
+
75
103
this . values = el . readAttribute ( "value" ) ;
76
104
if ( this . values ) {
77
105
this . values = this . values . split ( / [ , \s ] + / ) ;
106
+ if ( ! this . values [ 1 ] ) {
107
+ this . values [ 1 ] = this . values [ 0 ] ;
108
+ this . values [ 0 ] = this . min ;
109
+ }
78
110
this . values = [ this . values [ 0 ] * 1 , this . values [ 1 ] * 1 ] ;
79
111
} else
80
112
this . values = [ this . min , this . max ] ;
@@ -101,6 +133,14 @@ Framework.Components.registerComponent("range", {
101
133
this . makeDraggable ( this . minKnob ) ;
102
134
this . makeDraggable ( this . maxKnob ) ;
103
135
136
+ Event . on ( this . minKnob , "drag:start" , ( function ( e ) {
137
+ if ( this . disabled )
138
+ e . stop ( ) ; // Prevent event
139
+ } ) . bind ( this ) ) ;
140
+ Event . on ( this . maxKnob , "drag:start" , ( function ( e ) {
141
+ if ( this . disabled )
142
+ e . stop ( ) ; // Prevent event
143
+ } ) . bind ( this ) ) ;
104
144
Event . on ( this . minKnob , "drag:move" , ( function ( e ) {
105
145
var pos = e . memo ;
106
146
//console.log(pos);
@@ -127,7 +167,10 @@ Framework.Components.registerComponent("range", {
127
167
//console.log(pos);
128
168
129
169
var width = el . measure ( "width" ) ;
130
- pos . left = Math . max ( this . knobSize , pos . left ) ;
170
+ if ( this . singleMode )
171
+ pos . left = Math . max ( 0 , pos . left ) ;
172
+ else
173
+ pos . left = Math . max ( this . knobSize , pos . left ) ;
131
174
pos . left = Math . min ( width - this . knobSize , pos . left ) ;
132
175
this . maxKnob . setStyle ( { "left" : pos . left + "px" } ) ;
133
176
width -= this . knobSize * 2 ;
@@ -147,7 +190,7 @@ Framework.Components.registerComponent("range", {
147
190
Event . on ( this . minKnob , "drag:stop" , ( function ( e ) {
148
191
var val = this . minKnob . measure ( "left" ) ;
149
192
val /= el . measure ( "width" ) - ( this . knobSize * 2 ) ;
150
- console . log ( val ) ;
193
+ // console.log(val);
151
194
val *= this . valMod ;
152
195
val += this . min ;
153
196
@@ -159,9 +202,13 @@ Framework.Components.registerComponent("range", {
159
202
Event . on ( this . maxKnob , "drag:stop" , ( function ( e ) {
160
203
var val = this . maxKnob . measure ( "left" ) ;
161
204
162
- val -= this . knobSize ;
163
- val /= el . measure ( "width" ) - ( this . knobSize * 2 ) ;
164
- console . log ( val ) ;
205
+ if ( this . singleMode )
206
+ val /= el . measure ( "width" ) - this . knobSize ;
207
+ else {
208
+ val -= this . knobSize ;
209
+ val /= el . measure ( "width" ) - ( this . knobSize * 2 ) ;
210
+ }
211
+ //console.log(val);
165
212
val *= this . valMod ;
166
213
val += this . min ;
167
214
0 commit comments