From 2d1b9b391eadc979fb0988a76055ab5397e8b55f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Wed, 8 Jun 2011 22:14:37 +0200 Subject: [PATCH] Widget delegation: First draft --- ui/jquery.ui.widget.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 00bc07c4f..1c01ef7c9 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -301,9 +301,10 @@ $.Widget.prototype = { element = $( element ); this.bindings = this.bindings.add( element ); } + var instance = this; $.each( handlers, function( event, handler ) { - element.bind( event + "." + instance.widgetName, function() { + function handlerProxy() { // allow widgets to customize the disabled handling // - disabled as an array instead of boolean // - disabled class as method for disabling individual parts @@ -313,7 +314,15 @@ $.Widget.prototype = { } return ( typeof handler === "string" ? instance[ handler ] : handler ) .apply( instance, arguments ); - }); + } + var match = key.match( /^(\w+)\s*(.*)$/ ); + var eventName = match[1] + "." + instance.widgetName, + selector = match[2]; + if (selector === '') { + element.bind( eventName, handlerProxy ); + } else { + element.delegate( selector, eventName, handlerProxy ); + } }); }, -- 2.39.5