Skip to content

Deal with disable option on create #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions ui/widgets/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
5 changes: 5 additions & 0 deletions ui/widgets/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions ui/widgets/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 7 additions & 9 deletions ui/widgets/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {

Expand Down Expand Up @@ -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" );
Expand Down
11 changes: 7 additions & 4 deletions ui/widgets/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
},
Expand Down
34 changes: 16 additions & 18 deletions ui/widgets/selectmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ return $.widget( "ui.selectmenu", {

this._rendered = false;
this.menuItems = $();

if ( this.options.disabled ) {
this.disable();
}
},

_drawButton: function() {
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 6 additions & 5 deletions ui/widgets/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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() {
Expand Down
17 changes: 7 additions & 10 deletions ui/widgets/spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down
18 changes: 7 additions & 11 deletions ui/widgets/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) {
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 ) ) {
Expand All @@ -531,6 +524,9 @@ $.widget( "ui.tabs", {
}

this.options.disabled = disabled;

this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null,
disabled === true );
},

_setupEvents: function( event ) {
Expand Down Expand Up @@ -804,7 +800,7 @@ $.widget( "ui.tabs", {
} );
}
}
this._setupDisabled( disabled );
this._setOptionDisabled( disabled );
},

disable: function( index ) {
Expand All @@ -826,7 +822,7 @@ $.widget( "ui.tabs", {
disabled = [ index ];
}
}
this._setupDisabled( disabled );
this._setOptionDisabled( disabled );
},

load: function( index, event ) {
Expand Down
16 changes: 4 additions & 12 deletions ui/widgets/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $( "<div>" )
.attr( {
Expand All @@ -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" ) {
Expand All @@ -140,6 +128,10 @@ $.widget( "ui.tooltip", {
}
},

_setOptionDisabled: function( value ) {
this[ value ? "_disable" : "_enable" ]();
},

_disable: function() {
var that = this;

Expand Down