Commit 90c907e8 authored by Dave Methvin's avatar Dave Methvin

Fix #10701, .preventDefault if an inline handler returns false.

Baby unicorns are slapped each time you use inline handlers, so do it sparingly.
parent 1e677f30
...@@ -343,9 +343,10 @@ jQuery.event = { ...@@ -343,9 +343,10 @@ jQuery.event = {
if ( handle ) { if ( handle ) {
handle.apply( cur, data ); handle.apply( cur, data );
} }
// Note that this is a bare JS function and not a jQuery handler
handle = ontype && cur[ ontype ]; handle = ontype && cur[ ontype ];
if ( handle && jQuery.acceptData( cur ) ) { if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
handle.apply( cur, data ); event.preventDefault();
} }
if ( event.isPropagationStopped() ) { if ( event.isPropagationStopped() ) {
......
...@@ -2273,6 +2273,18 @@ test("Non DOM element events", function() { ...@@ -2273,6 +2273,18 @@ test("Non DOM element events", function() {
jQuery(o).trigger("nonelementobj"); jQuery(o).trigger("nonelementobj");
}); });
test("inline handler returning false stops default", function() {
expect(1);
var markup = jQuery('<div><a href="#" onclick="return false">x</a></div>');
markup.click(function(e) {
ok( e.isDefaultPrevented(), "inline handler prevented default");
return false;
});
markup.find("a").click();
markup.off("click");
});
test("window resize", function() { test("window resize", function() {
expect(2); expect(2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment