Skip to content

Commit 8b14b35

Browse files
committed
Widget delegation: Fix impl and add basisc test
1 parent aa7f819 commit 8b14b35

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

tests/unit/widget/widget_core.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,40 @@ test( "._bind() to descendent", function() {
666666
.trigger( "keydown" );
667667
});
668668

669+
test( "_bind() with delegate", function() {
670+
expect( 8 );
671+
$.widget( "ui.testWidget", {
672+
_create: function() {
673+
var that = this;
674+
this.element = {
675+
bind: function( event, handler ) {
676+
equal( event, "click.testWidget" );
677+
ok( $.isFunction(handler) );
678+
},
679+
delegate: function( selector, event, handler ) {
680+
equal( selector, "a" );
681+
equal( event, "click.testWidget" );
682+
ok( $.isFunction(handler) );
683+
},
684+
trigger: $.noop
685+
}
686+
this._bind({
687+
"click": "handler",
688+
"click a": "handler",
689+
});
690+
this.element.delegate = function( selector, event, handler ) {
691+
equal( selector, "form fieldset > input" );
692+
equal( event, "change.testWidget" );
693+
ok( $.isFunction(handler) );
694+
};
695+
this._bind({
696+
"change form fieldset > input": "handler"
697+
});
698+
}
699+
});
700+
$.ui.testWidget();
701+
})
702+
669703
test( "._hoverable()", function() {
670704
$.widget( "ui.testWidget", {
671705
_create: function() {

ui/jquery.ui.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ $.Widget.prototype = {
319319
return ( typeof handler === "string" ? instance[ handler ] : handler )
320320
.apply( instance, arguments );
321321
}
322-
var match = key.match( /^(\w+)\s*(.*)$/ );
322+
var match = event.match( /^(\w+)\s*(.*)$/ );
323323
var eventName = match[1] + "." + instance.widgetName,
324324
selector = match[2];
325325
if (selector === '') {

0 commit comments

Comments
 (0)