From 8b14b35dc72afce16b544b011a04d1e5ea1b7344 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Sun, 19 Jun 2011 14:59:18 +0200 Subject: [PATCH] Widget delegation: Fix impl and add basisc test --- tests/unit/widget/widget_core.js | 34 ++++++++++++++++++++++++++++++++ ui/jquery.ui.widget.js | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index bb21b74ea..c73f7284c 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.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() { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index cf138f774..0e5695d97 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -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 === '') { -- 2.39.5