- // private override
- initComponent : function(){
- if(!Ext.isDefined(this.value)){
- this.value = this.minValue;
- }
-
- <div id="prop-Ext.slider.MultiSlider-thumbs"></div>/**
- * @property thumbs
- * @type Array
- * Array containing references to each thumb
- */
- this.thumbs = [];
-
- Ext.slider.MultiSlider.superclass.initComponent.call(this);
-
- this.keyIncrement = Math.max(this.increment, this.keyIncrement);
- this.addEvents(
- <div id="event-Ext.slider.MultiSlider-beforechange"></div>/**
- * @event beforechange
- * Fires before the slider value is changed. By returning false from an event handler,
- * you can cancel the event and prevent the slider from changing.
- * @param {Ext.Slider} slider The slider
- * @param {Number} newValue The new value which the slider is being changed to.
- * @param {Number} oldValue The old value which the slider was previously.
- */
- 'beforechange',
-
- <div id="event-Ext.slider.MultiSlider-change"></div>/**
- * @event change
- * Fires when the slider value is changed.
- * @param {Ext.Slider} slider The slider
- * @param {Number} newValue The new value which the slider has been changed to.
- * @param {Ext.slider.Thumb} thumb The thumb that was changed
- */
- 'change',
-
- <div id="event-Ext.slider.MultiSlider-changecomplete"></div>/**
- * @event changecomplete
- * Fires when the slider value is changed by the user and any drag operations have completed.
- * @param {Ext.Slider} slider The slider
- * @param {Number} newValue The new value which the slider has been changed to.
- * @param {Ext.slider.Thumb} thumb The thumb that was changed
- */
- 'changecomplete',
-
- <div id="event-Ext.slider.MultiSlider-dragstart"></div>/**
- * @event dragstart
- * Fires after a drag operation has started.
- * @param {Ext.Slider} slider The slider
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
- */
- 'dragstart',
-
- <div id="event-Ext.slider.MultiSlider-drag"></div>/**
- * @event drag
- * Fires continuously during the drag operation while the mouse is moving.
- * @param {Ext.Slider} slider The slider
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
- */
- 'drag',
-
- <div id="event-Ext.slider.MultiSlider-dragend"></div>/**
- * @event dragend
- * Fires after the drag operation has completed.
- * @param {Ext.Slider} slider The slider
- * @param {Ext.EventObject} e The event fired from Ext.dd.DragTracker
- */
- 'dragend'
- );
-
- <div id="prop-Ext.slider.MultiSlider-values"></div>/**
- * @property values
- * @type Array
- * Array of values to initalize the thumbs with
- */
- if (this.values == undefined || Ext.isEmpty(this.values)) this.values = [0];
-
- var values = this.values;
-
- for (var i=0; i < values.length; i++) {
- this.addThumb(values[i]);
- }
-
- if(this.vertical){
- Ext.apply(this, Ext.slider.Vertical);
- }
- },
-
- <div id="method-Ext.slider.MultiSlider-addThumb"></div>/**
- * Creates a new thumb and adds it to the slider
- * @param {Number} value The initial value to set on the thumb. Defaults to 0
- */
- addThumb: function(value) {
- var thumb = new Ext.slider.Thumb({
- value : value,
- slider : this,
- index : this.thumbs.length,
- constrain: this.constrainThumbs
- });
- this.thumbs.push(thumb);
-
- //render the thumb now if needed
- if (this.rendered) thumb.render();
- },
-
- /**
- * @private
- * Moves the given thumb above all other by increasing its z-index. This is called when as drag
- * any thumb, so that the thumb that was just dragged is always at the highest z-index. This is
- * required when the thumbs are stacked on top of each other at one of the ends of the slider's
- * range, which can result in the user not being able to move any of them.
- * @param {Ext.slider.Thumb} topThumb The thumb to move to the top
- */
- promoteThumb: function(topThumb) {
- var thumbs = this.thumbs,
- zIndex, thumb;
-
- for (var i = 0, j = thumbs.length; i < j; i++) {
- thumb = thumbs[i];
-
- if (thumb == topThumb) {
- zIndex = this.topThumbZIndex;
- } else {
- zIndex = '';
- }
-
- thumb.el.setStyle('zIndex', zIndex);
- }
- },
-
- // private override
- onRender : function() {
- this.autoEl = {
- cls: 'x-slider ' + (this.vertical ? 'x-slider-vert' : 'x-slider-horz'),
- cn : {
- cls: 'x-slider-end',
- cn : {
- cls:'x-slider-inner',
- cn : [{tag:'a', cls:'x-slider-focus', href:"#", tabIndex: '-1', hidefocus:'on'}]
- }
- }
- };
-
- Ext.slider.MultiSlider.superclass.onRender.apply(this, arguments);
-
- this.endEl = this.el.first();
- this.innerEl = this.endEl.first();
- this.focusEl = this.innerEl.child('.x-slider-focus');
-
- //render each thumb
- for (var i=0; i < this.thumbs.length; i++) {
- this.thumbs[i].render();
- }
-
- //calculate the size of half a thumb
- var thumb = this.innerEl.child('.x-slider-thumb');
- this.halfThumb = (this.vertical ? thumb.getHeight() : thumb.getWidth()) / 2;
-
- this.initEvents();
- },
-
- /**
- * @private
- * Adds keyboard and mouse listeners on this.el. Ignores click events on the internal focus element.
- * Creates a new DragTracker which is used to control what happens when the user drags the thumb around.
- */
- initEvents : function(){
- this.mon(this.el, {
- scope : this,
- mousedown: this.onMouseDown,
- keydown : this.onKeyDown
- });
-
- this.focusEl.swallowEvent("click", true);
- },
-
- /**
- * @private
- * Mousedown handler for the slider. If the clickToChange is enabled and the click was not on the draggable 'thumb',
- * this calculates the new value of the slider and tells the implementation (Horizontal or Vertical) to move the thumb
- * @param {Ext.EventObject} e The click event
- */
- onMouseDown : function(e){
- if(this.disabled){
- return;
- }
-
- //see if the click was on any of the thumbs
- var thumbClicked = false;
- for (var i=0; i < this.thumbs.length; i++) {
- thumbClicked = thumbClicked || e.target == this.thumbs[i].el.dom;
- }
-
- if (this.clickToChange && !thumbClicked) {
- var local = this.innerEl.translatePoints(e.getXY());
- this.onClickChange(local);
- }
- this.focus();
- },
-
- /**
- * @private
- * Moves the thumb to the indicated position. Note that a Vertical implementation is provided in Ext.slider.Vertical.
- * Only changes the value if the click was within this.clickRange.
- * @param {Object} local Object containing top and left values for the click event.
- */
- onClickChange : function(local) {
- if (local.top > this.clickRange[0] && local.top < this.clickRange[1]) {
- //find the nearest thumb to the click event
- var thumb = this.getNearest(local, 'left'),
- index = thumb.index;
-
- this.setValue(index, Ext.util.Format.round(this.reverseValue(local.left), this.decimalPrecision), undefined, true);
- }
- },