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(), multiple events at once and namespaces", function() {
45 var div = jQuery("<div/>").bind("focusin.a", function(e) {
46 equals( e.type, cur, "Verify right single event was fired." );
50 div.trigger("focusin.a");
52 div = jQuery("<div/>").bind("click mouseover", obj, function(e) {
53 equals( e.type, cur, "Verify right multi event was fired." );
54 equals( e.data, obj, "Make sure the data came in correctly." );
61 div.trigger("mouseover");
63 div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) {
64 equals( e.type, cur, "Verify right multi event was fired." );
68 div.trigger("focusin.a");
71 div.trigger("focusout.b");
74 test("bind(), namespace with special add", function() {
77 var div = jQuery("<div/>").bind("test", function(e) {
78 ok( true, "Test event fired." );
83 jQuery.event.special.test = {
84 _default: function(e) {
85 equals( this, document, "Make sure we're at the top of the chain." );
86 equals( e.type, "test", "And that we're still dealing with a test event." );
87 equals( e.target, div[0], "And that the target is correct." );
90 teardown: function(){},
91 add: function( handleObj ) {
92 var handler = handleObj.handler;
93 handleObj.handler = function(e) {
95 handler.apply( this, arguments );
101 div.bind("test.a", {x: 1}, function(e) {
102 ok( !!e.xyz, "Make sure that the data is getting passed through." );
103 equals( e.data.x, 1, "Make sure data is attached properly." );
106 div.bind("test.b", {x: 2}, function(e) {
107 ok( !!e.xyz, "Make sure that the data is getting passed through." );
108 equals( e.data.x, 2, "Make sure data is attached properly." );
115 div.trigger("test.a");
118 div.trigger("test.b");
121 test("bind(), no data", function() {
123 var handler = function(event) {
124 ok ( !event.data, "Check that no data is added to the event object" );
126 jQuery("#firstp").bind("click", handler).trigger("click");
129 test("bind/one/unbind(Object)", function(){
132 var clickCounter = 0, mouseoverCounter = 0;
133 function handler(event) {
134 if (event.type == "click")
136 else if (event.type == "mouseover")
140 function handlerWithData(event) {
141 if (event.type == "click")
142 clickCounter += event.data;
143 else if (event.type == "mouseover")
144 mouseoverCounter += event.data;
148 $elem.trigger("click").trigger("mouseover");
151 var $elem = jQuery("#firstp")
159 click:handlerWithData,
160 mouseover:handlerWithData
165 equals( clickCounter, 3, "bind(Object)" );
166 equals( mouseoverCounter, 3, "bind(Object)" );
169 equals( clickCounter, 4, "bind(Object)" );
170 equals( mouseoverCounter, 4, "bind(Object)" );
172 jQuery("#firstp").unbind({
178 equals( clickCounter, 4, "bind(Object)" );
179 equals( mouseoverCounter, 4, "bind(Object)" );
182 test("bind(), iframes", function() {
183 // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
184 var doc = jQuery("#loadediframe").contents();
186 jQuery("div", doc).bind("click", function() {
187 ok( true, "Binding to element inside iframe" );
188 }).click().unbind('click');
191 test("bind(), trigger change on select", function() {
194 function selectOnChange(event) {
195 equals( event.data, counter++, "Event.data is not a global event object" );
197 jQuery("#form select").each(function(i){
198 jQuery(this).bind('change', i, selectOnChange);
199 }).trigger('change');
202 test("bind(), namespaced events, cloned events", function() {
205 jQuery("#firstp").bind("custom.test",function(e){
206 ok(true, "Custom event triggered");
209 jQuery("#firstp").bind("click",function(e){
210 ok(true, "Normal click triggered");
213 jQuery("#firstp").bind("click.test",function(e){
214 ok(true, "Namespaced click triggered");
217 // Trigger both bound fn (2)
218 jQuery("#firstp").trigger("click");
220 // Trigger one bound fn (1)
221 jQuery("#firstp").trigger("click.test");
223 // Remove only the one fn
224 jQuery("#firstp").unbind("click.test");
226 // Trigger the remaining fn (1)
227 jQuery("#firstp").trigger("click");
229 // Remove the remaining fn
230 jQuery("#firstp").unbind(".test");
232 // Trigger the remaining fn (0)
233 jQuery("#firstp").trigger("custom");
235 // using contents will get comments regular, text, and comment nodes
236 jQuery("#nonnodes").contents().bind("tester", function () {
237 equals(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
238 }).trigger("tester");
240 // Make sure events stick with appendTo'd elements (which are cloned) #2027
241 jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("p");
242 ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
245 test("bind(), multi-namespaced events", function() {
257 function check(name, msg){
258 same(name, order.shift(), msg);
261 jQuery("#firstp").bind("custom.test",function(e){
262 check("custom.test", "Custom event triggered");
265 jQuery("#firstp").bind("custom.test2",function(e){
266 check("custom.test2", "Custom event triggered");
269 jQuery("#firstp").bind("click.test",function(e){
270 check("click.test", "Normal click triggered");
273 jQuery("#firstp").bind("click.test.abc",function(e){
274 check("click.test.abc", "Namespaced click triggered");
277 // Those would not trigger/unbind (#5303)
278 jQuery("#firstp").trigger("click.a.test");
279 jQuery("#firstp").unbind("click.a.test");
281 // Trigger both bound fn (1)
282 jQuery("#firstp").trigger("click.test.abc");
284 // Trigger one bound fn (1)
285 jQuery("#firstp").trigger("click.abc");
287 // Trigger two bound fn (2)
288 jQuery("#firstp").trigger("click.test");
290 // Remove only the one fn
291 jQuery("#firstp").unbind("click.abc");
293 // Trigger the remaining fn (1)
294 jQuery("#firstp").trigger("click");
296 // Remove the remaining fn
297 jQuery("#firstp").unbind(".test");
299 // Trigger the remaining fn (1)
300 jQuery("#firstp").trigger("custom");
303 test("bind(), with same function", function() {
306 var count = 0 , func = function(){
310 jQuery("#liveHandlerOrder").bind("foo.bar", func).bind("foo.zar", func);
311 jQuery("#liveHandlerOrder").trigger("foo.bar");
313 equals(count, 1, "Verify binding function with multiple namespaces." );
315 jQuery("#liveHandlerOrder").unbind("foo.bar", func).unbind("foo.zar", func);
316 jQuery("#liveHandlerOrder").trigger("foo.bar");
318 equals(count, 1, "Verify that removing events still work." );
321 test("bind(), make sure order is maintained", function() {
324 var elem = jQuery("#firstp"), log = [], check = [];
326 for ( var i = 0; i < 100; i++ ) (function(i){
327 elem.bind( "click", function(){
334 elem.trigger("click");
336 equals( log.join(","), check.join(","), "Make sure order was maintained." );
338 elem.unbind("click");
341 test("bind(), with different this object", function() {
343 var thisObject = { myThis: true },
344 data = { myData: true },
345 handler1 = function( event ) {
346 equals( this, thisObject, "bind() with different this object" );
348 handler2 = function( event ) {
349 equals( this, thisObject, "bind() with different this object and data" );
350 equals( event.data, data, "bind() with different this object and data" );
354 .bind("click", jQuery.proxy(handler1, thisObject)).click().unbind("click", handler1)
355 .bind("click", data, jQuery.proxy(handler2, thisObject)).click().unbind("click", handler2);
357 ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
360 test("unbind(type)", function() {
363 var $elem = jQuery("#firstp"),
367 ok( false, message );
370 message = "unbind passing function";
371 $elem.bind('error', error).unbind('error',error).triggerHandler('error');
373 message = "unbind all from event";
374 $elem.bind('error', error).unbind('error').triggerHandler('error');
376 message = "unbind all";
377 $elem.bind('error', error).unbind().triggerHandler('error');
379 message = "unbind many with function";
380 $elem.bind('error error2',error)
381 .unbind('error error2', error )
382 .trigger('error').triggerHandler('error2');
384 message = "unbind many"; // #3538
385 $elem.bind('error error2',error)
386 .unbind('error error2')
387 .trigger('error').triggerHandler('error2');
389 message = "unbind without a type or handler";
390 $elem.bind("error error2.test",error)
392 .trigger("error").triggerHandler("error2");
395 test("unbind(eventObject)", function() {
398 var $elem = jQuery("#firstp"),
401 function assert( expected ){
403 $elem.trigger('foo').triggerHandler('bar');
404 equals( num, expected, "Check the right handlers are triggered" );
408 // This handler shouldn't be unbound
409 .bind('foo', function(){
412 .bind('foo', function(e){
417 .bind('bar', function(){
431 test("hover()", function() {
433 handler1 = function( event ) { ++times; },
434 handler2 = function( event ) { ++times; };
437 .hover(handler1, handler2)
438 .mouseenter().mouseleave()
439 .unbind("mouseenter", handler1)
440 .unbind("mouseleave", handler2)
442 .mouseenter().mouseleave()
443 .unbind("mouseenter mouseleave", handler1)
444 .mouseenter().mouseleave();
446 equals( times, 4, "hover handlers fired" );
449 test("trigger() shortcuts", function() {
451 jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
452 var close = jQuery('spanx', this); // same with jQuery(this).find('span');
453 equals( close.length, 0, "Context element does not exist, length must be zero" );
454 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
458 jQuery("#check1").click(function() {
459 ok( true, "click event handler for checkbox gets fired twice, see #815" );
463 jQuery('#firstp')[0].onclick = function(event) {
466 jQuery('#firstp').click();
467 equals( counter, 1, "Check that click, triggers onclick event handler also" );
469 var clickCounter = 0;
470 jQuery('#simon1')[0].onclick = function(event) {
473 jQuery('#simon1').click();
474 equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
476 jQuery('<img />').load(function(){
477 ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
481 test("trigger() bubbling", function() {
484 var doc = 0, html = 0, body = 0, main = 0, ap = 0;
486 jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
487 jQuery("html").bind("click", function(e){ html++; });
488 jQuery("body").bind("click", function(e){ body++; });
489 jQuery("#main").bind("click", function(e){ main++; });
490 jQuery("#ap").bind("click", function(){ ap++; return false; });
492 jQuery("html").trigger("click");
493 equals( doc, 1, "HTML bubble" );
494 equals( html, 1, "HTML bubble" );
496 jQuery("body").trigger("click");
497 equals( doc, 2, "Body bubble" );
498 equals( html, 2, "Body bubble" );
499 equals( body, 1, "Body bubble" );
501 jQuery("#main").trigger("click");
502 equals( doc, 3, "Main bubble" );
503 equals( html, 3, "Main bubble" );
504 equals( body, 2, "Main bubble" );
505 equals( main, 1, "Main bubble" );
507 jQuery("#ap").trigger("click");
508 equals( doc, 3, "ap bubble" );
509 equals( html, 3, "ap bubble" );
510 equals( body, 2, "ap bubble" );
511 equals( main, 1, "ap bubble" );
512 equals( ap, 1, "ap bubble" );
515 test("trigger(type, [data], [fn])", function() {
518 var handler = function(event, a, b, c) {
519 equals( event.type, "click", "check passed data" );
520 equals( a, 1, "check passed data" );
521 equals( b, "2", "check passed data" );
522 equals( c, "abc", "check passed data" );
526 var $elem = jQuery("#firstp");
528 // Simulate a "native" click
529 $elem[0].click = function(){
530 ok( true, "Native call was triggered" );
533 // Triggers handlrs and native
535 $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
537 // Simulate a "native" click
538 $elem[0].click = function(){
539 ok( false, "Native call was triggered" );
542 // Trigger only the handlers (no native)
544 equals( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
548 jQuery('#form input:first').hide().trigger('focus');
552 ok( pass, "Trigger focus on hidden element" );
556 jQuery('table:first').bind('test:test', function(){}).trigger('test:test');
560 ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
562 var form = jQuery("<form action=''></form>").appendTo("body");
564 // Make sure it can be prevented locally
565 form.submit(function(){
566 ok( true, "Local bind still works." );
571 form.trigger("submit");
573 form.unbind("submit");
575 jQuery(document).submit(function(){
576 ok( true, "Make sure bubble works up to document." );
581 form.trigger("submit");
583 jQuery(document).unbind("submit");
588 test("jQuery.Event.currentTarget", function(){
591 test("trigger(eventObject, [data], [fn])", function() {
594 var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
595 $child = jQuery('<p id="child">foo</p>').appendTo( $parent );
597 var event = jQuery.Event("noNew");
598 ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
599 equals( event.type, "noNew", "Verify its type" );
601 equals( event.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
602 equals( event.isPropagationStopped(), false, "Verify isPropagationStopped" );
603 equals( event.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
605 event.preventDefault();
606 equals( event.isDefaultPrevented(), true, "Verify isDefaultPrevented" );
607 event.stopPropagation();
608 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
610 event.isPropagationStopped = function(){ return false };
611 event.stopImmediatePropagation();
612 equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
613 equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
615 $parent.bind('foo',function(e){
617 equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
618 equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
619 equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
620 equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
623 // test with an event object
624 event = new jQuery.Event("foo");
625 event.secret = 'boo!';
626 $child.trigger(event);
628 // test with a literal object
629 $child.trigger({type:'foo', secret:'boo!'});
634 ok( false, "This assertion shouldn't be reached");
637 $parent.bind('foo', error );
639 $child.bind('foo',function(e, a, b, c ){
640 equals( arguments.length, 4, "Check arguments length");
641 equals( a, 1, "Check first custom argument");
642 equals( b, 2, "Check second custom argument");
643 equals( c, 3, "Check third custom argument");
645 equals( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
646 equals( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
647 equals( e.isImmediatePropagationStopped(), false, "Verify isImmediatePropagationStopped" );
650 e.stopImmediatePropagation();
655 // We should add this back in when we want to test the order
656 // in which event handlers are iterated.
657 //$child.bind('foo', error );
659 event = new jQuery.Event("foo");
660 $child.trigger( event, [1,2,3] ).unbind();
661 equals( event.result, "result", "Check event.result attribute");
663 // Will error if it bubbles
664 $child.triggerHandler('foo');
667 $parent.unbind().remove();
670 test("jQuery.Event.currentTarget", function(){
674 $elem = jQuery('<button>a</button>').click(function(e){
675 equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
679 $elem.trigger('click');
685 test("toggle(Function, Function, ...)", function() {
689 fn1 = function(e) { count++; },
690 fn2 = function(e) { count--; },
691 preventDefault = function(e) { e.preventDefault() },
692 link = jQuery('#mark');
693 link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
694 equals( count, 1, "Check for toggle(fn, fn)" );
696 jQuery("#firstp").toggle(function () {
697 equals(arguments.length, 4, "toggle correctly passes through additional triggered arguments, see #1701" )
698 }, function() {}).trigger("click", [ 1, 2, 3 ]);
701 jQuery("#simon1").one("click", function() {
702 ok( true, "Execute event only once" );
703 jQuery(this).toggle(function() {
704 equals( first++, 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
706 equals( first, 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
709 }).click().click().click();
724 var $div = jQuery("<div> </div>").toggle( fns[0], fns[1], fns[2] );
726 equals( turn, 1, "Trying toggle with 3 functions, attempt 1 yields 1");
728 equals( turn, 2, "Trying toggle with 3 functions, attempt 2 yields 2");
730 equals( turn, 3, "Trying toggle with 3 functions, attempt 3 yields 3");
732 equals( turn, 1, "Trying toggle with 3 functions, attempt 4 yields 1");
734 equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
736 $div.unbind('click',fns[0]);
737 var data = jQuery.data( $div[0], 'events' );
738 ok( !data, "Unbinding one function from toggle unbinds them all");
740 // Test Multi-Toggles
742 $div = jQuery("<div/>");
743 $div.toggle(function(){ a.push(1); }, function(){ a.push(2); });
745 same( a, [1], "Check that a click worked." );
747 $div.toggle(function(){ b.push(1); }, function(){ b.push(2); });
749 same( a, [1,2], "Check that a click worked with a second toggle." );
750 same( b, [1], "Check that a click worked with a second toggle." );
753 same( a, [1,2,1], "Check that a click worked with a second toggle, second click." );
754 same( b, [1,2], "Check that a click worked with a second toggle, second click." );
757 test(".live()/.die()", function() {
760 var submit = 0, div = 0, livea = 0, liveb = 0;
762 jQuery("div").live("submit", function(){ submit++; return false; });
763 jQuery("div").live("click", function(){ div++; });
764 jQuery("div#nothiddendiv").live("click", function(){ livea++; });
765 jQuery("div#nothiddendivchild").live("click", function(){ liveb++; });
767 // Nothing should trigger on the body
768 jQuery("body").trigger("click");
769 equals( submit, 0, "Click on body" );
770 equals( div, 0, "Click on body" );
771 equals( livea, 0, "Click on body" );
772 equals( liveb, 0, "Click on body" );
774 // This should trigger two events
775 jQuery("div#nothiddendiv").trigger("click");
776 equals( submit, 0, "Click on div" );
777 equals( div, 1, "Click on div" );
778 equals( livea, 1, "Click on div" );
779 equals( liveb, 0, "Click on div" );
781 // This should trigger three events (w/ bubbling)
782 jQuery("div#nothiddendivchild").trigger("click");
783 equals( submit, 0, "Click on inner div" );
784 equals( div, 2, "Click on inner div" );
785 equals( livea, 2, "Click on inner div" );
786 equals( liveb, 1, "Click on inner div" );
788 // This should trigger one submit
789 jQuery("div#nothiddendivchild").trigger("submit");
790 equals( submit, 1, "Submit on div" );
791 equals( div, 2, "Submit on div" );
792 equals( livea, 2, "Submit on div" );
793 equals( liveb, 1, "Submit on div" );
795 // Make sure no other events were removed in the process
796 jQuery("div#nothiddendivchild").trigger("click");
797 equals( submit, 1, "die Click on inner div" );
798 equals( div, 3, "die Click on inner div" );
799 equals( livea, 3, "die Click on inner div" );
800 equals( liveb, 2, "die Click on inner div" );
802 // Now make sure that the removal works
803 jQuery("div#nothiddendivchild").die("click");
804 jQuery("div#nothiddendivchild").trigger("click");
805 equals( submit, 1, "die Click on inner div" );
806 equals( div, 4, "die Click on inner div" );
807 equals( livea, 4, "die Click on inner div" );
808 equals( liveb, 2, "die Click on inner div" );
810 // Make sure that the click wasn't removed too early
811 jQuery("div#nothiddendiv").trigger("click");
812 equals( submit, 1, "die Click on inner div" );
813 equals( div, 5, "die Click on inner div" );
814 equals( livea, 5, "die Click on inner div" );
815 equals( liveb, 2, "die Click on inner div" );
817 // Make sure that stopPropgation doesn't stop live events
818 jQuery("div#nothiddendivchild").live("click", function(e){ liveb++; e.stopPropagation(); });
819 jQuery("div#nothiddendivchild").trigger("click");
820 equals( submit, 1, "stopPropagation Click on inner div" );
821 equals( div, 6, "stopPropagation Click on inner div" );
822 equals( livea, 6, "stopPropagation Click on inner div" );
823 equals( liveb, 3, "stopPropagation Click on inner div" );
825 // Make sure click events only fire with primary click
826 var event = jQuery.Event("click");
828 jQuery("div#nothiddendiv").trigger(event);
830 equals( livea, 6, "live secondary click" );
832 jQuery("div#nothiddendivchild").die("click");
833 jQuery("div#nothiddendiv").die("click");
834 jQuery("div").die("click");
835 jQuery("div").die("submit");
837 // Test binding with a different context
838 var clicked = 0, container = jQuery('#main')[0];
839 jQuery("#foo", container).live("click", function(e){ clicked++; });
840 jQuery("div").trigger('click');
841 jQuery("#foo").trigger('click');
842 jQuery("#main").trigger('click');
843 jQuery("body").trigger('click');
844 equals( clicked, 2, "live with a context" );
846 // Make sure the event is actually stored on the context
847 ok( jQuery.data(container, "events").live, "live with a context" );
849 // Test unbinding with a different context
850 jQuery("#foo", container).die("click");
851 jQuery("#foo").trigger('click');
852 equals( clicked, 2, "die with a context");
854 // Test binding with event data
855 jQuery("#foo").live("click", true, function(e){ equals( e.data, true, "live with event data" ); });
856 jQuery("#foo").trigger("click").die("click");
858 // Test binding with trigger data
859 jQuery("#foo").live("click", function(e, data){ equals( data, true, "live with trigger data" ); });
860 jQuery("#foo").trigger("click", true).die("click");
862 // Test binding with different this object
863 jQuery("#foo").live("click", jQuery.proxy(function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" }));
864 jQuery("#foo").trigger("click").die("click");
866 // Test binding with different this object, event data, and trigger data
867 jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){
868 equals( e.data, true, "live with with different this object, event data, and trigger data" );
869 equals( this.foo, "bar", "live with with different this object, event data, and trigger data" );
870 equals( data, true, "live with with different this object, event data, and trigger data")
872 jQuery("#foo").trigger("click", true).die("click");
874 // Verify that return false prevents default action
875 jQuery("#anchor2").live("click", function(){ return false; });
876 var hash = window.location.hash;
877 jQuery("#anchor2").trigger("click");
878 equals( window.location.hash, hash, "return false worked" );
879 jQuery("#anchor2").die("click");
881 // Verify that .preventDefault() prevents default action
882 jQuery("#anchor2").live("click", function(e){ e.preventDefault(); });
883 var hash = window.location.hash;
884 jQuery("#anchor2").trigger("click");
885 equals( window.location.hash, hash, "e.preventDefault() worked" );
886 jQuery("#anchor2").die("click");
888 // Test binding the same handler to multiple points
890 function callback(){ called++; return false; }
892 jQuery("#nothiddendiv").live("click", callback);
893 jQuery("#anchor2").live("click", callback);
895 jQuery("#nothiddendiv").trigger("click");
896 equals( called, 1, "Verify that only one click occurred." );
898 jQuery("#anchor2").trigger("click");
899 equals( called, 2, "Verify that only one click occurred." );
901 // Make sure that only one callback is removed
902 jQuery("#anchor2").die("click", callback);
904 jQuery("#nothiddendiv").trigger("click");
905 equals( called, 3, "Verify that only one click occurred." );
907 jQuery("#anchor2").trigger("click");
908 equals( called, 3, "Verify that no click occurred." );
910 // Make sure that it still works if the selector is the same,
911 // but the event type is different
912 jQuery("#nothiddendiv").live("foo", callback);
915 jQuery("#nothiddendiv").die("click", callback);
917 jQuery("#nothiddendiv").trigger("click");
918 equals( called, 3, "Verify that no click occurred." );
920 jQuery("#nothiddendiv").trigger("foo");
921 equals( called, 4, "Verify that one foo occurred." );
924 jQuery("#nothiddendiv").die("foo", callback);
926 // Make sure we don't loose the target by DOM modifications
927 // after the bubble already reached the liveHandler
928 var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
930 jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
931 jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
933 jQuery("#nothiddendiv span").click();
934 equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
935 equals( livec, 1, "Verify that second handler occurred even with nuked target." );
938 jQuery("#nothiddendivchild").die("click");
940 // Verify that .live() ocurs and cancel buble in the same order as
941 // we would expect .bind() and .click() without delegation
942 var lived = 0, livee = 0;
944 // bind one pair in one order
945 jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
946 jQuery('span#liveSpan1').live('click', function(){ livee++; });
948 jQuery('span#liveSpan1 a').click();
949 equals( lived, 1, "Verify that only one first handler occurred." );
950 equals( livee, 0, "Verify that second handler doesn't." );
952 // and one pair in inverse
953 jQuery('span#liveSpan2').live('click', function(){ livee++; });
954 jQuery('span#liveSpan2 a').live('click', function(){ lived++; return false; });
958 jQuery('span#liveSpan2 a').click();
959 equals( lived, 1, "Verify that only one first handler occurred." );
960 equals( livee, 0, "Verify that second handler doesn't." );
963 jQuery("span#liveSpan1 a").die("click")
964 jQuery("span#liveSpan1").die("click");
965 jQuery("span#liveSpan2 a").die("click");
966 jQuery("span#liveSpan2").die("click");
968 // Test this, target and currentTarget are correct
969 jQuery('span#liveSpan1').live('click', function(e){
970 equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
971 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
972 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
975 jQuery('span#liveSpan1 a').click();
977 jQuery('span#liveSpan1').die('click');
979 // Work with deep selectors
982 function clickB(){ livee++; }
984 jQuery("#nothiddendiv div").live("click", function(){ livee++; });
985 jQuery("#nothiddendiv div").live("click", clickB);
986 jQuery("#nothiddendiv div").live("mouseover", function(){ livee++; });
988 equals( livee, 0, "No clicks, deep selector." );
991 jQuery("#nothiddendivchild").trigger("click");
992 equals( livee, 2, "Click, deep selector." );
995 jQuery("#nothiddendivchild").trigger("mouseover");
996 equals( livee, 1, "Mouseover, deep selector." );
998 jQuery("#nothiddendiv div").die("mouseover");
1001 jQuery("#nothiddendivchild").trigger("click");
1002 equals( livee, 2, "Click, deep selector." );
1005 jQuery("#nothiddendivchild").trigger("mouseover");
1006 equals( livee, 0, "Mouseover, deep selector." );
1008 jQuery("#nothiddendiv div").die("click", clickB);
1011 jQuery("#nothiddendivchild").trigger("click");
1012 equals( livee, 1, "Click, deep selector." );
1014 jQuery("#nothiddendiv div").die("click");
1017 test("die all bound events", function(){
1021 var div = jQuery("div#nothiddendivchild");
1023 div.live("click submit", function(){ count++; });
1026 div.trigger("click");
1027 div.trigger("submit");
1029 equals( count, 0, "Make sure no events were triggered." );
1032 test("live with multiple events", function(){
1036 var div = jQuery("div#nothiddendivchild");
1038 div.live("click submit", function(){ count++; });
1040 div.trigger("click");
1041 div.trigger("submit");
1043 equals( count, 2, "Make sure both the click and submit were triggered." );
1046 test("live with change", function(){
1047 var selectChange = 0, checkboxChange = 0;
1049 var select = jQuery("select[name='S1']")
1050 select.live("change", function() {
1054 var checkbox = jQuery("#check2"),
1055 checkboxFunction = function(){
1058 checkbox.live("change", checkboxFunction);
1060 // test click on select
1062 // second click that changed it
1064 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1065 select.trigger("change");
1066 equals( selectChange, 1, "Change on click." );
1068 // test keys on select
1070 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1071 select.trigger("change");
1072 equals( selectChange, 1, "Change on keyup." );
1074 // test click on checkbox
1075 checkbox.trigger("change");
1076 equals( checkboxChange, 1, "Change on checkbox." );
1078 // test before activate on radio
1080 // test blur/focus on textarea
1081 var textarea = jQuery("#area1"), textareaChange = 0, oldVal = textarea.val();
1082 textarea.live("change", function() {
1086 textarea.val(oldVal + "foo");
1087 textarea.trigger("change");
1088 equals( textareaChange, 1, "Change on textarea." );
1090 textarea.val(oldVal);
1091 textarea.die("change");
1093 // test blur/focus on text
1094 var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
1095 text.live("change", function() {
1099 text.val(oldVal+"foo");
1100 text.trigger("change");
1101 equals( textChange, 1, "Change on text input." );
1103 text.val(oldTextVal);
1106 // test blur/focus on password
1107 var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
1108 password.live("change", function() {
1112 password.val(oldPasswordVal + "foo");
1113 password.trigger("change");
1114 equals( passwordChange, 1, "Change on password input." );
1116 password.val(oldPasswordVal);
1117 password.die("change");
1119 // make sure die works
1123 select.die("change");
1124 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1125 select.trigger("change");
1126 equals( selectChange, 0, "Die on click works." );
1129 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1130 select.trigger("change");
1131 equals( selectChange, 0, "Die on keyup works." );
1133 // die specific checkbox
1134 checkbox.die("change", checkboxFunction);
1135 checkbox.trigger("change");
1136 equals( checkboxChange, 1, "Die on checkbox." );
1139 test("live with submit", function() {
1140 var count1 = 0, count2 = 0;
1142 jQuery("#testForm").live("submit", function(ev) {
1144 ev.preventDefault();
1147 jQuery("body").live("submit", function(ev) {
1149 ev.preventDefault();
1152 if ( jQuery.support.submitBubbles ) {
1153 jQuery("#testForm input[name=sub1]")[0].click();
1157 jQuery("#testForm input[name=sub1]")[0].click();
1158 jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13});
1163 jQuery("#testForm").die("submit");
1164 jQuery("body").die("submit");
1167 test(".delegate()/.undelegate()", function() {
1170 var submit = 0, div = 0, livea = 0, liveb = 0;
1172 jQuery("#body").delegate("div", "submit", function(){ submit++; return false; });
1173 jQuery("#body").delegate("div", "click", function(){ div++; });
1174 jQuery("#body").delegate("div#nothiddendiv", "click", function(){ livea++; });
1175 jQuery("#body").delegate("div#nothiddendivchild", "click", function(){ liveb++; });
1177 // Nothing should trigger on the body
1178 jQuery("body").trigger("click");
1179 equals( submit, 0, "Click on body" );
1180 equals( div, 0, "Click on body" );
1181 equals( livea, 0, "Click on body" );
1182 equals( liveb, 0, "Click on body" );
1184 // This should trigger two events
1185 jQuery("div#nothiddendiv").trigger("click");
1186 equals( submit, 0, "Click on div" );
1187 equals( div, 1, "Click on div" );
1188 equals( livea, 1, "Click on div" );
1189 equals( liveb, 0, "Click on div" );
1191 // This should trigger three events (w/ bubbling)
1192 jQuery("div#nothiddendivchild").trigger("click");
1193 equals( submit, 0, "Click on inner div" );
1194 equals( div, 2, "Click on inner div" );
1195 equals( livea, 2, "Click on inner div" );
1196 equals( liveb, 1, "Click on inner div" );
1198 // This should trigger one submit
1199 jQuery("div#nothiddendivchild").trigger("submit");
1200 equals( submit, 1, "Submit on div" );
1201 equals( div, 2, "Submit on div" );
1202 equals( livea, 2, "Submit on div" );
1203 equals( liveb, 1, "Submit on div" );
1205 // Make sure no other events were removed in the process
1206 jQuery("div#nothiddendivchild").trigger("click");
1207 equals( submit, 1, "undelegate Click on inner div" );
1208 equals( div, 3, "undelegate Click on inner div" );
1209 equals( livea, 3, "undelegate Click on inner div" );
1210 equals( liveb, 2, "undelegate Click on inner div" );
1212 // Now make sure that the removal works
1213 jQuery("#body").undelegate("div#nothiddendivchild", "click");
1214 jQuery("div#nothiddendivchild").trigger("click");
1215 equals( submit, 1, "undelegate Click on inner div" );
1216 equals( div, 4, "undelegate Click on inner div" );
1217 equals( livea, 4, "undelegate Click on inner div" );
1218 equals( liveb, 2, "undelegate Click on inner div" );
1220 // Make sure that the click wasn't removed too early
1221 jQuery("div#nothiddendiv").trigger("click");
1222 equals( submit, 1, "undelegate Click on inner div" );
1223 equals( div, 5, "undelegate Click on inner div" );
1224 equals( livea, 5, "undelegate Click on inner div" );
1225 equals( liveb, 2, "undelegate Click on inner div" );
1227 // Make sure that stopPropgation doesn't stop live events
1228 jQuery("#body").delegate("div#nothiddendivchild", "click", function(e){ liveb++; e.stopPropagation(); });
1229 jQuery("div#nothiddendivchild").trigger("click");
1230 equals( submit, 1, "stopPropagation Click on inner div" );
1231 equals( div, 6, "stopPropagation Click on inner div" );
1232 equals( livea, 6, "stopPropagation Click on inner div" );
1233 equals( liveb, 3, "stopPropagation Click on inner div" );
1235 // Make sure click events only fire with primary click
1236 var event = jQuery.Event("click");
1238 jQuery("div#nothiddendiv").trigger(event);
1240 equals( livea, 6, "delegate secondary click" );
1242 jQuery("#body").undelegate("div#nothiddendivchild", "click");
1243 jQuery("#body").undelegate("div#nothiddendiv", "click");
1244 jQuery("#body").undelegate("div", "click");
1245 jQuery("#body").undelegate("div", "submit");
1247 // Test binding with a different context
1248 var clicked = 0, container = jQuery('#main')[0];
1249 jQuery("#main").delegate("#foo", "click", function(e){ clicked++; });
1250 jQuery("div").trigger('click');
1251 jQuery("#foo").trigger('click');
1252 jQuery("#main").trigger('click');
1253 jQuery("body").trigger('click');
1254 equals( clicked, 2, "delegate with a context" );
1256 // Make sure the event is actually stored on the context
1257 ok( jQuery.data(container, "events").live, "delegate with a context" );
1259 // Test unbinding with a different context
1260 jQuery("#main").undelegate("#foo", "click");
1261 jQuery("#foo").trigger('click');
1262 equals( clicked, 2, "undelegate with a context");
1264 // Test binding with event data
1265 jQuery("#body").delegate("#foo", "click", true, function(e){ equals( e.data, true, "delegate with event data" ); });
1266 jQuery("#foo").trigger("click");
1267 jQuery("#body").undelegate("#foo", "click");
1269 // Test binding with trigger data
1270 jQuery("#body").delegate("#foo", "click", function(e, data){ equals( data, true, "delegate with trigger data" ); });
1271 jQuery("#foo").trigger("click", true);
1272 jQuery("#body").undelegate("#foo", "click");
1274 // Test binding with different this object
1275 jQuery("#body").delegate("#foo", "click", jQuery.proxy(function(e){ equals( this.foo, "bar", "delegate with event scope" ); }, { foo: "bar" }));
1276 jQuery("#foo").trigger("click");
1277 jQuery("#body").undelegate("#foo", "click");
1279 // Test binding with different this object, event data, and trigger data
1280 jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){
1281 equals( e.data, true, "delegate with with different this object, event data, and trigger data" );
1282 equals( this.foo, "bar", "delegate with with different this object, event data, and trigger data" );
1283 equals( data, true, "delegate with with different this object, event data, and trigger data")
1284 }, { foo: "bar" }));
1285 jQuery("#foo").trigger("click", true);
1286 jQuery("#body").undelegate("#foo", "click");
1288 // Verify that return false prevents default action
1289 jQuery("#body").delegate("#anchor2", "click", function(){ return false; });
1290 var hash = window.location.hash;
1291 jQuery("#anchor2").trigger("click");
1292 equals( window.location.hash, hash, "return false worked" );
1293 jQuery("#body").undelegate("#anchor2", "click");
1295 // Verify that .preventDefault() prevents default action
1296 jQuery("#body").delegate("#anchor2", "click", function(e){ e.preventDefault(); });
1297 var hash = window.location.hash;
1298 jQuery("#anchor2").trigger("click");
1299 equals( window.location.hash, hash, "e.preventDefault() worked" );
1300 jQuery("#body").undelegate("#anchor2", "click");
1302 // Test binding the same handler to multiple points
1304 function callback(){ called++; return false; }
1306 jQuery("#body").delegate("#nothiddendiv", "click", callback);
1307 jQuery("#body").delegate("#anchor2", "click", callback);
1309 jQuery("#nothiddendiv").trigger("click");
1310 equals( called, 1, "Verify that only one click occurred." );
1312 jQuery("#anchor2").trigger("click");
1313 equals( called, 2, "Verify that only one click occurred." );
1315 // Make sure that only one callback is removed
1316 jQuery("#body").undelegate("#anchor2", "click", callback);
1318 jQuery("#nothiddendiv").trigger("click");
1319 equals( called, 3, "Verify that only one click occurred." );
1321 jQuery("#anchor2").trigger("click");
1322 equals( called, 3, "Verify that no click occurred." );
1324 // Make sure that it still works if the selector is the same,
1325 // but the event type is different
1326 jQuery("#body").delegate("#nothiddendiv", "foo", callback);
1329 jQuery("#body").undelegate("#nothiddendiv", "click", callback);
1331 jQuery("#nothiddendiv").trigger("click");
1332 equals( called, 3, "Verify that no click occurred." );
1334 jQuery("#nothiddendiv").trigger("foo");
1335 equals( called, 4, "Verify that one foo occurred." );
1338 jQuery("#body").undelegate("#nothiddendiv", "foo", callback);
1340 // Make sure we don't loose the target by DOM modifications
1341 // after the bubble already reached the liveHandler
1342 var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
1344 jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(''); });
1345 jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
1347 jQuery("#nothiddendiv span").click();
1348 equals( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
1349 equals( livec, 1, "Verify that second handler occurred even with nuked target." );
1352 jQuery("#body").undelegate("#nothiddendivchild", "click");
1354 // Verify that .live() ocurs and cancel buble in the same order as
1355 // we would expect .bind() and .click() without delegation
1356 var lived = 0, livee = 0;
1358 // bind one pair in one order
1359 jQuery("#body").delegate('span#liveSpan1 a', 'click', function(){ lived++; return false; });
1360 jQuery("#body").delegate('span#liveSpan1', 'click', function(){ livee++; });
1362 jQuery('span#liveSpan1 a').click();
1363 equals( lived, 1, "Verify that only one first handler occurred." );
1364 equals( livee, 0, "Verify that second handler doesn't." );
1366 // and one pair in inverse
1367 jQuery("#body").delegate('span#liveSpan2', 'click', function(){ livee++; });
1368 jQuery("#body").delegate('span#liveSpan2 a', 'click', function(){ lived++; return false; });
1372 jQuery('span#liveSpan2 a').click();
1373 equals( lived, 1, "Verify that only one first handler occurred." );
1374 equals( livee, 0, "Verify that second handler doesn't." );
1377 jQuery("#body").undelegate("click");
1379 // Test this, target and currentTarget are correct
1380 jQuery("#body").delegate('span#liveSpan1', 'click', function(e){
1381 equals( this.id, 'liveSpan1', 'Check the this within a delegate handler' );
1382 equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a delegate handler' );
1383 equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a delegate handler' );
1386 jQuery('span#liveSpan1 a').click();
1388 jQuery("#body").undelegate('span#liveSpan1', 'click');
1390 // Work with deep selectors
1393 function clickB(){ livee++; }
1395 jQuery("#body").delegate("#nothiddendiv div", "click", function(){ livee++; });
1396 jQuery("#body").delegate("#nothiddendiv div", "click", clickB);
1397 jQuery("#body").delegate("#nothiddendiv div", "mouseover", function(){ livee++; });
1399 equals( livee, 0, "No clicks, deep selector." );
1402 jQuery("#nothiddendivchild").trigger("click");
1403 equals( livee, 2, "Click, deep selector." );
1406 jQuery("#nothiddendivchild").trigger("mouseover");
1407 equals( livee, 1, "Mouseover, deep selector." );
1409 jQuery("#body").undelegate("#nothiddendiv div", "mouseover");
1412 jQuery("#nothiddendivchild").trigger("click");
1413 equals( livee, 2, "Click, deep selector." );
1416 jQuery("#nothiddendivchild").trigger("mouseover");
1417 equals( livee, 0, "Mouseover, deep selector." );
1419 jQuery("#body").undelegate("#nothiddendiv div", "click", clickB);
1422 jQuery("#nothiddendivchild").trigger("click");
1423 equals( livee, 1, "Click, deep selector." );
1425 jQuery("#body").undelegate("#nothiddendiv div", "click");
1428 test("undelegate all bound events", function(){
1432 var div = jQuery("#body");
1434 div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
1437 jQuery("div#nothiddendivchild").trigger("click");
1438 jQuery("div#nothiddendivchild").trigger("submit");
1440 equals( count, 0, "Make sure no events were triggered." );
1443 test("delegate with multiple events", function(){
1447 var div = jQuery("#body");
1449 div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
1451 jQuery("div#nothiddendivchild").trigger("click");
1452 jQuery("div#nothiddendivchild").trigger("submit");
1454 equals( count, 2, "Make sure both the click and submit were triggered." );
1456 jQuery("#body").undelegate();
1459 test("delegate with change", function(){
1460 var selectChange = 0, checkboxChange = 0;
1462 var select = jQuery("select[name='S1']");
1463 jQuery("#body").delegate("select[name='S1']", "change", function() {
1467 var checkbox = jQuery("#check2"),
1468 checkboxFunction = function(){
1471 jQuery("#body").delegate("#check2", "change", checkboxFunction);
1473 // test click on select
1475 // second click that changed it
1477 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1478 select.trigger("change");
1479 equals( selectChange, 1, "Change on click." );
1481 // test keys on select
1483 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1484 select.trigger("change");
1485 equals( selectChange, 1, "Change on keyup." );
1487 // test click on checkbox
1488 checkbox.trigger("change");
1489 equals( checkboxChange, 1, "Change on checkbox." );
1491 // test before activate on radio
1493 // test blur/focus on textarea
1494 var textarea = jQuery("#area1"), textareaChange = 0, oldVal = textarea.val();
1495 jQuery("#body").delegate("#area1", "change", function() {
1499 textarea.val(oldVal + "foo");
1500 textarea.trigger("change");
1501 equals( textareaChange, 1, "Change on textarea." );
1503 textarea.val(oldVal);
1504 jQuery("#body").undelegate("#area1", "change");
1506 // test blur/focus on text
1507 var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
1508 jQuery("#body").delegate("#name", "change", function() {
1512 text.val(oldVal+"foo");
1513 text.trigger("change");
1514 equals( textChange, 1, "Change on text input." );
1516 text.val(oldTextVal);
1517 jQuery("#body").die("change");
1519 // test blur/focus on password
1520 var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
1521 jQuery("#body").delegate("#name", "change", function() {
1525 password.val(oldPasswordVal + "foo");
1526 password.trigger("change");
1527 equals( passwordChange, 1, "Change on password input." );
1529 password.val(oldPasswordVal);
1530 jQuery("#body").undelegate("#name", "change");
1532 // make sure die works
1536 jQuery("#body").undelegate("select[name='S1']", "change");
1537 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1538 select.trigger("change");
1539 equals( selectChange, 0, "Die on click works." );
1542 select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
1543 select.trigger("change");
1544 equals( selectChange, 0, "Die on keyup works." );
1546 // die specific checkbox
1547 jQuery("#body").undelegate("#check2", "change", checkboxFunction);
1548 checkbox.trigger("change");
1549 equals( checkboxChange, 1, "Die on checkbox." );
1552 test("delegate with submit", function() {
1553 var count1 = 0, count2 = 0;
1555 jQuery("#body").delegate("#testForm", "submit", function(ev) {
1557 ev.preventDefault();
1560 jQuery(document).delegate("body", "submit", function(ev) {
1562 ev.preventDefault();
1565 if ( jQuery.support.submitBubbles ) {
1566 jQuery("#testForm input[name=sub1]")[0].click();
1570 jQuery("#testForm input[name=sub1]")[0].click();
1571 jQuery("#testForm input[name=T1]").trigger({type: "keypress", keyCode: 13});
1576 jQuery("#body").undelegate();
1577 jQuery(document).undelegate();
1580 test("Non DOM element events", function() {
1584 .bind('nonelementglobal', function(e) {
1585 ok( true, "Global event on non-DOM annonymos object triggered" );
1591 .bind('nonelementobj', function(e) {
1592 ok( true, "Event on non-DOM object triggered" );
1593 }).bind('nonelementglobal', function() {
1594 ok( true, "Global event on non-DOM object triggered" );
1597 jQuery(o).trigger('nonelementobj');
1598 jQuery.event.trigger('nonelementglobal');
1602 test("jQuery(function($) {})", function() {
1604 jQuery(function($) {
1605 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");
1610 test("event properties", function() {
1612 jQuery("#simon1").click(function(event) {
1613 ok( event.timeStamp, "assert event.timeStamp is present" );