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 // Trigger both bound fn (1)
197 jQuery("#firstp").trigger("click.test.abc");
199 // Trigger one bound fn (1)
200 jQuery("#firstp").trigger("click.abc");
202 // Trigger two bound fn (2)
203 jQuery("#firstp").trigger("click.test");
205 // Remove only the one fn
206 jQuery("#firstp").unbind("click.abc");
208 // Trigger the remaining fn (1)
209 jQuery("#firstp").trigger("click");
211 // Remove the remaining fn
212 jQuery("#firstp").unbind(".test");
214 // Trigger the remaining fn (1)
215 jQuery("#firstp").trigger("custom");
218 test("bind(), with different this object", function() {
220 var thisObject = { myThis: true },
221 data = { myData: true },
222 handler1 = function( event ) {
223 equals( this, thisObject, "bind() with different this object" );
225 handler2 = function( event ) {
226 equals( this, thisObject, "bind() with different this object and data" );
227 equals( event.data, data, "bind() with different this object and data" );
231 .bind("click", handler1, thisObject).click().unbind("click", handler1)
232 .bind("click", data, handler2, thisObject).click().unbind("click", handler2);
234 ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
237 test("unbind(type)", function() {
240 var $elem = jQuery("#firstp"),
244 ok( false, message );
247 message = "unbind passing function";
248 $elem.bind('error', error).unbind('error',error).triggerHandler('error');
250 message = "unbind all from event";
251 $elem.bind('error', error).unbind('error').triggerHandler('error');
253 message = "unbind all";
254 $elem.bind('error', error).unbind().triggerHandler('error');
256 message = "unbind many with function";
257 $elem.bind('error error2',error)
258 .unbind('error error2', error )
259 .trigger('error').triggerHandler('error2');
261 message = "unbind many"; // #3538
262 $elem.bind('error error2',error)
263 .unbind('error error2')
264 .trigger('error').triggerHandler('error2');
266 message = "unbind without a type or handler";
267 $elem.bind("error error2.test",error)
269 .trigger("error").triggerHandler("error2");
272 test("unbind(eventObject)", function() {
275 var $elem = jQuery("#firstp"),
278 function assert( expected ){
280 $elem.trigger('foo').triggerHandler('bar');
281 equals( num, expected, "Check the right handlers are triggered" );
285 // This handler shouldn't be unbound
286 .bind('foo', function(){
289 .bind('foo', function(e){
294 .bind('bar', function(){
308 test("hover()", function() {
310 handler1 = function( event ) { ++times; },
311 handler2 = function( event ) { ++times; };
314 .hover(handler1, handler2)
315 .mouseenter().mouseleave()
316 .unbind("mouseenter", handler1)
317 .unbind("mouseleave", handler2)
319 .mouseenter().mouseleave()
320 .unbind("mouseenter mouseleave", handler1)
321 .mouseenter().mouseleave();
323 equals( times, 4, "hover handlers fired" );
326 test("trigger() shortcuts", function() {
328 jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
329 var close = jQuery('spanx', this); // same with jQuery(this).find('span');
330 equals( close.length, 0, "Context element does not exist, length must be zero" );
331 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
335 jQuery("#check1").click(function() {
336 ok( true, "click event handler for checkbox gets fired twice, see #815" );
340 jQuery('#firstp')[0].onclick = function(event) {
343 jQuery('#firstp').click();
344 equals( counter, 1, "Check that click, triggers onclick event handler also" );
346 var clickCounter = 0;
347 jQuery('#simon1')[0].onclick = function(event) {
350 jQuery('#simon1').click();
351 equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
353 jQuery('<img />').load(function(){
354 ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
358 test("trigger() bubbling", function() {
361 var doc = 0, html = 0, body = 0, main = 0, ap = 0;
363 jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
364 jQuery("html").bind("click", function(e){ html++; });
365 jQuery("body").bind("click", function(e){ body++; });
366 jQuery("#main").bind("click", function(e){ main++; });
367 jQuery("#ap").bind("click", function(){ ap++; return false; });
369 jQuery("html").trigger("click");
370 equals( doc, 1, "HTML bubble" );
371 equals( html, 1, "HTML bubble" );
373 jQuery("body").trigger("click");
374 equals( doc, 2, "Body bubble" );
375 equals( html, 2, "Body bubble" );
376 equals( body, 1, "Body bubble" );
378 jQuery("#main").trigger("click");
379 equals( doc, 3, "Main bubble" );
380 equals( html, 3, "Main bubble" );
381 equals( body, 2, "Main bubble" );
382 equals( main, 1, "Main bubble" );
384 jQuery("#ap").trigger("click");
385 equals( doc, 3, "ap bubble" );
386 equals( html, 3, "ap bubble" );
387 equals( body, 2, "ap bubble" );
388 equals( main, 1, "ap bubble" );
389 equals( ap, 1, "ap bubble" );
392 test("trigger(type, [data], [fn])", function() {
395 var handler = function(event, a, b, c) {
396 equals( event.type, "click", "check passed data" );
397 equals( a, 1, "check passed data" );
398 equals( b, "2", "check passed data" );
399 equals( c, "abc", "check passed data" );
403 var $elem = jQuery("#firstp");
405 // Simulate a "native" click
406 $elem[0].click = function(){
407 ok( true, "Native call was triggered" );
410 // Triggers handlrs and native
412 $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
414 // Simulate a "native" click
415 $elem[0].click = function(){
416 ok( false, "Native call was triggered" );
419 // Trigger only the handlers (no native)
421 equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
425 jQuery('#form input:first').hide().trigger('focus');
429 ok( pass, "Trigger focus on hidden element" );
433 jQuery('table:first').bind('test:test', function(){}).trigger('test:test');
437 ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
440 test("trigger(eventObject, [data], [fn])", function() {
443 var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
444 $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
446 var event = jQuery.Event("noNew");
447 ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
448 equals( event.type, "noNew", "Verify its type" );
450 equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
451 equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
452 equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
454 event.preventDefault();
455 equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
456 event.stopPropagation();
457 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
459 event.isPropagationStopped = function(){ return false };
460 event.stopImmediatePropagation();
461 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
462 equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
464 $parent.bind('foo',function(e){
466 equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
467 equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
468 equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
469 equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
472 // test with an event object
473 event = new jQuery.Event("foo");
474 event.secret = 'boo!';
475 $child.trigger(event);
477 // test with a literal object
478 $child.trigger({type:'foo', secret:'boo!'});
483 ok( false, "This assertion shouldn't be reached");
486 $parent.bind('foo', error );
488 $child.bind('foo',function(e, a, b, c ){
489 equals( arguments.length, 4, "Check arguments length");
490 equals( a, 1, "Check first custom argument");
491 equals( b, 2, "Check second custom argument");
492 equals( c, 3, "Check third custom argument");
494 equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
495 equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
496 equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
499 e.stopImmediatePropagation();
504 // We should add this back in when we want to test the order
505 // in which event handlers are iterated.
506 //$child.bind('foo', error );
508 event = new jQuery.Event("foo");
509 $child.trigger( event, [1,2,3] ).unbind();
510 equals( event.result, "result", "Check event.result attribute");
512 // Will error if it bubbles
513 $child.triggerHandler('foo');
516 $parent.unbind().remove();
519 test("jQuery.Event.currentTarget", function(){
523 $elem = jQuery('<button>a</button>').click(function(e){
524 equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
528 $elem.trigger('click');
534 test("toggle(Function, Function, ...)", function() {
538 fn1 = function(e) { count++; },
539 fn2 = function(e) { count--; },
540 preventDefault = function(e) { e.preventDefault() },
541 link = jQuery('#mark');
542 link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
543 equals( count, 1, "Check for toggle(fn, fn)" );
545 jQuery("#firstp").toggle(function () {
546 equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
547 }, function() {}).trigger("click", [ 1, 2, 3 ]);
550 jQuery("#simon1").one("click", function() {
551 ok( true, "Execute event only once" );
552 jQuery(this).toggle(function() {
553 equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
555 equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
558 }).click().click().click();
573 var $div = jQuery("<div> </div>").toggle( fns[0], fns[1], fns[2] );
575 equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
577 equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
579 equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
581 equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
583 equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
585 $div.unbind('click',fns[0]);
586 var data = jQuery.data( $div[0], 'events' );
587 ok( !data, "Unbinding one function from toggle unbinds them all");
590 test(".live()/.die()", function() {
593 var submit = 0, div = 0, livea = 0, liveb = 0;
595 jQuery("div").live("submit", function(){ submit++; return false; });
596 jQuery("div").live("click", function(){ div++; });
597 jQuery("div#nothiddendiv").live("click", function(){ livea++; });
598 jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
600 // Nothing should trigger on the body
601 jQuery("body").trigger("click");
602 equals( submit, 0, "Click on body" );
603 equals( div, 0, "Click on body" );
604 equals( livea, 0, "Click on body" );
605 equals( liveb, 0, "Click on body" );
607 // This should trigger two events
608 jQuery("div#nothiddendiv").trigger("click");
609 equals( submit, 0, "Click on div" );
610 equals( div, 1, "Click on div" );
611 equals( livea, 1, "Click on div" );
612 equals( liveb, 0, "Click on div" );
614 // This should trigger three events (w/ bubbling)
615 jQuery("div#nothiddendivchild").trigger("click");
616 equals( submit, 0, "Click on inner div" );
617 equals( div, 2, "Click on inner div" );
618 equals( livea, 2, "Click on inner div" );
619 equals( liveb, 1, "Click on inner div" );
621 // This should trigger one submit
622 jQuery("div#nothiddendivchild").trigger("submit");
623 equals( submit, 1, "Submit on div" );
624 equals( div, 2, "Submit on div" );
625 equals( livea, 2, "Submit on div" );
626 equals( liveb, 1, "Submit on div" );
628 // Make sure no other events were removed in the process
629 jQuery("div#nothiddendivchild").trigger("click");
630 equals( submit, 1, "die Click on inner div" );
631 equals( div, 3, "die Click on inner div" );
632 equals( livea, 3, "die Click on inner div" );
633 equals( liveb, 2, "die Click on inner div" );
635 // Now make sure that the removal works
636 jQuery("div#nothiddendivchild").die("click");
637 jQuery("div#nothiddendivchild").trigger("click");
638 equals( submit, 1, "die Click on inner div" );
639 equals( div, 4, "die Click on inner div" );
640 equals( livea, 4, "die Click on inner div" );
641 equals( liveb, 2, "die Click on inner div" );
643 // Make sure that the click wasn't removed too early
644 jQuery("div#nothiddendiv").trigger("click");
645 equals( submit, 1, "die Click on inner div" );
646 equals( div, 5, "die Click on inner div" );
647 equals( livea, 5, "die Click on inner div" );
648 equals( liveb, 2, "die Click on inner div" );
650 // Make sure that stopPropgation doesn't stop live events
651 jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
652 jQuery("div#nothiddendivchild").trigger("click");
653 equals( submit, 1, "stopPropagation Click on inner div" );
654 equals( div, 6, "stopPropagation Click on inner div" );
655 equals( livea, 6, "stopPropagation Click on inner div" );
656 equals( liveb, 3, "stopPropagation Click on inner div" );
658 jQuery("div#nothiddendivchild").die("click");
659 jQuery("div#nothiddendiv").die("click");
660 jQuery("div").die("click");
661 jQuery("div").die("submit");
663 // Test binding with a different context
664 var clicked = 0, container = jQuery('#main')[0];
665 jQuery("#foo", container).live("click", function(e){ clicked++; });
666 jQuery("div").trigger('click');
667 jQuery("#foo").trigger('click');
668 jQuery("#main").trigger('click');
669 jQuery("body").trigger('click');
670 equals( clicked, 2, "live with a context" );
672 // Make sure the event is actually stored on the context
673 ok( jQuery.data(container, "events").live, "live with a context" );
675 // Test unbinding with a different context
676 jQuery("#foo", container).die("click");
677 jQuery("#foo").trigger('click');
678 equals( clicked, 2, "die with a context");
680 // Test binding with event data
681 jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); });
682 jQuery("#foo").trigger("click").die("click");
684 // Test binding with trigger data
685 jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); });
686 jQuery("#foo").trigger("click", true).die("click");
688 // Test binding with different this object
689 jQuery("#foo").live("click", function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" });
690 jQuery("#foo").trigger("click").die("click");
692 // Test binding with different this object, event data, and trigger data
693 jQuery("#foo").live("click", true, function(e, data){
694 equals( e.data, true, "live with with different this object, event data, and trigger data" );
695 equals( this.foo, "bar", "live with with different this object, event data, and trigger data" );
696 equals( data, true, "live with with different this object, event data, and trigger data")
698 jQuery("#foo").trigger("click", true).die("click");
700 // Verify that return false prevents default action
701 jQuery("#anchor2").live("click", function(){ return false; });
702 var hash = window.location.hash;
703 jQuery("#anchor2").trigger("click");
704 equals( window.location.hash, hash, "return false worked" );
705 jQuery("#anchor2").die("click");
707 // Verify that .preventDefault() prevents default action
708 jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
709 var hash = window.location.hash;
710 jQuery("#anchor2").trigger("click");
711 equals( window.location.hash, hash, "e.preventDefault() worked" );
712 jQuery("#anchor2").die("click");
714 // Test binding the same handler to multiple points
716 function callback(){ called++; return false; }
718 jQuery("#nothiddendiv").live("click", callback);
719 jQuery("#anchor2").live("click", callback);
721 jQuery("#nothiddendiv").trigger("click");
722 equals( called, 1, "Verify that only one click occurred." );
724 jQuery("#anchor2").trigger("click");
725 equals( called, 2, "Verify that only one click occurred." );
727 // Make sure that only one callback is removed
728 jQuery("#anchor2").die("click", callback);
730 jQuery("#nothiddendiv").trigger("click");
731 equals( called, 3, "Verify that only one click occurred." );
733 jQuery("#anchor2").trigger("click");
734 equals( called, 3, "Verify that no click occurred." );
736 // Make sure that it still works if the selector is the same,
737 // but the event type is different
738 jQuery("#nothiddendiv").live("foo", callback);
741 jQuery("#nothiddendiv").die("click", callback);
743 jQuery("#nothiddendiv").trigger("click");
744 equals( called, 3, "Verify that no click occurred." );
746 jQuery("#nothiddendiv").trigger("foo");
747 equals( called, 4, "Verify that one foo occurred." );
750 jQuery("#nothiddendiv").die("foo", callback);
752 // Make sure we don't loose the target by DOM modifications
753 // after the bubble already reached the liveHandler
754 var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
756 jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
757 jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
759 jQuery("#nothiddendiv span").click();
760 equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
761 equals( livec, 1, "Verify that second handler occurred even with nuked target." );
764 jQuery("#nothiddendivchild").die("click");
766 // Verify that .live() ocurs and cancel buble in the same order as
767 // we would expect .bind() and .click() without delegation
768 var lived = 0, livee = 0;
770 // bind one pair in one order
771 jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
772 jQuery('span#liveSpan1').live('click', function(){ livee++; });
774 jQuery('span#liveSpan1 a').click();
775 equals( lived, 1, "Verify that only one first handler occurred." );
776 equals( livee, 0, "Verify that second handler don't." );
778 // and one pair in inverse
779 jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
780 jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; });
782 jQuery('span#liveSpan2 a').click();
783 equals( lived, 2, "Verify that only one first handler occurred." );
784 equals( livee, 0, "Verify that second handler don't." );
787 jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click");
789 // Test this, target and currentTarget are correct
790 jQuery('span#liveSpan1').live('click', function(e){
791 equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
792 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
793 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
796 jQuery('span#liveSpan1 a').click();
798 jQuery('span#liveSpan1').die('click');
801 test("live with submit", function() {
804 jQuery("#testForm").live("submit", function() {
809 jQuery("#testForm input[name=sub1]")[0].click();
810 jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13});
814 jQuery("#testForm").die("submit");
817 test("live with focus/blur", function(){
821 jQuery("<input type='text' id='livefb' />").appendTo("body");
823 var $child = jQuery("#livefb"),
831 $child.live("focus", worked);
832 $child.live("blur", worked);
837 ok(true, "Test live() with focus event");
839 ok(true, "Cannot test focus because the window isn't focused");
843 ok( true, "Test live() with blur event");
845 ok(true, "Cannot test blur because the window isn't focused");
848 $child.die("focus", worked);
849 $child.die("blur", worked);
851 window.scrollTo(0,0);
854 test("Non DOM element events", function() {
858 .bind('nonelementglobal', function(e) {
859 ok( true, "Global event on non-DOM annonymos object triggered" );
865 .bind('nonelementobj', function(e) {
866 ok( true, "Event on non-DOM object triggered" );
867 }).bind('nonelementglobal', function() {
868 ok( true, "Global event on non-DOM object triggered" );
871 jQuery(o).trigger('nonelementobj');
872 jQuery.event.trigger('nonelementglobal');
876 test("jQuery(function($) {})", function() {
879 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");
884 test("event properties", function() {
886 jQuery("#simon1").click(function(event) {
887 ok( event.timeStamp, "assert event.timeStamp is present" );