@@ -36,7 +36,6 @@ $.widget( "ui.slider", $.ui.mouse, {
36
36
37
37
_create : function ( ) {
38
38
var i ,
39
- self = this ,
40
39
o = this . options ,
41
40
existingHandles = this . element . find ( ".ui-slider-handle" ) . addClass ( "ui-state-default ui-corner-all" ) ,
42
41
handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>" ,
@@ -83,7 +82,7 @@ $.widget( "ui.slider", $.ui.mouse, {
83
82
handles . push ( handle ) ;
84
83
}
85
84
86
- this . handles = existingHandles . add ( $ ( handles . join ( "" ) ) . appendTo ( self . element ) ) ;
85
+ this . handles = existingHandles . add ( $ ( handles . join ( "" ) ) . appendTo ( this . element ) ) ;
87
86
88
87
this . handle = this . handles . eq ( 0 ) ;
89
88
@@ -114,17 +113,10 @@ $.widget( "ui.slider", $.ui.mouse, {
114
113
$ ( this ) . data ( "ui-slider-handle-index" , i ) ;
115
114
} ) ;
116
115
117
- this . handles
118
- . keydown ( function ( event ) {
119
- var index = $ ( this ) . data ( "ui-slider-handle-index" ) ,
120
- allowed ,
121
- curVal ,
122
- newVal ,
123
- step ;
124
-
125
- if ( self . options . disabled ) {
126
- return ;
127
- }
116
+ this . _bind ( this . handles , {
117
+ keydown : function ( event ) {
118
+ var allowed , curVal , newVal , step ,
119
+ index = $ ( event . target ) . data ( "ui-slider-handle-index" ) ;
128
120
129
121
switch ( event . keyCode ) {
130
122
case $ . ui . keyCode . HOME :
@@ -136,66 +128,66 @@ $.widget( "ui.slider", $.ui.mouse, {
136
128
case $ . ui . keyCode . DOWN :
137
129
case $ . ui . keyCode . LEFT :
138
130
event . preventDefault ( ) ;
139
- if ( ! self . _keySliding ) {
140
- self . _keySliding = true ;
141
- $ ( this ) . addClass ( "ui-state-active" ) ;
142
- allowed = self . _start ( event , index ) ;
131
+ if ( ! this . _keySliding ) {
132
+ this . _keySliding = true ;
133
+ $ ( event . target ) . addClass ( "ui-state-active" ) ;
134
+ allowed = this . _start ( event , index ) ;
143
135
if ( allowed === false ) {
144
136
return ;
145
137
}
146
138
}
147
139
break ;
148
140
}
149
141
150
- step = self . options . step ;
151
- if ( self . options . values && self . options . values . length ) {
152
- curVal = newVal = self . values ( index ) ;
142
+ step = this . options . step ;
143
+ if ( this . options . values && this . options . values . length ) {
144
+ curVal = newVal = this . values ( index ) ;
153
145
} else {
154
- curVal = newVal = self . value ( ) ;
146
+ curVal = newVal = this . value ( ) ;
155
147
}
156
148
157
149
switch ( event . keyCode ) {
158
150
case $ . ui . keyCode . HOME :
159
- newVal = self . _valueMin ( ) ;
151
+ newVal = this . _valueMin ( ) ;
160
152
break ;
161
153
case $ . ui . keyCode . END :
162
- newVal = self . _valueMax ( ) ;
154
+ newVal = this . _valueMax ( ) ;
163
155
break ;
164
156
case $ . ui . keyCode . PAGE_UP :
165
- newVal = self . _trimAlignValue ( curVal + ( ( self . _valueMax ( ) - self . _valueMin ( ) ) / numPages ) ) ;
157
+ newVal = this . _trimAlignValue ( curVal + ( ( this . _valueMax ( ) - this . _valueMin ( ) ) / numPages ) ) ;
166
158
break ;
167
159
case $ . ui . keyCode . PAGE_DOWN :
168
- newVal = self . _trimAlignValue ( curVal - ( ( self . _valueMax ( ) - self . _valueMin ( ) ) / numPages ) ) ;
160
+ newVal = this . _trimAlignValue ( curVal - ( ( this . _valueMax ( ) - this . _valueMin ( ) ) / numPages ) ) ;
169
161
break ;
170
162
case $ . ui . keyCode . UP :
171
163
case $ . ui . keyCode . RIGHT :
172
- if ( curVal === self . _valueMax ( ) ) {
164
+ if ( curVal === this . _valueMax ( ) ) {
173
165
return ;
174
166
}
175
- newVal = self . _trimAlignValue ( curVal + step ) ;
167
+ newVal = this . _trimAlignValue ( curVal + step ) ;
176
168
break ;
177
169
case $ . ui . keyCode . DOWN :
178
170
case $ . ui . keyCode . LEFT :
179
- if ( curVal === self . _valueMin ( ) ) {
171
+ if ( curVal === this . _valueMin ( ) ) {
180
172
return ;
181
173
}
182
- newVal = self . _trimAlignValue ( curVal - step ) ;
174
+ newVal = this . _trimAlignValue ( curVal - step ) ;
183
175
break ;
184
176
}
185
177
186
- self . _slide ( event , index , newVal ) ;
187
- } )
188
- . keyup ( function ( event ) {
189
- var index = $ ( this ) . data ( "ui-slider-handle-index" ) ;
190
-
191
- if ( self . _keySliding ) {
192
- self . _keySliding = false ;
193
- self . _stop ( event , index ) ;
194
- self . _change ( event , index ) ;
195
- $ ( this ) . removeClass ( "ui-state-active" ) ;
196
- }
178
+ this . _slide ( event , index , newVal ) ;
179
+ } ,
180
+ keyup : function ( event ) {
181
+ var index = $ ( event . target ) . data ( "ui-slider-handle-index" ) ;
197
182
198
- } ) ;
183
+ if ( this . _keySliding ) {
184
+ this . _keySliding = false ;
185
+ this . _stop ( event , index ) ;
186
+ this . _change ( event , index ) ;
187
+ $ ( event . target ) . removeClass ( "ui-state-active" ) ;
188
+ }
189
+ }
190
+ } ) ;
199
191
200
192
this . _refreshValue ( ) ;
201
193
@@ -223,16 +215,9 @@ $.widget( "ui.slider", $.ui.mouse, {
223
215
} ,
224
216
225
217
_mouseCapture : function ( event ) {
226
- var o = this . options ,
227
- position ,
228
- normValue ,
229
- distance ,
230
- closestHandle ,
231
- self ,
232
- index ,
233
- allowed ,
234
- offset ,
235
- mouseOverHandle ;
218
+ var position , normValue , distance , closestHandle , index , allowed , offset , mouseOverHandle ,
219
+ that = this ,
220
+ o = this . options ;
236
221
237
222
if ( o . disabled ) {
238
223
return false ;
@@ -247,9 +232,8 @@ $.widget( "ui.slider", $.ui.mouse, {
247
232
position = { x : event . pageX , y : event . pageY } ;
248
233
normValue = this . _normValueFromMouse ( position ) ;
249
234
distance = this . _valueMax ( ) - this . _valueMin ( ) + 1 ;
250
- self = this ;
251
235
this . handles . each ( function ( i ) {
252
- var thisDistance = Math . abs ( normValue - self . values ( i ) ) ;
236
+ var thisDistance = Math . abs ( normValue - that . values ( i ) ) ;
253
237
if ( distance > thisDistance ) {
254
238
distance = thisDistance ;
255
239
closestHandle = $ ( this ) ;
@@ -271,7 +255,7 @@ $.widget( "ui.slider", $.ui.mouse, {
271
255
}
272
256
this . _mouseSliding = true ;
273
257
274
- self . _handleIndex = index ;
258
+ this . _handleIndex = index ;
275
259
276
260
closestHandle
277
261
. addClass ( "ui-state-active" )
@@ -594,36 +578,32 @@ $.widget( "ui.slider", $.ui.mouse, {
594
578
} ,
595
579
596
580
_refreshValue : function ( ) {
597
- var oRange = this . options . range ,
581
+ var lastValPercent , valPercent , value , valueMin , valueMax ,
582
+ oRange = this . options . range ,
598
583
o = this . options ,
599
- self = this ,
584
+ that = this ,
600
585
animate = ( ! this . _animateOff ) ? o . animate : false ,
601
- valPercent ,
602
- _set = { } ,
603
- lastValPercent ,
604
- value ,
605
- valueMin ,
606
- valueMax ;
586
+ _set = { } ;
607
587
608
588
if ( this . options . values && this . options . values . length ) {
609
589
this . handles . each ( function ( i , j ) {
610
- valPercent = ( self . values ( i ) - self . _valueMin ( ) ) / ( self . _valueMax ( ) - self . _valueMin ( ) ) * 100 ;
611
- _set [ self . orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%" ;
590
+ valPercent = ( that . values ( i ) - that . _valueMin ( ) ) / ( that . _valueMax ( ) - that . _valueMin ( ) ) * 100 ;
591
+ _set [ that . orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%" ;
612
592
$ ( this ) . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( _set , o . animate ) ;
613
- if ( self . options . range === true ) {
614
- if ( self . orientation === "horizontal" ) {
593
+ if ( that . options . range === true ) {
594
+ if ( that . orientation === "horizontal" ) {
615
595
if ( i === 0 ) {
616
- self . range . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( { left : valPercent + "%" } , o . animate ) ;
596
+ that . range . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( { left : valPercent + "%" } , o . animate ) ;
617
597
}
618
598
if ( i === 1 ) {
619
- self . range [ animate ? "animate" : "css" ] ( { width : ( valPercent - lastValPercent ) + "%" } , { queue : false , duration : o . animate } ) ;
599
+ that . range [ animate ? "animate" : "css" ] ( { width : ( valPercent - lastValPercent ) + "%" } , { queue : false , duration : o . animate } ) ;
620
600
}
621
601
} else {
622
602
if ( i === 0 ) {
623
- self . range . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( { bottom : ( valPercent ) + "%" } , o . animate ) ;
603
+ that . range . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( { bottom : ( valPercent ) + "%" } , o . animate ) ;
624
604
}
625
605
if ( i === 1 ) {
626
- self . range [ animate ? "animate" : "css" ] ( { height : ( valPercent - lastValPercent ) + "%" } , { queue : false , duration : o . animate } ) ;
606
+ that . range [ animate ? "animate" : "css" ] ( { height : ( valPercent - lastValPercent ) + "%" } , { queue : false , duration : o . animate } ) ;
627
607
}
628
608
}
629
609
}
@@ -636,7 +616,7 @@ $.widget( "ui.slider", $.ui.mouse, {
636
616
valPercent = ( valueMax !== valueMin ) ?
637
617
( value - valueMin ) / ( valueMax - valueMin ) * 100 :
638
618
0 ;
639
- _set [ self . orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%" ;
619
+ _set [ this . orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%" ;
640
620
this . handle . stop ( 1 , 1 ) [ animate ? "animate" : "css" ] ( _set , o . animate ) ;
641
621
642
622
if ( oRange === "min" && this . orientation === "horizontal" ) {
0 commit comments