]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget delegation: Fix impl and add basisc test
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Sun, 19 Jun 2011 12:59:18 +0000 (14:59 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sun, 19 Jun 2011 12:59:18 +0000 (14:59 +0200)
tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index bb21b74ea61fcc19d30155aa145a943b992500e7..c73f7284c2f7271b65c17f300bd00adc1a51036e 100644 (file)
@@ -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() {
index cf138f774b2b62071c8a53e5bc4b0aab978c6bb6..0e5695d97258b3f259897e2f6ac0abc5453a8523 100644 (file)
@@ -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 === '') {