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