From 4587f2de68a884bc6d749728bfd6a555efb14b54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Fri, 12 Aug 2011 22:10:31 -0400 Subject: [PATCH] Widget: Use this.widget() for event delegation. --- tests/unit/widget/widget_core.js | 30 +++++++++++++++++++----------- ui/jquery.ui.widget.js | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 8cacdd47d..41ae8ffb4 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -673,23 +673,31 @@ test( "_bind() with delegate", function() { 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) ); + ok( $.isFunction(handler) ); }, trigger: $.noop }; + this.widget = function() { + return { + delegate: function( selector, event, handler ) { + equal( selector, "a" ); + equal( event, "click.testWidget" ); + ok( $.isFunction(handler) ); + } + }; + }; this._bind({ "click": "handler", - "click a": "handler", + "click a": "handler" }); - this.element.delegate = function( selector, event, handler ) { - equal( selector, "form fieldset > input" ); - equal( event, "change.testWidget" ); - ok( $.isFunction(handler) ); + this.widget = function() { + return { + delegate: function( selector, event, handler ) { + equal( selector, "form fieldset > input" ); + equal( event, "change.testWidget" ); + ok( $.isFunction(handler) ); + } + }; }; this._bind({ "change form fieldset > input": "handler" diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 4c538d020..5b7942600 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -326,7 +326,7 @@ $.Widget.prototype = { eventName = match[1] + "." + instance.widgetName, selector = match[2]; if ( selector ) { - element.delegate( selector, eventName, handlerProxy ); + instance.widget().delegate( selector, eventName, handlerProxy ); } else { element.bind( eventName, handlerProxy ); } -- 2.39.5