3 * @class Ext.slider.Thumb
6 * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
7 * be created internally by an {@link Ext.slider.Multi Ext.Slider}.
9 Ext.define('Ext.slider.Thumb', {
10 requires: ['Ext.dd.DragTracker', 'Ext.util.Format'],
13 * @property topThumbZIndex
15 * The number used internally to set the z index of the top thumb (see promoteThumb for details)
20 * @cfg {Ext.slider.MultiSlider} slider The Slider to render to (required)
22 constructor: function(config) {
27 * @type Ext.slider.MultiSlider
28 * The slider this thumb is contained within
30 Ext.apply(me, config || {}, {
31 cls: Ext.baseCSSPrefix + 'slider-thumb',
34 * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
38 me.callParent([config]);
40 if (me.slider.vertical) {
41 Ext.apply(me, Ext.slider.Thumb.Vertical);
46 * Renders the thumb into a slider
51 me.el = me.slider.innerEl.insertFirst({cls: me.cls});
62 move: function(v, animate){
66 Ext.create('Ext.fx.Anim', {
78 * Bring thumb dom element to front.
80 bringToFront: function() {
81 this.el.setStyle('zIndex', this.topZIndex);
86 * Send thumb dom element to back.
88 sendToBack: function() {
89 this.el.setStyle('zIndex', '');
93 * Enables the thumb if it is currently disabled
100 me.el.removeCls(me.slider.disabledCls);
105 * Disables the thumb if it is currently enabled
107 disable: function() {
112 me.el.addCls(me.slider.disabledCls);
117 * Sets up an Ext.dd.DragTracker for this thumb
119 initEvents: function() {
123 me.tracker = Ext.create('Ext.dd.DragTracker', {
124 onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
125 onStart : Ext.Function.bind(me.onDragStart, me),
126 onDrag : Ext.Function.bind(me.onDrag, me),
127 onEnd : Ext.Function.bind(me.onDragEnd, me),
130 overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
133 me.tracker.initEl(el);
138 * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
139 * this returns false to disable the DragTracker too.
140 * @return {Boolean} False if the slider is currently disabled
142 onBeforeDragStart : function(e) {
146 this.slider.promoteThumb(this);
153 * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
154 * to the thumb and fires the 'dragstart' event
156 onDragStart: function(e){
159 me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
161 me.dragStartValue = me.value;
163 me.slider.fireEvent('dragstart', me.slider, e, me);
168 * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
169 * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
171 onDrag: function(e) {
175 newValue = me.getNewValue(),
180 above = slider.thumbs[index + 1];
181 below = slider.thumbs[index - 1];
183 if (below !== undefined && newValue <= below.value) {
184 newValue = below.value;
187 if (above !== undefined && newValue >= above.value) {
188 newValue = above.value;
192 slider.setValue(index, newValue, false);
193 slider.fireEvent('drag', slider, e, me);
196 getNewValue: function() {
197 var slider = this.slider,
198 pos = slider.innerEl.translatePoints(this.tracker.getXY());
200 return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
205 * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
206 * fires the 'changecomplete' event with the new value
208 onDragEnd: function(e) {
213 me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
216 slider.fireEvent('dragend', slider, e);
218 if (me.dragStartValue != value) {
219 slider.fireEvent('changecomplete', slider, value, me);
223 destroy: function() {
224 Ext.destroy(this.tracker);
227 // Method overrides to support vertical dragging of thumb within slider
229 getNewValue: function() {
230 var slider = this.slider,
231 innerEl = slider.innerEl,
232 pos = innerEl.translatePoints(this.tracker.getXY()),
233 bottom = innerEl.getHeight() - pos.top;
235 return Ext.util.Format.round(slider.reverseValue(bottom), slider.decimalPrecision);
237 move: function(v, animate) {
239 this.el.setBottom(v);
241 Ext.create('Ext.fx.Anim', {