diff options
author | Dominic Barnes <dominic@dbarnes.info> | 2012-12-06 16:11:23 -0600 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-12-18 11:48:10 -0500 |
commit | 209443d716587d896ffcdf26c0fd8c8a23437b3c (patch) | |
tree | cd763397039fadf9cd8b9a8c90b65724967ec298 | |
parent | 9cbd4b42221389277cf90a6662f17c500d1a77df (diff) | |
download | jquery-ui-209443d716587d896ffcdf26c0fd8c8a23437b3c.tar.gz jquery-ui-209443d716587d896ffcdf26c0fd8c8a23437b3c.zip |
Slider: Create clone of options.values during _create(). Fixed #8892 - Multiple Sliders have Conflict with options.values.
-rw-r--r-- | tests/unit/slider/slider_options.js | 31 | ||||
-rw-r--r-- | ui/jquery.ui.slider.js | 5 |
2 files changed, 31 insertions, 5 deletions
diff --git a/tests/unit/slider/slider_options.js b/tests/unit/slider/slider_options.js index 96d0d45d0..e34352eb0 100644 --- a/tests/unit/slider/slider_options.js +++ b/tests/unit/slider/slider_options.js @@ -143,8 +143,33 @@ test("step", function() { // ok(false, "missing test - untested code is broken code."); //}); -//test("values", function() { -// ok(false, "missing test - untested code is broken code."); -//}); +test("values", function() { + expect( 2 ); + + // testing multiple ranges on the same page, the object reference to the values + // property is preserved via multiple range elements, so updating options.values + // of 1 slider updates options.values of all the others + var ranges = $([ + document.createElement("div"), + document.createElement("div") + ]).slider({ + range: true, + values: [ 25, 75 ] + }); + + notStrictEqual( + ranges.eq(0).data("uiSlider").options.values, + ranges.eq(1).data("uiSlider").options.values, + "multiple range sliders should not have a reference to the same options.values array" + ); + + ranges.eq(0).slider("values", 0, 10); + + notEqual( + ranges.eq(0).slider("values", 0), + ranges.eq(1).slider("values", 0), + "the values for multiple sliders should be different" + ); +}); })(jQuery); diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index 4054f1848..712c6853d 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -62,9 +62,10 @@ $.widget( "ui.slider", $.ui.mouse, { if ( o.range === true ) { if ( !o.values ) { o.values = [ this._valueMin(), this._valueMin() ]; - } - if ( o.values.length && o.values.length !== 2 ) { + } else if ( o.values.length && o.values.length !== 2 ) { o.values = [ o.values[0], o.values[0] ]; + } else if ( $.isArray( o.values ) ) { + o.values = o.values.slice(0); } } |