]> source.dussan.org Git - jquery-ui.git/commitdiff
Slider: Moved events to named functions (to allow extended plugins to hook in).
authorDominic Barnes <dominic@dbarnes.info>
Tue, 8 Jan 2013 18:19:16 +0000 (12:19 -0600)
committerScott González <scott.gonzalez@gmail.com>
Mon, 14 Jan 2013 17:48:32 +0000 (12:48 -0500)
ui/jquery.ui.slider.js

index 658df7b2f9de3d2c6a4f078348a85347ff7ac007..9640361a1574d8367a42f86bdd1be3bcb7cc4520 100644 (file)
@@ -124,82 +124,7 @@ $.widget( "ui.slider", $.ui.mouse, {
 
                this._setOption( "disabled", o.disabled );
 
-               this._on( this.handles, {
-                       keydown: function( event ) {
-                               /*jshint maxcomplexity:25*/
-                               var allowed, curVal, newVal, step,
-                                       index = $( event.target ).data( "ui-slider-handle-index" );
-
-                               switch ( event.keyCode ) {
-                                       case $.ui.keyCode.HOME:
-                                       case $.ui.keyCode.END:
-                                       case $.ui.keyCode.PAGE_UP:
-                                       case $.ui.keyCode.PAGE_DOWN:
-                                       case $.ui.keyCode.UP:
-                                       case $.ui.keyCode.RIGHT:
-                                       case $.ui.keyCode.DOWN:
-                                       case $.ui.keyCode.LEFT:
-                                               event.preventDefault();
-                                               if ( !this._keySliding ) {
-                                                       this._keySliding = true;
-                                                       $( event.target ).addClass( "ui-state-active" );
-                                                       allowed = this._start( event, index );
-                                                       if ( allowed === false ) {
-                                                               return;
-                                                       }
-                                               }
-                                               break;
-                               }
-
-                               step = this.options.step;
-                               if ( this.options.values && this.options.values.length ) {
-                                       curVal = newVal = this.values( index );
-                               } else {
-                                       curVal = newVal = this.value();
-                               }
-
-                               switch ( event.keyCode ) {
-                                       case $.ui.keyCode.HOME:
-                                               newVal = this._valueMin();
-                                               break;
-                                       case $.ui.keyCode.END:
-                                               newVal = this._valueMax();
-                                               break;
-                                       case $.ui.keyCode.PAGE_UP:
-                                               newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
-                                               break;
-                                       case $.ui.keyCode.PAGE_DOWN:
-                                               newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
-                                               break;
-                                       case $.ui.keyCode.UP:
-                                       case $.ui.keyCode.RIGHT:
-                                               if ( curVal === this._valueMax() ) {
-                                                       return;
-                                               }
-                                               newVal = this._trimAlignValue( curVal + step );
-                                               break;
-                                       case $.ui.keyCode.DOWN:
-                                       case $.ui.keyCode.LEFT:
-                                               if ( curVal === this._valueMin() ) {
-                                                       return;
-                                               }
-                                               newVal = this._trimAlignValue( curVal - step );
-                                               break;
-                               }
-
-                               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._on( this.handles, this._handleEvents );
 
                this._refreshValue();
 
@@ -640,6 +565,83 @@ $.widget( "ui.slider", $.ui.mouse, {
                                this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
                        }
                }
+       },
+
+       _handleEvents: {
+               keydown: function( event ) {
+                       /*jshint maxcomplexity:25*/
+                       var allowed, curVal, newVal, step,
+                               index = $( event.target ).data( "ui-slider-handle-index" );
+
+                       switch ( event.keyCode ) {
+                               case $.ui.keyCode.HOME:
+                               case $.ui.keyCode.END:
+                               case $.ui.keyCode.PAGE_UP:
+                               case $.ui.keyCode.PAGE_DOWN:
+                               case $.ui.keyCode.UP:
+                               case $.ui.keyCode.RIGHT:
+                               case $.ui.keyCode.DOWN:
+                               case $.ui.keyCode.LEFT:
+                                       event.preventDefault();
+                                       if ( !this._keySliding ) {
+                                               this._keySliding = true;
+                                               $( event.target ).addClass( "ui-state-active" );
+                                               allowed = this._start( event, index );
+                                               if ( allowed === false ) {
+                                                       return;
+                                               }
+                                       }
+                                       break;
+                       }
+
+                       step = this.options.step;
+                       if ( this.options.values && this.options.values.length ) {
+                               curVal = newVal = this.values( index );
+                       } else {
+                               curVal = newVal = this.value();
+                       }
+
+                       switch ( event.keyCode ) {
+                               case $.ui.keyCode.HOME:
+                                       newVal = this._valueMin();
+                                       break;
+                               case $.ui.keyCode.END:
+                                       newVal = this._valueMax();
+                                       break;
+                               case $.ui.keyCode.PAGE_UP:
+                                       newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
+                                       break;
+                               case $.ui.keyCode.PAGE_DOWN:
+                                       newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
+                                       break;
+                               case $.ui.keyCode.UP:
+                               case $.ui.keyCode.RIGHT:
+                                       if ( curVal === this._valueMax() ) {
+                                               return;
+                                       }
+                                       newVal = this._trimAlignValue( curVal + step );
+                                       break;
+                               case $.ui.keyCode.DOWN:
+                               case $.ui.keyCode.LEFT:
+                                       if ( curVal === this._valueMin() ) {
+                                               return;
+                                       }
+                                       newVal = this._trimAlignValue( curVal - step );
+                                       break;
+                       }
+
+                       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" );
+                       }
+               }
        }
 
 });