Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / slider / Single.js
1 /**
2  * @class Ext.slider.Single
3  * @extends Ext.slider.Multi
4  * Slider which supports vertical or horizontal orientation, keyboard adjustments,
5  * configurable snapping, axis clicking and animation. Can be added as an item to
6  * any container. 
7  * {@img Ext.slider.Single/Ext.slider.Single.png Ext.slider.Single component}
8  * Example usage:
9 <pre><code>
10     Ext.create('Ext.slider.Single', {
11         width: 200,
12         value: 50,
13         increment: 10,
14         minValue: 0,
15         maxValue: 100,
16         renderTo: Ext.getBody()
17     });
18 </code></pre>
19  * The class Ext.slider.Single is aliased to Ext.Slider for backwards compatibility.
20  * @xtype slider
21  */
22 Ext.define('Ext.slider.Single', {
23     extend: 'Ext.slider.Multi',
24     alias: ['widget.slider', 'widget.sliderfield'],
25     alternateClassName: ['Ext.Slider', 'Ext.form.SliderField', 'Ext.slider.SingleSlider', 'Ext.slider.Slider'],
26
27     /**
28      * Returns the current value of the slider
29      * @return {Number} The current value of the slider
30      */
31     getValue: function() {
32         //just returns the value of the first thumb, which should be the only one in a single slider
33         return this.callParent([0]);
34     },
35
36     /**
37      * Programmatically sets the value of the Slider. Ensures that the value is constrained within
38      * the minValue and maxValue.
39      * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)
40      * @param {Boolean} animate Turn on or off animation, defaults to true
41      */
42     setValue: function(value, animate) {
43         var args = Ext.toArray(arguments),
44             len  = args.length;
45
46         //this is to maintain backwards compatiblity for sliders with only one thunb. Usually you must pass the thumb
47         //index to setValue, but if we only have one thumb we inject the index here first if given the multi-slider
48         //signature without the required index. The index will always be 0 for a single slider
49         if (len == 1 || (len <= 3 && typeof arguments[1] != 'number')) {
50             args.unshift(0);
51         }
52
53         return this.callParent(args);
54     },
55
56     // private
57     getNearest : function(){
58         // Since there's only 1 thumb, it's always the nearest
59         return this.thumbs[0];
60     }
61 });