fix for #4234. hover can take one function to use for both enter and leave.
[jquery.git] / test / unit / event.js
1 module("event");
2
3 test("bind(), with data", function() {
4         expect(3);
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" );
8         };
9         jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
10
11         ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
12 });
13
14 test("bind(), with data, trigger with data", function() {
15         expect(4);
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" );
21         };
22         jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
23 });
24
25 test("bind(), multiple events at once", function() {
26         expect(2);
27         var clickCounter = 0,
28                 mouseoverCounter = 0;
29         var handler = function(event) {
30                 if (event.type == "click")
31                         clickCounter += 1;
32                 else if (event.type == "mouseover")
33                         mouseoverCounter += 1;
34         };
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" );
38 });
39
40 test("bind(), no data", function() {
41         expect(1);
42         var handler = function(event) {
43                 ok ( !event.data, "Check that no data is added to the event object" );
44         };
45         jQuery("#firstp").bind("click", handler).trigger("click");
46 });
47
48 test("bind(), iframes", function() {
49         // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
50         var doc = jQuery("#loadediframe").contents();
51         
52         jQuery("div", doc).bind("click", function() {
53                 ok( true, "Binding to element inside iframe" );
54         }).click().unbind('click');
55 });
56
57 test("bind(), trigger change on select", function() {
58         expect(3);
59         var counter = 0;
60         function selectOnChange(event) {
61                 equals( event.data, counter++, "Event.data is not a global event object" );
62         };
63         jQuery("#form select").each(function(i){
64                 jQuery(this).bind('change', i, selectOnChange);
65         }).trigger('change');
66 });
67
68 test("bind(), namespaced events, cloned events", function() {
69         expect(6);
70
71         jQuery("#firstp").bind("custom.test",function(e){
72                 ok(true, "Custom event triggered");
73         });
74
75         jQuery("#firstp").bind("click",function(e){
76                 ok(true, "Normal click triggered");
77         });
78
79         jQuery("#firstp").bind("click.test",function(e){
80                 ok(true, "Namespaced click triggered");
81         });
82
83         // Trigger both bound fn (2)
84         jQuery("#firstp").trigger("click");
85
86         // Trigger one bound fn (1)
87         jQuery("#firstp").trigger("click.test");
88
89         // Remove only the one fn
90         jQuery("#firstp").unbind("click.test");
91
92         // Trigger the remaining fn (1)
93         jQuery("#firstp").trigger("click");
94
95         // Remove the remaining fn
96         jQuery("#firstp").unbind(".test");
97
98         // Trigger the remaining fn (0)
99         jQuery("#firstp").trigger("custom");
100
101         // using contents will get comments regular, text, and comment nodes
102         jQuery("#nonnodes").contents().bind("tester", function () {
103                 equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
104         }).trigger("tester");
105
106         // Make sure events stick with appendTo'd elements (which are cloned) #2027
107         jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
108         ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
109 });
110
111 test("bind(), multi-namespaced events", function() {
112         expect(6);
113         
114         var order = [
115                 "click.test.abc",
116                 "click.test.abc",
117                 "click.test",
118                 "click.test.abc",
119                 "click.test",
120                 "custom.test2"
121         ];
122         
123         function check(name, msg){
124                 same(name, order.shift(), msg);
125         }
126
127         jQuery("#firstp").bind("custom.test",function(e){
128                 check("custom.test", "Custom event triggered");
129         });
130
131         jQuery("#firstp").bind("custom.test2",function(e){
132                 check("custom.test2", "Custom event triggered");
133         });
134
135         jQuery("#firstp").bind("click.test",function(e){
136                 check("click.test", "Normal click triggered");
137         });
138
139         jQuery("#firstp").bind("click.test.abc",function(e){
140                 check("click.test.abc", "Namespaced click triggered");
141         });
142
143         // Trigger both bound fn (1)
144         jQuery("#firstp").trigger("click.test.abc");
145
146         // Trigger one bound fn (1)
147         jQuery("#firstp").trigger("click.abc");
148
149         // Trigger two bound fn (2)
150         jQuery("#firstp").trigger("click.test");
151
152         // Remove only the one fn
153         jQuery("#firstp").unbind("click.abc");
154
155         // Trigger the remaining fn (1)
156         jQuery("#firstp").trigger("click");
157
158         // Remove the remaining fn
159         jQuery("#firstp").unbind(".test");
160
161         // Trigger the remaining fn (1)
162         jQuery("#firstp").trigger("custom");
163 });
164
165 test("unbind(type)", function() {
166         expect( 0 );
167         
168         var $elem = jQuery("#firstp"),
169                 message;
170
171         function error(){
172                 ok( false, message );
173         }
174         
175         message = "unbind passing function";
176         $elem.bind('error', error).unbind('error',error).triggerHandler('error');
177         
178         message = "unbind all from event";
179         $elem.bind('error', error).unbind('error').triggerHandler('error');
180         
181         message = "unbind all";
182         $elem.bind('error', error).unbind().triggerHandler('error');
183         
184         message = "unbind many with function";
185         $elem.bind('error error2',error)
186                  .unbind('error error2', error )
187                  .trigger('error').triggerHandler('error2');
188
189         message = "unbind many"; // #3538
190         $elem.bind('error error2',error)
191                  .unbind('error error2')
192                  .trigger('error').triggerHandler('error2');
193         
194         message = "unbind without a type or handler";
195         $elem.bind("error error2.test",error)
196                  .unbind()
197                  .trigger("error").triggerHandler("error2");
198 });
199
200 test("unbind(eventObject)", function() {
201         expect(4);
202         
203         var $elem = jQuery("#firstp"),
204                 num;
205
206         function assert( expected ){
207                 num = 0;
208                 $elem.trigger('foo').triggerHandler('bar');
209                 equals( num, expected, "Check the right handlers are triggered" );
210         }
211         
212         $elem
213                 // This handler shouldn't be unbound
214                 .bind('foo', function(){
215                         num += 1;
216                 })
217                 .bind('foo', function(e){
218                         $elem.unbind( e )
219                         num += 2;
220                 })
221                 // Neither this one
222                 .bind('bar', function(){
223                         num += 4;
224                 });
225                 
226         assert( 7 );
227         assert( 5 );
228         
229         $elem.unbind('bar');
230         assert( 1 );
231         
232         $elem.unbind(); 
233         assert( 0 );
234 });
235
236 test("hover()", function() {
237         var times = 0,
238                 handler1 = function( event ) { ++times; },
239                 handler2 = function( event ) { ++times; };
240
241         jQuery("#firstp")
242                 .hover(handler1, handler2)
243                 .mouseenter().mouseleave()
244                 .unbind("mouseenter", handler1)
245                 .unbind("mouseleave", handler2)
246                 .hover(handler1)
247                 .mouseenter().mouseleave()
248                 .unbind("mouseenter mouseleave", handler1)
249                 .mouseenter().mouseleave();
250
251         equals( times, 4, "hover handlers fired" );
252 });
253
254 test("trigger() shortcuts", function() {
255         expect(6);
256         jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
257                 var close = jQuery('spanx', this); // same with jQuery(this).find('span');
258                 equals( close.length, 0, "Context element does not exist, length must be zero" );
259                 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
260                 return false;
261         }).click();
262         
263         jQuery("#check1").click(function() {
264                 ok( true, "click event handler for checkbox gets fired twice, see #815" );
265         }).click();
266         
267         var counter = 0;
268         jQuery('#firstp')[0].onclick = function(event) {
269                 counter++;
270         };
271         jQuery('#firstp').click();
272         equals( counter, 1, "Check that click, triggers onclick event handler also" );
273         
274         var clickCounter = 0;
275         jQuery('#simon1')[0].onclick = function(event) {
276                 clickCounter++;
277         };
278         jQuery('#simon1').click();
279         equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
280         
281         jQuery('<img />').load(function(){
282                 ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
283         }).load();
284 });
285
286 test("trigger() bubbling", function() {
287         expect(14);
288
289         var doc = 0, html = 0, body = 0, main = 0, ap = 0;
290
291         jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
292         jQuery("html").bind("click", function(e){ html++; });
293         jQuery("body").bind("click", function(e){ body++; });
294         jQuery("#main").bind("click", function(e){ main++; });
295         jQuery("#ap").bind("click", function(){ ap++; return false; });
296
297         jQuery("html").trigger("click");
298         equals( doc, 1, "HTML bubble" );
299         equals( html, 1, "HTML bubble" );
300
301         jQuery("body").trigger("click");
302         equals( doc, 2, "Body bubble" );
303         equals( html, 2, "Body bubble" );
304         equals( body, 1, "Body bubble" );
305
306         jQuery("#main").trigger("click");
307         equals( doc, 3, "Main bubble" );
308         equals( html, 3, "Main bubble" );
309         equals( body, 2, "Main bubble" );
310         equals( main, 1, "Main bubble" );
311
312         jQuery("#ap").trigger("click");
313         equals( doc, 3, "ap bubble" );
314         equals( html, 3, "ap bubble" );
315         equals( body, 2, "ap bubble" );
316         equals( main, 1, "ap bubble" );
317         equals( ap, 1, "ap bubble" );
318 });
319
320 test("trigger(type, [data], [fn])", function() {
321         expect(11);
322
323         var handler = function(event, a, b, c) {
324                 equals( event.type, "click", "check passed data" );
325                 equals( a, 1, "check passed data" );
326                 equals( b, "2", "check passed data" );
327                 equals( c, "abc", "check passed data" );
328                 return "test";
329         };
330
331         var $elem = jQuery("#firstp");
332
333         // Simulate a "native" click
334         $elem[0].click = function(){
335                 ok( true, "Native call was triggered" );
336         };
337
338         // Triggers handlrs and native
339         // Trigger 5
340         $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
341
342         // Simulate a "native" click
343         $elem[0].click = function(){
344                 ok( false, "Native call was triggered" );
345         };
346
347         // Trigger only the handlers (no native)
348         // Triggers 5
349         equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
350
351         var pass = true;
352         try {
353                 jQuery('#form input:first').hide().trigger('focus');
354         } catch(e) {
355                 pass = false;
356         }
357         ok( pass, "Trigger focus on hidden element" );
358 });
359
360 test("trigger(eventObject, [data], [fn])", function() {
361         expect(25);
362         
363         var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
364                 $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
365         
366         var event = jQuery.Event("noNew");      
367         ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
368         equals( event.type, "noNew", "Verify its type" );
369         
370         equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
371         equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
372         equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
373         
374         event.preventDefault();
375         equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
376         event.stopPropagation();
377         equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
378         
379         event.isPropagationStopped = function(){ return false };
380         event.stopImmediatePropagation();
381         equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
382         equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
383         
384         $parent.bind('foo',function(e){
385                 // Tries bubbling
386                 equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
387                 equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
388                 equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
389                 equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
390         });
391         
392         // test with an event object
393         event = new jQuery.Event("foo");
394         event.secret = 'boo!';
395         $child.trigger(event);
396         
397         // test with a literal object
398         $child.trigger({type:'foo', secret:'boo!'});
399         
400         $parent.unbind();
401
402         function error(){
403                 ok( false, "This assertion shouldn't be reached");
404         }
405         
406         $parent.bind('foo', error );
407         
408         $child.bind('foo',function(e, a, b, c ){
409                 equals( arguments.length, 4, "Check arguments length");
410                 equals( a, 1, "Check first custom argument");
411                 equals( b, 2, "Check second custom argument");
412                 equals( c, 3, "Check third custom argument");
413                 
414                 equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
415                 equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
416                 equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
417                 
418                 // Skips both errors
419                 e.stopImmediatePropagation();
420                 
421                 return "result";
422         });
423         
424         // We should add this back in when we want to test the order
425         // in which event handlers are iterated.
426         //$child.bind('foo', error );
427         
428         event = new jQuery.Event("foo");
429         $child.trigger( event, [1,2,3] ).unbind();
430         equals( event.result, "result", "Check event.result attribute");
431         
432         // Will error if it bubbles
433         $child.triggerHandler('foo');
434         
435         $child.unbind();
436         $parent.unbind().remove();
437 });
438
439 test("jQuery.Event.currentTarget", function(){
440         expect(1);
441         
442         var counter = 0,
443                 $elem = jQuery('<button>a</button>').click(function(e){
444                 equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
445         });
446         
447         // Fake event
448         $elem.trigger('click');
449         
450         // Cleanup
451         $elem.unbind();
452 });
453
454 test("toggle(Function, Function, ...)", function() {
455         expect(11);
456         
457         var count = 0,
458                 fn1 = function(e) { count++; },
459                 fn2 = function(e) { count--; },
460                 preventDefault = function(e) { e.preventDefault() },
461                 link = jQuery('#mark');
462         link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
463         equals( count, 1, "Check for toggle(fn, fn)" );
464
465         jQuery("#firstp").toggle(function () {
466                 equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
467         }, function() {}).trigger("click", [ 1, 2, 3 ]);
468
469         var first = 0;
470         jQuery("#simon1").one("click", function() {
471                 ok( true, "Execute event only once" );
472                 jQuery(this).toggle(function() {
473                         equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
474                 }, function() {
475                         equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
476                 });
477                 return false;
478         }).click().click().click();
479         
480         var turn = 0;
481         var fns = [
482                 function(){
483                         turn = 1;
484                 },
485                 function(){
486                         turn = 2;
487                 },
488                 function(){
489                         turn = 3;
490                 }
491         ];
492         
493         var $div = jQuery("<div>&nbsp;</div>").toggle( fns[0], fns[1], fns[2] );
494         $div.click();
495         equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
496         $div.click();
497         equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
498         $div.click();
499         equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
500         $div.click();
501         equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
502         $div.click();
503         equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
504         
505         $div.unbind('click',fns[0]);
506         var data = jQuery.data( $div[0], 'events' );
507         ok( !data, "Unbinding one function from toggle unbinds them all");
508 });
509
510 test(".live()/.die()", function() {
511         expect(54);
512
513         var submit = 0, div = 0, livea = 0, liveb = 0;
514
515         jQuery("div").live("submit", function(){ submit++; return false; });
516         jQuery("div").live("click", function(){ div++; });
517         jQuery("div#nothiddendiv").live("click", function(){ livea++; });
518         jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
519
520         // Nothing should trigger on the body
521         jQuery("body").trigger("click");
522         equals( submit, 0, "Click on body" );
523         equals( div, 0, "Click on body" );
524         equals( livea, 0, "Click on body" );
525         equals( liveb, 0, "Click on body" );
526
527         // This should trigger two events
528         jQuery("div#nothiddendiv").trigger("click");
529         equals( submit, 0, "Click on div" );
530         equals( div, 1, "Click on div" );
531         equals( livea, 1, "Click on div" );
532         equals( liveb, 0, "Click on div" );
533
534         // This should trigger three events (w/ bubbling)
535         jQuery("div#nothiddendivchild").trigger("click");
536         equals( submit, 0, "Click on inner div" );
537         equals( div, 2, "Click on inner div" );
538         equals( livea, 2, "Click on inner div" );
539         equals( liveb, 1, "Click on inner div" );
540
541         // This should trigger one submit
542         jQuery("div#nothiddendivchild").trigger("submit");
543         equals( submit, 1, "Submit on div" );
544         equals( div, 2, "Submit on div" );
545         equals( livea, 2, "Submit on div" );
546         equals( liveb, 1, "Submit on div" );
547
548         // Make sure no other events were removed in the process
549         jQuery("div#nothiddendivchild").trigger("click");
550         equals( submit, 1, "die Click on inner div" );
551         equals( div, 3, "die Click on inner div" );
552         equals( livea, 3, "die Click on inner div" );
553         equals( liveb, 2, "die Click on inner div" );
554
555         // Now make sure that the removal works
556         jQuery("div#nothiddendivchild").die("click");
557         jQuery("div#nothiddendivchild").trigger("click");
558         equals( submit, 1, "die Click on inner div" );
559         equals( div, 4, "die Click on inner div" );
560         equals( livea, 4, "die Click on inner div" );
561         equals( liveb, 2, "die Click on inner div" );
562
563         // Make sure that the click wasn't removed too early
564         jQuery("div#nothiddendiv").trigger("click");
565         equals( submit, 1, "die Click on inner div" );
566         equals( div, 5, "die Click on inner div" );
567         equals( livea, 5, "die Click on inner div" );
568         equals( liveb, 2, "die Click on inner div" );
569
570         // Make sure that stopPropgation doesn't stop live events
571         jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
572         jQuery("div#nothiddendivchild").trigger("click");
573         equals( submit, 1, "stopPropagation Click on inner div" );
574         equals( div, 6, "stopPropagation Click on inner div" );
575         equals( livea, 6, "stopPropagation Click on inner div" );
576         equals( liveb, 3, "stopPropagation Click on inner div" );
577
578         jQuery("div#nothiddendivchild").die("click");
579         jQuery("div#nothiddendiv").die("click");
580         jQuery("div").die("click");
581         jQuery("div").die("submit");
582
583         // Test binding with a different context
584         var clicked = 0, container = jQuery('#main')[0];
585         jQuery("#foo", container).live("click", function(e){ clicked++; });
586         jQuery("div").trigger('click');
587         jQuery("#foo").trigger('click');
588         jQuery("#main").trigger('click');
589         jQuery("body").trigger('click');
590         equals( clicked, 2, "live with a context" );
591
592         // Make sure the event is actually stored on the context
593         ok( jQuery.data(container, "events").live, "live with a context" );
594
595         // Test unbinding with a different context
596         jQuery("#foo", container).die("click");
597         jQuery("#foo").trigger('click');
598         equals( clicked, 2, "die with a context");
599
600         // Test binding with event data
601         jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); });
602         jQuery("#foo").trigger("click").die("click");
603
604         // Test binding with trigger data
605         jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); });
606         jQuery("#foo").trigger("click", true).die("click");
607
608         // Verify that return false prevents default action
609         jQuery("#anchor2").live("click", function(){ return false; });
610         var hash = window.location.hash;
611         jQuery("#anchor2").trigger("click");
612         equals( window.location.hash, hash, "return false worked" );
613         jQuery("#anchor2").die("click");
614
615         // Verify that .preventDefault() prevents default action
616         jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
617         var hash = window.location.hash;
618         jQuery("#anchor2").trigger("click");
619         equals( window.location.hash, hash, "e.preventDefault() worked" );
620         jQuery("#anchor2").die("click");
621
622         // Test binding the same handler to multiple points
623         var called = 0;
624         function callback(){ called++; return false; }
625
626         jQuery("#nothiddendiv").live("click", callback);
627         jQuery("#anchor2").live("click", callback);
628
629         jQuery("#nothiddendiv").trigger("click");
630         equals( called, 1, "Verify that only one click occurred." );
631
632         jQuery("#anchor2").trigger("click");
633         equals( called, 2, "Verify that only one click occurred." );
634
635         // Make sure that only one callback is removed
636         jQuery("#anchor2").die("click", callback);
637
638         jQuery("#nothiddendiv").trigger("click");
639         equals( called, 3, "Verify that only one click occurred." );
640
641         jQuery("#anchor2").trigger("click");
642         equals( called, 3, "Verify that no click occurred." );
643
644         // Make sure that it still works if the selector is the same,
645         // but the event type is different
646         jQuery("#nothiddendiv").live("foo", callback);
647
648         // Cleanup
649         jQuery("#nothiddendiv").die("click", callback);
650
651         jQuery("#nothiddendiv").trigger("click");
652         equals( called, 3, "Verify that no click occurred." );
653
654         jQuery("#nothiddendiv").trigger("foo");
655         equals( called, 4, "Verify that one foo occurred." );
656
657         // Cleanup
658         jQuery("#nothiddendiv").die("foo", callback);
659         
660         // Make sure we don't loose the target by DOM modifications
661         // after the bubble already reached the liveHandler
662         var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
663         
664         jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
665         jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
666         
667         jQuery("#nothiddendiv span").click();
668         equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
669         equals( livec, 1, "Verify that second handler occurred even with nuked target." );
670         
671         // Cleanup
672         jQuery("#nothiddendivchild").die("click");
673
674         // Verify that .live() ocurs and cancel buble in the same order as
675         // we would expect .bind() and .click() without delegation
676         var lived = 0, livee = 0;
677         
678         // bind one pair in one order
679         jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
680         jQuery('span#liveSpan1').live('click', function(){ livee++; });
681
682         jQuery('span#liveSpan1 a').click();
683         equals( lived, 1, "Verify that only one first handler occurred." );
684         equals( livee, 0, "Verify that second handler don't." );
685
686         // and one pair in inverse
687         jQuery('#liveHandlerOrder span#liveSpan2').live('click', function(){ livee++; });
688         jQuery('#liveHandlerOrder span#liveSpan2 a').live('click', function(){ lived++; return false; });
689
690         jQuery('span#liveSpan2 a').click();
691         equals( lived, 2, "Verify that only one first handler occurred." );
692         equals( livee, 0, "Verify that second handler don't." );
693         
694         // Cleanup
695         jQuery("span#liveSpan1 a, span#liveSpan1, span#liveSpan2 a, span#liveSpan2").die("click");
696         
697         // Test this, target and currentTarget are correct
698         jQuery('span#liveSpan1').live('click', function(e){ 
699                 equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
700                 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
701                 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
702         });
703         
704         jQuery('span#liveSpan1 a').click();
705         
706         jQuery('span#liveSpan1').die('click');
707 });
708
709 test("Non DOM element events", function() {
710         expect(3);
711
712         jQuery({})
713                 .bind('nonelementglobal', function(e) {
714                         ok( true, "Global event on non-DOM annonymos object triggered" );
715                 });
716
717         var o = {};
718
719         jQuery(o)
720                 .bind('nonelementobj', function(e) {
721                         ok( true, "Event on non-DOM object triggered" );
722                 }).bind('nonelementglobal', function() {
723                         ok( true, "Global event on non-DOM object triggered" );
724                 });
725
726         jQuery(o).trigger('nonelementobj');
727         jQuery.event.trigger('nonelementglobal');
728 });
729
730 /*
731 test("jQuery(function($) {})", function() {
732         stop();
733         jQuery(function($) {
734                 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");
735                 start();
736         });
737 });
738
739 test("event properties", function() {
740         stop();
741         jQuery("#simon1").click(function(event) {
742                 ok( event.timeStamp, "assert event.timeStamp is present" );
743                 start();
744         }).click();
745 });
746 */