}
},
- trigger: function( event, data, elem, extra) {
+ trigger: function( event, data, elem) {
// Event object or event type
var type = event.type || event;
// Extra functions don't get the custom event object
data.shift();
- // Handle triggering of extra function
- if ( extra && jQuery.isFunction( extra ) ) {
- // call the extra function and tack the current return value on the end for possible inspection
- var ret = extra.apply( elem, event.result == null ? data : data.concat( event.result ) );
- // if anything is returned, give it precedence and have it overwrite the previous value
- if ( ret !== undefined )
- event.result = ret;
- }
-
// Trigger the native events (except for clicks on links)
if ( event.target === elem && fn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
this.triggered = true;
});
},
- trigger: function( type, data, fn ) {
+ trigger: function( type, data ) {
return this.each(function(){
- jQuery.event.trigger( type, data, this, fn );
+ jQuery.event.trigger( type, data, this );
});
},
- triggerHandler: function( type, data, fn ) {
+ triggerHandler: function( type, data ) {
if( this[0] ){
var event = jQuery.Event(type);
event.preventDefault();
event.stopPropagation();
- jQuery.event.trigger( event, data, this[0], fn );
+ jQuery.event.trigger( event, data, this[0] );
return event.result;
}
},
});
test("trigger(type, [data], [fn])", function() {
- expect(46);
+ expect(11);
var handler = function(event, a, b, c) {
equals( event.type, "click", "check passed data" );
return "test";
};
- var handler2 = function(a, b, c) {
- equals( a, 1, "check passed data" );
- equals( b, "2", "check passed data" );
- equals( c, "abc", "check passed data" );
- return false;
- };
-
- var handler3 = function(a, b, c, v) {
- equals( a, 1, "check passed data" );
- equals( b, "2", "check passed data" );
- equals( c, "abc", "check passed data" );
- equals( v, "test", "check current value" );
- return "newVal";
- };
-
- var handler4 = function(a, b, c, v) {
- equals( a, 1, "check passed data" );
- equals( b, "2", "check passed data" );
- equals( c, "abc", "check passed data" );
- equals( v, "test", "check current value" );
- };
-
var $elem = jQuery("#firstp");
// Simulate a "native" click
// Trigger 5
$elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
- // Triggers handlers, native, and extra fn
- // Triggers 9
- $elem.trigger("click", [1, "2", "abc"], handler4);
-
// Simulate a "native" click
$elem[0].click = function(){
ok( false, "Native call was triggered" );
// Triggers 5
equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
- // Trigger only the handlers (no native) and extra fn
- // Triggers 8
- equals( $elem.triggerHandler("click", [1, "2", "abc"], handler2), false, "Verify handler response" );
var pass = true;
try {
jQuery('#form input:first').hide().trigger('focus');
pass = false;
}
ok( pass, "Trigger focus on hidden element" );
-
- // have the extra handler override the return
- // Triggers 9
- equals( $elem.triggerHandler("click", [1, "2", "abc"], handler3), "newVal", "Verify triggerHandler return is overwritten by extra function" );
-
- // have the extra handler leave the return value alone
- // Triggers 9
- equals( $elem.triggerHandler("click", [1, "2", "abc"], handler4), "test", "Verify triggerHandler return is not overwritten by extra function" );
});
test("trigger(eventObject, [data], [fn])", function() {