Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix for #3533, triggering an event with a colon in the name on a tabl…
…e no longer throws an error in IE
  • Loading branch information
brandonaaron committed Jun 17, 2009
1 parent 739644d commit ee34b69
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/event.js
Expand Up @@ -247,16 +247,22 @@ jQuery.event = {
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)
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;
}

// 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;
try {
elem[ type ]();
nativeFn();
// prevent IE from throwing an error for some hidden elements
} catch (e) {}
}
Expand Down Expand Up @@ -368,7 +374,7 @@ jQuery.event = {

// Add which for click: 1 == left; 2 == middle; 3 == right
// 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 ) ));
}

Expand Down
10 changes: 9 additions & 1 deletion test/unit/event.js
Expand Up @@ -337,7 +337,7 @@ test("trigger() bubbling", function() {
});

test("trigger(type, [data], [fn])", function() {
expect(11);
expect(12);

var handler = function(event, a, b, c) {
equals( event.type, "click", "check passed data" );
Expand Down Expand Up @@ -374,6 +374,14 @@ test("trigger(type, [data], [fn])", function() {
pass = false;
}
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() {
Expand Down

0 comments on commit ee34b69

Please sign in to comment.