Skip to content

Commit 14b09ef

Browse files
committed
Ref #12652: Allow overriding native .click() suppression
1 parent e3777b6 commit 14b09ef

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

src/event.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ jQuery.event = {
308308
// If nobody prevented the default action, do it now
309309
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
310310

311-
if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
312-
!(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
311+
if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
312+
jQuery.acceptData( elem ) ) {
313313

314314
// Call a native DOM method on the target with the same name name as the event.
315315
// Can't use an .isFunction() check here because IE6/7 fails that test.
@@ -552,15 +552,6 @@ jQuery.event = {
552552
// Prevent triggered image.load events from bubbling to window.load
553553
noBubble: true
554554
},
555-
click: {
556-
// For checkbox, fire native event so checked state will be right
557-
trigger: function() {
558-
if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) {
559-
this.click();
560-
return false;
561-
}
562-
}
563-
},
564555
focus: {
565556
// Fire native event if possible so blur/focus sequence is correct
566557
trigger: function() {
@@ -586,6 +577,20 @@ jQuery.event = {
586577
},
587578
delegateType: "focusout"
588579
},
580+
click: {
581+
// For checkbox, fire native event so checked state will be right
582+
trigger: function() {
583+
if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) {
584+
this.click();
585+
return false;
586+
}
587+
},
588+
589+
// For cross-browser consistency, don't fire native .click() on links
590+
_default: function( event ) {
591+
return jQuery.nodeName( event.target, "a" );
592+
}
593+
},
589594

590595
beforeunload: {
591596
postDispatch: function( event ) {

test/unit/event.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,58 +177,57 @@ test("on(), multiple events at once and namespaces", function() {
177177
test("on(), namespace with special add", function() {
178178
expect(27);
179179

180-
var div = jQuery("<div/>").on("test", function(e) {
181-
ok( true, "Test event fired." );
182-
});
183-
184-
var i = 0;
180+
var i = 0,
181+
div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function(e) {
182+
ok( true, "Test event fired." );
183+
});
185184

186185
jQuery.event.special["test"] = {
187-
_default: function(e, data) {
188-
equal( this, document, "Make sure we're at the top of the chain." );
189-
equal( e.type, "test", "And that we're still dealing with a test event." );
190-
equal( e.target, div[0], "And that the target is correct." );
191-
ok( data !== undefined , "And that trigger data was passed." );
186+
_default: function( e, data ) {
187+
equal( e.type, "test", "Make sure we're dealing with a test event." );
188+
ok( data, "And that trigger data was passed." );
189+
strictEqual( e.target, div[0], "And that the target is correct." );
190+
equal( this, window, "And that the context is correct." );
192191
},
193-
setup: function(){},
194-
teardown: function(){
195-
ok(true, "Teardown called.");
192+
setup: function() {},
193+
teardown: function() {
194+
ok( true, "Teardown called." );
196195
},
197196
add: function( handleObj ) {
198197
var handler = handleObj.handler;
199-
handleObj.handler = function(e) {
198+
handleObj.handler = function( e ) {
200199
e.xyz = ++i;
201200
handler.apply( this, arguments );
202201
};
203202
},
204203
remove: function() {
205-
ok(true, "Remove called.");
204+
ok( true, "Remove called." );
206205
}
207206
};
208207

209-
div.on("test.a", {"x": 1}, function(e) {
208+
div.on( "test.a", { x: 1 }, function( e ) {
210209
ok( !!e.xyz, "Make sure that the data is getting passed through." );
211210
equal( e.data["x"], 1, "Make sure data is attached properly." );
212211
});
213212

214-
div.on("test.b", {"x": 2}, function(e) {
213+
div.on( "test.b", { x: 2 }, function( e ) {
215214
ok( !!e.xyz, "Make sure that the data is getting passed through." );
216215
equal( e.data["x"], 2, "Make sure data is attached properly." );
217216
});
218217

219218
// Should trigger 5
220-
div.trigger("test", 33.33);
219+
div.trigger( "test", 33.33 );
221220

222221
// Should trigger 2
223-
div.trigger("test.a", "George Harrison");
222+
div.trigger( "test.a", "George Harrison" );
224223

225224
// Should trigger 2
226-
div.trigger("test.b", { year: 1982 });
225+
div.trigger( "test.b", { year: 1982 } );
227226

228227
// Should trigger 4
229228
div.off("test");
230229

231-
div = jQuery("<div/>").on("test", function(e) {
230+
div = jQuery("<div/>").on( "test", function( e ) {
232231
ok( true, "Test event fired." );
233232
});
234233

0 commit comments

Comments
 (0)