Skip to content

Commit

Permalink
button: fixed #5328 - button disabled only visually when disabled opt…
Browse files Browse the repository at this point in the history
…ion set, still functional
  • Loading branch information
rdworth committed Mar 15, 2010
1 parent a0ac772 commit a842215
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ui/jquery.ui.button.js
Expand Up @@ -69,6 +69,10 @@ $.widget( "ui.button", {
options.label = this.buttonElement.html(); options.label = this.buttonElement.html();
} }


if ( this.element.is(":disabled") ) {
options.disabled = true;
}

this.buttonElement this.buttonElement
.addClass( baseClasses ) .addClass( baseClasses )
.attr( "role", "button" ) .attr( "role", "button" )
Expand Down Expand Up @@ -104,15 +108,15 @@ $.widget( "ui.button", {
if ( this.type === "checkbox" ) { if ( this.type === "checkbox" ) {
this.buttonElement.bind( "click.button", function() { this.buttonElement.bind( "click.button", function() {
if ( options.disabled ) { if ( options.disabled ) {
return; return false;
} }
$( this ).toggleClass( "ui-state-active" ); $( this ).toggleClass( "ui-state-active" );
self.buttonElement.attr( "aria-pressed", self.element[0].checked ); self.buttonElement.attr( "aria-pressed", self.element[0].checked );
}); });
} else if ( this.type === "radio" ) { } else if ( this.type === "radio" ) {
this.buttonElement.bind( "click.button", function() { this.buttonElement.bind( "click.button", function() {
if ( options.disabled ) { if ( options.disabled ) {
return; return false;
} }
$( this ).addClass( "ui-state-active" ); $( this ).addClass( "ui-state-active" );
self.buttonElement.attr( "aria-pressed", true ); self.buttonElement.attr( "aria-pressed", true );
Expand All @@ -130,7 +134,7 @@ $.widget( "ui.button", {
this.buttonElement this.buttonElement
.bind( "mousedown.button", function() { .bind( "mousedown.button", function() {
if ( options.disabled ) { if ( options.disabled ) {
return; return false;
} }
$( this ).addClass( "ui-state-active" ); $( this ).addClass( "ui-state-active" );
lastActive = this; lastActive = this;
Expand All @@ -140,13 +144,13 @@ $.widget( "ui.button", {
}) })
.bind( "mouseup.button", function() { .bind( "mouseup.button", function() {
if ( options.disabled ) { if ( options.disabled ) {
return; return false;
} }
$( this ).removeClass( "ui-state-active" ); $( this ).removeClass( "ui-state-active" );
}) })
.bind( "keydown.button", function(event) { .bind( "keydown.button", function(event) {
if ( options.disabled ) { if ( options.disabled ) {
return; return false;
} }
if ( event.keyCode == $.ui.keyCode.SPACE || event.keyCode == $.ui.keyCode.ENTER ) { if ( event.keyCode == $.ui.keyCode.SPACE || event.keyCode == $.ui.keyCode.ENTER ) {
$( this ).addClass( "ui-state-active" ); $( this ).addClass( "ui-state-active" );
Expand Down Expand Up @@ -225,6 +229,9 @@ $.widget( "ui.button", {


_setOption: function( key, value ) { _setOption: function( key, value ) {
$.Widget.prototype._setOption.apply( this, arguments ); $.Widget.prototype._setOption.apply( this, arguments );
if ( key === "disabled" ) {
this.element.attr("disabled", value);
}
this._resetButton(); this._resetButton();
}, },


Expand Down

0 comments on commit a842215

Please sign in to comment.