2 Copyright (c) 2006, 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 * A DragDrop implementation that can be used as a background for a
24 * slider. It takes a reference to the thumb instance
25 * so it can delegate some of the events to it. The goal is to make the
26 * thumb jump to the location on the background when the background is
30 * @extends YAHOO.util.DragDrop
31 * @uses YAHOO.util.EventProvider
33 * @param {String} id The id of the element linked to this instance
34 * @param {String} sGroup The group of related DragDrop items
35 * @param {SliderThumb} oThumb The thumb for this slider
36 * @param {String} sType The type of slider (horiz, vert, region)
38 YAHOO.widget.Slider = function(sElementId, sGroup, oThumb, sType) {
40 this.init(sElementId, sGroup, true);
41 this.initSlider(sType);
42 this.initThumb(oThumb);
47 * Factory method for creating a horizontal slider
48 * @method YAHOO.widget.Slider.getHorizSlider
50 * @param {String} sBGElId the id of the slider's background element
51 * @param {String} sHandleElId the id of the thumb element
52 * @param {int} iLeft the number of pixels the element can move left
53 * @param {int} iRight the number of pixels the element can move right
54 * @param {int} iTickSize optional parameter for specifying that the element
55 * should move a certain number pixels at a time.
56 * @return {Slider} a horizontal slider control
58 YAHOO.widget.Slider.getHorizSlider =
59 function (sBGElId, sHandleElId, iLeft, iRight, iTickSize) {
60 return new YAHOO.widget.Slider(sBGElId, sBGElId,
61 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId,
62 iLeft, iRight, 0, 0, iTickSize), "horiz");
66 * Factory method for creating a vertical slider
67 * @method YAHOO.widget.Slider.getVertSlider
69 * @param {String} sBGElId the id of the slider's background element
70 * @param {String} sHandleElId the id of the thumb element
71 * @param {int} iUp the number of pixels the element can move up
72 * @param {int} iDown the number of pixels the element can move down
73 * @param {int} iTickSize optional parameter for specifying that the element
74 * should move a certain number pixels at a time.
75 * @return {Slider} a vertical slider control
77 YAHOO.widget.Slider.getVertSlider =
78 function (sBGElId, sHandleElId, iUp, iDown, iTickSize) {
79 return new YAHOO.widget.Slider(sBGElId, sBGElId,
80 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, 0, 0,
81 iUp, iDown, iTickSize), "vert");
85 * Factory method for creating a slider region like the one in the color
87 * @method YAHOO.widget.Slider.getSliderRegion
89 * @param {String} sBGElId the id of the slider's background element
90 * @param {String} sHandleElId the id of the thumb element
91 * @param {int} iLeft the number of pixels the element can move left
92 * @param {int} iRight the number of pixels the element can move right
93 * @param {int} iUp the number of pixels the element can move up
94 * @param {int} iDown the number of pixels the element can move down
95 * @param {int} iTickSize optional parameter for specifying that the element
96 * should move a certain number pixels at a time.
97 * @return {Slider} a slider region control
99 YAHOO.widget.Slider.getSliderRegion =
100 function (sBGElId, sHandleElId, iLeft, iRight, iUp, iDown, iTickSize) {
101 return new YAHOO.widget.Slider(sBGElId, sBGElId,
102 new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, iLeft, iRight,
103 iUp, iDown, iTickSize), "region");
107 * By default, animation is available if the animation library is detected.
108 * @property YAHOO.widget.Slider.ANIM_AVAIL
112 YAHOO.widget.Slider.ANIM_AVAIL = true;
114 YAHOO.extend(YAHOO.widget.Slider, YAHOO.util.DragDrop, {
117 * Initializes the slider. Executed in the constructor
119 * @param {string} sType the type of slider (horiz, vert, region)
121 initSlider: function(sType) {
124 * The type of the slider (horiz, vert, region)
130 //this.removeInvalidHandleType("A");
134 * Event the fires when the value of the control changes. If
135 * the control is animated the event will fire every point
138 * @param {int} newOffset|x the new offset for normal sliders, or the new
139 * x offset for region sliders
140 * @param {int} y the number of pixels the thumb has moved on the y axis
141 * (region sliders only)
143 this.createEvent("change", this);
146 * Event that fires at the beginning of a slider thumb move.
149 this.createEvent("slideStart", this);
152 * Event that fires at the end of a slider thumb move
155 this.createEvent("slideEnd", this);
158 * Overrides the isTarget property in YAHOO.util.DragDrop
162 this.isTarget = false;
165 * Flag that determines if the thumb will animate when moved
169 this.animate = YAHOO.widget.Slider.ANIM_AVAIL;
172 * Set to false to disable a background click thumb move
173 * @property backgroundEnabled
176 this.backgroundEnabled = true;
179 * Adjustment factor for tick animation, the more ticks, the
180 * faster the animation (by default)
181 * @property tickPause
187 * Enables the arrow, home and end keys, defaults to true.
188 * @property enableKeys
191 this.enableKeys = true;
194 * Specifies the number of pixels the arrow keys will move the slider.
196 * @property keyIncrement
199 this.keyIncrement = 20;
202 * moveComplete is set to true when the slider has moved to its final
203 * destination. For animated slider, this value can be checked in
204 * the onChange handler to make it possible to execute logic only
205 * when the move is complete rather than at all points along the way.
207 * @property moveComplete
210 this.moveComplete = true;
213 * If animation is configured, specifies the length of the animation
215 * @property animationDuration
219 this.animationDuration = 0.2;
223 * Initializes the slider's thumb. Executed in the constructor.
225 * @param {YAHOO.widget.SliderThumb} t the slider thumb
227 initThumb: function(t) {
232 * A YAHOO.widget.SliderThumb instance that we will use to
233 * reposition the thumb when the background is clicked
235 * @type YAHOO.widget.SliderThumb
238 t.cacheBetweenDrags = true;
240 // add handler for the handle onchange event
241 t.onChange = function() {
242 self.handleThumbChange();
245 if (t._isHoriz && t.xTicks && t.xTicks.length) {
246 this.tickPause = Math.round(360 / t.xTicks.length);
247 } else if (t.yTicks && t.yTicks.length) {
248 this.tickPause = Math.round(360 / t.yTicks.length);
252 // delegate thumb methods
253 t.onMouseDown = function () { return self.focus(); };
254 t.onMouseUp = function() { self.thumbMouseUp(); };
255 t.onDrag = function() { self.fireEvents(true); };
256 t.onAvailable = function() { return self.setStartSliderState(); };
261 * Executed when the slider element is available
262 * @method onAvailable
264 onAvailable: function() {
265 var Event = YAHOO.util.Event;
266 Event.on(this.id, "keydown", this.handleKeyDown, this, true);
267 Event.on(this.id, "keypress", this.handleKeyPress, this, true);
271 * Executed when a keypress event happens with the control focused.
272 * Prevents the default behavior for navigation keys. The actual
273 * logic for moving the slider thumb in response to a key event
274 * happens in handleKeyDown.
275 * @param {Event} e the keypress event
277 handleKeyPress: function(e) {
278 if (this.enableKeys) {
279 var Event = YAHOO.util.Event;
280 var kc = Event.getCharCode(e);
288 Event.preventDefault(e);
296 * Executed when a keydown event happens with the control focused.
297 * Updates the slider value and display when the keypress is an
298 * arrow key, home, or end as long as enableKeys is set to true.
299 * @param {Event} e the keydown event
301 handleKeyDown: function(e) {
302 if (this.enableKeys) {
303 var Event = YAHOO.util.Event;
305 var kc = Event.getCharCode(e), t=this.thumb;
306 var h=this.getXValue(),v=this.getYValue();
309 var changeValue = true;
313 case 0x25: h -= this.keyIncrement; break;
316 case 0x26: v -= this.keyIncrement; break;
319 case 0x27: h += this.keyIncrement; break;
322 case 0x28: v += this.keyIncrement; break;
325 case 0x24: h = t.leftConstraint;
330 case 0x23: h = t.rightConstraint;
331 v = t.bottomConstraint;
334 default: changeValue = false;
339 this.setRegionValue(h, v, true);
341 var newVal = (t._isHoriz) ? h : v;
342 this.setValue(newVal, true);
351 * Initialization that sets up the value offsets once the elements are ready
352 * @method setStartSliderState
354 setStartSliderState: function() {
357 this.setThumbCenterPoint();
360 * The basline position of the background element, used
361 * to determine if the background has moved since the last
363 * @property baselinePos
366 this.baselinePos = YAHOO.util.Dom.getXY(this.getEl());
368 this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos);
370 if (this.thumb._isRegion) {
371 if (this.deferredSetRegionValue) {
372 this.setRegionValue.apply(this, this.deferredSetRegionValue, true);
373 this.deferredSetRegionValue = null;
375 this.setRegionValue(0, 0, true, true);
378 if (this.deferredSetValue) {
379 this.setValue.apply(this, this.deferredSetValue, true);
380 this.deferredSetValue = null;
382 this.setValue(0, true, true);
388 * When the thumb is available, we cache the centerpoint of the element so
389 * we can position the element correctly when the background is clicked
390 * @method setThumbCenterPoint
392 setThumbCenterPoint: function() {
394 var el = this.thumb.getEl();
398 * The center of the slider element is stored so we can
399 * place it in the correct position when the background is clicked.
400 * @property thumbCenterPoint
401 * @type {"x": int, "y": int}
403 this.thumbCenterPoint = {
404 x: parseInt(el.offsetWidth/2, 10),
405 y: parseInt(el.offsetHeight/2, 10)
412 * Locks the slider, overrides YAHOO.util.DragDrop
421 * Unlocks the slider, overrides YAHOO.util.DragDrop
430 * Handles mouseup event on the slider background
431 * @method thumbMouseUp
434 thumbMouseUp: function() {
435 if (!this.isLocked() && !this.moveComplete) {
442 * Returns a reference to this slider's thumb
444 * @return {SliderThumb} this slider's thumb
446 getThumb: function() {
451 * Try to focus the element when clicked so we can add
452 * accessibility features
458 // Focus the background element if possible
459 var el = this.getEl();
465 // Prevent permission denied unhandled exception in FF that can
466 // happen when setting focus while another element is handling
467 // the blur. @TODO this is still writing to the error log
468 // (unhandled error) in FF1.5 with strict error checking on.
474 if (this.isLocked()) {
483 * Event that fires when the value of the slider has changed
485 * @param {int} firstOffset the number of pixels the thumb has moved
486 * from its start position. Normal horizontal and vertical sliders will only
487 * have the firstOffset. Regions will have both, the first is the horizontal
488 * offset, the second the vertical.
489 * @param {int} secondOffset the y offset for region sliders
490 * @deprecated use instance.subscribe("change") instead
492 onChange: function (firstOffset, secondOffset) {
497 * Event that fires when the at the beginning of the slider thumb move
498 * @method onSlideStart
499 * @deprecated use instance.subscribe("slideStart") instead
501 onSlideStart: function () {
506 * Event that fires at the end of a slider thumb move
507 * @method onSliderEnd
508 * @deprecated use instance.subscribe("slideEnd") instead
510 onSlideEnd: function () {
515 * Returns the slider's thumb offset from the start position
517 * @return {int} the current value
519 getValue: function () {
520 return this.thumb.getValue();
524 * Returns the slider's thumb X offset from the start position
526 * @return {int} the current horizontal offset
528 getXValue: function () {
529 return this.thumb.getXValue();
533 * Returns the slider's thumb Y offset from the start position
535 * @return {int} the current vertical offset
537 getYValue: function () {
538 return this.thumb.getYValue();
542 * Internal handler for the slider thumb's onChange event
543 * @method handleThumbChange
546 handleThumbChange: function () {
549 t.onChange(t.getXValue(), t.getYValue());
550 this.fireEvent("change", { x: t.getXValue(), y: t.getYValue() } );
552 t.onChange(t.getValue());
553 this.fireEvent("change", t.getValue());
559 * Provides a way to set the value of the slider in code.
561 * @param {int} newOffset the number of pixels the thumb should be
562 * positioned away from the initial start point
563 * @param {boolean} skipAnim set to true to disable the animation
564 * for this move action (but not others).
565 * @param {boolean} force ignore the locked setting and set value anyway
566 * @return {boolean} true if the move was performed, false if it failed
568 setValue: function(newOffset, skipAnim, force) {
570 if (!this.thumb.available) {
571 this.deferredSetValue = arguments;
575 if (this.isLocked() && !force) {
579 if ( isNaN(newOffset) ) {
585 this.verifyOffset(true);
588 } else if (t._isHoriz) {
590 // this.fireEvent("slideStart");
591 newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
592 this.moveThumb(newX, t.initPageY, skipAnim);
595 // this.fireEvent("slideStart");
596 newY = t.initPageY + newOffset + this.thumbCenterPoint.y;
597 this.moveThumb(t.initPageX, newY, skipAnim);
604 * Provides a way to set the value of the region slider in code.
605 * @method setRegionValue
606 * @param {int} newOffset the number of pixels the thumb should be
607 * positioned away from the initial start point (x axis for region)
608 * @param {int} newOffset2 the number of pixels the thumb should be
609 * positioned away from the initial start point (y axis for region)
610 * @param {boolean} skipAnim set to true to disable the animation
611 * for this move action (but not others).
612 * @param {boolean} force ignore the locked setting and set value anyway
613 * @return {boolean} true if the move was performed, false if it failed
615 setRegionValue: function(newOffset, newOffset2, skipAnim, force) {
617 if (!this.thumb.available) {
618 this.deferredSetRegionValue = arguments;
622 if (this.isLocked() && !force) {
626 if ( isNaN(newOffset) ) {
633 var newX = t.initPageX + newOffset + this.thumbCenterPoint.x;
634 var newY = t.initPageY + newOffset2 + this.thumbCenterPoint.y;
635 this.moveThumb(newX, newY, skipAnim);
644 * Checks the background position element position. If it has moved from the
645 * baseline position, the constraints for the thumb are reset
646 * @param checkPos {boolean} check the position instead of using cached value
647 * @method verifyOffset
648 * @return {boolean} True if the offset is the same as the baseline.
650 verifyOffset: function(checkPos) {
652 var newPos = YAHOO.util.Dom.getXY(this.getEl());
653 //var newPos = [this.initPageX, this.initPageY];
656 if (newPos[0] != this.baselinePos[0] || newPos[1] != this.baselinePos[1]) {
657 this.thumb.resetConstraints();
658 this.baselinePos = newPos;
666 * Move the associated slider moved to a timeout to try to get around the
667 * mousedown stealing moz does when I move the slider element between the
668 * cursor and the background during the mouseup event
670 * @param {int} x the X coordinate of the click
671 * @param {int} y the Y coordinate of the click
672 * @param {boolean} skipAnim don't animate if the move happend onDrag
675 moveThumb: function(x, y, skipAnim) {
686 // this.verifyOffset();
688 t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y);
690 var _p = t.getTargetCoord(x, y);
691 var p = [_p.x, _p.y];
693 this.fireEvent("slideStart");
695 if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && t._graduated && !skipAnim) {
696 // this.thumb._animating = true;
699 // cache the current thumb pos
700 this.curCoord = YAHOO.util.Dom.getXY(this.thumb.getEl());
702 setTimeout( function() { self.moveOneTick(p); }, this.tickPause );
704 } else if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && !skipAnim) {
706 // this.thumb._animating = true;
709 var oAnim = new YAHOO.util.Motion(
710 t.id, { points: { to: p } },
711 this.animationDuration,
712 YAHOO.util.Easing.easeOut );
714 oAnim.onComplete.subscribe( function() { self.endMove(); } );
717 t.setDragElPos(x, y);
718 // this.fireEvents();
724 * Move the slider one tick mark towards its final coordinate. Used
725 * for the animation when tick marks are defined
726 * @method moveOneTick
727 * @param {int[]} the destination coordinate
730 moveOneTick: function(finalCoord) {
732 var t = this.thumb, tmp;
734 // redundant call to getXY since we set the position most of time prior
735 // to getting here. Moved to this.curCoord
736 //var curCoord = YAHOO.util.Dom.getXY(t.getEl());
738 // alignElWithMouse caches position in lastPageX, lastPageY .. doesn't work
739 //var curCoord = [this.lastPageX, this.lastPageY];
741 // var thresh = Math.min(t.tickSize + (Math.floor(t.tickSize/2)), 10);
743 // var thresh = t.tickSize + (Math.floor(t.tickSize/2));
745 var nextCoord = null;
748 nextCoord = this._getNextX(this.curCoord, finalCoord);
749 var tmpX = (nextCoord) ? nextCoord[0] : this.curCoord[0];
750 nextCoord = this._getNextY([tmpX, this.curCoord[1]], finalCoord);
752 } else if (t._isHoriz) {
753 nextCoord = this._getNextX(this.curCoord, finalCoord);
755 nextCoord = this._getNextY(this.curCoord, finalCoord);
761 // cache the position
762 this.curCoord = nextCoord;
764 // move to the next coord
765 // YAHOO.util.Dom.setXY(t.getEl(), nextCoord);
767 // var el = t.getEl();
768 // YAHOO.util.Dom.setStyle(el, "left", (nextCoord[0] + this.thumb.deltaSetXY[0]) + "px");
769 // YAHOO.util.Dom.setStyle(el, "top", (nextCoord[1] + this.thumb.deltaSetXY[1]) + "px");
771 this.thumb.alignElWithMouse(t.getEl(), nextCoord[0], nextCoord[1]);
773 // check if we are in the final position, if not make a recursive call
774 if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) {
776 setTimeout(function() { self.moveOneTick(finalCoord); },
785 //this.tickPause = Math.round(this.tickPause/2);
789 * Returns the next X tick value based on the current coord and the target coord.
793 _getNextX: function(curCoord, finalCoord) {
797 var nextCoord = null;
798 if (curCoord[0] > finalCoord[0]) {
799 thresh = t.tickSize - this.thumbCenterPoint.x;
800 tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] );
801 nextCoord = [tmp.x, tmp.y];
802 } else if (curCoord[0] < finalCoord[0]) {
803 thresh = t.tickSize + this.thumbCenterPoint.x;
804 tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] );
805 nextCoord = [tmp.x, tmp.y];
814 * Returns the next Y tick value based on the current coord and the target coord.
818 _getNextY: function(curCoord, finalCoord) {
822 var nextCoord = null;
824 if (curCoord[1] > finalCoord[1]) {
825 thresh = t.tickSize - this.thumbCenterPoint.y;
826 tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh );
827 nextCoord = [tmp.x, tmp.y];
828 } else if (curCoord[1] < finalCoord[1]) {
829 thresh = t.tickSize + this.thumbCenterPoint.y;
830 tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh );
831 nextCoord = [tmp.x, tmp.y];
840 * Resets the constraints before moving the thumb.
841 * @method b4MouseDown
844 b4MouseDown: function(e) {
845 this.thumb.autoOffset();
846 this.thumb.resetConstraints();
850 * Handles the mousedown event for the slider background
851 * @method onMouseDown
854 onMouseDown: function(e) {
855 // this.resetConstraints(true);
856 // this.thumb.resetConstraints(true);
858 if (! this.isLocked() && this.backgroundEnabled) {
859 var x = YAHOO.util.Event.getPageX(e);
860 var y = YAHOO.util.Event.getPageY(e);
863 this.moveThumb(x, y);
869 * Handles the onDrag event for the slider background
873 onDrag: function(e) {
874 if (! this.isLocked()) {
875 var x = YAHOO.util.Event.getPageX(e);
876 var y = YAHOO.util.Event.getPageY(e);
877 this.moveThumb(x, y, true);
882 * Fired when the slider movement ends
886 endMove: function () {
887 // this._animating = false;
889 this.moveComplete = true;
894 * Fires the change event if the value has been changed. Ignored if we are in
895 * the middle of an animation as the event will fire when the animation is
898 * @param {boolean} thumbEvent set to true if this event is fired from an event
899 * that occurred on the thumb. If it is, the state of the
900 * thumb dd object should be correct. Otherwise, the event
901 * originated on the background, so the thumb state needs to
902 * be refreshed before proceeding.
905 fireEvents: function (thumbEvent) {
913 if (! this.isLocked()) {
915 var newX = t.getXValue();
916 var newY = t.getYValue();
918 if (newX != this.previousX || newY != this.previousY) {
919 this.onChange(newX, newY);
920 this.fireEvent("change", { x: newX, y: newY });
923 this.previousX = newX;
924 this.previousY = newY;
927 var newVal = t.getValue();
928 if (newVal != this.previousVal) {
929 this.onChange( newVal );
930 this.fireEvent("change", newVal);
932 this.previousVal = newVal;
935 if (this.moveComplete) {
937 this.fireEvent("slideEnd");
938 this.moveComplete = false;
947 * @return {string} string representation of the instance
949 toString: function () {
950 return ("Slider (" + this.type +") " + this.id);
955 YAHOO.augment(YAHOO.widget.Slider, YAHOO.util.EventProvider);
958 * A drag and drop implementation to be used as the thumb of a slider.
960 * @extends YAHOO.util.DD
962 * @param {String} id the id of the slider html element
963 * @param {String} sGroup the group of related DragDrop items
964 * @param {int} iLeft the number of pixels the element can move left
965 * @param {int} iRight the number of pixels the element can move right
966 * @param {int} iUp the number of pixels the element can move up
967 * @param {int} iDown the number of pixels the element can move down
968 * @param {int} iTickSize optional parameter for specifying that the element
969 * should move a certain number pixels at a time.
971 YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) {
974 //this.init(id, sGroup);
975 YAHOO.widget.SliderThumb.superclass.constructor.call(this, id, sGroup);
978 * The id of the thumbs parent HTML element (the slider background
980 * @property parentElId
983 this.parentElId = sGroup;
986 //this.removeInvalidHandleType("A");
990 * Overrides the isTarget property in YAHOO.util.DragDrop
994 this.isTarget = false;
997 * The tick size for this slider
1002 this.tickSize = iTickSize;
1005 * Informs the drag and drop util that the offsets should remain when
1006 * resetting the constraints. This preserves the slider value when
1007 * the constraints are reset
1008 * @property maintainOffset
1012 this.maintainOffset = true;
1014 this.initSlider(iLeft, iRight, iUp, iDown, iTickSize);
1017 * Turns off the autoscroll feature in drag and drop
1021 this.scroll = false;
1025 YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, {
1028 * The (X and Y) difference between the thumb location and its parent
1029 * (the slider background) when the control is instantiated.
1030 * @property startOffset
1036 * Flag used to figure out if this is a horizontal or vertical slider
1037 * @property _isHoriz
1044 * Cache the last value so we can check for change
1045 * @property _prevVal
1052 * The slider is _graduated if there is a tick interval defined
1053 * @property _graduated
1060 * Returns the difference between the location of the thumb and its parent.
1061 * @method getOffsetFromParent
1062 * @param {[int, int]} parentPos Optionally accepts the position of the parent
1065 getOffsetFromParent0: function(parentPos) {
1066 var myPos = YAHOO.util.Dom.getXY(this.getEl());
1067 var ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
1069 return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
1072 getOffsetFromParent: function(parentPos) {
1074 var el = this.getEl();
1076 if (!this.deltaOffset) {
1078 var myPos = YAHOO.util.Dom.getXY(el);
1079 var ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
1081 var newOffset = [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
1083 var l = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
1084 var t = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
1086 var deltaX = l - newOffset[0];
1087 var deltaY = t - newOffset[1];
1089 if (isNaN(deltaX) || isNaN(deltaY)) {
1091 this.deltaOffset = [deltaX, deltaY];
1095 var newLeft = parseInt( YAHOO.util.Dom.getStyle(el, "left"), 10 );
1096 var newTop = parseInt( YAHOO.util.Dom.getStyle(el, "top" ), 10 );
1098 newOffset = [newLeft + this.deltaOffset[0], newTop + this.deltaOffset[1]];
1103 //return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
1107 * Set up the slider, must be called in the constructor of all subclasses
1108 * @method initSlider
1109 * @param {int} iLeft the number of pixels the element can move left
1110 * @param {int} iRight the number of pixels the element can move right
1111 * @param {int} iUp the number of pixels the element can move up
1112 * @param {int} iDown the number of pixels the element can move down
1113 * @param {int} iTickSize the width of the tick interval.
1115 initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) {
1117 //document these. new for 0.12.1
1118 this.initLeft = iLeft;
1119 this.initRight = iRight;
1121 this.initDown = iDown;
1123 this.setXConstraint(iLeft, iRight, iTickSize);
1124 this.setYConstraint(iUp, iDown, iTickSize);
1126 if (iTickSize && iTickSize > 1) {
1127 this._graduated = true;
1130 this._isHoriz = (iLeft || iRight);
1131 this._isVert = (iUp || iDown);
1132 this._isRegion = (this._isHoriz && this._isVert);
1137 * Clear's the slider's ticks
1138 * @method clearTicks
1140 clearTicks: function () {
1141 YAHOO.widget.SliderThumb.superclass.clearTicks.call(this);
1143 this._graduated = false;
1147 * Gets the current offset from the element's start position in
1150 * @return {int} the number of pixels (positive or negative) the
1151 * slider has moved from the start position.
1153 getValue: function () {
1154 if (!this.available) { return 0; }
1155 var val = (this._isHoriz) ? this.getXValue() : this.getYValue();
1160 * Gets the current X offset from the element's start position in
1163 * @return {int} the number of pixels (positive or negative) the
1164 * slider has moved horizontally from the start position.
1166 getXValue: function () {
1167 if (!this.available) { return 0; }
1168 var newOffset = this.getOffsetFromParent();
1169 return (newOffset[0] - this.startOffset[0]);
1173 * Gets the current Y offset from the element's start position in
1176 * @return {int} the number of pixels (positive or negative) the
1177 * slider has moved vertically from the start position.
1179 getYValue: function () {
1180 if (!this.available) { return 0; }
1181 var newOffset = this.getOffsetFromParent();
1182 return (newOffset[1] - this.startOffset[1]);
1188 * @return {string} string representation of the instance
1190 toString: function () {
1191 return "SliderThumb " + this.id;
1195 * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider
1196 * instance it belongs to.
1200 onChange: function (x, y) {
1205 if ("undefined" == typeof YAHOO.util.Anim) {
1206 YAHOO.widget.Slider.ANIM_AVAIL = false;