Skip to content
Permalink
Browse files

Widget delegation: Fix impl and add basisc test

  • Loading branch information
jzaefferer committed Jun 19, 2011
1 parent aa7f819 commit 8b14b35dc72afce16b544b011a04d1e5ea1b7344
Showing with 35 additions and 1 deletion.
  1. +34 −0 tests/unit/widget/widget_core.js
  2. +1 −1 ui/jquery.ui.widget.js
@@ -666,6 +666,40 @@ test( "._bind() to descendent", function() {
.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() {
$.widget( "ui.testWidget", {
_create: function() {
@@ -319,7 +319,7 @@ $.Widget.prototype = {
return ( typeof handler === "string" ? instance[ handler ] : handler )
.apply( instance, arguments );
}
var match = key.match( /^(\w+)\s*(.*)$/ );
var match = event.match( /^(\w+)\s*(.*)$/ );
var eventName = match[1] + "." + instance.widgetName,
selector = match[2];
if (selector === '') {

0 comments on commit 8b14b35

Please sign in to comment.
You can’t perform that action at this time.