]> source.dussan.org Git - jquery.git/commitdiff
Followup to #8753. Modify new Event constructor signature to jQuery.event(type, props...
authorDave Methvin <dave.methvin@gmail.com>
Tue, 12 Apr 2011 23:29:09 +0000 (19:29 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 12 Apr 2011 23:29:09 +0000 (19:29 -0400)
src/event.js
test/unit/event.js

index f005f7285a652359b33ed609d9cc22547a6a8cd8..dd48e7f777056f5ddb900565be63a49395573fa3 100644 (file)
@@ -304,9 +304,9 @@ jQuery.event = {
                        // jQuery.Event object
                        event[ jQuery.expando ] ? event :
                        // Object literal
-                       jQuery.extend( new jQuery.Event(type), event ) :
+                       new jQuery.Event( type, event ) :
                        // Just the event type (string)
-                       new jQuery.Event(type);
+                       new jQuery.Event( type );
 
                event.type = type;
                event.namespace = namespaces.join(".");
@@ -563,26 +563,15 @@ jQuery.removeEvent = document.removeEventListener ?
                }
        };
 
-jQuery.Event = function( src ) {
+jQuery.Event = function( src, props ) {
        // Allow instantiation without the 'new' keyword
        if ( !this.preventDefault ) {
-               return new jQuery.Event( src );
+               return new jQuery.Event( src, props );
        }
 
        // Event object
        if ( src && src.type ) {
                this.originalEvent = src;
-
-               // Push explicitly provided properties onto the event object
-               for ( var prop in src ) {
-                       //      Ensure we don't clobber jQuery.Event prototype
-                       //      with own properties.
-                       if ( hasOwn.call( src, prop ) ) {
-                               this[ prop ] = src[ prop ];
-                       }
-               }
-
-               // Always ensure a type has been explicitly set
                this.type = src.type;
 
                // Events bubbling up the document may have been marked as prevented
@@ -595,6 +584,11 @@ jQuery.Event = function( src ) {
                this.type = src;
        }
 
+       // Put explicitly provided properties onto the event object
+       if ( props ) {
+               jQuery.extend( this, props );
+       }
+
        // timeStamp is buggy for some events on Firefox(#3843)
        // So we won't rely on the native value
        this.timeStamp = jQuery.now();
index 491396f93ccbd49c6bc03231cfd1548a740474c5..d4e3994e529bfd1eeb8f9f324de64a2e9171d7c8 100644 (file)
@@ -978,11 +978,11 @@ test("trigger(eventObject, [data], [fn])", function() {
        $parent.unbind().remove();
 });
 
-test("jQuery.Event({ /* props */ })", function() {
+test("jQuery.Event( type, props )", function() {
 
        expect(4);
 
-       var event = jQuery.Event({ type: "keydown", keyCode: 64 }),
+       var event = jQuery.Event( "keydown", { keyCode: 64 }),
                        handler = function( event ) {
                                ok( "keyCode" in event, "Special property 'keyCode' exists" );
                                equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );