Skip to content
Permalink
Browse files

jquery event: closes #3772. The extra function on $.event.trigger isn…

…'t supported anymore.
  • Loading branch information
flesler committed Jan 2, 2009
1 parent d20e7fe commit 989e3f61f78c773d5c6066152c0bf3fd61d752ed
Showing with 6 additions and 52 deletions.
  1. +5 −14 src/event.js
  2. +1 −38 test/unit/event.js
@@ -163,7 +163,7 @@ jQuery.event = {
}
},

trigger: function( event, data, elem, extra) {
trigger: function( event, data, elem) {
// Event object or event type
var type = event.type || event;

@@ -227,15 +227,6 @@ jQuery.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;
@@ -508,18 +499,18 @@ jQuery.fn.extend({
});
},

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;
}
},
@@ -270,7 +270,7 @@ test("unbind(event)", function() {
});

test("trigger(type, [data], [fn])", function() {
expect(46);
expect(11);

var handler = function(event, a, b, c) {
equals( event.type, "click", "check passed data" );
@@ -280,28 +280,6 @@ test("trigger(type, [data], [fn])", function() {
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
@@ -313,10 +291,6 @@ test("trigger(type, [data], [fn])", function() {
// 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" );
@@ -326,24 +300,13 @@ test("trigger(type, [data], [fn])", function() {
// 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');
} catch(e) {
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() {

0 comments on commit 989e3f6

Please sign in to comment.
You can’t perform that action at this time.