From 8fba171fec64cae094566c6777e40c252ecef812 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Mon, 3 Jun 2013 15:14:08 -0400 Subject: [PATCH] Slider: Remove range div when changing range option to false. Fixes #9355 - Slider: Changing range option to false does not remove range div. (cherry picked from commit 2ba75e2c93638d89e89de52347da0013a7a841b8) --- tests/unit/slider/slider_options.js | 17 ++++++++++++++++- ui/jquery.ui.slider.js | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/unit/slider/slider_options.js b/tests/unit/slider/slider_options.js index f46dbde99..d4403d1af 100644 --- a/tests/unit/slider/slider_options.js +++ b/tests/unit/slider/slider_options.js @@ -200,7 +200,7 @@ test( "values", function() { }); test( "range", function() { - expect( 27 ); + expect( 33 ); var range; // min @@ -300,6 +300,21 @@ test( "range", function() { equal( element.slider( "option", "values" ), null, "values" ); deepEqual( element.slider( "values" ), [] , "values" ); element.slider( "destroy" ); + + // Change range from true to false + element = $( "
" ).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 ); diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index 9338559b4..7d4fb36d1 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -131,7 +131,10 @@ $.widget( "ui.slider", $.ui.mouse, { this.range.addClass( classes + ( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) ); } else { - this.range = $([]); + if ( this.range ) { + this.range.remove(); + } + this.range = null; } }, @@ -145,7 +148,9 @@ $.widget( "ui.slider", $.ui.mouse, { _destroy: function() { this.handles.remove(); - this.range.remove(); + if ( this.range ) { + this.range.remove(); + } this.element .removeClass( "ui-slider" + -- 2.39.5