Widget delegation: Fix impl and add basisc test

This commit is contained in:
Jörn Zaefferer 2011-06-19 14:59:18 +02:00
parent aa7f8195f8
commit 8b14b35dc7
2 changed files with 35 additions and 1 deletions

View File

@ -666,6 +666,40 @@ test( "._bind() to descendent", function() {
.trigger( "keydown" ); .trigger( "keydown" );
}); });
test( "_bind() with delegate", function() {
expect( 8 );
$.widget( "ui.testWidget", {
_create: function() {
var that = this;
this.element = {
bind: function( event, handler ) {
equal( event, "click.testWidget" );
ok( $.isFunction(handler) );
},
delegate: function( selector, event, handler ) {
equal( selector, "a" );
equal( event, "click.testWidget" );
ok( $.isFunction(handler) );
},
trigger: $.noop
}
this._bind({
"click": "handler",
"click a": "handler",
});
this.element.delegate = function( selector, event, handler ) {
equal( selector, "form fieldset > input" );
equal( event, "change.testWidget" );
ok( $.isFunction(handler) );
};
this._bind({
"change form fieldset > input": "handler"
});
}
});
$.ui.testWidget();
})
test( "._hoverable()", function() { test( "._hoverable()", function() {
$.widget( "ui.testWidget", { $.widget( "ui.testWidget", {
_create: function() { _create: function() {

View File

@ -319,7 +319,7 @@ $.Widget.prototype = {
return ( typeof handler === "string" ? instance[ handler ] : handler ) return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments ); .apply( instance, arguments );
} }
var match = key.match( /^(\w+)\s*(.*)$/ ); var match = event.match( /^(\w+)\s*(.*)$/ );
var eventName = match[1] + "." + instance.widgetName, var eventName = match[1] + "." + instance.widgetName,
selector = match[2]; selector = match[2];
if (selector === '') { if (selector === '') {