]> source.dussan.org Git - jquery.git/commitdiff
Ref #13353: capture onlyHandlers in jQuery.Event.isTrigger. Close gh-1183.
authorRichard Gibson <richard.gibson@gmail.com>
Sat, 2 Feb 2013 02:20:15 +0000 (21:20 -0500)
committerDave Methvin <dave.methvin@gmail.com>
Thu, 4 Apr 2013 00:25:50 +0000 (20:25 -0400)
src/event.js
test/unit/event.js

index 102659a7e3a3eb8ae35f41995f176cb22064d107..21996a0c8f35cd8901718b25e3ec4d6f2b5499de 100644 (file)
@@ -240,7 +240,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("\\.(?:.*\\.|)") + "(\\.|$)" ) :
index dab120d0c91d1407101680da3b7111b488128b01..070f75a0b9e767fdea8b5ad6b0e7224233e75183 100644 (file)
@@ -1487,21 +1487,42 @@ test("jQuery.Event( type, props )", function() {
 
 });
 
-test("jQuery.Event.currentTarget", function(){
-       expect(2);
+test("jQuery.Event properties", function(){
+       expect(12);
 
-       jQuery("<div><p><button>shiny</button></p></div>")
-               .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("<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>"),
+               $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() {