2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 * The Slider component is a UI control that enables the user to adjust
9 * values in a finite range along one or two axes. Typically, the Slider
10 * control is used in a web application as a rich, visual replacement
11 * for an input box that takes a number as input. The Slider control can
12 * also easily accommodate a second dimension, providing x,y output for
13 * a selection point chosen from a rectangular region.
16 * @title Slider Widget
17 * @namespace YAHOO.widget
18 * @requires yahoo,dom,dragdrop,event
23 var getXY = YAHOO.util.Dom.getXY,
24 Event = YAHOO.util.Event,
25 _AS = Array.prototype.slice;
28 * A DragDrop implementation that can be used as a background for a
29 * slider. It takes a reference to the thumb instance
30 * so it can delegate some of the events to it. The goal is to make the
31 * thumb jump to the location on the background when the background is
35 * @extends YAHOO.util.DragDrop
36 * @uses YAHOO.util.EventProvider
38 * @param {String} id The id of the element linked to this instance
39 * @param {String} sGroup The group of related DragDrop items
40 * @param {SliderThumb} oThumb The thumb for this slider
41 * @param {String} sType The type of slider (horiz, vert, region)
43 function Slider(sElementId, sGroup, oThumb, sType) {
45 Slider.ANIM_AVAIL = (!YAHOO.lang.isUndefined(YAHOO.util.Anim));
48 this.init(sElementId, sGroup, true);
49 this.initSlider(sType);
50 this.initThumb(oThumb);
54 YAHOO.lang.augmentObject(Slider,{
56 * Factory method for creating a horizontal slider
57 * @method YAHOO.widget.Slider.getHorizSlider
59 * @param {String} sBGElId the id of the slider's background element
60 * @param {String} sHandleElId the id of the thumb element
61 * @param {int} iLeft the number of pixels the element can move left
62 * @param {int} iRight the number of pixels the element can move right
63 * @param {int} iTickSize optional parameter for specifying that the element
64 * should move a certain number pixels at a time.
65 * @return {Slider} a horizontal slider control
68 function (sBGElId, sHandleElId, iLeft, iRight, iTickSize) {
69 return new Slider(sBGElId, sBGElId,
70 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId,
71 iLeft, iRight, 0, 0, iTickSize), "horiz");
75 * Factory method for creating a vertical slider
76 * @method YAHOO.widget.Slider.getVertSlider
78 * @param {String} sBGElId the id of the slider's background element
79 * @param {String} sHandleElId the id of the thumb element
80 * @param {int} iUp the number of pixels the element can move up
81 * @param {int} iDown the number of pixels the element can move down
82 * @param {int} iTickSize optional parameter for specifying that the element
83 * should move a certain number pixels at a time.
84 * @return {Slider} a vertical slider control
87 function (sBGElId, sHandleElId, iUp, iDown, iTickSize) {
88 return new Slider(sBGElId, sBGElId,
89 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, 0, 0,
90 iUp, iDown, iTickSize), "vert");
94 * Factory method for creating a slider region like the one in the color
96 * @method YAHOO.widget.Slider.getSliderRegion
98 * @param {String} sBGElId the id of the slider's background element
99 * @param {String} sHandleElId the id of the thumb element
100 * @param {int} iLeft the number of pixels the element can move left
101 * @param {int} iRight the number of pixels the element can move right
102 * @param {int} iUp the number of pixels the element can move up
103 * @param {int} iDown the number of pixels the element can move down
104 * @param {int} iTickSize optional parameter for specifying that the element
105 * should move a certain number pixels at a time.
106 * @return {Slider} a slider region control
109 function (sBGElId, sHandleElId, iLeft, iRight, iUp, iDown, iTickSize) {
110 return new Slider(sBGElId, sBGElId,
111 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, iLeft, iRight,
112 iUp, iDown, iTickSize), "region");
116 * Constant for valueChangeSource, indicating that the user clicked or
117 * dragged the slider to change the value.
118 * @property Slider.SOURCE_UI_EVENT
126 * Constant for valueChangeSource, indicating that the value was altered
127 * by a programmatic call to setValue/setRegionValue.
128 * @property Slider.SOURCE_SET_VALUE
133 SOURCE_SET_VALUE : 2,
136 * Constant for valueChangeSource, indicating that the value was altered
137 * by hitting any of the supported keyboard characters.
138 * @property Slider.SOURCE_KEY_EVENT
143 SOURCE_KEY_EVENT : 3,
146 * By default, animation is available if the animation utility is detected.
147 * @property Slider.ANIM_AVAIL
154 YAHOO.extend(Slider, YAHOO.util.DragDrop, {
157 * Tracks the state of the mouse button to aid in when events are fired.
159 * @property _mouseDown
167 * Override the default setting of dragOnly to true.
175 * Initializes the slider. Executed in the constructor
177 * @param {string} sType the type of slider (horiz, vert, region)
179 initSlider: function(sType) {
182 * The type of the slider (horiz, vert, region)
188 //this.removeInvalidHandleType("A");
190 this.logger = new YAHOO.widget.LogWriter(this.toString());
193 * Event the fires when the value of the control changes. If
194 * the control is animated the event will fire every point
197 * @param {int} newOffset|x the new offset for normal sliders, or the new
198 * x offset for region sliders
199 * @param {int} y the number of pixels the thumb has moved on the y axis
200 * (region sliders only)
202 this.createEvent("change", this);
205 * Event that fires at the beginning of a slider thumb move.
208 this.createEvent("slideStart", this);
211 * Event that fires at the end of a slider thumb move
214 this.createEvent("slideEnd", this);
217 * Overrides the isTarget property in YAHOO.util.DragDrop
221 this.isTarget = false;
224 * Flag that determines if the thumb will animate when moved
228 this.animate = Slider.ANIM_AVAIL;
231 * Set to false to disable a background click thumb move
232 * @property backgroundEnabled
235 this.backgroundEnabled = true;
238 * Adjustment factor for tick animation, the more ticks, the
239 * faster the animation (by default)
240 * @property tickPause
246 * Enables the arrow, home and end keys, defaults to true.
247 * @property enableKeys
250 this.enableKeys = true;
253 * Specifies the number of pixels the arrow keys will move the slider.
255 * @property keyIncrement
258 this.keyIncrement = 20;
261 * moveComplete is set to true when the slider has moved to its final
262 * destination. For animated slider, this value can be checked in
263 * the onChange handler to make it possible to execute logic only
264 * when the move is complete rather than at all points along the way.
265 * Deprecated because this flag is only useful when the background is
266 * clicked and the slider is animated. If the user drags the thumb,
267 * the flag is updated when the drag is over ... the final onDrag event
268 * fires before the mouseup the ends the drag, so the implementer will
271 * @property moveComplete
273 * @deprecated use the slideEnd event instead
275 this.moveComplete = true;
278 * If animation is configured, specifies the length of the animation
280 * @property animationDuration
284 this.animationDuration = 0.2;
287 * Constant for valueChangeSource, indicating that the user clicked or
288 * dragged the slider to change the value.
289 * @property SOURCE_UI_EVENT
292 * @deprecated use static Slider.SOURCE_UI_EVENT
294 this.SOURCE_UI_EVENT = 1;
297 * Constant for valueChangeSource, indicating that the value was altered
298 * by a programmatic call to setValue/setRegionValue.
299 * @property SOURCE_SET_VALUE
302 * @deprecated use static Slider.SOURCE_SET_VALUE
304 this.SOURCE_SET_VALUE = 2;
307 * When the slider value changes, this property is set to identify where
308 * the update came from. This will be either 1, meaning the slider was
309 * clicked or dragged, or 2, meaning that it was set via a setValue() call.
310 * This can be used within event handlers to apply some of the logic only
311 * when dealing with one source or another.
312 * @property valueChangeSource
316 this.valueChangeSource = 0;
319 * Indicates whether or not events will be supressed for the current
325 this._silent = false;
328 * Saved offset used to protect against NaN problems when slider is
329 * set to display:none
330 * @property lastOffset
333 this.lastOffset = [0,0];
337 * Initializes the slider's thumb. Executed in the constructor.
339 * @param {YAHOO.widget.SliderThumb} t the slider thumb
341 initThumb: function(t) {
346 * A YAHOO.widget.SliderThumb instance that we will use to
347 * reposition the thumb when the background is clicked
349 * @type YAHOO.widget.SliderThumb
353 t.cacheBetweenDrags = true;
355 if (t._isHoriz && t.xTicks && t.xTicks.length) {
356 this.tickPause = Math.round(360 / t.xTicks.length);
357 } else if (t.yTicks && t.yTicks.length) {
358 this.tickPause = Math.round(360 / t.yTicks.length);
361 this.logger.log("tickPause: " + this.tickPause);
363 // delegate thumb methods
364 t.onAvailable = function() {
365 return self.setStartSliderState();
367 t.onMouseDown = function () {
368 self._mouseDown = true;
369 self.logger.log('thumb mousedown');
372 t.startDrag = function() {
373 self.logger.log('thumb startDrag');
376 t.onDrag = function() {
377 self.logger.log('thumb drag');
378 self.fireEvents(true);
380 t.onMouseUp = function() {
387 * Executed when the slider element is available
388 * @method onAvailable
390 onAvailable: function() {
391 this._bindKeyEvents();
395 * Sets up the listeners for keydown and key press events.
397 * @method _bindKeyEvents
400 _bindKeyEvents : function () {
401 Event.on(this.id, "keydown", this.handleKeyDown, this, true);
402 Event.on(this.id, "keypress", this.handleKeyPress, this, true);
406 * Executed when a keypress event happens with the control focused.
407 * Prevents the default behavior for navigation keys. The actual
408 * logic for moving the slider thumb in response to a key event
409 * happens in handleKeyDown.
410 * @param {Event} e the keypress event
412 handleKeyPress: function(e) {
413 if (this.enableKeys) {
414 var kc = Event.getCharCode(e);
423 Event.preventDefault(e);
431 * Executed when a keydown event happens with the control focused.
432 * Updates the slider value and display when the keypress is an
433 * arrow key, home, or end as long as enableKeys is set to true.
434 * @param {Event} e the keydown event
436 handleKeyDown: function(e) {
437 if (this.enableKeys) {
438 var kc = Event.getCharCode(e),
440 h = this.getXValue(),
441 v = this.getYValue(),
447 case 0x25: h -= this.keyIncrement; break;
450 case 0x26: v -= this.keyIncrement; break;
453 case 0x27: h += this.keyIncrement; break;
456 case 0x28: v += this.keyIncrement; break;
459 case 0x24: h = t.leftConstraint;
464 case 0x23: h = t.rightConstraint;
465 v = t.bottomConstraint;
468 default: changeValue = false;
473 this._setRegionValue(Slider.SOURCE_KEY_EVENT, h, v, true);
475 this._setValue(Slider.SOURCE_KEY_EVENT,
476 (t._isHoriz ? h : v), true);
485 * Initialization that sets up the value offsets once the elements are ready
486 * @method setStartSliderState
488 setStartSliderState: function() {
490 this.logger.log("Fixing state");
492 this.setThumbCenterPoint();
495 * The basline position of the background element, used
496 * to determine if the background has moved since the last
498 * @property baselinePos
501 this.baselinePos = getXY(this.getEl());
503 this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos);
505 if (this.thumb._isRegion) {
506 if (this.deferredSetRegionValue) {
507 this._setRegionValue.apply(this, this.deferredSetRegionValue);
508 this.deferredSetRegionValue = null;
510 this.setRegionValue(0, 0, true, true, true);
513 if (this.deferredSetValue) {
514 this._setValue.apply(this, this.deferredSetValue);
515 this.deferredSetValue = null;
517 this.setValue(0, true, true, true);
523 * When the thumb is available, we cache the centerpoint of the element so
524 * we can position the element correctly when the background is clicked
525 * @method setThumbCenterPoint
527 setThumbCenterPoint: function() {
529 var el = this.thumb.getEl();
533 * The center of the slider element is stored so we can
534 * place it in the correct position when the background is clicked.
535 * @property thumbCenterPoint
536 * @type {"x": int, "y": int}
538 this.thumbCenterPoint = {
539 x: parseInt(el.offsetWidth/2, 10),
540 y: parseInt(el.offsetHeight/2, 10)
547 * Locks the slider, overrides YAHOO.util.DragDrop
551 this.logger.log("locking");
557 * Unlocks the slider, overrides YAHOO.util.DragDrop
561 this.logger.log("unlocking");
567 * Handles mouseup event on the thumb
568 * @method thumbMouseUp
571 thumbMouseUp: function() {
572 this._mouseDown = false;
573 this.logger.log("thumb mouseup");
574 if (!this.isLocked()) {
580 onMouseUp: function() {
581 this._mouseDown = false;
582 this.logger.log("background mouseup");
583 if (this.backgroundEnabled && !this.isLocked()) {
589 * Returns a reference to this slider's thumb
591 * @return {SliderThumb} this slider's thumb
593 getThumb: function() {
598 * Try to focus the element when clicked so we can add
599 * accessibility features
604 this.logger.log("focus");
605 this.valueChangeSource = Slider.SOURCE_UI_EVENT;
607 // Focus the background element if possible
608 var el = this.getEl();
614 // Prevent permission denied unhandled exception in FF that can
615 // happen when setting focus while another element is handling
616 // the blur. @TODO this is still writing to the error log
617 // (unhandled error) in FF1.5 with strict error checking on.
623 return !this.isLocked();
627 * Event that fires when the value of the slider has changed
629 * @param {int} firstOffset the number of pixels the thumb has moved
630 * from its start position. Normal horizontal and vertical sliders will only
631 * have the firstOffset. Regions will have both, the first is the horizontal
632 * offset, the second the vertical.
633 * @param {int} secondOffset the y offset for region sliders
634 * @deprecated use instance.subscribe("change") instead
636 onChange: function (firstOffset, secondOffset) {
638 this.logger.log("onChange: " + firstOffset + ", " + secondOffset);
642 * Event that fires when the at the beginning of the slider thumb move
643 * @method onSlideStart
644 * @deprecated use instance.subscribe("slideStart") instead
646 onSlideStart: function () {
648 this.logger.log("onSlideStart");
652 * Event that fires at the end of a slider thumb move
653 * @method onSliderEnd
654 * @deprecated use instance.subscribe("slideEnd") instead
656 onSlideEnd: function () {
658 this.logger.log("onSlideEnd");
662 * Returns the slider's thumb offset from the start position
664 * @return {int} the current value
666 getValue: function () {
667 return this.thumb.getValue();
671 * Returns the slider's thumb X offset from the start position
673 * @return {int} the current horizontal offset
675 getXValue: function () {
676 return this.thumb.getXValue();
680 * Returns the slider's thumb Y offset from the start position
682 * @return {int} the current vertical offset
684 getYValue: function () {
685 return this.thumb.getYValue();
689 * Provides a way to set the value of the slider in code.
692 * @param {int} newOffset the number of pixels the thumb should be
693 * positioned away from the initial start point
694 * @param {boolean} skipAnim set to true to disable the animation
695 * for this move action (but not others).
696 * @param {boolean} force ignore the locked setting and set value anyway
697 * @param {boolean} silent when true, do not fire events
698 * @return {boolean} true if the move was performed, false if it failed
700 setValue: function() {
701 var args = _AS.call(arguments);
702 args.unshift(Slider.SOURCE_SET_VALUE);
703 return this._setValue.apply(this,args);
707 * Worker function to execute the value set operation. Accepts type of
708 * set operation in addition to the usual setValue params.
711 * @param source {int} what triggered the set (e.g. Slider.SOURCE_SET_VALUE)
712 * @param {int} newOffset the number of pixels the thumb should be
713 * positioned away from the initial start point
714 * @param {boolean} skipAnim set to true to disable the animation
715 * for this move action (but not others).
716 * @param {boolean} force ignore the locked setting and set value anyway
717 * @param {boolean} silent when true, do not fire events
718 * @return {boolean} true if the move was performed, false if it failed
721 _setValue: function(source, newOffset, skipAnim, force, silent) {
722 var t = this.thumb, newX, newY;
725 this.logger.log("defer setValue until after onAvailble");
726 this.deferredSetValue = arguments;
730 if (this.isLocked() && !force) {
731 this.logger.log("Can't set the value, the control is locked");
735 if ( isNaN(newOffset) ) {
736 this.logger.log("setValue, Illegal argument: " + newOffset);
741 this.logger.log("Call to setValue for region Slider ignored. Use setRegionValue","warn");
745 this.logger.log("setValue " + newOffset);
747 this._silent = silent;
748 this.valueChangeSource = source || Slider.SOURCE_SET_VALUE;
750 t.lastOffset = [newOffset, newOffset];
756 newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
757 this.moveThumb(newX, t.initPageY, skipAnim);
759 newY = t.initPageY + newOffset + this.thumbCenterPoint.y;
760 this.moveThumb(t.initPageX, newY, skipAnim);
767 * Provides a way to set the value of the region slider in code.
768 * @method setRegionValue
769 * @param {int} newOffset the number of pixels the thumb should be
770 * positioned away from the initial start point (x axis for region)
771 * @param {int} newOffset2 the number of pixels the thumb should be
772 * positioned away from the initial start point (y axis for region)
773 * @param {boolean} skipAnim set to true to disable the animation
774 * for this move action (but not others).
775 * @param {boolean} force ignore the locked setting and set value anyway
776 * @param {boolean} silent when true, do not fire events
777 * @return {boolean} true if the move was performed, false if it failed
779 setRegionValue : function () {
780 var args = _AS.call(arguments);
781 args.unshift(Slider.SOURCE_SET_VALUE);
782 return this._setRegionValue.apply(this,args);
786 * Worker function to execute the value set operation. Accepts type of
787 * set operation in addition to the usual setValue params.
789 * @method _setRegionValue
790 * @param source {int} what triggered the set (e.g. Slider.SOURCE_SET_VALUE)
791 * @param {int} newOffset the number of pixels the thumb should be
792 * positioned away from the initial start point (x axis for region)
793 * @param {int} newOffset2 the number of pixels the thumb should be
794 * positioned away from the initial start point (y axis for region)
795 * @param {boolean} skipAnim set to true to disable the animation
796 * for this move action (but not others).
797 * @param {boolean} force ignore the locked setting and set value anyway
798 * @param {boolean} silent when true, do not fire events
799 * @return {boolean} true if the move was performed, false if it failed
802 _setRegionValue: function(source, newOffset, newOffset2, skipAnim, force, silent) {
803 var t = this.thumb, newX, newY;
806 this.logger.log("defer setRegionValue until after onAvailble");
807 this.deferredSetRegionValue = arguments;
811 if (this.isLocked() && !force) {
812 this.logger.log("Can't set the value, the control is locked");
816 if ( isNaN(newOffset) ) {
817 this.logger.log("setRegionValue, Illegal argument: " + newOffset);
822 this.logger.log("Call to setRegionValue for non-region Slider ignored. Use setValue","warn");
826 this._silent = silent;
828 this.valueChangeSource = source || Slider.SOURCE_SET_VALUE;
830 t.lastOffset = [newOffset, newOffset2];
835 newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
836 newY = t.initPageY + newOffset2 + this.thumbCenterPoint.y;
837 this.moveThumb(newX, newY, skipAnim);
843 * Checks the background position element position. If it has moved from the
844 * baseline position, the constraints for the thumb are reset
845 * @method verifyOffset
846 * @return {boolean} True if the offset is the same as the baseline.
848 verifyOffset: function() {
850 var xy = getXY(this.getEl()),
853 if (!this.thumbCenterPoint || !this.thumbCenterPoint.x) {
854 this.setThumbCenterPoint();
859 this.logger.log("newPos: " + xy);
861 if (xy[0] != this.baselinePos[0] || xy[1] != this.baselinePos[1]) {
862 this.logger.log("background moved, resetting constraints");
865 this.setInitPosition();
866 this.baselinePos = xy;
869 t.initPageX = this.initPageX + t.startOffset[0];
870 t.initPageY = this.initPageY + t.startOffset[1];
872 this.resetThumbConstraints();
882 * Move the associated slider moved to a timeout to try to get around the
883 * mousedown stealing moz does when I move the slider element between the
884 * cursor and the background during the mouseup event
886 * @param {int} x the X coordinate of the click
887 * @param {int} y the Y coordinate of the click
888 * @param {boolean} skipAnim don't animate if the move happend onDrag
889 * @param {boolean} midMove set to true if this is not terminating
890 * the slider movement
893 moveThumb: function(x, y, skipAnim, midMove) {
900 this.logger.log("thumb is not available yet, aborting move");
904 this.logger.log("move thumb, x: " + x + ", y: " + y);
906 t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y);
908 _p = t.getTargetCoord(x, y);
909 p = [Math.round(_p.x), Math.round(_p.y)];
911 if (this.animate && t._graduated && !skipAnim) {
912 this.logger.log("graduated");
915 // cache the current thumb pos
916 this.curCoord = getXY(this.thumb.getEl());
917 this.curCoord = [Math.round(this.curCoord[0]), Math.round(this.curCoord[1])];
919 setTimeout( function() { self.moveOneTick(p); }, this.tickPause );
921 } else if (this.animate && Slider.ANIM_AVAIL && !skipAnim) {
922 this.logger.log("animating to " + p);
926 anim = new YAHOO.util.Motion(
927 t.id, { points: { to: p } },
928 this.animationDuration,
929 YAHOO.util.Easing.easeOut );
931 anim.onComplete.subscribe( function() {
932 self.logger.log("Animation completed _mouseDown:" + self._mouseDown);
934 if (!self._mouseDown) {
941 t.setDragElPos(x, y);
942 if (!midMove && !this._mouseDown) {
948 _slideStart: function() {
949 if (!this._sliding) {
952 this.fireEvent("slideStart");
954 this._sliding = true;
955 this.moveComplete = false; // for backward compatibility. Deprecated
959 _slideEnd: function() {
961 // Reset state before firing slideEnd
962 var silent = this._silent;
963 this._sliding = false;
964 this.moveComplete = true; // for backward compatibility. Deprecated
965 this._silent = false;
968 this.fireEvent("slideEnd");
974 * Move the slider one tick mark towards its final coordinate. Used
975 * for the animation when tick marks are defined
976 * @method moveOneTick
977 * @param {int[]} the destination coordinate
980 moveOneTick: function(finalCoord) {
988 nextCoord = this._getNextX(this.curCoord, finalCoord);
989 tmpX = (nextCoord !== null) ? nextCoord[0] : this.curCoord[0];
990 nextCoord = this._getNextY(this.curCoord, finalCoord);
991 tmpY = (nextCoord !== null) ? nextCoord[1] : this.curCoord[1];
993 nextCoord = tmpX !== this.curCoord[0] || tmpY !== this.curCoord[1] ?
994 [ tmpX, tmpY ] : null;
995 } else if (t._isHoriz) {
996 nextCoord = this._getNextX(this.curCoord, finalCoord);
998 nextCoord = this._getNextY(this.curCoord, finalCoord);
1001 this.logger.log("moveOneTick: " +
1002 " finalCoord: " + finalCoord +
1003 " this.curCoord: " + this.curCoord +
1004 " nextCoord: " + nextCoord);
1008 // cache the position
1009 this.curCoord = nextCoord;
1011 // move to the next coord
1012 this.thumb.alignElWithMouse(t.getEl(), nextCoord[0] + this.thumbCenterPoint.x, nextCoord[1] + this.thumbCenterPoint.y);
1014 // check if we are in the final position, if not make a recursive call
1015 if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) {
1016 setTimeout(function() { self.moveOneTick(finalCoord); },
1020 if (!this._mouseDown) {
1026 if (!this._mouseDown) {
1033 * Returns the next X tick value based on the current coord and the target coord.
1037 _getNextX: function(curCoord, finalCoord) {
1038 this.logger.log("getNextX: " + curCoord + ", " + finalCoord);
1044 if (curCoord[0] > finalCoord[0]) {
1045 thresh = t.tickSize - this.thumbCenterPoint.x;
1046 tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] );
1047 nextCoord = [tmp.x, tmp.y];
1048 } else if (curCoord[0] < finalCoord[0]) {
1049 thresh = t.tickSize + this.thumbCenterPoint.x;
1050 tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] );
1051 nextCoord = [tmp.x, tmp.y];
1053 // equal, do nothing
1060 * Returns the next Y tick value based on the current coord and the target coord.
1064 _getNextY: function(curCoord, finalCoord) {
1070 if (curCoord[1] > finalCoord[1]) {
1071 thresh = t.tickSize - this.thumbCenterPoint.y;
1072 tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh );
1073 nextCoord = [tmp.x, tmp.y];
1074 } else if (curCoord[1] < finalCoord[1]) {
1075 thresh = t.tickSize + this.thumbCenterPoint.y;
1076 tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh );
1077 nextCoord = [tmp.x, tmp.y];
1079 // equal, do nothing
1086 * Resets the constraints before moving the thumb.
1087 * @method b4MouseDown
1090 b4MouseDown: function(e) {
1091 if (!this.backgroundEnabled) {
1095 this.thumb.autoOffset();
1096 this.baselinePos = [];
1100 * Handles the mousedown event for the slider background
1101 * @method onMouseDown
1104 onMouseDown: function(e) {
1105 if (!this.backgroundEnabled || this.isLocked()) {
1109 this._mouseDown = true;
1111 var x = Event.getPageX(e),
1112 y = Event.getPageY(e);
1114 this.logger.log("bg mousedown: " + x + "," + y);
1118 this.moveThumb(x, y);
1122 * Handles the onDrag event for the slider background
1126 onDrag: function(e) {
1127 this.logger.log("background drag");
1128 if (this.backgroundEnabled && !this.isLocked()) {
1129 var x = Event.getPageX(e),
1130 y = Event.getPageY(e);
1131 this.moveThumb(x, y, true, true);
1137 * Fired when the slider movement ends
1141 endMove: function () {
1142 this.logger.log("endMove");
1149 * Resets the X and Y contraints for the thumb. Used in lieu of the thumb
1150 * instance's inherited resetConstraints because some logic was not
1152 * @method resetThumbConstraints
1155 resetThumbConstraints: function () {
1158 t.setXConstraint(t.leftConstraint, t.rightConstraint, t.xTickSize);
1159 t.setYConstraint(t.topConstraint, t.bottomConstraint, t.xTickSize);
1163 * Fires the change event if the value has been changed. Ignored if we are in
1164 * the middle of an animation as the event will fire when the animation is
1166 * @method fireEvents
1167 * @param {boolean} thumbEvent set to true if this event is fired from an event
1168 * that occurred on the thumb. If it is, the state of the
1169 * thumb dd object should be correct. Otherwise, the event
1170 * originated on the background, so the thumb state needs to
1171 * be refreshed before proceeding.
1174 fireEvents: function (thumbEvent) {
1176 var t = this.thumb, newX, newY, newVal;
1182 if (! this.isLocked()) {
1184 newX = t.getXValue();
1185 newY = t.getYValue();
1187 if (newX != this.previousX || newY != this.previousY) {
1188 if (!this._silent) {
1189 this.onChange(newX, newY);
1190 this.fireEvent("change", { x: newX, y: newY });
1194 this.previousX = newX;
1195 this.previousY = newY;
1198 newVal = t.getValue();
1199 if (newVal != this.previousVal) {
1200 this.logger.log("Firing onchange: " + newVal);
1201 if (!this._silent) {
1202 this.onChange( newVal );
1203 this.fireEvent("change", newVal);
1206 this.previousVal = newVal;
1215 * @return {string} string representation of the instance
1217 toString: function () {
1218 return ("Slider (" + this.type +") " + this.id);
1223 YAHOO.lang.augmentProto(Slider, YAHOO.util.EventProvider);
1225 YAHOO.widget.Slider = Slider;
1228 * A drag and drop implementation to be used as the thumb of a slider.
1229 * @class SliderThumb
1230 * @extends YAHOO.util.DD
1232 * @param {String} id the id of the slider html element
1233 * @param {String} sGroup the group of related DragDrop items
1234 * @param {int} iLeft the number of pixels the element can move left
1235 * @param {int} iRight the number of pixels the element can move right
1236 * @param {int} iUp the number of pixels the element can move up
1237 * @param {int} iDown the number of pixels the element can move down
1238 * @param {int} iTickSize optional parameter for specifying that the element
1239 * should move a certain number pixels at a time.
1241 YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) {
1244 YAHOO.widget.SliderThumb.superclass.constructor.call(this, id, sGroup);
1247 * The id of the thumbs parent HTML element (the slider background
1249 * @property parentElId
1252 this.parentElId = sGroup;
1256 this.logger = new YAHOO.widget.LogWriter(this.toString());
1259 * Overrides the isTarget property in YAHOO.util.DragDrop
1260 * @property isTarget
1263 this.isTarget = false;
1266 * The tick size for this slider
1267 * @property tickSize
1271 this.tickSize = iTickSize;
1274 * Informs the drag and drop util that the offsets should remain when
1275 * resetting the constraints. This preserves the slider value when
1276 * the constraints are reset
1277 * @property maintainOffset
1281 this.maintainOffset = true;
1283 this.initSlider(iLeft, iRight, iUp, iDown, iTickSize);
1286 * Turns off the autoscroll feature in drag and drop
1290 this.scroll = false;
1294 YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, {
1297 * The (X and Y) difference between the thumb location and its parent
1298 * (the slider background) when the control is instantiated.
1299 * @property startOffset
1305 * Override the default setting of dragOnly to true.
1306 * @property dragOnly
1313 * Flag used to figure out if this is a horizontal or vertical slider
1314 * @property _isHoriz
1321 * Cache the last value so we can check for change
1322 * @property _prevVal
1329 * The slider is _graduated if there is a tick interval defined
1330 * @property _graduated
1338 * Returns the difference between the location of the thumb and its parent.
1339 * @method getOffsetFromParent
1340 * @param {[int, int]} parentPos Optionally accepts the position of the parent
1343 getOffsetFromParent0: function(parentPos) {
1344 var myPos = YAHOO.util.Dom.getXY(this.getEl()),
1345 ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
1347 return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
1350 getOffsetFromParent: function(parentPos) {
1352 var el = this.getEl(), newOffset,
1353 myPos,ppos,l,t,deltaX,deltaY,newLeft,newTop;
1355 if (!this.deltaOffset) {
1357 myPos = YAHOO.util.Dom.getXY(el);
1358 ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
1360 newOffset = [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
1362 l = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
1363 t = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
1365 deltaX = l - newOffset[0];
1366 deltaY = t - newOffset[1];
1368 if (isNaN(deltaX) || isNaN(deltaY)) {
1369 this.logger.log("element does not have a position style def yet");
1371 this.deltaOffset = [deltaX, deltaY];
1375 newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
1376 newTop = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
1378 newOffset = [newLeft + this.deltaOffset[0], newTop + this.deltaOffset[1]];
1385 * Set up the slider, must be called in the constructor of all subclasses
1386 * @method initSlider
1387 * @param {int} iLeft the number of pixels the element can move left
1388 * @param {int} iRight the number of pixels the element can move right
1389 * @param {int} iUp the number of pixels the element can move up
1390 * @param {int} iDown the number of pixels the element can move down
1391 * @param {int} iTickSize the width of the tick interval.
1393 initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) {
1394 this.initLeft = iLeft;
1395 this.initRight = iRight;
1397 this.initDown = iDown;
1399 this.setXConstraint(iLeft, iRight, iTickSize);
1400 this.setYConstraint(iUp, iDown, iTickSize);
1402 if (iTickSize && iTickSize > 1) {
1403 this._graduated = true;
1406 this._isHoriz = (iLeft || iRight);
1407 this._isVert = (iUp || iDown);
1408 this._isRegion = (this._isHoriz && this._isVert);
1413 * Clear's the slider's ticks
1414 * @method clearTicks
1416 clearTicks: function () {
1417 YAHOO.widget.SliderThumb.superclass.clearTicks.call(this);
1419 this._graduated = false;
1424 * Gets the current offset from the element's start position in
1427 * @return {int} the number of pixels (positive or negative) the
1428 * slider has moved from the start position.
1430 getValue: function () {
1431 return (this._isHoriz) ? this.getXValue() : this.getYValue();
1435 * Gets the current X offset from the element's start position in
1438 * @return {int} the number of pixels (positive or negative) the
1439 * slider has moved horizontally from the start position.
1441 getXValue: function () {
1442 if (!this.available) {
1445 var newOffset = this.getOffsetFromParent();
1446 if (YAHOO.lang.isNumber(newOffset[0])) {
1447 this.lastOffset = newOffset;
1448 return (newOffset[0] - this.startOffset[0]);
1450 this.logger.log("can't get offset, using old value: " +
1451 this.lastOffset[0]);
1452 return (this.lastOffset[0] - this.startOffset[0]);
1457 * Gets the current Y offset from the element's start position in
1460 * @return {int} the number of pixels (positive or negative) the
1461 * slider has moved vertically from the start position.
1463 getYValue: function () {
1464 if (!this.available) {
1467 var newOffset = this.getOffsetFromParent();
1468 if (YAHOO.lang.isNumber(newOffset[1])) {
1469 this.lastOffset = newOffset;
1470 return (newOffset[1] - this.startOffset[1]);
1472 this.logger.log("can't get offset, using old value: " +
1473 this.lastOffset[1]);
1474 return (this.lastOffset[1] - this.startOffset[1]);
1481 * @return {string} string representation of the instance
1483 toString: function () {
1484 return "SliderThumb " + this.id;
1488 * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider
1489 * instance it belongs to.
1493 onChange: function (x, y) {
1498 * A slider with two thumbs, one that represents the min value and
1499 * the other the max. Actually a composition of two sliders, both with
1500 * the same background. The constraints for each slider are adjusted
1501 * dynamically so that the min value of the max slider is equal or greater
1502 * to the current value of the min slider, and the max value of the min
1503 * slider is the current value of the max slider.
1504 * Constructor assumes both thumbs are positioned absolutely at the 0 mark on
1507 * @namespace YAHOO.widget
1509 * @uses YAHOO.util.EventProvider
1511 * @param {Slider} minSlider The Slider instance used for the min value thumb
1512 * @param {Slider} maxSlider The Slider instance used for the max value thumb
1513 * @param {int} range The number of pixels the thumbs may move within
1514 * @param {Array} initVals (optional) [min,max] Initial thumb placement
1518 var Event = YAHOO.util.Event,
1521 function DualSlider(minSlider, maxSlider, range, initVals) {
1524 ready = { min : false, max : false },
1525 minThumbOnMouseDown, maxThumbOnMouseDown;
1528 * A slider instance that keeps track of the lower value of the range.
1529 * <strong>read only</strong>
1530 * @property minSlider
1533 this.minSlider = minSlider;
1536 * A slider instance that keeps track of the upper value of the range.
1537 * <strong>read only</strong>
1538 * @property maxSlider
1541 this.maxSlider = maxSlider;
1544 * The currently active slider (min or max). <strong>read only</strong>
1545 * @property activeSlider
1548 this.activeSlider = minSlider;
1551 * Is the DualSlider oriented horizontally or vertically?
1552 * <strong>read only</strong>
1556 this.isHoriz = minSlider.thumb._isHoriz;
1558 //FIXME: this is horrible
1559 minThumbOnMouseDown = this.minSlider.thumb.onMouseDown;
1560 maxThumbOnMouseDown = this.maxSlider.thumb.onMouseDown;
1561 this.minSlider.thumb.onMouseDown = function() {
1562 self.activeSlider = self.minSlider;
1563 minThumbOnMouseDown.apply(this,arguments);
1565 this.maxSlider.thumb.onMouseDown = function () {
1566 self.activeSlider = self.maxSlider;
1567 maxThumbOnMouseDown.apply(this,arguments);
1570 this.minSlider.thumb.onAvailable = function () {
1571 minSlider.setStartSliderState();
1574 self.fireEvent('ready',self);
1577 this.maxSlider.thumb.onAvailable = function () {
1578 maxSlider.setStartSliderState();
1581 self.fireEvent('ready',self);
1585 // dispatch mousedowns to the active slider
1586 minSlider.onMouseDown =
1587 maxSlider.onMouseDown = function(e) {
1588 return this.backgroundEnabled && self._handleMouseDown(e);
1591 // Fix the drag behavior so that only the active slider
1594 maxSlider.onDrag = function(e) {
1595 self._handleDrag(e);
1598 // Likely only the minSlider's onMouseUp will be executed, but both are
1599 // overridden just to be safe
1600 minSlider.onMouseUp =
1601 maxSlider.onMouseUp = function (e) {
1602 self._handleMouseUp(e);
1605 // Replace the _bindKeyEvents for the minSlider and remove that for the
1606 // maxSlider since they share the same bg element.
1607 minSlider._bindKeyEvents = function () {
1608 self._bindKeyEvents(this);
1610 maxSlider._bindKeyEvents = function () {};
1612 // The core events for each slider are handled so we can expose a single
1613 // event for when the event happens on either slider
1614 minSlider.subscribe("change", this._handleMinChange, minSlider, this);
1615 minSlider.subscribe("slideStart", this._handleSlideStart, minSlider, this);
1616 minSlider.subscribe("slideEnd", this._handleSlideEnd, minSlider, this);
1618 maxSlider.subscribe("change", this._handleMaxChange, maxSlider, this);
1619 maxSlider.subscribe("slideStart", this._handleSlideStart, maxSlider, this);
1620 maxSlider.subscribe("slideEnd", this._handleSlideEnd, maxSlider, this);
1623 * Event that fires when the slider is finished setting up
1625 * @param {DualSlider} dualslider the DualSlider instance
1627 this.createEvent("ready", this);
1630 * Event that fires when either the min or max value changes
1632 * @param {DualSlider} dualslider the DualSlider instance
1634 this.createEvent("change", this);
1637 * Event that fires when one of the thumbs begins to move
1639 * @param {Slider} activeSlider the moving slider
1641 this.createEvent("slideStart", this);
1644 * Event that fires when one of the thumbs finishes moving
1646 * @param {Slider} activeSlider the moving slider
1648 this.createEvent("slideEnd", this);
1650 // Validate initial values
1651 initVals = YAHOO.lang.isArray(initVals) ? initVals : [0,range];
1652 initVals[0] = Math.min(Math.max(parseInt(initVals[0],10)|0,0),range);
1653 initVals[1] = Math.max(Math.min(parseInt(initVals[1],10)|0,range),0);
1654 // Swap initVals if min > max
1655 if (initVals[0] > initVals[1]) {
1656 initVals.splice(0,2,initVals[1],initVals[0]);
1658 this.minVal = initVals[0];
1659 this.maxVal = initVals[1];
1661 // Set values so initial assignment when the slider thumbs are ready will
1663 this.minSlider.setValue(this.minVal,true,true,true);
1664 this.maxSlider.setValue(this.maxVal,true,true,true);
1666 YAHOO.log("Setting initial values " + this.minVal + ", " + this.maxVal,"info","DualSlider");
1669 DualSlider.prototype = {
1672 * The current value of the min thumb. <strong>read only</strong>.
1679 * The current value of the max thumb. <strong>read only</strong>.
1686 * Pixel distance to maintain between thumbs.
1687 * @property minRange
1694 * Executed when one of the sliders fires the slideStart event
1695 * @method _handleSlideStart
1698 _handleSlideStart: function(data, slider) {
1699 this.fireEvent("slideStart", slider);
1703 * Executed when one of the sliders fires the slideEnd event
1704 * @method _handleSlideEnd
1707 _handleSlideEnd: function(data, slider) {
1708 this.fireEvent("slideEnd", slider);
1712 * Overrides the onDrag method for both sliders
1713 * @method _handleDrag
1716 _handleDrag: function(e) {
1717 YW.Slider.prototype.onDrag.call(this.activeSlider, e);
1721 * Executed when the min slider fires the change event
1722 * @method _handleMinChange
1725 _handleMinChange: function() {
1726 this.activeSlider = this.minSlider;
1731 * Executed when the max slider fires the change event
1732 * @method _handleMaxChange
1735 _handleMaxChange: function() {
1736 this.activeSlider = this.maxSlider;
1741 * Set up the listeners for the keydown and keypress events.
1743 * @method _bindKeyEvents
1746 _bindKeyEvents : function (slider) {
1747 Event.on(slider.id,'keydown', this._handleKeyDown, this,true);
1748 Event.on(slider.id,'keypress',this._handleKeyPress,this,true);
1752 * Delegate event handling to the active Slider. See Slider.handleKeyDown.
1754 * @method _handleKeyDown
1755 * @param e {Event} the mousedown DOM event
1758 _handleKeyDown : function (e) {
1759 this.activeSlider.handleKeyDown.apply(this.activeSlider,arguments);
1763 * Delegate event handling to the active Slider. See Slider.handleKeyPress.
1765 * @method _handleKeyPress
1766 * @param e {Event} the mousedown DOM event
1769 _handleKeyPress : function (e) {
1770 this.activeSlider.handleKeyPress.apply(this.activeSlider,arguments);
1774 * Sets the min and max thumbs to new values.
1776 * @param min {int} Pixel offset to assign to the min thumb
1777 * @param max {int} Pixel offset to assign to the max thumb
1778 * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
1780 * @param force {boolean} (optional) ignore the locked setting and set
1781 * value anyway. Default false
1782 * @param silent {boolean} (optional) Set to true to skip firing change
1783 * events. Default false
1785 setValues : function (min, max, skipAnim, force, silent) {
1786 var mins = this.minSlider,
1787 maxs = this.maxSlider,
1791 done = { min : false, max : false };
1793 // Clear constraints to prevent animated thumbs from prematurely
1794 // stopping when hitting a constraint that's moving with the other
1796 if (mint._isHoriz) {
1797 mint.setXConstraint(mint.leftConstraint,maxt.rightConstraint,mint.tickSize);
1798 maxt.setXConstraint(mint.leftConstraint,maxt.rightConstraint,maxt.tickSize);
1800 mint.setYConstraint(mint.topConstraint,maxt.bottomConstraint,mint.tickSize);
1801 maxt.setYConstraint(mint.topConstraint,maxt.bottomConstraint,maxt.tickSize);
1804 // Set up one-time slideEnd callbacks to call updateValue when both
1805 // thumbs have been set
1806 this._oneTimeCallback(mins,'slideEnd',function () {
1809 self.updateValue(silent);
1810 // Clean the slider's slideEnd events on a timeout since this
1811 // will be executed from inside the event's fire
1812 setTimeout(function () {
1813 self._cleanEvent(mins,'slideEnd');
1814 self._cleanEvent(maxs,'slideEnd');
1819 this._oneTimeCallback(maxs,'slideEnd',function () {
1822 self.updateValue(silent);
1823 // Clean both sliders' slideEnd events on a timeout since this
1824 // will be executed from inside one of the event's fire
1825 setTimeout(function () {
1826 self._cleanEvent(mins,'slideEnd');
1827 self._cleanEvent(maxs,'slideEnd');
1832 // Must emit Slider slideEnd event to propagate to updateValue
1833 mins.setValue(min,skipAnim,force,false);
1834 maxs.setValue(max,skipAnim,force,false);
1838 * Set the min thumb position to a new value.
1839 * @method setMinValue
1840 * @param min {int} Pixel offset for min thumb
1841 * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
1843 * @param force {boolean} (optional) ignore the locked setting and set
1844 * value anyway. Default false
1845 * @param silent {boolean} (optional) Set to true to skip firing change
1846 * events. Default false
1848 setMinValue : function (min, skipAnim, force, silent) {
1849 var mins = this.minSlider,
1852 this.activeSlider = mins;
1854 // Use a one-time event callback to delay the updateValue call
1855 // until after the slide operation is done
1857 this._oneTimeCallback(mins,'slideEnd',function () {
1858 self.updateValue(silent);
1859 // Clean the slideEnd event on a timeout since this
1860 // will be executed from inside the event's fire
1861 setTimeout(function () { self._cleanEvent(mins,'slideEnd'); }, 0);
1864 mins.setValue(min, skipAnim, force);
1868 * Set the max thumb position to a new value.
1869 * @method setMaxValue
1870 * @param max {int} Pixel offset for max thumb
1871 * @param skipAnim {boolean} (optional) Set to true to skip thumb animation.
1873 * @param force {boolean} (optional) ignore the locked setting and set
1874 * value anyway. Default false
1875 * @param silent {boolean} (optional) Set to true to skip firing change
1876 * events. Default false
1878 setMaxValue : function (max, skipAnim, force, silent) {
1879 var maxs = this.maxSlider,
1882 this.activeSlider = maxs;
1884 // Use a one-time event callback to delay the updateValue call
1885 // until after the slide operation is done
1886 this._oneTimeCallback(maxs,'slideEnd',function () {
1887 self.updateValue(silent);
1888 // Clean the slideEnd event on a timeout since this
1889 // will be executed from inside the event's fire
1890 setTimeout(function () { self._cleanEvent(maxs,'slideEnd'); }, 0);
1893 maxs.setValue(max, skipAnim, force);
1897 * Executed when one of the sliders is moved
1898 * @method updateValue
1899 * @param silent {boolean} (optional) Set to true to skip firing change
1900 * events. Default false
1903 updateValue: function(silent) {
1904 var min = this.minSlider.getValue(),
1905 max = this.maxSlider.getValue(),
1907 mint,maxt,dim,minConstraint,maxConstraint,thumbInnerWidth;
1909 if (min != this.minVal || max != this.maxVal) {
1912 mint = this.minSlider.thumb;
1913 maxt = this.maxSlider.thumb;
1914 dim = this.isHoriz ? 'x' : 'y';
1916 thumbInnerWidth = this.minSlider.thumbCenterPoint[dim] +
1917 this.maxSlider.thumbCenterPoint[dim];
1919 // Establish barriers within the respective other thumb's edge, less
1920 // the minRange. Limit to the Slider's range in the case of
1921 // negative minRanges.
1922 minConstraint = Math.max(max-thumbInnerWidth-this.minRange,0);
1923 maxConstraint = Math.min(-min-thumbInnerWidth-this.minRange,0);
1926 minConstraint = Math.min(minConstraint,maxt.rightConstraint);
1928 mint.setXConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
1930 maxt.setXConstraint(maxConstraint,maxt.rightConstraint, maxt.tickSize);
1932 minConstraint = Math.min(minConstraint,maxt.bottomConstraint);
1933 mint.setYConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
1935 maxt.setYConstraint(maxConstraint,maxt.bottomConstraint, maxt.tickSize);
1942 if (changed && !silent) {
1943 this.fireEvent("change", this);
1948 * A background click will move the slider thumb nearest to the click.
1949 * Override if you need different behavior.
1950 * @method selectActiveSlider
1951 * @param e {Event} the mousedown event
1954 selectActiveSlider: function(e) {
1955 var min = this.minSlider,
1956 max = this.maxSlider,
1957 minLocked = min.isLocked() || !min.backgroundEnabled,
1958 maxLocked = max.isLocked() || !min.backgroundEnabled,
1959 Ev = YAHOO.util.Event,
1962 if (minLocked || maxLocked) {
1963 this.activeSlider = minLocked ? max : min;
1966 d = Ev.getPageX(e)-min.thumb.initPageX-min.thumbCenterPoint.x;
1968 d = Ev.getPageY(e)-min.thumb.initPageY-min.thumbCenterPoint.y;
1971 this.activeSlider = d*2 > max.getValue()+min.getValue() ? max : min;
1976 * Delegates the onMouseDown to the appropriate Slider
1978 * @method _handleMouseDown
1979 * @param e {Event} mouseup event
1982 _handleMouseDown: function(e) {
1983 if (!e._handled && !this.minSlider._sliding && !this.maxSlider._sliding) {
1985 this.selectActiveSlider(e);
1986 return YW.Slider.prototype.onMouseDown.call(this.activeSlider, e);
1993 * Delegates the onMouseUp to the active Slider
1995 * @method _handleMouseUp
1996 * @param e {Event} mouseup event
1999 _handleMouseUp : function (e) {
2000 YW.Slider.prototype.onMouseUp.apply(
2001 this.activeSlider, arguments);
2005 * Schedule an event callback that will execute once, then unsubscribe
2007 * @method _oneTimeCallback
2008 * @param o {EventProvider} Object to attach the event to
2009 * @param evt {string} Name of the event
2010 * @param fn {Function} function to execute once
2013 _oneTimeCallback : function (o,evt,fn) {
2014 var sub = function () {
2015 // Unsubscribe myself
2016 o.unsubscribe(evt, sub);
2017 // Pass the event handler arguments to the one time callback
2018 fn.apply({},arguments);
2020 o.subscribe(evt,sub);
2024 * Clean up the slideEnd event subscribers array, since each one-time
2025 * callback will be replaced in the event's subscribers property with
2026 * null. This will cause memory bloat and loss of performance.
2027 * @method _cleanEvent
2028 * @param o {EventProvider} object housing the CustomEvent
2029 * @param evt {string} name of the CustomEvent
2032 _cleanEvent : function (o,evt) {
2033 var ce,i,len,j,subs,newSubs;
2035 if (o.__yui_events && o.events[evt]) {
2036 for (i = o.__yui_events.length; i >= 0; --i) {
2037 if (o.__yui_events[i].type === evt) {
2038 ce = o.__yui_events[i];
2043 subs = ce.subscribers;
2046 for (i = 0, len = subs.length; i < len; ++i) {
2048 newSubs[j++] = subs[i];
2051 ce.subscribers = newSubs;
2058 YAHOO.lang.augmentProto(DualSlider, YAHOO.util.EventProvider);
2062 * Factory method for creating a horizontal dual-thumb slider
2063 * @for YAHOO.widget.Slider
2064 * @method YAHOO.widget.Slider.getHorizDualSlider
2066 * @param {String} bg the id of the slider's background element
2067 * @param {String} minthumb the id of the min thumb
2068 * @param {String} maxthumb the id of the thumb thumb
2069 * @param {int} range the number of pixels the thumbs can move within
2070 * @param {int} iTickSize (optional) the element should move this many pixels
2072 * @param {Array} initVals (optional) [min,max] Initial thumb placement
2073 * @return {DualSlider} a horizontal dual-thumb slider control
2075 YW.Slider.getHorizDualSlider =
2076 function (bg, minthumb, maxthumb, range, iTickSize, initVals) {
2077 var mint = new YW.SliderThumb(minthumb, bg, 0, range, 0, 0, iTickSize),
2078 maxt = new YW.SliderThumb(maxthumb, bg, 0, range, 0, 0, iTickSize);
2080 return new DualSlider(
2081 new YW.Slider(bg, bg, mint, "horiz"),
2082 new YW.Slider(bg, bg, maxt, "horiz"),
2087 * Factory method for creating a vertical dual-thumb slider.
2088 * @for YAHOO.widget.Slider
2089 * @method YAHOO.widget.Slider.getVertDualSlider
2091 * @param {String} bg the id of the slider's background element
2092 * @param {String} minthumb the id of the min thumb
2093 * @param {String} maxthumb the id of the thumb thumb
2094 * @param {int} range the number of pixels the thumbs can move within
2095 * @param {int} iTickSize (optional) the element should move this many pixels
2097 * @param {Array} initVals (optional) [min,max] Initial thumb placement
2098 * @return {DualSlider} a vertical dual-thumb slider control
2100 YW.Slider.getVertDualSlider =
2101 function (bg, minthumb, maxthumb, range, iTickSize, initVals) {
2102 var mint = new YW.SliderThumb(minthumb, bg, 0, 0, 0, range, iTickSize),
2103 maxt = new YW.SliderThumb(maxthumb, bg, 0, 0, 0, range, iTickSize);
2105 return new YW.DualSlider(
2106 new YW.Slider(bg, bg, mint, "vert"),
2107 new YW.Slider(bg, bg, maxt, "vert"),
2111 YAHOO.widget.DualSlider = DualSlider;
2114 YAHOO.register("slider", YAHOO.widget.Slider, {version: "2.8.0r4", build: "2449"});