trigger DOM0 event handlers when doing a trigger (#1363)

This commit is contained in:
Brandon Aaron 2007-07-21 01:04:59 +00:00
parent e20e8e6e3c
commit 24463a04ce
2 changed files with 15 additions and 4 deletions

View file

@ -148,11 +148,15 @@ jQuery.event = {
data.unshift( this.fix({ type: type, target: element }) ); data.unshift( this.fix({ type: type, target: element }) );
// Trigger the event // Trigger the event
if ( jQuery.isFunction(element.$handle) && (val = element.$handle.apply( element, data )) !== false ) if ( jQuery.isFunction( element.$handle ) )
this.triggered = true; val = element.$handle.apply( element, data );
if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
val = false;
if ( fn && val !== false && !jQuery.nodeName(element, 'a') ) if ( fn && val !== false && !jQuery.nodeName(element, 'a') ) {
this.triggered = true;
element[ type ](); element[ type ]();
}
this.triggered = false; this.triggered = false;
} }

View file

@ -48,7 +48,7 @@ test("bind()", function() {
}); });
test("click()", function() { test("click()", function() {
expect(3); expect(4);
$('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() { $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
var close = $('spanx', this); // same with $(this).find('span'); var close = $('spanx', this); // same with $(this).find('span');
ok( close.length == 0, "Context element does not exist, length must be zero" ); ok( close.length == 0, "Context element does not exist, length must be zero" );
@ -59,6 +59,13 @@ test("click()", function() {
$("#check1").click(function() { $("#check1").click(function() {
ok( true, "click event handler for checkbox gets fired twice, see #815" ); ok( true, "click event handler for checkbox gets fired twice, see #815" );
}).click(); }).click();
var counter = 0;
$('#firstp')[0].onclick = function(event) {
counter++;
};
$('#firstp').click();
ok( counter == 1, "Check that click, triggers onclick event handler also" );
}); });
test("unbind(event)", function() { test("unbind(event)", function() {