Skip to content

Commit 897a238

Browse files
atomiomiscottgonzalez
authored andcommitted
Slider: Range fills all space after changing orientation
Resets width/height of range Fixes #12205 Closes jquerygh-1533
1 parent ec952e2 commit 897a238

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

tests/unit/slider/options.js

+39-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ test( "min", function() {
109109
});
110110

111111
test( "orientation", function( assert ) {
112-
expect( 8 );
112+
expect( 14 );
113113
element = $( "#slider1" );
114114

115115
options = {
@@ -119,7 +119,8 @@ test( "orientation", function( assert ) {
119119
value: 1
120120
};
121121

122-
var percentVal = ( options.value - options.min ) / ( options.max - options.min ) * 100;
122+
var newValue, rangeSize,
123+
percentVal = ( options.value - options.min ) / ( options.max - options.min ) * 100;
123124

124125
element.slider( options ).slider( "option", "orientation", "horizontal" );
125126
assert.hasClasses( element, "ui-slider-horizontal" );
@@ -146,6 +147,42 @@ test( "orientation", function( assert ) {
146147

147148
element.slider( "destroy" );
148149

150+
newValue = 7;
151+
rangeSize = 500 - (500 * newValue / 10);
152+
element = $( "#slider2" ).slider({
153+
range: "max",
154+
min: 0,
155+
max: 10
156+
});
157+
158+
element.slider( "option", "value", newValue );
159+
element.slider( "option", "orientation", "vertical" );
160+
equal( element.find( ".ui-slider-range" ).width(), 12,
161+
"range should occupy all horizontal space after changing orientation to vertical" );
162+
equal( element.find( ".ui-slider-range" ).height(), rangeSize,
163+
"range height of vertical slider should be proportional to the value" );
164+
165+
element.slider( "option", "orientation", "horizontal" );
166+
equal( element.find( ".ui-slider-range " ).height(), 12,
167+
"range should occupy all vertical space after changing orientation to horizontal" );
168+
equal( element.find( ".ui-slider-range" ).width(), rangeSize,
169+
"range width of horizontal slider should be proportional to the value" );
170+
171+
element.slider( "destroy" );
172+
173+
element = $( "#slider2" ).slider({
174+
range: true,
175+
min: 0,
176+
max: 100
177+
});
178+
element.slider( "option", { values: [ 60, 70 ] } );
179+
notEqual( element.find( ".ui-slider-range " ).position().left, 0,
180+
"range should not pull over to the track's border" );
181+
element.slider( "option", "orientation", "vertical" );
182+
equal( element.find( ".ui-slider-range " ).position().left, 0,
183+
"range should pull over to the track's border" );
184+
185+
element.slider( "destroy" );
149186
});
150187

151188
//spec: http://wiki.jqueryui.com/Slider#specs

tests/unit/slider/slider.html

+11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@
77
<script src="../../../external/requirejs/require.js"></script>
88
<script src="../../lib/css.js" data-modules="core slider"></script>
99
<script src="../../lib/bootstrap.js" data-widget="slider"></script>
10+
<style>
11+
#slider2.ui-slider-horizontal {
12+
height: 12px;
13+
width: 500px;
14+
}
15+
#slider2.ui-slider-vertical {
16+
width: 12px;
17+
height: 500px;
18+
}
19+
</style>
1020
</head>
1121
<body>
1222

1323
<div id="qunit"></div>
1424
<div id="qunit-fixture">
1525

1626
<div id="slider1"></div>
27+
<div id="slider2"></div>
1728
<div id="slider3" style="position: relative; margin: 40px; width: 217px; height: 28px;">
1829
<div class="ui-slider-handle" style="position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px;"></div>
1930
</div>

ui/slider.js

+12
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
440440
this._removeClass( "ui-slider-horizontal ui-slider-vertical" )
441441
._addClass( "ui-slider-" + this.orientation );
442442
this._refreshValue();
443+
if ( this.options.range ) {
444+
this._refreshRange( value );
445+
}
443446

444447
// Reset positioning from previous orientation
445448
this.handles.css( value === "horizontal" ? "bottom" : "left", "" );
@@ -564,6 +567,15 @@ return $.widget( "ui.slider", $.ui.mouse, {
564567
return this.max;
565568
},
566569

570+
_refreshRange: function ( orientation ) {
571+
if ( orientation === "vertical" ) {
572+
this.range.css( { "width": "", "left": "" } );
573+
}
574+
if ( orientation === "horizontal" ) {
575+
this.range.css( { "height": "", "bottom": "" } );
576+
}
577+
},
578+
567579
_refreshValue: function() {
568580
var lastValPercent, valPercent, value, valueMin, valueMax,
569581
oRange = this.options.range,

0 commit comments

Comments
 (0)