Skip to content
Permalink
Browse files

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 ee34b6982ab25cd7699f68506d7b18a02c3c4d44
Showing with 19 additions and 5 deletions.
  1. +10 −4 src/event.js
  2. +9 −1 test/unit/event.js
@@ -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) {}
}
@@ -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 ) ));
}

@@ -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" );
@@ -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() {

0 comments on commit ee34b69

Please sign in to comment.
You can’t perform that action at this time.