From aef1989ba74ee568f8bab3ac0967fd849816da12 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Thu, 30 Apr 2009 21:50:15 +0000 Subject: [PATCH] live event handlers now receive data from trigger, fixes #4532, thanks nbubna --- src/event.js | 4 ++-- test/unit/event.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index 6987300..232fa27 100644 --- a/src/event.js +++ b/src/event.js @@ -601,7 +601,7 @@ jQuery.fn.extend({ }); function liveHandler( event ) { - var stop = true, elems = []; + var stop = true, elems = [], args = arguments; jQuery.each( jQuery.data( this, "events" ).live || [], function( i, fn ) { if ( fn.live === event.type ) { @@ -619,7 +619,7 @@ function liveHandler( event ) { jQuery.each(elems, function() { event.currentTarget = this.elem; event.data = this.fn.data - if ( this.fn.call( this.elem, event, this.fn.selector ) === false ) { + if ( this.fn.apply( this.elem, args ) === false ) { return (stop = false); } }); diff --git a/test/unit/event.js b/test/unit/event.js index b2270ad..dea17a1 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -490,7 +490,7 @@ test("toggle(Function, Function, ...)", function() { }); test(".live()/.die()", function() { - expect(53); + expect(54); var submit = 0, div = 0, livea = 0, liveb = 0; @@ -583,6 +583,10 @@ test(".live()/.die()", function() { jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); }); jQuery("#foo").trigger("click").die("click"); + // Test binding with trigger data + jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); }); + jQuery("#foo").trigger("click", true).die("click"); + // Verify that return false prevents default action jQuery("#anchor2").live("click", function(){ return false; }); var hash = window.location.hash; -- 1.7.10.4