From cb748b4a6f32aa5748d6777e7871c96f70ad2207 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Samuel=20Bov=C3=A9e?= Date: Fri, 16 Nov 2012 12:47:22 +0100 Subject: [PATCH] Slider: factorize code with Widget method call. Fixed #8772 - Wrong slider UI state when disabled at init --- tests/unit/slider/slider_methods.js | 8 ++++---- ui/jquery.ui.slider.js | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/unit/slider/slider_methods.js b/tests/unit/slider/slider_methods.js index 11d679845..83e78b855 100644 --- a/tests/unit/slider/slider_methods.js +++ b/tests/unit/slider/slider_methods.js @@ -41,10 +41,10 @@ test("enable", function() { equal(actual, expected, 'enable is chainable'); el = $('
').slider({ disabled: true }); - ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class before enable method call'); + ok(el.hasClass('ui-state-disabled'), 'slider has ui-state-disabled class before enable method call'); ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class before enable method call'); el.slider('enable'); - ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class after enable method call'); + ok(!el.hasClass('ui-state-disabled'), 'slider does not have ui-state-disabled class after enable method call'); ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class after enable method call'); }); @@ -56,10 +56,10 @@ test("disable", function() { equal(actual, expected, 'disable is chainable'); el = $('
').slider({ disabled: false }); - ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class before disabled method call'); + ok(!el.hasClass('ui-state-disabled'), 'slider does not have ui-state-disabled class before disabled method call'); ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class before disable method call'); el.slider('disable'); - ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class after disable method call'); + ok(el.hasClass('ui-state-disabled'), 'slider has ui-state-disabled class after disable method call'); ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class after disable method call'); }); diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index 90de25316..d9fc1b132 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -54,8 +54,7 @@ $.widget( "ui.slider", $.ui.mouse, { " ui-slider-" + this.orientation + " ui-widget" + " ui-widget-content" + - " ui-corner-all" + - ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) ); + " ui-corner-all"); this.range = $([]); @@ -116,6 +115,8 @@ $.widget( "ui.slider", $.ui.mouse, { $( this ).data( "ui-slider-handle-index", i ); }); + this._setOption( "disabled", o.disabled ); + this._on( this.handles, { keydown: function( event ) { var allowed, curVal, newVal, step, @@ -205,7 +206,6 @@ $.widget( "ui.slider", $.ui.mouse, { .removeClass( "ui-slider" + " ui-slider-horizontal" + " ui-slider-vertical" + - " ui-slider-disabled" + " ui-widget" + " ui-widget-content" + " ui-corner-all" ); @@ -480,10 +480,8 @@ $.widget( "ui.slider", $.ui.mouse, { this.handles.filter( ".ui-state-focus" ).blur(); this.handles.removeClass( "ui-state-hover" ); this.handles.prop( "disabled", true ); - this.element.addClass( "ui-disabled" ); } else { this.handles.prop( "disabled", false ); - this.element.removeClass( "ui-disabled" ); } break; case "orientation": -- 2.39.5