Skip to content

Commit

Permalink
Widget: modified _trigger to invoke callbacks with apply so that hand…
Browse files Browse the repository at this point in the history
…lers are invoked the same way bind invokes them. #6795 - Widget: _trigger passes array arguments to handlers inconsistently
  • Loading branch information
Michael DellaNoce committed Dec 30, 2010
1 parent 74ddb30 commit ca8585e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
49 changes: 49 additions & 0 deletions tests/unit/widget/widget_tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,53 @@ test( "#5830 - Widget: Using inheritance overwrites the base classes options", f
delete $.ui.testWidgetExtension;
});

test( "#6795 - Widget: handle array arguments to _trigger consistently", function() {
expect( 4 );

var originalEvent = $.Event( "originalTest" );
$.widget( "ui.testWidget", {
_create: function() {},
testEvent: function() {
var ui = {
foo: "bar",
baz: {
qux: 5,
quux: 20
}
};
var extra = {
bar: 5
};
this._trigger( "foo", originalEvent, [ui, extra] );
}
});
$( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) {
same( ui, {
foo: "bar",
baz: {
qux: 5,
quux: 20
}
}, "ui hash passed" );
same( extra, {
bar: 5
}, "extra argument passed" );
});
$( "#widget" ).testWidget({
foo: function( event, ui, extra ) {
same( ui, {
foo: "bar",
baz: {
qux: 5,
quux: 20
}
}, "ui hash passed" );
same( extra, {
bar: 5
}, "extra argument passed" );
}
})
.testWidget( "testEvent" );
});

})( jQuery );
8 changes: 6 additions & 2 deletions ui/jquery.ui.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ $.Widget.prototype = {
},

_trigger: function( type, event, data ) {
var callback = this.options[ type ];
var args, callback = this.options[ type ];

event = $.Event( event );
event.type = ( type === this.widgetEventPrefix ?
Expand All @@ -247,8 +247,12 @@ $.Widget.prototype = {

this.element.trigger( event, data );

args = $.isArray(data) ?
[event].concat(data) :
[event, data];

return !( $.isFunction(callback) &&
callback.call( this.element[0], event, data ) === false ||
callback.apply( this.element[0], args ) === false ||
event.isDefaultPrevented() );
}
};
Expand Down

1 comment on commit ca8585e

@scottgonzalez
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdellanoce Can you please sign our CLA?

Please sign in to comment.