Fix for #1486. Prevent IE from throwing an error when triggering focus on hidden input.

This commit is contained in:
Brandon Aaron 2007-12-08 02:54:09 +00:00
parent ffbedf0262
commit 91f1299f68
2 changed files with 15 additions and 2 deletions

View file

@ -193,7 +193,10 @@ jQuery.event = {
// Trigger the native events (except for clicks on links) // Trigger the native events (except for clicks on links)
if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) { if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
this.triggered = true; this.triggered = true;
try {
element[ type ](); element[ type ]();
// prevent IE from throwing an error for some hidden elements
} catch (e) {}
} }
this.triggered = false; this.triggered = false;

View file

@ -121,7 +121,7 @@ test("unbind(event)", function() {
}); });
test("trigger(event, [data], [fn])", function() { test("trigger(event, [data], [fn])", function() {
expect(66); expect(67);
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" );
@ -194,6 +194,16 @@ test("trigger(event, [data], [fn])", function() {
// Triggers 9 // Triggers 9
equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" ); equals( $("#firstp").triggerHandler("click", [eventObj, 1, "2", "abc"], handler), "test", "Verify handler response" );
var pass = true;
try {
$('input:first')
.hide()
.trigger('focus');
} catch(e) {
pass = false;
}
ok( pass, "Trigger focus on hidden element" );
// have the extra handler override the return // have the extra handler override the return
// Triggers 9 // Triggers 9
equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" ); equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" );