From 8d31e4fc860d9cee2e6303d41a0ac9531585de11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Thu, 17 Sep 2015 08:47:08 -0400 Subject: [PATCH 01/11] Widget: Call `._setOptionDisabled()` on init if the widget is disabled Fixes #9151 --- tests/unit/widget/core.js | 33 +++++++++++++++++++++++++++++++++ ui/widget.js | 23 ++++++++++++++++------- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/unit/widget/core.js b/tests/unit/widget/core.js index 6ad1e74fc4b..93bfe875af6 100644 --- a/tests/unit/widget/core.js +++ b/tests/unit/widget/core.js @@ -729,6 +729,39 @@ test( ".disable()", function() { $( "
" ).testWidget().testWidget( "disable" ); } ); +test( "._setOptionDisabled()", function() { + expect( 3 ); + + var method; + var widget; + + $.widget( "ui.testWidget", { + _setOptionDisabled: function( value ) { + method( value ); + } + } ); + + method = function() { + ok( false, "._setOptionDisabled() called on init when not disabled" ); + }; + $( "
" ).testWidget(); + + method = function( value ) { + strictEqual( value, true, "._setOptionDisabled called on init when disabled" ); + }; + widget = $( "
" ).testWidget( { disabled: true } ); + + method = function( value ) { + strictEqual( value, false, "._setOptionDisabled called when enabling" ); + }; + widget.testWidget( "enable" ); + + method = function( value ) { + strictEqual( value, true, "._setOptionDisabled called when disabling" ); + }; + widget.testWidget( "option", "disabled", true ); +} ); + test( ".widget() - base", function() { expect( 2 ); var constructor = $.widget( "ui.testWidget", { diff --git a/ui/widget.js b/ui/widget.js index 2477595796a..1542cc88b5d 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -318,6 +318,11 @@ $.Widget.prototype = { options ); this._create(); + + if ( this.options.disabled ) { + this._setOptionDisabled( this.options.disabled ); + } + this._trigger( "create", null, this._getCreateEventData() ); this._init(); }, @@ -419,13 +424,7 @@ $.Widget.prototype = { this.options[ key ] = value; if ( key === "disabled" ) { - this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value ); - - // If the widget is becoming disabled, then nothing is interactive - if ( value ) { - this._removeClass( this.hoverable, null, "ui-state-hover" ); - this._removeClass( this.focusable, null, "ui-state-focus" ); - } + this._setOptionDisabled( value ); } return this; @@ -462,6 +461,16 @@ $.Widget.prototype = { } }, + _setOptionDisabled: function( value ) { + this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value ); + + // If the widget is becoming disabled, then nothing is interactive + if ( value ) { + this._removeClass( this.hoverable, null, "ui-state-hover" ); + this._removeClass( this.focusable, null, "ui-state-focus" ); + } + }, + enable: function() { return this._setOptions( { disabled: false } ); }, From 89225124563085c58eb31ae6584aaa45fb077a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 12:29:46 +0200 Subject: [PATCH 02/11] Accordion: Handle disabled option on create, through _setOptionDisabled Ref #9151 --- ui/widgets/accordion.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/widgets/accordion.js b/ui/widgets/accordion.js index 78fea52b1fe..360ac170032 100644 --- a/ui/widgets/accordion.js +++ b/ui/widgets/accordion.js @@ -174,17 +174,19 @@ return $.widget( "ui.accordion", { this._createIcons(); } } + }, + + _setOptionDisabled: function( value ) { + this._super( value ); + + this.element.attr( "aria-disabled", value ); // Support: IE8 Only // #5332 / #6059 - opacity doesn't cascade to positioned elements in IE // so we need to add the disabled class to the headers and panels - if ( key === "disabled" ) { - this.element.attr( "aria-disabled", value ); - - this._toggleClass( null, "ui-state-disabled", !!value ); - this._toggleClass( this.headers.add( this.headers.next() ), null, "ui-state-disabled", - !!value ); - } + this._toggleClass( null, "ui-state-disabled", !!value ); + this._toggleClass( this.headers.add( this.headers.next() ), null, "ui-state-disabled", + !!value ); }, _keydown: function( event ) { From a747ab05d814a1238d534896de4665cd07d7786c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 12:39:09 +0200 Subject: [PATCH 03/11] Dialog: Override disabled option on create, force always-enabled state Without this, _on will still respect the disabled option and ends up preventing closing the dialog. Ref #9151 --- ui/widgets/dialog.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index 4380c6f8fa2..6070014c9d5 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -129,6 +129,11 @@ $.widget( "ui.dialog", { this.options.title = this.originalTitle; } + // Dialogs can't be disabled + if ( this.options.disabled ) { + this.options.disabled = false; + } + this._createWrapper(); this.element From 5ede8f4abff2849ce741c123987a22797f499408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 12:42:56 +0200 Subject: [PATCH 04/11] Draggable: Remove redundant handling of disabled class on create _setOptionDisabled in $.Widget is now handling that. Ref #9151 --- ui/widgets/draggable.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/ui/widgets/draggable.js b/ui/widgets/draggable.js index fc340626ea6..f61c38ce0a3 100644 --- a/ui/widgets/draggable.js +++ b/ui/widgets/draggable.js @@ -78,9 +78,6 @@ $.widget( "ui.draggable", $.ui.mouse, { if ( this.options.addClasses ) { this._addClass( "ui-draggable" ); } - if ( this.options.disabled ) { - this._addClass( "ui-draggable-disabled" ); - } this._setHandleClassName(); this._mouseInit(); From 4a59488313b88a062d4cbf88c9b5cfe95a0eb5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 12:49:41 +0200 Subject: [PATCH 05/11] Menu: Remove redundant handling of disabled option on create Ref #9151 --- ui/widgets/menu.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ui/widgets/menu.js b/ui/widgets/menu.js index f7fa2b65193..d42d65bacd1 100644 --- a/ui/widgets/menu.js +++ b/ui/widgets/menu.js @@ -71,11 +71,6 @@ return $.widget( "ui.menu", { tabIndex: 0 } ); - if ( this.options.disabled ) { - this._addClass( null, "ui-state-disabled" ); - this.element.attr( "aria-disabled", "true" ); - } - this._addClass( "ui-menu", "ui-widget ui-widget-content" ); this._on( { @@ -359,13 +354,16 @@ return $.widget( "ui.menu", { this._removeClass( icons, null, this.options.icons.submenu ) ._addClass( icons, null, value.submenu ); } - if ( key === "disabled" ) { - this.element.attr( "aria-disabled", value ); - this._toggleClass( null, "ui-state-disabled", !!value ); - } this._super( key, value ); }, + _setOptionDisabled: function( value ) { + this._super( value ); + + this.element.attr( "aria-disabled", String( value ) ); + this._toggleClass( null, "ui-state-disabled", !!value ); + }, + focus: function( event, item ) { var nested, focused, activeParent; this.blur( event, event && event.type === "focus" ); From 2104241a5158bbe5aad3f4fe7f03ff7997d3b7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 12:55:33 +0200 Subject: [PATCH 06/11] Progressbar: Handle disabled option on create, using _setOptionDisabled Ref #9151 --- ui/widgets/progressbar.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/widgets/progressbar.js b/ui/widgets/progressbar.js index b2c7259ba03..7e2695994af 100644 --- a/ui/widgets/progressbar.js +++ b/ui/widgets/progressbar.js @@ -117,13 +117,16 @@ return $.widget( "ui.progressbar", { // Don't allow a max less than min value = Math.max( this.min, value ); } - if ( key === "disabled" ) { - this.element.attr( "aria-disabled", value ); - this._toggleClass( null, "ui-state-disabled", !!value ); - } this._super( key, value ); }, + _setOptionDisabled: function( value ) { + this._super( value ); + + this.element.attr( "aria-disabled", value ); + this._toggleClass( null, "ui-state-disabled", !!value ); + }, + _percentage: function() { return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min ); }, From 850fe6a3ed5062d691513836cb0cb05e13608f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 13:01:13 +0200 Subject: [PATCH 07/11] Selectmenu: Remove redundant handling of disabled option on create Ref #9151 --- ui/widgets/selectmenu.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/ui/widgets/selectmenu.js b/ui/widgets/selectmenu.js index 820e6857054..30d8c71af63 100644 --- a/ui/widgets/selectmenu.js +++ b/ui/widgets/selectmenu.js @@ -79,10 +79,6 @@ return $.widget( "ui.selectmenu", { this._rendered = false; this.menuItems = $(); - - if ( this.options.disabled ) { - this.disable(); - } }, _drawButton: function() { @@ -562,25 +558,27 @@ return $.widget( "ui.selectmenu", { this.menuWrap.appendTo( this._appendTo() ); } - if ( key === "disabled" ) { - this.menuInstance.option( "disabled", value ); - this.button.attr( "aria-disabled", value ); - this._toggleClass( this.button, null, "ui-state-disabled", value ); - - this.element.prop( "disabled", value ); - if ( value ) { - this.button.attr( "tabindex", -1 ); - this.close(); - } else { - this.button.attr( "tabindex", 0 ); - } - } - if ( key === "width" ) { this._resizeButton(); } }, + _setOptionDisabled: function( value ) { + this._super( value ); + + this.menuInstance.option( "disabled", value ); + this.button.attr( "aria-disabled", value ); + this._toggleClass( this.button, null, "ui-state-disabled", value ); + + this.element.prop( "disabled", value ); + if ( value ) { + this.button.attr( "tabindex", -1 ); + this.close(); + } else { + this.button.attr( "tabindex", 0 ); + } + }, + _appendTo: function() { var element = this.options.appendTo; From ade17bf810ddad39c26b0d19ce333f0c5e4b8403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 13:04:08 +0200 Subject: [PATCH 08/11] Slider: Remove redundant handling of disabled option on create Ref #9151 --- ui/widgets/slider.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/widgets/slider.js b/ui/widgets/slider.js index 5c4f252d596..8b8a7292af7 100644 --- a/ui/widgets/slider.js +++ b/ui/widgets/slider.js @@ -81,7 +81,6 @@ return $.widget( "ui.slider", $.ui.mouse, { "ui-widget ui-widget-content" ); this._refresh(); - this._setOption( "disabled", this.options.disabled ); this._animateOff = false; }, @@ -430,10 +429,6 @@ return $.widget( "ui.slider", $.ui.mouse, { valsLength = this.options.values.length; } - if ( key === "disabled" ) { - this._toggleClass( null, "ui-state-disabled", !!value ); - } - this._super( key, value ); switch ( key ) { @@ -481,6 +476,12 @@ return $.widget( "ui.slider", $.ui.mouse, { } }, + _setOptionDisabled: function( value ) { + this._super( value ); + + this._toggleClass( null, "ui-state-disabled", !!value ); + }, + //internal value getter // _value() returns value trimmed by min and max, aligned by step _value: function() { From 2136be39b1053d249a8116b2c17fec5666a61e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 13:20:09 +0200 Subject: [PATCH 09/11] Spinner: Remove redundant handling of disabled option on create Ref #9151 --- ui/widgets/spinner.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ui/widgets/spinner.js b/ui/widgets/spinner.js index 369e29bd719..f79b2baedf2 100644 --- a/ui/widgets/spinner.js +++ b/ui/widgets/spinner.js @@ -268,11 +268,6 @@ $.widget( "ui.spinner", { this.uiSpinner.height() > 0 ) { this.uiSpinner.height( this.uiSpinner.height() ); } - - // Disable spinner if element was already disabled - if ( this.options.disabled ) { - this.disable(); - } }, _keydown: function( event ) { @@ -427,12 +422,14 @@ $.widget( "ui.spinner", { } this._super( key, value ); + }, - if ( key === "disabled" ) { - this._toggleClass( this.uiSpinner, null, "ui-state-disabled", !!value ); - this.element.prop( "disabled", !!value ); - this.buttons.button( value ? "disable" : "enable" ); - } + _setOptionDisabled: function( value ) { + this._super( value ); + + this._toggleClass( this.uiSpinner, null, "ui-state-disabled", !!value ); + this.element.prop( "disabled", !!value ); + this.buttons.button( value ? "disable" : "enable" ); }, _setOptions: spinnerModifer( function( options ) { From 19c78526f742d58ff394e08aca3631dd0ef26e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 21 Sep 2015 13:37:51 +0200 Subject: [PATCH 10/11] Tooltip: Don't apply disabled style changes on create Ref #9151 --- ui/widgets/tooltip.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/ui/widgets/tooltip.js b/ui/widgets/tooltip.js index 512224050f4..daf783a98a2 100644 --- a/ui/widgets/tooltip.js +++ b/ui/widgets/tooltip.js @@ -105,10 +105,6 @@ $.widget( "ui.tooltip", { // IDs of parent tooltips where we removed the title attribute this.parents = {}; - if ( this.options.disabled ) { - this._disable(); - } - // Append the aria-live region so tooltips announce correctly this.liveRegion = $( "
" ) .attr( { @@ -123,14 +119,6 @@ $.widget( "ui.tooltip", { _setOption: function( key, value ) { var that = this; - if ( key === "disabled" ) { - this[ value ? "_disable" : "_enable" ](); - this.options[ key ] = value; - - // disable element style changes - return; - } - this._super( key, value ); if ( key === "content" ) { @@ -140,6 +128,10 @@ $.widget( "ui.tooltip", { } }, + _setOptionDisabled: function( value ) { + this[ value ? "_disable" : "_enable" ](); + }, + _disable: function() { var that = this; From 80f85e04ac1fe12dcf63a2207f698591d5a1ebf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rn=20Zaefferer?= Date: Tue, 22 Sep 2015 13:14:25 +0200 Subject: [PATCH 11/11] Tabs: Adjust handling of disabled option, using _setOptionDisabled Tabs support multiple values to disable individual tabs. Only add the ui-tabs-disabled class when all tabs are disabled. Ref #9151 --- ui/widgets/tabs.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ui/widgets/tabs.js b/ui/widgets/tabs.js index ff3a64ec8c0..baece431d7a 100644 --- a/ui/widgets/tabs.js +++ b/ui/widgets/tabs.js @@ -291,13 +291,6 @@ $.widget( "ui.tabs", { return; } - if ( key === "disabled" ) { - - // don't use the widget factory's disabled handling - this._setupDisabled( value ); - return; - } - this._super( key, value ); if ( key === "collapsible" ) { @@ -363,7 +356,7 @@ $.widget( "ui.tabs", { }, _refresh: function() { - this._setupDisabled( this.options.disabled ); + this._setOptionDisabled( this.options.disabled ); this._setupEvents( this.options.event ); this._setupHeightStyle( this.options.heightStyle ); @@ -507,7 +500,7 @@ $.widget( "ui.tabs", { .data( "ui-tabs-destroy", true ); }, - _setupDisabled: function( disabled ) { + _setOptionDisabled: function( disabled ) { var currentItem, li, i; if ( $.isArray( disabled ) ) { @@ -531,6 +524,9 @@ $.widget( "ui.tabs", { } this.options.disabled = disabled; + + this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, + disabled === true ); }, _setupEvents: function( event ) { @@ -804,7 +800,7 @@ $.widget( "ui.tabs", { } ); } } - this._setupDisabled( disabled ); + this._setOptionDisabled( disabled ); }, disable: function( index ) { @@ -826,7 +822,7 @@ $.widget( "ui.tabs", { disabled = [ index ]; } } - this._setupDisabled( disabled ); + this._setOptionDisabled( disabled ); }, load: function( index, event ) {