mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: Call ._setOptionDisabled()
on init if the widget is disabled
Fixes #9151 Ref gh-1599
This commit is contained in:
parent
0db243a736
commit
7dde5c9d75
@ -729,6 +729,39 @@ test( ".disable()", function() {
|
|||||||
$( "<div>" ).testWidget().testWidget( "disable" );
|
$( "<div>" ).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" );
|
||||||
|
};
|
||||||
|
$( "<div>" ).testWidget();
|
||||||
|
|
||||||
|
method = function( value ) {
|
||||||
|
strictEqual( value, true, "._setOptionDisabled called on init when disabled" );
|
||||||
|
};
|
||||||
|
widget = $( "<div>" ).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() {
|
test( ".widget() - base", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
var constructor = $.widget( "ui.testWidget", {
|
var constructor = $.widget( "ui.testWidget", {
|
||||||
|
23
ui/widget.js
23
ui/widget.js
@ -318,6 +318,11 @@ $.Widget.prototype = {
|
|||||||
options );
|
options );
|
||||||
|
|
||||||
this._create();
|
this._create();
|
||||||
|
|
||||||
|
if ( this.options.disabled ) {
|
||||||
|
this._setOptionDisabled( this.options.disabled );
|
||||||
|
}
|
||||||
|
|
||||||
this._trigger( "create", null, this._getCreateEventData() );
|
this._trigger( "create", null, this._getCreateEventData() );
|
||||||
this._init();
|
this._init();
|
||||||
},
|
},
|
||||||
@ -419,13 +424,7 @@ $.Widget.prototype = {
|
|||||||
this.options[ key ] = value;
|
this.options[ key ] = value;
|
||||||
|
|
||||||
if ( key === "disabled" ) {
|
if ( key === "disabled" ) {
|
||||||
this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
|
this._setOptionDisabled( 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" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
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() {
|
enable: function() {
|
||||||
return this._setOptions( { disabled: false } );
|
return this._setOptions( { disabled: false } );
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user