diff options
-rw-r--r-- | tests/unit/widget/widget_core.js | 20 | ||||
-rw-r--r-- | ui/jquery.ui.widget.js | 13 |
2 files changed, 21 insertions, 12 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 40fd97ba5..bb21b74ea 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -89,7 +89,7 @@ test( "jQuery usage", function() { "parameter passed via .pluginName(methodName, param)" ); equals( param2, "value2", "multiple parameters passed via .pluginName(methodName, param, param)" ); - + return this; }, getterSetterMethod: function( val ) { @@ -153,9 +153,9 @@ test( "direct usage", function() { } } }); - + var elem = $( "<div>" )[ 0 ]; - + shouldCreate = true; var instance = new $.ui.testWidget( {}, elem ); shouldCreate = false; @@ -163,7 +163,7 @@ test( "direct usage", function() { equals( $( elem ).data( "testWidget" ), instance, "instance stored in .data(pluginName)" ); equals( instance.element[ 0 ], elem, "element stored on widget" ); - + var ret = instance.methodWithParams( "value1", "value2" ); equals( ret, instance, "plugin returned from method call" ); @@ -193,7 +193,7 @@ test( "error handling", function() { equal( msg, "no such method '_privateMethod' for testWidget widget instance", "invalid method call on widget instance" ); }; - $( "<div>" ).testWidget().testWidget( "_privateMethod" ); + $( "<div>" ).testWidget().testWidget( "_privateMethod" ); $.error = error; }); @@ -463,7 +463,7 @@ test( ".option() - delegate to ._setOptions()", function() { calls = []; div.testWidget( "option", "foo", "bar" ); same( calls, [{ foo: "bar" }], "_setOptions called for single option" ); - + calls = []; div.testWidget( "option", { bar: "qux", @@ -490,7 +490,7 @@ test( ".option() - delegate to ._setOption()", function() { div.testWidget( "option", "foo", "bar" ); same( calls, [{ key: "foo", val: "bar" }], "_setOption called for single option" ); - + calls = []; div.testWidget( "option", { bar: "qux", @@ -703,14 +703,14 @@ test( "._focusable()", function() { this._focusable( this.element.children() ); } }); - + var div = $( "#widget" ).testWidget().children(); ok( !div.hasClass( "ui-state-focus" ), "not focused on init" ); div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); div.trigger( "focusout" ); ok( !div.hasClass( "ui-state-focus" ), "not focused after blur" ); - + div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); $( "#widget" ).testWidget( "disable" ); @@ -719,7 +719,7 @@ test( "._focusable()", function() { ok( !div.hasClass( "ui-state-focus" ), "can't focus while disabled" ); $( "#widget" ).testWidget( "enable" ); ok( !div.hasClass( "ui-state-focus" ), "enabling doesn't reset focus" ); - + div.trigger( "focusin" ); ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); $( "#widget" ).testWidget( "destroy" ); diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 59d110b6a..cf138f774 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -305,9 +305,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 @@ -317,7 +318,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 ); + } }); }, |