From 3f05afbd8d9bbc75d30b68e720324d1ed984a315 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 1 Feb 2013 21:20:15 -0500 Subject: [PATCH] Ref #13353, gh-1183: Capture onlyHandlers in jQuery.Event.isTrigger. --- src/event.js | 3 ++- test/unit/event.js | 49 +++++++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/event.js b/src/event.js index e65be9a54..c9de8e617 100644 --- a/src/event.js +++ b/src/event.js @@ -235,7 +235,8 @@ jQuery.event = { event : new jQuery.Event( type, typeof event === "object" && event ); - event.isTrigger = true; + // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true) + event.isTrigger = onlyHandlers ? 2 : 3; event.namespace = namespaces.join("."); event.namespace_re = event.namespace ? new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : diff --git a/test/unit/event.js b/test/unit/event.js index 670fa9111..67d87ded0 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1432,21 +1432,42 @@ test("jQuery.Event( type, props )", function() { }); -test("jQuery.Event.currentTarget", function(){ - expect(2); +test("jQuery.Event properties", function(){ + expect(12); - jQuery("

") - .on( "click", "p", function( e ){ - equal( e.currentTarget, this, "Check delegated currentTarget on event" ); - }) - .find( "button" ) - .on( "click", function( e ){ - equal( e.currentTarget, this, "Check currentTarget on event" ); - }) - .trigger("click") - .off( "click" ) - .end() - .off( "click" ); + var handler, + $structure = jQuery("

shiny

"), + $target = $structure.find("#target"); + + handler = function( e ) { + strictEqual( e.currentTarget, this, "currentTarget at " + this.id ); + equal( e.isTrigger, 3, "trigger at " + this.id ); + }; + $structure.one( "click", handler ); + $structure.one( "click", "p", handler ); + $target.one( "click", handler ); + $target[0].onclick = function( e ) { + strictEqual( e.currentTarget, this, "currentTarget at target (native handler)" ); + equal( e.isTrigger, 3, "trigger at target (native handler)" ); + }; + $target.trigger("click"); + + $target.one( "click", function( e ) { + equal( e.isTrigger, 2, "triggerHandler at target" ); + }); + $target[0].onclick = function( e ) { + equal( e.isTrigger, 2, "triggerHandler at target (native handler)" ); + }; + $target.triggerHandler("click"); + + handler = function( e ) { + strictEqual( e.isTrigger, undefined, "native event at " + this.id ); + }; + $target.one( "click", handler ); + $target[0].onclick = function( e ) { + strictEqual( e.isTrigger, undefined, "native event at target (native handler)" ); + }; + fireNative( $target[0], "click" ); }); test(".delegate()/.undelegate()", function() {