]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Modified _trigger to invoke callbacks with apply so that handlers are invoked...
authorMichael DellaNoce <mdellanoce@mailtrust.com>
Tue, 1 Feb 2011 11:57:48 +0000 (06:57 -0500)
committerScott González <scott.gonzalez@gmail.com>
Tue, 1 Feb 2011 11:57:48 +0000 (06:57 -0500)
tests/unit/widget/widget_tickets.js
ui/jquery.ui.widget.js

index 0267c8ff49c0c1fc1762fe021a2164e9f2317aa7..9c0bddf0396c7791b7b453e063c8819ae5766fd4 100644 (file)
@@ -40,4 +40,52 @@ test( "#5830 - Widget: Using inheritance overwrites the base classes options", f
        delete $.ui.testWidgetExtension;
 });
 
+test( "#6795 - Widget: handle array arguments to _trigger consistently", function() {
+       expect( 4 );
+
+       $.widget( "ui.testWidget", {
+               _create: function() {},
+               testEvent: function() {
+                       var ui = {
+                                       foo: "bar",
+                                       baz: {
+                                               qux: 5,
+                                               quux: 20
+                                       }
+                               };
+                       var extra = {
+                               bar: 5
+                       };
+                       this._trigger( "foo", null, [ ui, extra ] );
+               }
+       });
+       $( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) {
+               same( ui, {
+                       foo: "bar",
+                       baz: {
+                               qux: 5,
+                               quux: 20
+                       }
+               }, "event: ui hash passed" );
+               same( extra, {
+                       bar: 5
+               }, "event: extra argument passed" );
+       });
+       $( "#widget" ).testWidget({
+               foo: function( event, ui, extra ) {
+                       same( ui, {
+                               foo: "bar",
+                               baz: {
+                                       qux: 5,
+                                       quux: 20
+                               }
+                       }, "callback: ui hash passed" );
+                       same( extra, {
+                               bar: 5
+                       }, "callback: extra argument passed" );
+               }
+       })
+       .testWidget( "testEvent" );
+});
+
 }( jQuery ) );
index c8e5348ac43e83932f7b2b65729606904f3ffdd7..1ec934469f084efab2f5957a7d58f711677080b3 100644 (file)
@@ -289,7 +289,8 @@ $.Widget.prototype = {
        },
 
        _trigger: function( type, event, data ) {
-               var callback = this.options[ type ];
+               var callback = this.options[ type ],
+                       args;
 
                event = $.Event( event );
                event.type = ( type === this.widgetEventPrefix ?
@@ -309,8 +310,12 @@ $.Widget.prototype = {
 
                this.element.trigger( event, data );
 
-               return !( $.isFunction(callback) &&
-                       callback.call( this.element[0], event, data ) === false ||
+               args = $.isArray( data ) ?
+                       [ event ].concat( data ) :
+                       [ event, data ];
+
+               return !( $.isFunction( callback ) &&
+                       callback.apply( this.element[0], args ) === false ||
                        event.isDefaultPrevented() );
        }
 };