Skip to content

Commit 2d1b9b3

Browse files
committed
Widget delegation: First draft
1 parent 0e9f87f commit 2d1b9b3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ui/jquery.ui.widget.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ $.Widget.prototype = {
301301
element = $( element );
302302
this.bindings = this.bindings.add( element );
303303
}
304+
304305
var instance = this;
305306
$.each( handlers, function( event, handler ) {
306-
element.bind( event + "." + instance.widgetName, function() {
307+
function handlerProxy() {
307308
// allow widgets to customize the disabled handling
308309
// - disabled as an array instead of boolean
309310
// - disabled class as method for disabling individual parts
@@ -313,7 +314,15 @@ $.Widget.prototype = {
313314
}
314315
return ( typeof handler === "string" ? instance[ handler ] : handler )
315316
.apply( instance, arguments );
316-
});
317+
}
318+
var match = key.match( /^(\w+)\s*(.*)$/ );
319+
var eventName = match[1] + "." + instance.widgetName,
320+
selector = match[2];
321+
if (selector === '') {
322+
element.bind( eventName, handlerProxy );
323+
} else {
324+
element.delegate( selector, eventName, handlerProxy );
325+
}
317326
});
318327
},
319328

0 commit comments

Comments
 (0)