Skip to content

Commit

Permalink
Widget: Added suppressDisabledCheck flag to _on(). Fixes #8800 - Widg…
Browse files Browse the repository at this point in the history
…et: Ability to use _on() even when disabled.

(cherry picked from commit 84cd214)
  • Loading branch information
scottgonzalez committed Nov 13, 2012
1 parent db1a622 commit f8c154b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
40 changes: 40 additions & 0 deletions tests/unit/widget/widget_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,46 @@ test( "._on() to element (default)", function() {
.trigger( "keydown" );
});

test( "._on() to element with suppressDisabledCheck", function() {
expect( 18 );
var that, widget;
$.widget( "ui.testWidget", {
_create: function() {
that = this;
this._on( true, {
keyup: this.keyup,
keydown: "keydown"
});
},
keyup: function( event ) {
equal( that, this );
equal( that.element[0], event.currentTarget );
equal( "keyup", event.type );
},
keydown: function( event ) {
equal( that, this );
equal( that.element[0], event.currentTarget );
equal( "keydown", event.type );
}
});
widget = $( "<div></div>" )
.testWidget()
.trigger( "keyup" )
.trigger( "keydown" );
widget
.testWidget( "disable" )
.trigger( "keyup" )
.trigger( "keydown" );
widget
.testWidget( "enable" )
.trigger( "keyup" )
.trigger( "keydown" );
widget
.testWidget( "destroy" )
.trigger( "keyup" )
.trigger( "keydown" );
});

test( "._on() to descendent", function() {
expect( 12 );
var that, widget, descendant;
Expand Down
15 changes: 12 additions & 3 deletions ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,17 @@ $.Widget.prototype = {
return this._setOption( "disabled", true );
},

_on: function( element, handlers ) {
_on: function( suppressDisabledCheck, element, handlers ) {
var delegateElement,
instance = this;

// no suppressDisabledCheck flag, shuffle arguments
if ( typeof suppressDisabledCheck !== "boolean" ) {
handlers = element;
element = suppressDisabledCheck;
suppressDisabledCheck = false;
}

// no element argument, shuffle and use this.element
if ( !handlers ) {
handlers = element;
Expand All @@ -380,8 +388,9 @@ $.Widget.prototype = {
// allow widgets to customize the disabled handling
// - disabled as an array instead of boolean
// - disabled class as method for disabling individual parts
if ( instance.options.disabled === true ||
$( this ).hasClass( "ui-state-disabled" ) ) {
if ( !suppressDisabledCheck &&
( instance.options.disabled === true ||
$( this ).hasClass( "ui-state-disabled" ) ) ) {
return;
}
return ( typeof handler === "string" ? instance[ handler ] : handler )
Expand Down

0 comments on commit f8c154b

Please sign in to comment.