| | 349 | |
| | 350 | test("custom event bubbling", function() { |
| | 351 | expect(6); |
| | 352 | |
| | 353 | jQuery(document).bind('acustomevent', function(e) { |
| | 354 | ok(false, 'customevent should not bubble to document as a previous handler returned false'); |
| | 355 | }); |
| | 356 | |
| | 357 | jQuery('#main').bind('acustomevent', function(e, data) { |
| | 358 | ok(true, 'acustomevent has bubbled to the parent element'); |
| | 359 | equals(e.target, jQuery('#firstp')[0], 'target is the original element that triggered the event'); |
| | 360 | equals(e.type, 'acustomevent', 'event type is preserved in bubble'); |
| | 361 | equals(data, 5, 'data is bubbled up with event'); |
| | 362 | return false; |
| | 363 | }); |
| | 364 | |
| | 365 | jQuery('#firstp').trigger('acustomevent', 5); |
| | 366 | |
| | 367 | jQuery(document).bind('anothercustomevent', function(e) { |
| | 368 | ok(false, 'anothercustomevent should not bubble to document'); |
| | 369 | }); |
| | 370 | |
| | 371 | jQuery('#main').bind('anothercustomevent', function(e) { |
| | 372 | ok(true, 'anothercustomevent has bubbled to the parent element as a previous handler called stopPropagation'); |
| | 373 | e.stopPropagation(); |
| | 374 | }); |
| | 375 | |
| | 376 | jQuery('#firstp').trigger('anothercustomevent'); |
| | 377 | |
| | 378 | jQuery(document).bind('onemorecustomevent', function() { |
| | 379 | ok(true, 'onemorecustomevent still bubbles to document even if no handler bound to original target'); |
| | 380 | }); |
| | 381 | |
| | 382 | jQuery('#firstp').trigger('onemorecustomevent'); |
| | 383 | |
| | 384 | jQuery(document).unbind('acustomevent'); |
| | 385 | jQuery(document).unbind('anothercustomevent'); |
| | 386 | jQuery(document).unbind('onemorecustomevent'); |
| | 387 | jQuery('#main').unbind('acustomevent'); |
| | 388 | jQuery('#main').unbind('anothercustomevent'); |
| | 389 | }); |