Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Honor stopImmediatePropagation for live/delegate event handlers. Fixe…

…s #7217.
  • Loading branch information...
commit 974b5aeab7a3788ff5fb9db87b9567784e0249fc 1 parent ee845c4
Dave Methvin authored October 23, 2010 jeresig committed October 25, 2010
3  src/event.js
@@ -1132,6 +1132,9 @@ function liveHandler( event ) {
1132 1132
 			if ( ret === false ) {
1133 1133
 				stop = false;
1134 1134
 			}
  1135
+			if ( event.isImmediatePropagationStopped() ) {
  1136
+				break;
  1137
+			}
1135 1138
 		}
1136 1139
 	}
1137 1140
 
30  test/unit/event.js
@@ -265,6 +265,36 @@ test("live/die(Object), delegate/undelegate(String, Object)", function() {
265 265
 	equals( mouseoverCounter, 4, "die" );
266 266
 });
267 267
 
  268
+test("live/delegate immediate propagation", function() {
  269
+	expect(2);
  270
+	
  271
+	var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
  272
+	
  273
+	lastClick = "";
  274
+	$a.live( "click", function(e) { 
  275
+		lastClick = "click1"; 
  276
+		e.stopImmediatePropagation();
  277
+	});
  278
+	$a.live( "click", function(e) {
  279
+		lastClick = "click2";
  280
+	});
  281
+	$a.trigger( "click" );
  282
+	equals( lastClick, "click1", "live stopImmediatePropagation" );
  283
+	$a.die( "click" );
  284
+	
  285
+	lastClick = "";
  286
+	$p.delegate( "a", "click", function(e) { 
  287
+		lastClick = "click1"; 
  288
+		e.stopImmediatePropagation();
  289
+	});
  290
+	$p.delegate( "a", "click", function(e) {
  291
+		lastClick = "click2";
  292
+	});
  293
+	$a.trigger( "click" );
  294
+	equals( lastClick, "click1", "delegate stopImmediatePropagation" );
  295
+	$p.undelegate( "click" );
  296
+});
  297
+
268 298
 test("bind(), iframes", function() {
269 299
 	// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
270 300
 	var doc = jQuery("#loadediframe").contents();

0 notes on commit 974b5ae

Please sign in to comment.
Something went wrong with that request. Please try again.