Ref #13353: capture onlyHandlers in jQuery.Event.isTrigger. Close gh-1183.

This commit is contained in:
Richard Gibson 2013-02-01 21:20:15 -05:00 committed by Dave Methvin
parent b6dd1c67a6
commit 65a6648932
2 changed files with 37 additions and 15 deletions

View File

@ -240,7 +240,8 @@ jQuery.event = {
event : event :
new jQuery.Event( type, typeof event === "object" && 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 = namespaces.join(".");
event.namespace_re = event.namespace ? event.namespace_re = event.namespace ?
new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :

View File

@ -1487,21 +1487,42 @@ test("jQuery.Event( type, props )", function() {
}); });
test("jQuery.Event.currentTarget", function(){ test("jQuery.Event properties", function(){
expect(2); expect(12);
jQuery("<div><p><button>shiny</button></p></div>") var handler,
.on( "click", "p", function( e ){ $structure = jQuery("<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>"),
equal( e.currentTarget, this, "Check delegated currentTarget on event" ); $target = $structure.find("#target");
})
.find( "button" ) handler = function( e ) {
.on( "click", function( e ){ strictEqual( e.currentTarget, this, "currentTarget at " + this.id );
equal( e.currentTarget, this, "Check currentTarget on event" ); equal( e.isTrigger, 3, "trigger at " + this.id );
}) };
.trigger("click") $structure.one( "click", handler );
.off( "click" ) $structure.one( "click", "p", handler );
.end() $target.one( "click", handler );
.off( "click" ); $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() { test(".delegate()/.undelegate()", function() {