]> source.dussan.org Git - jquery.git/commitdiff
Ref #12652: Allow overriding native .click() suppression
authorRichard Gibson <richard.gibson@gmail.com>
Sun, 7 Apr 2013 02:56:03 +0000 (22:56 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Mon, 8 Apr 2013 17:57:11 +0000 (13:57 -0400)
(cherry picked from commit 14b09ef98eb11aae04c028a3b3d7af116c7d2c20)

src/event.js
test/unit/event.js

index 45e82ccc4d50eb615afb74f0ae6731ffefb7dc24..961e580b4d4cd97061f205dec24cd2c7327b21d2 100644 (file)
@@ -303,8 +303,8 @@ jQuery.event = {
                // If nobody prevented the default action, do it now
                if ( !onlyHandlers && !event.isDefaultPrevented() ) {
 
-                       if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
-                               !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
+                       if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
+                               jQuery.acceptData( elem ) ) {
 
                                // Call a native DOM method on the target with the same name name as the event.
                                // Don't do default actions on window, that's where global variables be (#6170)
@@ -522,15 +522,6 @@ jQuery.event = {
                        // Prevent triggered image.load events from bubbling to window.load
                        noBubble: true
                },
-               click: {
-                       // For checkbox, fire native event so checked state will be right
-                       trigger: function() {
-                               if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
-                                       this.click();
-                                       return false;
-                               }
-                       }
-               },
                focus: {
                        // Fire native event if possible so blur/focus sequence is correct
                        trigger: function() {
@@ -550,6 +541,20 @@ jQuery.event = {
                        },
                        delegateType: "focusout"
                },
+               click: {
+                       // For checkbox, fire native event so checked state will be right
+                       trigger: function() {
+                               if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
+                                       this.click();
+                                       return false;
+                               }
+                       },
+
+                       // For cross-browser consistency, don't fire native .click() on links
+                       _default: function( event ) {
+                               return jQuery.nodeName( event.target, "a" );
+                       }
+               },
 
                beforeunload: {
                        postDispatch: function( event ) {
index 1dd7510332dad5de23d6aeba45b3b835e6c58305..60f2c7a0a7bc59195fdb0a11605b6ff75e890ac8 100644 (file)
@@ -177,58 +177,57 @@ test("on(), multiple events at once and namespaces", function() {
 test("on(), namespace with special add", function() {
        expect(27);
 
-       var div = jQuery("<div/>").on("test", function(e) {
-               ok( true, "Test event fired." );
-       });
-
-       var i = 0;
+       var i = 0,
+               div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function(e) {
+                       ok( true, "Test event fired." );
+               });
 
        jQuery.event.special["test"] = {
-               _default: function(e, data) {
-                       equal( this, document, "Make sure we're at the top of the chain." );
-                       equal( e.type, "test", "And that we're still dealing with a test event." );
-                       equal( e.target, div[0], "And that the target is correct." );
-                       ok( data !== undefined , "And that trigger data was passed." );
+               _default: function( e, data ) {
+                       equal( e.type, "test", "Make sure we're dealing with a test event." );
+                       ok( data, "And that trigger data was passed." );
+                       strictEqual( e.target, div[0], "And that the target is correct." );
+                       equal( this, window, "And that the context is correct." );
                },
-               setup: function(){},
-               teardown: function(){
-                       ok(true, "Teardown called.");
+               setup: function() {},
+               teardown: function() {
+                       ok( true, "Teardown called." );
                },
                add: function( handleObj ) {
                        var handler = handleObj.handler;
-                       handleObj.handler = function(e) {
+                       handleObj.handler = function( e ) {
                                e.xyz = ++i;
                                handler.apply( this, arguments );
                        };
                },
                remove: function() {
-                       ok(true, "Remove called.");
+                       ok( true, "Remove called." );
                }
        };
 
-       div.on("test.a", {"x": 1}, function(e) {
+       div.on( "test.a", { x: 1 }, function( e ) {
                ok( !!e.xyz, "Make sure that the data is getting passed through." );
                equal( e.data["x"], 1, "Make sure data is attached properly." );
        });
 
-       div.on("test.b", {"x": 2}, function(e) {
+       div.on( "test.b", { x: 2 }, function( e ) {
                ok( !!e.xyz, "Make sure that the data is getting passed through." );
                equal( e.data["x"], 2, "Make sure data is attached properly." );
        });
 
        // Should trigger 5
-       div.trigger("test", 33.33);
+       div.trigger( "test", 33.33 );
 
        // Should trigger 2
-       div.trigger("test.a", "George Harrison");
+       div.trigger( "test.a", "George Harrison" );
 
        // Should trigger 2
-       div.trigger("test.b", { year: 1982 });
+       div.trigger( "test.b", { year: 1982 } );
 
        // Should trigger 4
        div.off("test");
 
-       div = jQuery("<div/>").on("test", function(e) {
+       div = jQuery("<div/>").on( "test", function( e ) {
                ok( true, "Test event fired." );
        });