3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.slider.Thumb
19 * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
20 * be created internally by an {@link Ext.slider.Multi Ext.Slider}.
22 Ext.define('Ext.slider.Thumb', {
23 requires: ['Ext.dd.DragTracker', 'Ext.util.Format'],
26 * @property topThumbZIndex
28 * The number used internally to set the z index of the top thumb (see promoteThumb for details)
32 * @cfg {Ext.slider.MultiSlider} slider The Slider to render to (required)
35 * Creates new slider thumb.
36 * @param {Object} config (optional) Config object.
38 constructor: function(config) {
43 * @type Ext.slider.MultiSlider
44 * The slider this thumb is contained within
46 Ext.apply(me, config || {}, {
47 cls: Ext.baseCSSPrefix + 'slider-thumb',
50 * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
54 me.callParent([config]);
56 if (me.slider.vertical) {
57 Ext.apply(me, Ext.slider.Thumb.Vertical);
62 * Renders the thumb into a slider
67 me.el = me.slider.innerEl.insertFirst({cls: me.cls});
78 move: function(v, animate){
82 Ext.create('Ext.fx.Anim', {
94 * Bring thumb dom element to front.
96 bringToFront: function() {
97 this.el.setStyle('zIndex', this.topZIndex);
102 * Send thumb dom element to back.
104 sendToBack: function() {
105 this.el.setStyle('zIndex', '');
109 * Enables the thumb if it is currently disabled
116 me.el.removeCls(me.slider.disabledCls);
121 * Disables the thumb if it is currently enabled
123 disable: function() {
128 me.el.addCls(me.slider.disabledCls);
133 * Sets up an Ext.dd.DragTracker for this thumb
135 initEvents: function() {
139 me.tracker = Ext.create('Ext.dd.DragTracker', {
140 onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
141 onStart : Ext.Function.bind(me.onDragStart, me),
142 onDrag : Ext.Function.bind(me.onDrag, me),
143 onEnd : Ext.Function.bind(me.onDragEnd, me),
146 overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
149 me.tracker.initEl(el);
154 * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
155 * this returns false to disable the DragTracker too.
156 * @return {Boolean} False if the slider is currently disabled
158 onBeforeDragStart : function(e) {
162 this.slider.promoteThumb(this);
169 * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
170 * to the thumb and fires the 'dragstart' event
172 onDragStart: function(e){
175 me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
177 me.dragStartValue = me.value;
179 me.slider.fireEvent('dragstart', me.slider, e, me);
184 * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
185 * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
187 onDrag: function(e) {
191 newValue = me.getNewValue(),
196 above = slider.thumbs[index + 1];
197 below = slider.thumbs[index - 1];
199 if (below !== undefined && newValue <= below.value) {
200 newValue = below.value;
203 if (above !== undefined && newValue >= above.value) {
204 newValue = above.value;
208 slider.setValue(index, newValue, false);
209 slider.fireEvent('drag', slider, e, me);
212 getNewValue: function() {
213 var slider = this.slider,
214 pos = slider.innerEl.translatePoints(this.tracker.getXY());
216 return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
221 * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
222 * fires the 'changecomplete' event with the new value
224 onDragEnd: function(e) {
229 me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
232 slider.fireEvent('dragend', slider, e);
234 if (me.dragStartValue != value) {
235 slider.fireEvent('changecomplete', slider, value, me);
239 destroy: function() {
240 Ext.destroy(this.tracker);
243 // Method overrides to support vertical dragging of thumb within slider
245 getNewValue: function() {
246 var slider = this.slider,
247 innerEl = slider.innerEl,
248 pos = innerEl.translatePoints(this.tracker.getXY()),
249 bottom = innerEl.getHeight() - pos.top;
251 return Ext.util.Format.round(slider.reverseValue(bottom), slider.decimalPrecision);
253 move: function(v, animate) {
255 this.el.setBottom(v);
257 Ext.create('Ext.fx.Anim', {