3 test("bind(), with data", function() {
5 var handler = function(event) {
6 ok( event.data, "bind() with data, check passed data exists" );
7 equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
9 jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
11 ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
14 test("bind(), with data, trigger with data", function() {
16 var handler = function(event, data) {
17 ok( event.data, "check passed data exists" );
18 equals( event.data.foo, "bar", "Check value of passed data" );
19 ok( data, "Check trigger data" );
20 equals( data.bar, "foo", "Check value of trigger data" );
22 jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
25 test("bind(), multiple events at once", function() {
29 var handler = function(event) {
30 if (event.type == "click")
32 else if (event.type == "mouseover")
33 mouseoverCounter += 1;
35 jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
36 equals( clickCounter, 1, "bind() with multiple events at once" );
37 equals( mouseoverCounter, 1, "bind() with multiple events at once" );
40 test("bind(), no data", function() {
42 var handler = function(event) {
43 ok ( !event.data, "Check that no data is added to the event object" );
45 jQuery("#firstp").bind("click", handler).trigger("click");
48 test("bind/one/unbind(Object)", function(){
51 var clickCounter = 0, mouseoverCounter = 0;
52 function handler(event) {
53 if (event.type == "click")
55 else if (event.type == "mouseover")
59 function handlerWithData(event) {
60 if (event.type == "click")
61 clickCounter += event.data;
62 else if (event.type == "mouseover")
63 mouseoverCounter += event.data;
67 $elem.trigger("click").trigger("mouseover");
70 var $elem = jQuery("#firstp")
78 click:handlerWithData,
79 mouseover:handlerWithData
84 equals( clickCounter, 3, "bind(Object)" );
85 equals( mouseoverCounter, 3, "bind(Object)" );
88 equals( clickCounter, 4, "bind(Object)" );
89 equals( mouseoverCounter, 4, "bind(Object)" );
91 jQuery("#firstp").unbind({
97 equals( clickCounter, 4, "bind(Object)" );
98 equals( mouseoverCounter, 4, "bind(Object)" );
101 test("bind(), iframes", function() {
102 // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
103 var doc = jQuery("#loadediframe").contents();
105 jQuery("div", doc).bind("click", function() {
106 ok( true, "Binding to element inside iframe" );
107 }).click().unbind('click');
110 test("bind(), trigger change on select", function() {
113 function selectOnChange(event) {
114 equals( event.data, counter++, "Event.data is not a global event object" );
116 jQuery("#form select").each(function(i){
117 jQuery(this).bind('change', i, selectOnChange);
118 }).trigger('change');
121 test("bind(), namespaced events, cloned events", function() {
124 jQuery("#firstp").bind("custom.test",function(e){
125 ok(true, "Custom event triggered");
128 jQuery("#firstp").bind("click",function(e){
129 ok(true, "Normal click triggered");
132 jQuery("#firstp").bind("click.test",function(e){
133 ok(true, "Namespaced click triggered");
136 // Trigger both bound fn (2)
137 jQuery("#firstp").trigger("click");
139 // Trigger one bound fn (1)
140 jQuery("#firstp").trigger("click.test");
142 // Remove only the one fn
143 jQuery("#firstp").unbind("click.test");
145 // Trigger the remaining fn (1)
146 jQuery("#firstp").trigger("click");
148 // Remove the remaining fn
149 jQuery("#firstp").unbind(".test");
151 // Trigger the remaining fn (0)
152 jQuery("#firstp").trigger("custom");
154 // using contents will get comments regular, text, and comment nodes
155 jQuery("#nonnodes").contents().bind("tester", function () {
156 equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
157 }).trigger("tester");
159 // Make sure events stick with appendTo'd elements (which are cloned) #2027
160 jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
161 ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
164 test("bind(), multi-namespaced events", function() {
176 function check(name, msg){
177 same(name, order.shift(), msg);
180 jQuery("#firstp").bind("custom.test",function(e){
181 check("custom.test", "Custom event triggered");
184 jQuery("#firstp").bind("custom.test2",function(e){
185 check("custom.test2", "Custom event triggered");
188 jQuery("#firstp").bind("click.test",function(e){
189 check("click.test", "Normal click triggered");
192 jQuery("#firstp").bind("click.test.abc",function(e){
193 check("click.test.abc", "Namespaced click triggered");
196 // Those would not trigger/unbind (#5303)
197 jQuery("#firstp").trigger("click.a.test");
198 jQuery("#firstp").unbind("click.a.test");
200 // Trigger both bound fn (1)
201 jQuery("#firstp").trigger("click.test.abc");
203 // Trigger one bound fn (1)
204 jQuery("#firstp").trigger("click.abc");
206 // Trigger two bound fn (2)
207 jQuery("#firstp").trigger("click.test");
209 // Remove only the one fn
210 jQuery("#firstp").unbind("click.abc");
212 // Trigger the remaining fn (1)
213 jQuery("#firstp").trigger("click");
215 // Remove the remaining fn
216 jQuery("#firstp").unbind(".test");
218 // Trigger the remaining fn (1)
219 jQuery("#firstp").trigger("custom");
222 test("bind(), with different this object", function() {
224 var thisObject = { myThis: true },
225 data = { myData: true },
226 handler1 = function( event ) {
227 equals( this, thisObject, "bind() with different this object" );
229 handler2 = function( event ) {
230 equals( this, thisObject, "bind() with different this object and data" );
231 equals( event.data, data, "bind() with different this object and data" );
235 .bind("click", handler1, thisObject).click().unbind("click", handler1)
236 .bind("click", data, handler2, thisObject).click().unbind("click", handler2);
238 ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
241 test("unbind(type)", function() {
244 var $elem = jQuery("#firstp"),
248 ok( false, message );
251 message = "unbind passing function";
252 $elem.bind('error', error).unbind('error',error).triggerHandler('error');
254 message = "unbind all from event";
255 $elem.bind('error', error).unbind('error').triggerHandler('error');
257 message = "unbind all";
258 $elem.bind('error', error).unbind().triggerHandler('error');
260 message = "unbind many with function";
261 $elem.bind('error error2',error)
262 .unbind('error error2', error )
263 .trigger('error').triggerHandler('error2');
265 message = "unbind many"; // #3538
266 $elem.bind('error error2',error)
267 .unbind('error error2')
268 .trigger('error').triggerHandler('error2');
270 message = "unbind without a type or handler";
271 $elem.bind("error error2.test",error)
273 .trigger("error").triggerHandler("error2");
276 test("unbind(eventObject)", function() {
279 var $elem = jQuery("#firstp"),
282 function assert( expected ){
284 $elem.trigger('foo').triggerHandler('bar');
285 equals( num, expected, "Check the right handlers are triggered" );
289 // This handler shouldn't be unbound
290 .bind('foo', function(){
293 .bind('foo', function(e){
298 .bind('bar', function(){
312 test("hover()", function() {
314 handler1 = function( event ) { ++times; },
315 handler2 = function( event ) { ++times; };
318 .hover(handler1, handler2)
319 .mouseenter().mouseleave()
320 .unbind("mouseenter", handler1)
321 .unbind("mouseleave", handler2)
323 .mouseenter().mouseleave()
324 .unbind("mouseenter mouseleave", handler1)
325 .mouseenter().mouseleave();
327 equals( times, 4, "hover handlers fired" );
330 test("trigger() shortcuts", function() {
332 jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
333 var close = jQuery('spanx', this); // same with jQuery(this).find('span');
334 equals( close.length, 0, "Context element does not exist, length must be zero" );
335 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
339 jQuery("#check1").click(function() {
340 ok( true, "click event handler for checkbox gets fired twice, see #815" );
344 jQuery('#firstp')[0].onclick = function(event) {
347 jQuery('#firstp').click();
348 equals( counter, 1, "Check that click, triggers onclick event handler also" );
350 var clickCounter = 0;
351 jQuery('#simon1')[0].onclick = function(event) {
354 jQuery('#simon1').click();
355 equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
357 jQuery('<img />').load(function(){
358 ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
362 test("trigger() bubbling", function() {
365 var doc = 0, html = 0, body = 0, main = 0, ap = 0;
367 jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
368 jQuery("html").bind("click", function(e){ html++; });
369 jQuery("body").bind("click", function(e){ body++; });
370 jQuery("#main").bind("click", function(e){ main++; });
371 jQuery("#ap").bind("click", function(){ ap++; return false; });
373 jQuery("html").trigger("click");
374 equals( doc, 1, "HTML bubble" );
375 equals( html, 1, "HTML bubble" );
377 jQuery("body").trigger("click");
378 equals( doc, 2, "Body bubble" );
379 equals( html, 2, "Body bubble" );
380 equals( body, 1, "Body bubble" );
382 jQuery("#main").trigger("click");
383 equals( doc, 3, "Main bubble" );
384 equals( html, 3, "Main bubble" );
385 equals( body, 2, "Main bubble" );
386 equals( main, 1, "Main bubble" );
388 jQuery("#ap").trigger("click");
389 equals( doc, 3, "ap bubble" );
390 equals( html, 3, "ap bubble" );
391 equals( body, 2, "ap bubble" );
392 equals( main, 1, "ap bubble" );
393 equals( ap, 1, "ap bubble" );
396 test("trigger(type, [data], [fn])", function() {
399 var handler = function(event, a, b, c) {
400 equals( event.type, "click", "check passed data" );
401 equals( a, 1, "check passed data" );
402 equals( b, "2", "check passed data" );
403 equals( c, "abc", "check passed data" );
407 var $elem = jQuery("#firstp");
409 // Simulate a "native" click
410 $elem[0].click = function(){
411 ok( true, "Native call was triggered" );
414 // Triggers handlrs and native
416 $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
418 // Simulate a "native" click
419 $elem[0].click = function(){
420 ok( false, "Native call was triggered" );
423 // Trigger only the handlers (no native)
425 equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
429 jQuery('#form input:first').hide().trigger('focus');
433 ok( pass, "Trigger focus on hidden element" );
437 jQuery('table:first').bind('test:test', function(){}).trigger('test:test');
441 ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
444 test("trigger(eventObject, [data], [fn])", function() {
447 var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
448 $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
450 var event = jQuery.Event("noNew");
451 ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
452 equals( event.type, "noNew", "Verify its type" );
454 equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
455 equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
456 equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
458 event.preventDefault();
459 equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
460 event.stopPropagation();
461 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
463 event.isPropagationStopped = function(){ return false };
464 event.stopImmediatePropagation();
465 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
466 equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
468 $parent.bind('foo',function(e){
470 equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
471 equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
472 equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
473 equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
476 // test with an event object
477 event = new jQuery.Event("foo");
478 event.secret = 'boo!';
479 $child.trigger(event);
481 // test with a literal object
482 $child.trigger({type:'foo', secret:'boo!'});
487 ok( false, "This assertion shouldn't be reached");
490 $parent.bind('foo', error );
492 $child.bind('foo',function(e, a, b, c ){
493 equals( arguments.length, 4, "Check arguments length");
494 equals( a, 1, "Check first custom argument");
495 equals( b, 2, "Check second custom argument");
496 equals( c, 3, "Check third custom argument");
498 equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
499 equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
500 equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
503 e.stopImmediatePropagation();
508 // We should add this back in when we want to test the order
509 // in which event handlers are iterated.
510 //$child.bind('foo', error );
512 event = new jQuery.Event("foo");
513 $child.trigger( event, [1,2,3] ).unbind();
514 equals( event.result, "result", "Check event.result attribute");
516 // Will error if it bubbles
517 $child.triggerHandler('foo');
520 $parent.unbind().remove();
523 test("jQuery.Event.currentTarget", function(){
527 $elem = jQuery('<button>a</button>').click(function(e){
528 equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
532 $elem.trigger('click');
538 test("toggle(Function, Function, ...)", function() {
542 fn1 = function(e) { count++; },
543 fn2 = function(e) { count--; },
544 preventDefault = function(e) { e.preventDefault() },
545 link = jQuery('#mark');
546 link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
547 equals( count, 1, "Check for toggle(fn, fn)" );
549 jQuery("#firstp").toggle(function () {
550 equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
551 }, function() {}).trigger("click", [ 1, 2, 3 ]);
554 jQuery("#simon1").one("click", function() {
555 ok( true, "Execute event only once" );
556 jQuery(this).toggle(function() {
557 equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
559 equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
562 }).click().click().click();
577 var $div = jQuery("<div> </div>").toggle( fns[0], fns[1], fns[2] );
579 equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
581 equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
583 equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
585 equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
587 equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
589 $div.unbind('click',fns[0]);
590 var data = jQuery.data( $div[0], 'events' );
591 ok( !data, "Unbinding one function from toggle unbinds them all");
593 // Test Multi-Toggles
595 $div = jQuery("<div/>");
596 $div.toggle(function(){ a.push(1); }, function(){ a.push(2); });
598 same( a, [1], "Check that a click worked." );
600 $div.toggle(function(){ b.push(1); }, function(){ b.push(2); });
602 same( a, [1,2], "Check that a click worked with a second toggle." );
603 same( b, [1], "Check that a click worked with a second toggle." );
606 same( a, [1,2,1], "Check that a click worked with a second toggle, second click." );
607 same( b, [1,2], "Check that a click worked with a second toggle, second click." );
610 test(".live()/.die()", function() {
613 var submit = 0, div = 0, livea = 0, liveb = 0;
615 jQuery("div").live("submit", function(){ submit++; return false; });
616 jQuery("div").live("click", function(){ div++; });
617 jQuery("div#nothiddendiv").live("click", function(){ livea++; });
618 jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
620 // Nothing should trigger on the body
621 jQuery("body").trigger("click");
622 equals( submit, 0, "Click on body" );
623 equals( div, 0, "Click on body" );
624 equals( livea, 0, "Click on body" );
625 equals( liveb, 0, "Click on body" );
627 // This should trigger two events
628 jQuery("div#nothiddendiv").trigger("click");
629 equals( submit, 0, "Click on div" );
630 equals( div, 1, "Click on div" );
631 equals( livea, 1, "Click on div" );
632 equals( liveb, 0, "Click on div" );
634 // This should trigger three events (w/ bubbling)
635 jQuery("div#nothiddendivchild").trigger("click");
636 equals( submit, 0, "Click on inner div" );
637 equals( div, 2, "Click on inner div" );
638 equals( livea, 2, "Click on inner div" );
639 equals( liveb, 1, "Click on inner div" );
641 // This should trigger one submit
642 jQuery("div#nothiddendivchild").trigger("submit");
643 equals( submit, 1, "Submit on div" );
644 equals( div, 2, "Submit on div" );
645 equals( livea, 2, "Submit on div" );
646 equals( liveb, 1, "Submit on div" );
648 // Make sure no other events were removed in the process
649 jQuery("div#nothiddendivchild").trigger("click");
650 equals( submit, 1, "die Click on inner div" );
651 equals( div, 3, "die Click on inner div" );
652 equals( livea, 3, "die Click on inner div" );
653 equals( liveb, 2, "die Click on inner div" );
655 // Now make sure that the removal works
656 jQuery("div#nothiddendivchild").die("click");
657 jQuery("div#nothiddendivchild").trigger("click");
658 equals( submit, 1, "die Click on inner div" );
659 equals( div, 4, "die Click on inner div" );
660 equals( livea, 4, "die Click on inner div" );
661 equals( liveb, 2, "die Click on inner div" );
663 // Make sure that the click wasn't removed too early
664 jQuery("div#nothiddendiv").trigger("click");
665 equals( submit, 1, "die Click on inner div" );
666 equals( div, 5, "die Click on inner div" );
667 equals( livea, 5, "die Click on inner div" );
668 equals( liveb, 2, "die Click on inner div" );
670 // Make sure that stopPropgation doesn't stop live events
671 jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
672 jQuery("div#nothiddendivchild").trigger("click");
673 equals( submit, 1, "stopPropagation Click on inner div" );
674 equals( div, 6, "stopPropagation Click on inner div" );
675 equals( livea, 6, "stopPropagation Click on inner div" );
676 equals( liveb, 3, "stopPropagation Click on inner div" );
678 jQuery("div#nothiddendivchild").die("click");
679 jQuery("div#nothiddendiv").die("click");
680 jQuery("div").die("click");
681 jQuery("div").die("submit");
683 // Test binding with a different context
684 var clicked = 0, container = jQuery('#main')[0];
685 jQuery("#foo", container).live("click", function(e){ clicked++; });
686 jQuery("div").trigger('click');
687 jQuery("#foo").trigger('click');
688 jQuery("#main").trigger('click');
689 jQuery("body").trigger('click');
690 equals( clicked, 2, "live with a context" );
692 // Make sure the event is actually stored on the context
693 ok( jQuery.data(container, "events").live, "live with a context" );
695 // Test unbinding with a different context
696 jQuery("#foo", container).die("click");
697 jQuery("#foo").trigger('click');
698 equals( clicked, 2, "die with a context");
700 // Test binding with event data
701 jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); });
702 jQuery("#foo").trigger("click").die("click");
704 // Test binding with trigger data
705 jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); });
706 jQuery("#foo").trigger("click", true).die("click");
708 // Test binding with different this object
709 jQuery("#foo").live("click", function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" });
710 jQuery("#foo").trigger("click").die("click");
712 // Test binding with different this object, event data, and trigger data
713 jQuery("#foo").live("click", true, function(e, data){
714 equals( e.data, true, "live with with different this object, event data, and trigger data" );
715 equals( this.foo, "bar", "live with with different this object, event data, and trigger data" );
716 equals( data, true, "live with with different this object, event data, and trigger data")
718 jQuery("#foo").trigger("click", true).die("click");
720 // Verify that return false prevents default action
721 jQuery("#anchor2").live("click", function(){ return false; });
722 var hash = window.location.hash;
723 jQuery("#anchor2").trigger("click");
724 equals( window.location.hash, hash, "return false worked" );
725 jQuery("#anchor2").die("click");
727 // Verify that .preventDefault() prevents default action
728 jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
729 var hash = window.location.hash;
730 jQuery("#anchor2").trigger("click");
731 equals( window.location.hash, hash, "e.preventDefault() worked" );
732 jQuery("#anchor2").die("click");
734 // Test binding the same handler to multiple points
736 function callback(){ called++; return false; }
738 jQuery("#nothiddendiv").live("click", callback);
739 jQuery("#anchor2").live("click", callback);
741 jQuery("#nothiddendiv").trigger("click");
742 equals( called, 1, "Verify that only one click occurred." );
744 jQuery("#anchor2").trigger("click");
745 equals( called, 2, "Verify that only one click occurred." );
747 // Make sure that only one callback is removed
748 jQuery("#anchor2").die("click", callback);
750 jQuery("#nothiddendiv").trigger("click");
751 equals( called, 3, "Verify that only one click occurred." );
753 jQuery("#anchor2").trigger("click");
754 equals( called, 3, "Verify that no click occurred." );
756 // Make sure that it still works if the selector is the same,
757 // but the event type is different
758 jQuery("#nothiddendiv").live("foo", callback);
761 jQuery("#nothiddendiv").die("click", callback);
763 jQuery("#nothiddendiv").trigger("click");
764 equals( called, 3, "Verify that no click occurred." );
766 jQuery("#nothiddendiv").trigger("foo");
767 equals( called, 4, "Verify that one foo occurred." );
770 jQuery("#nothiddendiv").die("foo", callback);
772 // Make sure we don't loose the target by DOM modifications
773 // after the bubble already reached the liveHandler
774 var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
776 jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
777 jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
779 jQuery("#nothiddendiv span").click();
780 equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
781 equals( livec, 1, "Verify that second handler occurred even with nuked target." );
784 jQuery("#nothiddendivchild").die("click");
786 // Verify that .live() ocurs and cancel buble in the same order as
787 // we would expect .bind() and .click() without delegation
788 var lived = 0, livee = 0;
790 // bind one pair in one order
791 jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
792 jQuery('span#liveSpan1').live('click', function(){ livee++; });
794 jQuery('span#liveSpan1 a').click();
795 equals( lived, 1, "Verify that only one first handler occurred." );
796 equals( livee, 0, "Verify that second handler doesn't." );
798 // and one pair in inverse
799 jQuery('span#liveSpan2').live('click', function(){ livee++; });
800 jQuery('span#liveSpan2 a').live('click', function(){ lived++; return false; });
804 jQuery('span#liveSpan2 a').click();
805 equals( lived, 1, "Verify that only one first handler occurred." );
806 equals( livee, 0, "Verify that second handler doesn't." );
809 jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click");
811 // Test this, target and currentTarget are correct
812 jQuery('span#liveSpan1').live('click', function(e){
813 equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
814 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
815 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
818 jQuery('span#liveSpan1 a').click();
820 jQuery('span#liveSpan1').die('click');
823 test("live with submit", function() {
826 jQuery("#testForm").live("submit", function() {
831 jQuery("#testForm input[name=sub1]")[0].click();
832 jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13});
836 jQuery("#testForm").die("submit");
839 test("live with focus/blur", function(){
843 jQuery("<input type='text' id='livefb' />").appendTo("body");
845 var $child = jQuery("#livefb"),
853 $child.live("focus", worked);
854 $child.live("blur", worked);
859 ok(true, "Test live() with focus event");
861 ok(true, "Cannot test focus because the window isn't focused");
865 ok( true, "Test live() with blur event");
867 ok(true, "Cannot test blur because the window isn't focused");
870 $child.die("focus", worked);
871 $child.die("blur", worked);
873 window.scrollTo(0,0);
876 test("Non DOM element events", function() {
880 .bind('nonelementglobal', function(e) {
881 ok( true, "Global event on non-DOM annonymos object triggered" );
887 .bind('nonelementobj', function(e) {
888 ok( true, "Event on non-DOM object triggered" );
889 }).bind('nonelementglobal', function() {
890 ok( true, "Global event on non-DOM object triggered" );
893 jQuery(o).trigger('nonelementobj');
894 jQuery.event.trigger('nonelementglobal');
898 test("jQuery(function($) {})", function() {
901 equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
906 test("event properties", function() {
908 jQuery("#simon1").click(function(event) {
909 ok( event.timeStamp, "assert event.timeStamp is present" );