Jonathan Sharp schrieb:
$(window)
.bind('testEvent', function(e) {
alert('1');
e.stopPropagation();
e.preventDefault();
return false;
})
.bind('testEvent', function() {
alert('2');
})
.trigger('testEvent');
The above code doesn't stop the testEvent from triggering the second
alert. Is the propagation prevention just for standard events such as
'click', etc.?
Yep. jQuery makes no attempt to implement any of those two for custom
events. But its an interesting idea and not too hard to implement.
If you want to give an implementation a try, you'd have to start at this
line:
data.unshift( this.fix({ type: type, target: element }) );
You could provide implementations for preventDefault and stopPropagation
here.
The jQuery.event.handle method would have to be modified to check if one
of those two was called and cancel event handling when dealing with
triggered events.
-- Jörn