/*!
- * Ext JS Library 3.0.0
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.1.1
+ * Copyright(c) 2006-2010 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
</code></pre>\r
*/\r
Ext.Slider = Ext.extend(Ext.BoxComponent, {\r
- /**\r
- * @cfg {Number} value The value to initialize the slider with. Defaults to minValue.\r
- */\r
- /**\r
- * @cfg {Boolean} vertical Orient the Slider vertically rather than horizontally, defaults to false.\r
- */\r
+ /**\r
+ * @cfg {Number} value The value to initialize the slider with. Defaults to minValue.\r
+ */\r
+ /**\r
+ * @cfg {Boolean} vertical Orient the Slider vertically rather than horizontally, defaults to false.\r
+ */\r
vertical: false,\r
- /**\r
- * @cfg {Number} minValue The minimum value for the Slider. Defaults to 0.\r
- */\r
+ /**\r
+ * @cfg {Number} minValue The minimum value for the Slider. Defaults to 0.\r
+ */\r
minValue: 0,\r
- /**\r
- * @cfg {Number} maxValue The maximum value for the Slider. Defaults to 100.\r
- */\r
+ /**\r
+ * @cfg {Number} maxValue The maximum value for the Slider. Defaults to 100.\r
+ */\r
maxValue: 100,\r
/**\r
* @cfg {Number/Boolean} decimalPrecision.\r
* <p>To disable rounding, configure as <tt><b>false</b></tt>.</p>\r
*/\r
decimalPrecision: 0,\r
- /**\r
- * @cfg {Number} keyIncrement How many units to change the Slider when adjusting with keyboard navigation. Defaults to 1. If the increment config is larger, it will be used instead.\r
- */\r
+ /**\r
+ * @cfg {Number} keyIncrement How many units to change the Slider when adjusting with keyboard navigation. Defaults to 1. If the increment config is larger, it will be used instead.\r
+ */\r
keyIncrement: 1,\r
- /**\r
- * @cfg {Number} increment How many units to change the slider when adjusting by drag and drop. Use this option to enable 'snapping'.\r
- */\r
+ /**\r
+ * @cfg {Number} increment How many units to change the slider when adjusting by drag and drop. Use this option to enable 'snapping'.\r
+ */\r
increment: 0,\r
- // private\r
+ // private\r
clickRange: [5,15],\r
- /**\r
- * @cfg {Boolean} clickToChange Determines whether or not clicking on the Slider axis will change the slider. Defaults to true\r
- */\r
+ /**\r
+ * @cfg {Boolean} clickToChange Determines whether or not clicking on the Slider axis will change the slider. Defaults to true\r
+ */\r
clickToChange : true,\r
- /**\r
- * @cfg {Boolean} animate Turn on or off animation. Defaults to true\r
- */\r
+ /**\r
+ * @cfg {Boolean} animate Turn on or off animation. Defaults to true\r
+ */\r
animate: true,\r
\r
/**\r
* @event beforechange\r
* Fires before the slider value is changed. By returning false from an event handler,\r
* you can cancel the event and prevent the slider from changing.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Number} newValue The new value which the slider is being changed to.\r
- * @param {Number} oldValue The old value which the slider was previously.\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Number} newValue The new value which the slider is being changed to.\r
+ * @param {Number} oldValue The old value which the slider was previously.\r
+ */\r
+ 'beforechange',\r
+ /**\r
+ * @event change\r
+ * Fires when the slider value is changed.\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Number} newValue The new value which the slider has been changed to.\r
*/\r
- 'beforechange',\r
- /**\r
- * @event change\r
- * Fires when the slider value is changed.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Number} newValue The new value which the slider has been changed to.\r
- */\r
- 'change',\r
- /**\r
- * @event changecomplete\r
- * Fires when the slider value is changed by the user and any drag operations have completed.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Number} newValue The new value which the slider has been changed to.\r
- */\r
- 'changecomplete',\r
- /**\r
- * @event dragstart\r
+ 'change',\r
+ /**\r
+ * @event changecomplete\r
+ * Fires when the slider value is changed by the user and any drag operations have completed.\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Number} newValue The new value which the slider has been changed to.\r
+ */\r
+ 'changecomplete',\r
+ /**\r
+ * @event dragstart\r
* Fires after a drag operation has started.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
- */\r
- 'dragstart',\r
- /**\r
- * @event drag\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
+ */\r
+ 'dragstart',\r
+ /**\r
+ * @event drag\r
* Fires continuously during the drag operation while the mouse is moving.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
- */\r
- 'drag',\r
- /**\r
- * @event dragend\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
+ */\r
+ 'drag',\r
+ /**\r
+ * @event dragend\r
* Fires after the drag operation has completed.\r
- * @param {Ext.Slider} slider The slider\r
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
- */\r
- 'dragend'\r
- );\r
+ * @param {Ext.Slider} slider The slider\r
+ * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker\r
+ */\r
+ 'dragend'\r
+ );\r
\r
if(this.vertical){\r
Ext.apply(this, Ext.Slider.Vertical);\r
}\r
},\r
\r
- // private override\r
+ // private override\r
onRender : function(){\r
this.autoEl = {\r
cls: 'x-slider ' + (this.vertical ? 'x-slider-vert' : 'x-slider-horz'),\r
this.initEvents();\r
},\r
\r
- // private override\r
+ // private override\r
initEvents : function(){\r
this.thumb.addClassOnOver('x-slider-thumb-over');\r
this.mon(this.el, {\r
autoStart: 300\r
});\r
this.tracker.initEl(this.thumb);\r
- this.on('beforedestroy', this.tracker.destroy, this.tracker);\r
},\r
\r
- // private override\r
+ // private override\r
onMouseDown : function(e){\r
- if(this.disabled) {return;}\r
+ if(this.disabled){\r
+ return;\r
+ }\r
if(this.clickToChange && e.target != this.thumb.dom){\r
var local = this.innerEl.translatePoints(e.getXY());\r
this.onClickChange(local);\r
this.focus();\r
},\r
\r
- // private\r
+ // private\r
onClickChange : function(local){\r
if(local.top > this.clickRange[0] && local.top < this.clickRange[1]){\r
this.setValue(Ext.util.Format.round(this.reverseValue(local.left), this.decimalPrecision), undefined, true);\r
}\r
},\r
\r
- // private\r
+ // private\r
onKeyDown : function(e){\r
if(this.disabled){e.preventDefault();return;}\r
var k = e.getKey();\r
}\r
},\r
\r
- // private\r
+ // private\r
doSnap : function(value){\r
- if(!this.increment || this.increment == 1 || !value) {\r
+ if(!(this.increment && value)){\r
return value;\r
}\r
- var newValue = value, inc = this.increment;\r
- var m = value % inc;\r
+ var newValue = value,\r
+ inc = this.increment,\r
+ m = value % inc;\r
if(m != 0){\r
newValue -= m;\r
if(m * 2 > inc){\r
return newValue.constrain(this.minValue, this.maxValue);\r
},\r
\r
- // private\r
+ // private\r
afterRender : function(){\r
Ext.Slider.superclass.afterRender.apply(this, arguments);\r
if(this.value !== undefined){\r
}\r
},\r
\r
- // private\r
+ // private\r
getRatio : function(){\r
- var w = this.innerEl.getWidth();\r
- var v = this.maxValue - this.minValue;\r
+ var w = this.innerEl.getWidth(),\r
+ v = this.maxValue - this.minValue;\r
return v == 0 ? w : (w/v);\r
},\r
\r
- // private\r
+ // private\r
normalizeValue : function(v){\r
v = this.doSnap(v);\r
v = Ext.util.Format.round(v, this.decimalPrecision);\r
v = v.constrain(this.minValue, this.maxValue);\r
return v;\r
},\r
+ \r
+ /**\r
+ * Sets the minimum value for the slider instance. If the current value is less than the \r
+ * minimum value, the current value will be changed.\r
+ * @param {Number} val The new minimum value\r
+ */\r
+ setMinValue : function(val){\r
+ this.minValue = val;\r
+ this.syncThumb();\r
+ if(this.value < val){\r
+ this.setValue(val);\r
+ }\r
+ },\r
+ \r
+ /**\r
+ * Sets the maximum value for the slider instance. If the current value is more than the \r
+ * maximum value, the current value will be changed.\r
+ * @param {Number} val The new maximum value\r
+ */\r
+ setMaxValue : function(val){\r
+ this.maxValue = val;\r
+ this.syncThumb();\r
+ if(this.value > val){\r
+ this.setValue(val);\r
+ }\r
+ },\r
\r
- /**\r
- * Programmatically sets the value of the Slider. Ensures that the value is constrained within\r
- * the minValue and maxValue.\r
- * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)\r
- * @param {Boolean} animate Turn on or off animation, defaults to true\r
- */\r
+ /**\r
+ * Programmatically sets the value of the Slider. Ensures that the value is constrained within\r
+ * the minValue and maxValue.\r
+ * @param {Number} value The value to set the slider to. (This will be constrained within minValue and maxValue)\r
+ * @param {Boolean} animate Turn on or off animation, defaults to true\r
+ */\r
setValue : function(v, animate, changeComplete){\r
v = this.normalizeValue(v);\r
if(v !== this.value && this.fireEvent('beforechange', this, v, this.value) !== false){\r
}\r
},\r
\r
- // private\r
+ // private\r
translateValue : function(v){\r
var ratio = this.getRatio();\r
- return (v * ratio)-(this.minValue * ratio)-this.halfThumb;\r
+ return (v * ratio) - (this.minValue * ratio) - this.halfThumb;\r
},\r
\r
- reverseValue : function(pos){\r
+ reverseValue : function(pos){\r
var ratio = this.getRatio();\r
- return (pos+this.halfThumb+(this.minValue * ratio))/ratio;\r
+ return (pos + (this.minValue * ratio)) / ratio;\r
},\r
\r
- // private\r
+ // private\r
moveThumb: function(v, animate){\r
if(!animate || this.animate === false){\r
this.thumb.setLeft(v);\r
}\r
},\r
\r
- // private\r
+ // private\r
focus : function(){\r
this.focusEl.focus(10);\r
},\r
\r
- // private\r
+ // private\r
onBeforeDragStart : function(e){\r
return !this.disabled;\r
},\r
\r
- // private\r
+ // private\r
onDragStart: function(e){\r
this.thumb.addClass('x-slider-thumb-drag');\r
this.dragging = true;\r
this.fireEvent('dragstart', this, e);\r
},\r
\r
- // private\r
+ // private\r
onDrag: function(e){\r
var pos = this.innerEl.translatePoints(this.tracker.getXY());\r
this.setValue(Ext.util.Format.round(this.reverseValue(pos.left), this.decimalPrecision), false);\r
this.fireEvent('drag', this, e);\r
},\r
\r
- // private\r
+ // private\r
onDragEnd: function(e){\r
this.thumb.removeClass('x-slider-thumb-drag');\r
this.dragging = false;\r
}\r
},\r
\r
- // private\r
+ // private\r
onResize : function(w, h){\r
this.innerEl.setWidth(w - (this.el.getPadding('l') + this.endEl.getPadding('r')));\r
this.syncThumb();\r
+ Ext.Slider.superclass.onResize.apply(this, arguments);\r
},\r
- \r
+\r
//private\r
onDisable: function(){\r
Ext.Slider.superclass.onDisable.call(this);\r
this.thumb.hide();\r
this.innerEl.addClass(this.disabledClass).dom.disabled = true;\r
if (!this.thumbHolder){\r
- this.thumbHolder = this.endEl.createChild({cls: 'x-slider-thumb ' + this.disabledClass}); \r
+ this.thumbHolder = this.endEl.createChild({cls: 'x-slider-thumb ' + this.disabledClass});\r
}\r
this.thumbHolder.show().setXY(xy);\r
}\r
},\r
- \r
+\r
//private\r
onEnable: function(){\r
Ext.Slider.superclass.onEnable.call(this);\r
this.thumb.removeClass(this.disabledClass);\r
if(Ext.isIE){\r
this.innerEl.removeClass(this.disabledClass).dom.disabled = false;\r
- if (this.thumbHolder){\r
+ if(this.thumbHolder){\r
this.thumbHolder.hide();\r
}\r
this.thumb.show();\r
this.syncThumb();\r
}\r
},\r
- \r
+\r
/**\r
* Synchronizes the thumb position to the proper proportion of the total component width based\r
* on the current slider {@link #value}. This will be called automatically when the Slider\r
}\r
},\r
\r
- /**\r
- * Returns the current value of the slider\r
- * @return {Number} The current value of the slider\r
- */\r
+ /**\r
+ * Returns the current value of the slider\r
+ * @return {Number} The current value of the slider\r
+ */\r
getValue : function(){\r
return this.value;\r
+ },\r
+\r
+ // private\r
+ beforeDestroy : function(){\r
+ Ext.destroyMembers(this, 'endEl', 'innerEl', 'thumb', 'halfThumb', 'focusEl', 'tracker', 'thumbHolder');\r
+ Ext.Slider.superclass.beforeDestroy.call(this);\r
}\r
});\r
Ext.reg('slider', Ext.Slider);\r
},\r
\r
getRatio : function(){\r
- var h = this.innerEl.getHeight();\r
- var v = this.maxValue - this.minValue;\r
+ var h = this.innerEl.getHeight(),\r
+ v = this.maxValue - this.minValue;\r
return h/v;\r
},\r
\r
},\r
\r
onDrag: function(e){\r
- var pos = this.innerEl.translatePoints(this.tracker.getXY());\r
- var bottom = this.innerEl.getHeight()-pos.top;\r
+ var pos = this.innerEl.translatePoints(this.tracker.getXY()),\r
+ bottom = this.innerEl.getHeight()-pos.top;\r
this.setValue(this.minValue + Ext.util.Format.round(bottom/this.getRatio(), this.decimalPrecision), false);\r
this.fireEvent('drag', this, e);\r
},\r
\r
onClickChange : function(local){\r
if(local.left > this.clickRange[0] && local.left < this.clickRange[1]){\r
- var bottom = this.innerEl.getHeight()-local.top;\r
+ var bottom = this.innerEl.getHeight() - local.top;\r
this.setValue(this.minValue + Ext.util.Format.round(bottom/this.getRatio(), this.decimalPrecision), undefined, true);\r
}\r
}\r