Skip to content

Commit

Permalink
Fixes #8722. Remove try/catch used by #3533 to fix the IE Table Colon…
Browse files Browse the repository at this point in the history
… Blow bug, and instead check for colon in the event name. Thanks to daguej for scoping this out -- a colonoscopy you might say.
  • Loading branch information
dmethvin committed Apr 8, 2011
1 parent c470db6 commit 98d83ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ jQuery.event = {
trigger: function( event, data, elem ) {
// Event object or event type
var type = event.type || event,
ontype = "on" + type,
namespaces = [],
cur = elem;
namespaces = [];

event = typeof event === "object" ?
// jQuery.Event object
Expand Down Expand Up @@ -342,6 +340,10 @@ jQuery.event = {
data = jQuery.makeArray( data );
data.unshift( event );

var cur = elem,
// IE doesn't like method names with a colon (#3533, #8272)
ontype = type.indexOf(":") < 0? "on" + type : "";

// Fire event on the current element, then bubble up the DOM tree
do {
var handle = jQuery._data( cur, "handle" );
Expand All @@ -351,13 +353,11 @@ jQuery.event = {
handle.apply( cur, data );
}

// Trigger an inline bound script; IE<9 dies on special-char event name
try {
if ( jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) {
event.result = false;
event.preventDefault();
}
} catch ( ieError1 ) {}
// Trigger an inline bound script
if ( ontype &&jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) {
event.result = false;
event.preventDefault();
}

// Bubble up to document, then to window
cur = cur.parentNode || cur.ownerDocument || cur === event.target.ownerDocument && window;
Expand All @@ -373,9 +373,9 @@ jQuery.event = {

// Call a native DOM method on the target with the same name name as the event.
// Can't use an .isFunction)() check here because IE6/7 fails that test.
// Use try/catch so IE<9 won't die on special-char event name or hidden element (#3533).
// IE<9 dies on focus to hidden element (#1486), may want to revisit a try/catch.
try {
if ( elem[ type ] ) {
if ( ontype && elem[ type ] ) {
// Don't re-trigger an onFOO event when we call its FOO() method
old = elem[ ontype ];

Expand All @@ -386,7 +386,7 @@ jQuery.event = {
jQuery.event.triggered = type;
elem[ type ]();
}
} catch ( ieError2 ) {}
} catch ( ieError ) {}

if ( old ) {
elem[ ontype ] = old;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,19 @@ test("focusin bubbles", function() {
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
});

test("custom events with colons (#3533, #8272)", function() {
expect(1);

var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body");
try {
tab.trigger("back:forth");
ok( true, "colon events don't throw" );
} catch ( e ) {
ok( false, "colon events die" );
};
tab.remove();

});

(function(){
// This code must be run before DOM ready!
Expand Down

1 comment on commit 98d83ef

@pdokas
Copy link

@pdokas pdokas commented on 98d83ef Apr 8, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be one of the best commit messages in the repo!

Please sign in to comment.