fix for #3533, triggering an event with a colon in the name on a table no longer throws an error in IE

This commit is contained in:
Brandon Aaron 2009-06-17 02:31:45 +00:00
parent 739644dce5
commit ee34b6982a
2 changed files with 19 additions and 5 deletions

View file

@ -247,16 +247,22 @@ jQuery.event = {
handle.apply( elem, data ); handle.apply( elem, data );
} }
var nativeFn, nativeHandler;
try {
nativeFn = elem[ type ];
nativeHandler = elem[ "on" + type ];
// prevent IE from throwing an error for some elements with some event types, see #3533
} catch (e) {}
// Handle triggering native .onfoo handlers (and on links since we don't call .click() for links) // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links)
if ( (!elem[ type ] || (jQuery.nodeName(elem, 'a') && type === "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) { if ( (!nativeFn || (jQuery.nodeName(elem, 'a') && type === "click")) && nativeHandler && nativeHandler.apply( elem, data ) === false ) {
event.result = false; event.result = false;
} }
// Trigger the native events (except for clicks on links) // Trigger the native events (except for clicks on links)
if ( !bubbling && elem[ type ] && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type === "click") ) { if ( !bubbling && nativeFn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type === "click") ) {
this.triggered = true; this.triggered = true;
try { try {
elem[ type ](); nativeFn();
// prevent IE from throwing an error for some hidden elements // prevent IE from throwing an error for some hidden elements
} catch (e) {} } catch (e) {}
} }
@ -368,7 +374,7 @@ jQuery.event = {
// Add which for click: 1 == left; 2 == middle; 3 == right // Add which for click: 1 == left; 2 == middle; 3 == right
// Note: button is not normalized, so don't use it // Note: button is not normalized, so don't use it
if ( !event.which && event.button ) { if ( !event.which && event.button !== undefined ) {
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
} }

View file

@ -337,7 +337,7 @@ test("trigger() bubbling", function() {
}); });
test("trigger(type, [data], [fn])", function() { test("trigger(type, [data], [fn])", function() {
expect(11); expect(12);
var handler = function(event, a, b, c) { var handler = function(event, a, b, c) {
equals( event.type, "click", "check passed data" ); equals( event.type, "click", "check passed data" );
@ -374,6 +374,14 @@ test("trigger(type, [data], [fn])", function() {
pass = false; pass = false;
} }
ok( pass, "Trigger focus on hidden element" ); ok( pass, "Trigger focus on hidden element" );
pass = true;
try {
jQuery('table:first').bind('test:test', function(){}).trigger('test:test');
} catch (e) {
pass = false;
}
ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
}); });
test("trigger(eventObject, [data], [fn])", function() { test("trigger(eventObject, [data], [fn])", function() {