diff options
author | Alexander Schmitz <arschmitz@gmail.com> | 2015-08-24 08:58:09 -0400 |
---|---|---|
committer | Alexander Schmitz <arschmitz@gmail.com> | 2015-09-11 08:29:08 -0400 |
commit | e583a512d7cc66a2b3d0915db1b0164b9a0a710e (patch) | |
tree | d82792cc3b9e739114eed02f1552a3252748f59f /ui | |
parent | 62c8217185bdf6b043d76d0e2498c22a043aab2c (diff) | |
download | jquery-ui-e583a512d7cc66a2b3d0915db1b0164b9a0a710e.tar.gz jquery-ui-e583a512d7cc66a2b3d0915db1b0164b9a0a710e.zip |
Slider: Style updates
Ref #14246
Diffstat (limited to 'ui')
-rw-r--r-- | ui/widgets/slider.js | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/ui/widgets/slider.js b/ui/widgets/slider.js index 792fa4da2..5c4f252d5 100644 --- a/ui/widgets/slider.js +++ b/ui/widgets/slider.js @@ -16,11 +16,11 @@ //>>css.structure: ../themes/base/slider.css //>>css.theme: ../themes/base/theme.css -(function( factory ) { +( function( factory ) { if ( typeof define === "function" && define.amd ) { // AMD. Register as an anonymous module. - define([ + define( [ "jquery", "./mouse", "../keycode", @@ -32,7 +32,7 @@ // Browser globals factory( jQuery ); } -}(function( $ ) { +}( function( $ ) { return $.widget( "ui.slider", $.ui.mouse, { version: "@VERSION", @@ -117,9 +117,9 @@ return $.widget( "ui.slider", $.ui.mouse, { this.handle = this.handles.eq( 0 ); - this.handles.each(function( i ) { + this.handles.each( function( i ) { $( this ).data( "ui-slider-handle-index", i ); - }); + } ); }, _createRange: function() { @@ -130,9 +130,9 @@ return $.widget( "ui.slider", $.ui.mouse, { if ( !options.values ) { options.values = [ this._valueMin(), this._valueMin() ]; } else if ( options.values.length && options.values.length !== 2 ) { - options.values = [ options.values[0], options.values[0] ]; + options.values = [ options.values[ 0 ], options.values[ 0 ] ]; } else if ( $.isArray( options.values ) ) { - options.values = options.values.slice(0); + options.values = options.values.slice( 0 ); } } @@ -145,10 +145,10 @@ return $.widget( "ui.slider", $.ui.mouse, { this._removeClass( this.range, "ui-slider-range-min ui-slider-range-max" ); // Handle range switching from true to min/max - this.range.css({ + this.range.css( { "left": "", "bottom": "" - }); + } ); } if ( options.range === "min" || options.range === "max" ) { this._addClass( this.range, "ui-slider-range-" + options.range ); @@ -195,16 +195,16 @@ return $.widget( "ui.slider", $.ui.mouse, { position = { x: event.pageX, y: event.pageY }; normValue = this._normValueFromMouse( position ); distance = this._valueMax() - this._valueMin() + 1; - this.handles.each(function( i ) { - var thisDistance = Math.abs( normValue - that.values(i) ); - if (( distance > thisDistance ) || + this.handles.each( function( i ) { + var thisDistance = Math.abs( normValue - that.values( i ) ); + if ( ( distance > thisDistance ) || ( distance === thisDistance && - (i === that._lastChangedValue || that.values(i) === o.min ))) { + ( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) { distance = thisDistance; closestHandle = $( this ); index = i; } - }); + } ); allowed = this._start( event, index ); if ( allowed === false ) { @@ -223,9 +223,9 @@ return $.widget( "ui.slider", $.ui.mouse, { left: event.pageX - offset.left - ( closestHandle.width() / 2 ), top: event.pageY - offset.top - ( closestHandle.height() / 2 ) - - ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) - - ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) + - ( parseInt( closestHandle.css("marginTop"), 10 ) || 0) + ( parseInt( closestHandle.css( "borderTopWidth" ), 10 ) || 0 ) - + ( parseInt( closestHandle.css( "borderBottomWidth" ), 10 ) || 0 ) + + ( parseInt( closestHandle.css( "marginTop" ), 10 ) || 0 ) }; if ( !this.handles.hasClass( "ui-state-hover" ) ) { @@ -361,6 +361,7 @@ return $.widget( "ui.slider", $.ui.mouse, { _change: function( event, index ) { if ( !this._keySliding && !this._mouseSliding ) { + //store the last changed value index for reference when handles overlap this._lastChangedValue = index; this._trigger( "change", event, this._uiHash( index ) ); @@ -503,10 +504,11 @@ return $.widget( "ui.slider", $.ui.mouse, { return val; } else if ( this._hasMultipleValues() ) { + // .slice() creates a copy of the array // this copy gets trimmed by min and max and then returned vals = this.options.values.slice(); - for ( i = 0; i < vals.length; i += 1) { + for ( i = 0; i < vals.length; i += 1 ) { vals[ i ] = this._trimAlignValue( vals[ i ] ); } @@ -525,16 +527,16 @@ return $.widget( "ui.slider", $.ui.mouse, { return this._valueMax(); } var step = ( this.options.step > 0 ) ? this.options.step : 1, - valModStep = (val - this._valueMin()) % step, + valModStep = ( val - this._valueMin() ) % step, alignValue = val - valModStep; - if ( Math.abs(valModStep) * 2 >= step ) { + if ( Math.abs( valModStep ) * 2 >= step ) { alignValue += ( valModStep > 0 ) ? step : ( -step ); } // Since JavaScript has problems with large floats, round // the final value to 5 digits after the decimal point (see #4124) - return parseFloat( alignValue.toFixed(5) ); + return parseFloat( alignValue.toFixed( 5 ) ); }, _calculateNewMax: function() { @@ -568,7 +570,7 @@ return $.widget( "ui.slider", $.ui.mouse, { return this.max; }, - _refreshRange: function ( orientation ) { + _refreshRange: function( orientation ) { if ( orientation === "vertical" ) { this.range.css( { "width": "", "left": "" } ); } @@ -586,8 +588,8 @@ return $.widget( "ui.slider", $.ui.mouse, { _set = {}; if ( this._hasMultipleValues() ) { - this.handles.each(function( i ) { - valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; + this.handles.each( function( i ) { + 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 ( that.options.range === true ) { @@ -608,7 +610,7 @@ return $.widget( "ui.slider", $.ui.mouse, { } } lastValPercent = valPercent; - }); + } ); } else { value = this.value(); valueMin = this._valueMin(); @@ -681,7 +683,7 @@ return $.widget( "ui.slider", $.ui.mouse, { break; case $.ui.keyCode.PAGE_DOWN: newVal = this._trimAlignValue( - curVal - ( (this._valueMax() - this._valueMin()) / this.numPages ) ); + curVal - ( ( this._valueMax() - this._valueMin() ) / this.numPages ) ); break; case $.ui.keyCode.UP: case $.ui.keyCode.RIGHT: @@ -712,6 +714,6 @@ return $.widget( "ui.slider", $.ui.mouse, { } } } -}); +} ); -})); +} ) ); |