Skip to content

Commit 176e0ed

Browse files
dominicbarnesscottgonzalez
authored andcommitted
Slider: Moved events to named functions (to allow extended plugins to hook in).
1 parent e4a786e commit 176e0ed

File tree

1 file changed

+78
-76
lines changed

1 file changed

+78
-76
lines changed

ui/jquery.ui.slider.js

Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -124,82 +124,7 @@ $.widget( "ui.slider", $.ui.mouse, {
124124

125125
this._setOption( "disabled", o.disabled );
126126

127-
this._on( this.handles, {
128-
keydown: function( event ) {
129-
/*jshint maxcomplexity:25*/
130-
var allowed, curVal, newVal, step,
131-
index = $( event.target ).data( "ui-slider-handle-index" );
132-
133-
switch ( event.keyCode ) {
134-
case $.ui.keyCode.HOME:
135-
case $.ui.keyCode.END:
136-
case $.ui.keyCode.PAGE_UP:
137-
case $.ui.keyCode.PAGE_DOWN:
138-
case $.ui.keyCode.UP:
139-
case $.ui.keyCode.RIGHT:
140-
case $.ui.keyCode.DOWN:
141-
case $.ui.keyCode.LEFT:
142-
event.preventDefault();
143-
if ( !this._keySliding ) {
144-
this._keySliding = true;
145-
$( event.target ).addClass( "ui-state-active" );
146-
allowed = this._start( event, index );
147-
if ( allowed === false ) {
148-
return;
149-
}
150-
}
151-
break;
152-
}
153-
154-
step = this.options.step;
155-
if ( this.options.values && this.options.values.length ) {
156-
curVal = newVal = this.values( index );
157-
} else {
158-
curVal = newVal = this.value();
159-
}
160-
161-
switch ( event.keyCode ) {
162-
case $.ui.keyCode.HOME:
163-
newVal = this._valueMin();
164-
break;
165-
case $.ui.keyCode.END:
166-
newVal = this._valueMax();
167-
break;
168-
case $.ui.keyCode.PAGE_UP:
169-
newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
170-
break;
171-
case $.ui.keyCode.PAGE_DOWN:
172-
newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
173-
break;
174-
case $.ui.keyCode.UP:
175-
case $.ui.keyCode.RIGHT:
176-
if ( curVal === this._valueMax() ) {
177-
return;
178-
}
179-
newVal = this._trimAlignValue( curVal + step );
180-
break;
181-
case $.ui.keyCode.DOWN:
182-
case $.ui.keyCode.LEFT:
183-
if ( curVal === this._valueMin() ) {
184-
return;
185-
}
186-
newVal = this._trimAlignValue( curVal - step );
187-
break;
188-
}
189-
190-
this._slide( event, index, newVal );
191-
},
192-
keyup: function( event ) {
193-
var index = $( event.target ).data( "ui-slider-handle-index" );
194-
195-
if ( this._keySliding ) {
196-
this._keySliding = false;
197-
this._stop( event, index );
198-
this._change( event, index );
199-
$( event.target ).removeClass( "ui-state-active" );
200-
}
201-
}
202-
});
127+
this._on( this.handles, this._handleEvents );
203128

204129
this._refreshValue();
205130

@@ -640,6 +565,83 @@ $.widget( "ui.slider", $.ui.mouse, {
640565
this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
641566
}
642567
}
568+
},
569+
570+
_handleEvents: {
571+
keydown: function( event ) {
572+
/*jshint maxcomplexity:25*/
573+
var allowed, curVal, newVal, step,
574+
index = $( event.target ).data( "ui-slider-handle-index" );
575+
576+
switch ( event.keyCode ) {
577+
case $.ui.keyCode.HOME:
578+
case $.ui.keyCode.END:
579+
case $.ui.keyCode.PAGE_UP:
580+
case $.ui.keyCode.PAGE_DOWN:
581+
case $.ui.keyCode.UP:
582+
case $.ui.keyCode.RIGHT:
583+
case $.ui.keyCode.DOWN:
584+
case $.ui.keyCode.LEFT:
585+
event.preventDefault();
586+
if ( !this._keySliding ) {
587+
this._keySliding = true;
588+
$( event.target ).addClass( "ui-state-active" );
589+
allowed = this._start( event, index );
590+
if ( allowed === false ) {
591+
return;
592+
}
593+
}
594+
break;
595+
}
596+
597+
step = this.options.step;
598+
if ( this.options.values && this.options.values.length ) {
599+
curVal = newVal = this.values( index );
600+
} else {
601+
curVal = newVal = this.value();
602+
}
603+
604+
switch ( event.keyCode ) {
605+
case $.ui.keyCode.HOME:
606+
newVal = this._valueMin();
607+
break;
608+
case $.ui.keyCode.END:
609+
newVal = this._valueMax();
610+
break;
611+
case $.ui.keyCode.PAGE_UP:
612+
newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
613+
break;
614+
case $.ui.keyCode.PAGE_DOWN:
615+
newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
616+
break;
617+
case $.ui.keyCode.UP:
618+
case $.ui.keyCode.RIGHT:
619+
if ( curVal === this._valueMax() ) {
620+
return;
621+
}
622+
newVal = this._trimAlignValue( curVal + step );
623+
break;
624+
case $.ui.keyCode.DOWN:
625+
case $.ui.keyCode.LEFT:
626+
if ( curVal === this._valueMin() ) {
627+
return;
628+
}
629+
newVal = this._trimAlignValue( curVal - step );
630+
break;
631+
}
632+
633+
this._slide( event, index, newVal );
634+
},
635+
keyup: function( event ) {
636+
var index = $( event.target ).data( "ui-slider-handle-index" );
637+
638+
if ( this._keySliding ) {
639+
this._keySliding = false;
640+
this._stop( event, index );
641+
this._change( event, index );
642+
$( event.target ).removeClass( "ui-state-active" );
643+
}
644+
}
643645
}
644646

645647
});

0 commit comments

Comments
 (0)