Thumb.html
8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-slider-Thumb'>/**
</span> * @class Ext.slider.Thumb
* @private
* Represents a single thumb element on a Slider. This would not usually be created manually and would instead
* be created internally by an {@link Ext.slider.Multi Multi slider}.
*/
Ext.define('Ext.slider.Thumb', {
requires: ['Ext.dd.DragTracker', 'Ext.util.Format'],
<span id='Ext-slider-Thumb-property-topThumbZIndex'> /**
</span> * @private
* @property {Number} topThumbZIndex
* The number used internally to set the z index of the top thumb (see promoteThumb for details)
*/
topZIndex: 10000,
<span id='Ext-slider-Thumb-cfg-slider'> /**
</span> * @cfg {Ext.slider.MultiSlider} slider (required)
* The Slider to render to.
*/
<span id='Ext-slider-Thumb-method-constructor'> /**
</span> * Creates new slider thumb.
* @param {Object} [config] Config object.
*/
constructor: function(config) {
var me = this;
<span id='Ext-slider-Thumb-property-slider'> /**
</span> * @property {Ext.slider.MultiSlider} slider
* The slider this thumb is contained within
*/
Ext.apply(me, config || {}, {
cls: Ext.baseCSSPrefix + 'slider-thumb',
<span id='Ext-slider-Thumb-cfg-constrain'> /**
</span> * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
*/
constrain: false
});
me.callParent([config]);
},
<span id='Ext-slider-Thumb-method-render'> /**
</span> * Renders the thumb into a slider
*/
render: function() {
var me = this;
me.el = me.slider.innerEl.insertFirst(me.getElConfig());
me.onRender();
},
onRender: function() {
if (this.disabled) {
this.disable();
}
this.initEvents();
},
getElConfig: function() {
var me = this,
slider = me.slider,
style = {};
style[slider.vertical ? 'bottom' : 'left'] = slider.calculateThumbPosition(slider.normalizeValue(me.value)) + '%';
return {
style: style,
id : this.id,
cls : this.cls
};
},
<span id='Ext-slider-Thumb-method-move'> /**
</span> * @private
* move the thumb
*/
move: function(v, animate) {
var el = this.el,
styleProp = this.slider.vertical ? 'bottom' : 'left',
to,
from;
v += '%';
if (!animate) {
el.dom.style[styleProp] = v;
} else {
to = {};
to[styleProp] = v;
if (!Ext.supports.GetPositionPercentage) {
from = {};
from[styleProp] = el.dom.style[styleProp];
}
new Ext.fx.Anim({
target: el,
duration: 350,
from: from,
to: to
});
}
},
<span id='Ext-slider-Thumb-method-bringToFront'> /**
</span> * @private
* Bring thumb dom element to front.
*/
bringToFront: function() {
this.el.setStyle('zIndex', this.topZIndex);
},
<span id='Ext-slider-Thumb-method-sendToBack'> /**
</span> * @private
* Send thumb dom element to back.
*/
sendToBack: function() {
this.el.setStyle('zIndex', '');
},
<span id='Ext-slider-Thumb-method-enable'> /**
</span> * Enables the thumb if it is currently disabled
*/
enable: function() {
var me = this;
me.disabled = false;
if (me.el) {
me.el.removeCls(me.slider.disabledCls);
}
},
<span id='Ext-slider-Thumb-method-disable'> /**
</span> * Disables the thumb if it is currently enabled
*/
disable: function() {
var me = this;
me.disabled = true;
if (me.el) {
me.el.addCls(me.slider.disabledCls);
}
},
<span id='Ext-slider-Thumb-method-initEvents'> /**
</span> * Sets up an Ext.dd.DragTracker for this thumb
*/
initEvents: function() {
var me = this,
el = me.el;
me.tracker = new Ext.dd.DragTracker({
onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
onStart : Ext.Function.bind(me.onDragStart, me),
onDrag : Ext.Function.bind(me.onDrag, me),
onEnd : Ext.Function.bind(me.onDragEnd, me),
tolerance : 3,
autoStart : 300,
overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
});
me.tracker.initEl(el);
},
<span id='Ext-slider-Thumb-method-onBeforeDragStart'> /**
</span> * @private
* This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
* this returns false to disable the DragTracker too.
* @return {Boolean} False if the slider is currently disabled
*/
onBeforeDragStart : function(e) {
if (this.disabled) {
return false;
} else {
this.slider.promoteThumb(this);
return true;
}
},
<span id='Ext-slider-Thumb-method-onDragStart'> /**
</span> * @private
* This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
* to the thumb and fires the 'dragstart' event
*/
onDragStart: function(e){
var me = this;
me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
me.dragging = me.slider.dragging = true;
me.dragStartValue = me.value;
me.slider.fireEvent('dragstart', me.slider, e, me);
},
<span id='Ext-slider-Thumb-method-onDrag'> /**
</span> * @private
* This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
* the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
*/
onDrag: function(e) {
var me = this,
slider = me.slider,
index = me.index,
newValue = me.getValueFromTracker(),
above,
below;
// If dragged out of range, value will be undefined
if (newValue !== undefined) {
if (me.constrain) {
above = slider.thumbs[index + 1];
below = slider.thumbs[index - 1];
if (below !== undefined && newValue <= below.value) {
newValue = below.value;
}
if (above !== undefined && newValue >= above.value) {
newValue = above.value;
}
}
slider.setValue(index, newValue, false);
slider.fireEvent('drag', slider, e, me);
}
},
getValueFromTracker: function() {
var slider = this.slider,
trackPoint = slider.getTrackpoint(this.tracker.getXY());
// If dragged out of range, value will be undefined
if (trackPoint !== undefined) {
return slider.reversePixelValue(trackPoint);
}
},
<span id='Ext-slider-Thumb-method-onDragEnd'> /**
</span> * @private
* This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
* fires the 'changecomplete' event with the new value
*/
onDragEnd: function(e) {
var me = this,
slider = me.slider,
value = me.value;
me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
me.dragging = slider.dragging = false;
slider.fireEvent('dragend', slider, e);
if (me.dragStartValue != value) {
slider.fireEvent('changecomplete', slider, value, me);
}
},
destroy: function() {
Ext.destroy(this.tracker);
}
});
</pre>
</body>
</html>