4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-slider-Thumb'>/**
19 </span> * @class Ext.slider.Thumb
22 * Represents a single thumb element on a Slider. This would not usually be created manually and would instead
23 * be created internally by an {@link Ext.slider.Multi Ext.Slider}.
25 Ext.define('Ext.slider.Thumb', {
26 requires: ['Ext.dd.DragTracker', 'Ext.util.Format'],
27 <span id='Ext-slider-Thumb-property-topThumbZIndex'> /**
29 * @property topThumbZIndex
31 * The number used internally to set the z index of the top thumb (see promoteThumb for details)
34 <span id='Ext-slider-Thumb-cfg-slider'> /**
35 </span> * @cfg {Ext.slider.MultiSlider} slider The Slider to render to (required)
37 <span id='Ext-slider-Thumb-method-constructor'> /**
38 </span> * Creates new slider thumb.
39 * @param {Object} config (optional) Config object.
41 constructor: function(config) {
44 <span id='Ext-slider-Thumb-property-slider'> /**
45 </span> * @property slider
46 * @type Ext.slider.MultiSlider
47 * The slider this thumb is contained within
49 Ext.apply(me, config || {}, {
50 cls: Ext.baseCSSPrefix + 'slider-thumb',
52 <span id='Ext-slider-Thumb-cfg-constrain'> /**
53 </span> * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
57 me.callParent([config]);
59 if (me.slider.vertical) {
60 Ext.apply(me, Ext.slider.Thumb.Vertical);
64 <span id='Ext-slider-Thumb-method-render'> /**
65 </span> * Renders the thumb into a slider
70 me.el = me.slider.innerEl.insertFirst({cls: me.cls});
77 <span id='Ext-slider-Thumb-method-move'> /**
81 move: function(v, animate){
85 Ext.create('Ext.fx.Anim', {
95 <span id='Ext-slider-Thumb-method-bringToFront'> /**
97 * Bring thumb dom element to front.
99 bringToFront: function() {
100 this.el.setStyle('zIndex', this.topZIndex);
103 <span id='Ext-slider-Thumb-method-sendToBack'> /**
105 * Send thumb dom element to back.
107 sendToBack: function() {
108 this.el.setStyle('zIndex', '');
111 <span id='Ext-slider-Thumb-method-enable'> /**
112 </span> * Enables the thumb if it is currently disabled
119 me.el.removeCls(me.slider.disabledCls);
123 <span id='Ext-slider-Thumb-method-disable'> /**
124 </span> * Disables the thumb if it is currently enabled
126 disable: function() {
131 me.el.addCls(me.slider.disabledCls);
135 <span id='Ext-slider-Thumb-method-initEvents'> /**
136 </span> * Sets up an Ext.dd.DragTracker for this thumb
138 initEvents: function() {
142 me.tracker = Ext.create('Ext.dd.DragTracker', {
143 onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
144 onStart : Ext.Function.bind(me.onDragStart, me),
145 onDrag : Ext.Function.bind(me.onDrag, me),
146 onEnd : Ext.Function.bind(me.onDragEnd, me),
149 overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
152 me.tracker.initEl(el);
155 <span id='Ext-slider-Thumb-method-onBeforeDragStart'> /**
157 * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
158 * this returns false to disable the DragTracker too.
159 * @return {Boolean} False if the slider is currently disabled
161 onBeforeDragStart : function(e) {
165 this.slider.promoteThumb(this);
170 <span id='Ext-slider-Thumb-method-onDragStart'> /**
172 * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
173 * to the thumb and fires the 'dragstart' event
175 onDragStart: function(e){
178 me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
180 me.dragStartValue = me.value;
182 me.slider.fireEvent('dragstart', me.slider, e, me);
185 <span id='Ext-slider-Thumb-method-onDrag'> /**
187 * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
188 * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
190 onDrag: function(e) {
194 newValue = me.getNewValue(),
199 above = slider.thumbs[index + 1];
200 below = slider.thumbs[index - 1];
202 if (below !== undefined && newValue <= below.value) {
203 newValue = below.value;
206 if (above !== undefined && newValue >= above.value) {
207 newValue = above.value;
211 slider.setValue(index, newValue, false);
212 slider.fireEvent('drag', slider, e, me);
215 getNewValue: function() {
216 var slider = this.slider,
217 pos = slider.innerEl.translatePoints(this.tracker.getXY());
219 return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
222 <span id='Ext-slider-Thumb-method-onDragEnd'> /**
224 * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
225 * fires the 'changecomplete' event with the new value
227 onDragEnd: function(e) {
232 me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
235 slider.fireEvent('dragend', slider, e);
237 if (me.dragStartValue != value) {
238 slider.fireEvent('changecomplete', slider, value, me);
242 destroy: function() {
243 Ext.destroy(this.tracker);
246 // Method overrides to support vertical dragging of thumb within slider
248 getNewValue: function() {
249 var slider = this.slider,
250 innerEl = slider.innerEl,
251 pos = innerEl.translatePoints(this.tracker.getXY()),
252 bottom = innerEl.getHeight() - pos.top;
254 return Ext.util.Format.round(slider.reverseValue(bottom), slider.decimalPrecision);
256 move: function(v, animate) {
258 this.el.setBottom(v);
260 Ext.create('Ext.fx.Anim', {