diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-05-09 15:29:14 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-05-09 15:29:14 -0400 |
commit | d89b8f05091d1f34508c5bad1dbb6a74cf6492b4 (patch) | |
tree | 2dcc8c5a69b70aeea654ca7b73392cd94cbd1a5e | |
parent | 653673ed64176645128782038e0ee99c05514b92 (diff) | |
download | jquery-ui-d89b8f05091d1f34508c5bad1dbb6a74cf6492b4.tar.gz jquery-ui-d89b8f05091d1f34508c5bad1dbb6a74cf6492b4.zip |
Slider: Remove uses of self var; use new APIs or that var.
-rw-r--r-- | ui/jquery.ui.slider.js | 122 |
1 files changed, 51 insertions, 71 deletions
diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index b355f8c7e..cb806605c 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -36,7 +36,6 @@ $.widget( "ui.slider", $.ui.mouse, { _create: function() { var i, - self = this, o = this.options, existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ), handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>", @@ -83,7 +82,7 @@ $.widget( "ui.slider", $.ui.mouse, { handles.push( handle ); } - this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.element ) ); + this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) ); this.handle = this.handles.eq( 0 ); @@ -114,17 +113,10 @@ $.widget( "ui.slider", $.ui.mouse, { $( this ).data( "ui-slider-handle-index", i ); }); - this.handles - .keydown(function( event ) { - var index = $( this ).data( "ui-slider-handle-index" ), - allowed, - curVal, - newVal, - step; - - if ( self.options.disabled ) { - return; - } + this._bind( this.handles, { + keydown: function( event ) { + var allowed, curVal, newVal, step, + index = $( event.target ).data( "ui-slider-handle-index" ); switch ( event.keyCode ) { case $.ui.keyCode.HOME: @@ -136,10 +128,10 @@ $.widget( "ui.slider", $.ui.mouse, { case $.ui.keyCode.DOWN: case $.ui.keyCode.LEFT: event.preventDefault(); - if ( !self._keySliding ) { - self._keySliding = true; - $( this ).addClass( "ui-state-active" ); - allowed = self._start( event, index ); + if ( !this._keySliding ) { + this._keySliding = true; + $( event.target ).addClass( "ui-state-active" ); + allowed = this._start( event, index ); if ( allowed === false ) { return; } @@ -147,55 +139,55 @@ $.widget( "ui.slider", $.ui.mouse, { break; } - step = self.options.step; - if ( self.options.values && self.options.values.length ) { - curVal = newVal = self.values( index ); + step = this.options.step; + if ( this.options.values && this.options.values.length ) { + curVal = newVal = this.values( index ); } else { - curVal = newVal = self.value(); + curVal = newVal = this.value(); } switch ( event.keyCode ) { case $.ui.keyCode.HOME: - newVal = self._valueMin(); + newVal = this._valueMin(); break; case $.ui.keyCode.END: - newVal = self._valueMax(); + newVal = this._valueMax(); break; case $.ui.keyCode.PAGE_UP: - newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) ); + newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) ); break; case $.ui.keyCode.PAGE_DOWN: - newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) ); + newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) ); break; case $.ui.keyCode.UP: case $.ui.keyCode.RIGHT: - if ( curVal === self._valueMax() ) { + if ( curVal === this._valueMax() ) { return; } - newVal = self._trimAlignValue( curVal + step ); + newVal = this._trimAlignValue( curVal + step ); break; case $.ui.keyCode.DOWN: case $.ui.keyCode.LEFT: - if ( curVal === self._valueMin() ) { + if ( curVal === this._valueMin() ) { return; } - newVal = self._trimAlignValue( curVal - step ); + newVal = this._trimAlignValue( curVal - step ); break; } - self._slide( event, index, newVal ); - }) - .keyup(function( event ) { - var index = $( this ).data( "ui-slider-handle-index" ); - - if ( self._keySliding ) { - self._keySliding = false; - self._stop( event, index ); - self._change( event, index ); - $( this ).removeClass( "ui-state-active" ); - } + this._slide( event, index, newVal ); + }, + keyup: function( event ) { + var index = $( event.target ).data( "ui-slider-handle-index" ); - }); + if ( this._keySliding ) { + this._keySliding = false; + this._stop( event, index ); + this._change( event, index ); + $( event.target ).removeClass( "ui-state-active" ); + } + } + }); this._refreshValue(); @@ -223,16 +215,9 @@ $.widget( "ui.slider", $.ui.mouse, { }, _mouseCapture: function( event ) { - var o = this.options, - position, - normValue, - distance, - closestHandle, - self, - index, - allowed, - offset, - mouseOverHandle; + var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle, + that = this, + o = this.options; if ( o.disabled ) { return false; @@ -247,9 +232,8 @@ $.widget( "ui.slider", $.ui.mouse, { position = { x: event.pageX, y: event.pageY }; normValue = this._normValueFromMouse( position ); distance = this._valueMax() - this._valueMin() + 1; - self = this; this.handles.each(function( i ) { - var thisDistance = Math.abs( normValue - self.values(i) ); + var thisDistance = Math.abs( normValue - that.values(i) ); if ( distance > thisDistance ) { distance = thisDistance; closestHandle = $( this ); @@ -271,7 +255,7 @@ $.widget( "ui.slider", $.ui.mouse, { } this._mouseSliding = true; - self._handleIndex = index; + this._handleIndex = index; closestHandle .addClass( "ui-state-active" ) @@ -594,36 +578,32 @@ $.widget( "ui.slider", $.ui.mouse, { }, _refreshValue: function() { - var oRange = this.options.range, + var lastValPercent, valPercent, value, valueMin, valueMax, + oRange = this.options.range, o = this.options, - self = this, + that = this, animate = ( !this._animateOff ) ? o.animate : false, - valPercent, - _set = {}, - lastValPercent, - value, - valueMin, - valueMax; + _set = {}; if ( this.options.values && this.options.values.length ) { this.handles.each(function( i, j ) { - valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100; - _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; + valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; + _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); - if ( self.options.range === true ) { - if ( self.orientation === "horizontal" ) { + if ( that.options.range === true ) { + if ( that.orientation === "horizontal" ) { if ( i === 0 ) { - self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate ); + that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate ); } if ( i === 1 ) { - self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); + that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); } } else { if ( i === 0 ) { - self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate ); + that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate ); } if ( i === 1 ) { - self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); + that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); } } } @@ -636,7 +616,7 @@ $.widget( "ui.slider", $.ui.mouse, { valPercent = ( valueMax !== valueMin ) ? ( value - valueMin ) / ( valueMax - valueMin ) * 100 : 0; - _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; + _set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); if ( oRange === "min" && this.orientation === "horizontal" ) { |