4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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 Multi 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 {Number} topThumbZIndex
30 * 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 (required)
36 * The Slider to render to.
39 <span id='Ext-slider-Thumb-method-constructor'> /**
40 </span> * Creates new slider thumb.
41 * @param {Object} config (optional) Config object.
43 constructor: function(config) {
46 <span id='Ext-slider-Thumb-property-slider'> /**
47 </span> * @property {Ext.slider.MultiSlider} slider
48 * The slider this thumb is contained within
50 Ext.apply(me, config || {}, {
51 cls: Ext.baseCSSPrefix + 'slider-thumb',
53 <span id='Ext-slider-Thumb-cfg-constrain'> /**
54 </span> * @cfg {Boolean} constrain True to constrain the thumb so that it cannot overlap its siblings
58 me.callParent([config]);
60 if (me.slider.vertical) {
61 Ext.apply(me, Ext.slider.Thumb.Vertical);
65 <span id='Ext-slider-Thumb-method-render'> /**
66 </span> * Renders the thumb into a slider
71 me.el = me.slider.innerEl.insertFirst({cls: me.cls});
78 <span id='Ext-slider-Thumb-method-move'> /**
82 move: function(v, animate){
86 Ext.create('Ext.fx.Anim', {
96 <span id='Ext-slider-Thumb-method-bringToFront'> /**
98 * Bring thumb dom element to front.
100 bringToFront: function() {
101 this.el.setStyle('zIndex', this.topZIndex);
104 <span id='Ext-slider-Thumb-method-sendToBack'> /**
106 * Send thumb dom element to back.
108 sendToBack: function() {
109 this.el.setStyle('zIndex', '');
112 <span id='Ext-slider-Thumb-method-enable'> /**
113 </span> * Enables the thumb if it is currently disabled
120 me.el.removeCls(me.slider.disabledCls);
124 <span id='Ext-slider-Thumb-method-disable'> /**
125 </span> * Disables the thumb if it is currently enabled
127 disable: function() {
132 me.el.addCls(me.slider.disabledCls);
136 <span id='Ext-slider-Thumb-method-initEvents'> /**
137 </span> * Sets up an Ext.dd.DragTracker for this thumb
139 initEvents: function() {
143 me.tracker = Ext.create('Ext.dd.DragTracker', {
144 onBeforeStart: Ext.Function.bind(me.onBeforeDragStart, me),
145 onStart : Ext.Function.bind(me.onDragStart, me),
146 onDrag : Ext.Function.bind(me.onDrag, me),
147 onEnd : Ext.Function.bind(me.onDragEnd, me),
150 overCls : Ext.baseCSSPrefix + 'slider-thumb-over'
153 me.tracker.initEl(el);
156 <span id='Ext-slider-Thumb-method-onBeforeDragStart'> /**
158 * This is tied into the internal Ext.dd.DragTracker. If the slider is currently disabled,
159 * this returns false to disable the DragTracker too.
160 * @return {Boolean} False if the slider is currently disabled
162 onBeforeDragStart : function(e) {
166 this.slider.promoteThumb(this);
171 <span id='Ext-slider-Thumb-method-onDragStart'> /**
173 * This is tied into the internal Ext.dd.DragTracker's onStart template method. Adds the drag CSS class
174 * to the thumb and fires the 'dragstart' event
176 onDragStart: function(e){
179 me.el.addCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
181 me.dragStartValue = me.value;
183 me.slider.fireEvent('dragstart', me.slider, e, me);
186 <span id='Ext-slider-Thumb-method-onDrag'> /**
188 * This is tied into the internal Ext.dd.DragTracker's onDrag template method. This is called every time
189 * the DragTracker detects a drag movement. It updates the Slider's value using the position of the drag
191 onDrag: function(e) {
195 newValue = me.getNewValue(),
200 above = slider.thumbs[index + 1];
201 below = slider.thumbs[index - 1];
203 if (below !== undefined && newValue <= below.value) {
204 newValue = below.value;
207 if (above !== undefined && newValue >= above.value) {
208 newValue = above.value;
212 slider.setValue(index, newValue, false);
213 slider.fireEvent('drag', slider, e, me);
216 getNewValue: function() {
217 var slider = this.slider,
218 pos = slider.innerEl.translatePoints(this.tracker.getXY());
220 return Ext.util.Format.round(slider.reverseValue(pos.left), slider.decimalPrecision);
223 <span id='Ext-slider-Thumb-method-onDragEnd'> /**
225 * This is tied to the internal Ext.dd.DragTracker's onEnd template method. Removes the drag CSS class and
226 * fires the 'changecomplete' event with the new value
228 onDragEnd: function(e) {
233 me.el.removeCls(Ext.baseCSSPrefix + 'slider-thumb-drag');
236 slider.fireEvent('dragend', slider, e);
238 if (me.dragStartValue != value) {
239 slider.fireEvent('changecomplete', slider, value, me);
243 destroy: function() {
244 Ext.destroy(this.tracker);
247 // Method overrides to support vertical dragging of thumb within slider
249 getNewValue: function() {
250 var slider = this.slider,
251 innerEl = slider.innerEl,
252 pos = innerEl.translatePoints(this.tracker.getXY()),
253 bottom = innerEl.getHeight() - pos.top;
255 return Ext.util.Format.round(slider.reverseValue(bottom), slider.decimalPrecision);
257 move: function(v, animate) {
259 this.el.setBottom(v);
261 Ext.create('Ext.fx.Anim', {