+test("live/die(Object), delegate/undelegate(String, Object)", function() {
+ expect(6);
+
+ var clickCounter = 0, mouseoverCounter = 0,
+ $p = jQuery("#firstp"), $a = $p.find("a:first");
+
+ var events = {
+ click: function( event ) {
+ clickCounter += ( event.data || 1 );
+ },
+ mouseover: function( event ) {
+ mouseoverCounter += ( event.data || 1 );
+ }
+ };
+
+ function trigger() {
+ $a.trigger("click").trigger("mouseover");
+ }
+
+ $a.live( events );
+ $p.delegate( "a", events, 2 );
+
+ trigger();
+ equals( clickCounter, 3, "live/delegate" );
+ equals( mouseoverCounter, 3, "live/delegate" );
+
+ $p.undelegate( "a", events );
+
+ trigger();
+ equals( clickCounter, 4, "undelegate" );
+ equals( mouseoverCounter, 4, "undelegate" );
+
+ $a.die( events );
+
+ trigger();
+ equals( clickCounter, 4, "die" );
+ equals( mouseoverCounter, 4, "die" );
+});
+
+test("live/delegate immediate propagation", function() {
+ expect(2);
+
+ var $p = jQuery("#firstp"), $a = $p.find("a:first"), lastClick;
+
+ lastClick = "";
+ $a.live( "click", function(e) {
+ lastClick = "click1";
+ e.stopImmediatePropagation();
+ });
+ $a.live( "click", function(e) {
+ lastClick = "click2";
+ });
+ $a.trigger( "click" );
+ equals( lastClick, "click1", "live stopImmediatePropagation" );
+ $a.die( "click" );
+
+ lastClick = "";
+ $p.delegate( "a", "click", function(e) {
+ lastClick = "click1";
+ e.stopImmediatePropagation();
+ });
+ $p.delegate( "a", "click", function(e) {
+ lastClick = "click2";
+ });
+ $a.trigger( "click" );
+ equals( lastClick, "click1", "delegate stopImmediatePropagation" );
+ $p.undelegate( "click" );
+});
+
+test("bind/delegate bubbling, isDefaultPrevented (Bug #7793)", function() {
+ expect(2);
+ var $anchor2 = jQuery( "#anchor2" ),
+ $main = jQuery( "#main" ),
+ fakeClick = function($jq) {
+ // Use a native click so we don't get jQuery simulated bubbling
+ if ( document.createEvent ) {
+ var e = document.createEvent( "MouseEvents" );
+ e.initEvent( "click", true, true );
+ $jq[0].dispatchEvent(e);
+ }
+ else if ( $jq[0].click ) {
+ $jq[0].click(); // IE
+ }
+ };
+ $anchor2.click(function(e) {
+ e.preventDefault();
+ });
+ $main.delegate("#foo", "click", function(e) {
+ equals( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
+ });
+ fakeClick( $anchor2 );
+ $anchor2.unbind( "click" );
+ $main.undelegate( "click" );
+ $anchor2.click(function(e) {
+ // Let the default action occur
+ });
+ $main.delegate("#foo", "click", function(e) {
+ equals( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
+ });
+ fakeClick( $anchor2 );
+ $anchor2.unbind( "click" );
+ $main.undelegate( "click" );
+});
+