Slider: Remove range div when changing range option to false. Fixes #9355 - Slider: Changing range option to false does not remove range div.

This commit is contained in:
Scott González 2013-06-03 15:14:08 -04:00
parent 3ec371bca4
commit 2ba75e2c93
2 changed files with 23 additions and 3 deletions

View File

@ -200,7 +200,7 @@ test( "values", function() {
}); });
test( "range", function() { test( "range", function() {
expect( 27 ); expect( 33 );
var range; var range;
// min // min
@ -300,6 +300,21 @@ test( "range", function() {
equal( element.slider( "option", "values" ), null, "values" ); equal( element.slider( "option", "values" ), null, "values" );
deepEqual( element.slider( "values" ), [] , "values" ); deepEqual( element.slider( "values" ), [] , "values" );
element.slider( "destroy" ); element.slider( "destroy" );
// Change range from true to false
element = $( "<div></div>" ).slider({
range: true,
min: 1,
max: 10,
step: 1
}).slider( "option", "range", false );
equal( element.find( ".ui-slider-handle" ).length, 2, "range switch from true to false, both handles remain" );
equal( element.find( ".ui-slider-range" ).length, 0, "range switch from true to false" );
equal( element.slider( "option", "value" ), 0 , "option value" );
equal( element.slider( "value" ), 1 , "value" );
deepEqual( element.slider( "option", "values" ), [1, 1], "option values" );
deepEqual( element.slider( "values" ), [1, 1], "values" );
element.slider( "destroy" );
}); });
})( jQuery ); })( jQuery );

View File

@ -131,7 +131,10 @@ $.widget( "ui.slider", $.ui.mouse, {
this.range.addClass( classes + this.range.addClass( classes +
( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) ); ( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) );
} else { } else {
this.range = $([]); if ( this.range ) {
this.range.remove();
}
this.range = null;
} }
}, },
@ -145,7 +148,9 @@ $.widget( "ui.slider", $.ui.mouse, {
_destroy: function() { _destroy: function() {
this.handles.remove(); this.handles.remove();
this.range.remove(); if ( this.range ) {
this.range.remove();
}
this.element this.element
.removeClass( "ui-slider" + .removeClass( "ui-slider" +