3 test("bind()", function() {
6 var handler = function(event) {
7 ok( event.data, "bind() with data, check passed data exists" );
8 ok( event.data.foo == "bar", "bind() with data, Check value of passed data" );
10 $("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
12 ok( !$("#firstp").get(0).$events, "Event handler unbound when using data." );
15 var handler = function(event, data) {
16 ok( event.data, "check passed data exists" );
17 ok( event.data.foo == "bar", "Check value of passed data" );
18 ok( data, "Check trigger data" );
19 ok( data.bar == "foo", "Check value of trigger data" );
21 $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind(handler);
24 var handler = function(event) {
25 ok ( !event.data, "Check that no data is added to the event object" );
27 $("#firstp").bind("click", handler).trigger("click");
30 // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
31 // var doc = document.getElementById("iframe").contentDocument;
33 // doc.body.innerHTML = "<input type='text'/>";
35 // var input = doc.getElementsByTagName("input")[0];
37 // $(input).bind("click",function() {
38 // ok( true, "Binding to element inside iframe" );
42 function selectOnChange(event) {
43 equals( event.data, counter++, "Event.data is not a global event object" );
45 $("select").each(function(i){
46 $(this).bind('change', i, selectOnChange);
50 test("click()", function() {
52 $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
53 var close = $('spanx', this); // same with $(this).find('span');
54 ok( close.length == 0, "Context element does not exist, length must be zero" );
55 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
59 $("#check1").click(function() {
60 ok( true, "click event handler for checkbox gets fired twice, see #815" );
64 $('#firstp')[0].onclick = function(event) {
68 ok( counter == 1, "Check that click, triggers onclick event handler also" );
71 test("unbind(event)", function() {
73 var el = $("#firstp");
75 ok( true, "Fake normal bind" );
77 el.click(function(event) {
79 ok( true, "Fake onebind" );
83 el.click(function() { return; });
85 ok( !el[0].onclick, "Handler is removed" ); // Bug #964
87 el.click(function() { return; });
88 el.unbind('change',function(){ return; });
89 for (var ret in el[0].$events['click']) break;
90 ok( ret, "Extra handlers weren't accidentally removed." );
93 ok( !el[0].$events, "Removed the events expando after all handlers are unbound." );
96 test("trigger(event, [data]", function() {
99 var handler = function(event, a, b, c) {
100 equals( event.type, "click", "check passed data" );
101 equals( a, 1, "check passed data" );
102 equals( b, "2", "check passed data" );
103 equals( c, "abc", "check passed data" );
107 // Simulate a "native" click
108 $("#firstp")[0].click = function(){
109 ok( true, "Native call was triggered" );
112 // Triggers handlrs and native
114 $("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
116 // Triggers handlers, native, and extra fn
118 $("#firstp").trigger("click", [1, "2", "abc"], handler);
120 // Simulate a "native" click
121 $("#firstp")[0].click = function(){
122 ok( false, "Native call was triggered" );
125 // Trigger only the handlers (no native)
127 equals( $("#firstp").triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
129 // Trigger only the handlers (no native) and extra fn
131 equals( $("#firstp").triggerHandler("click", [1, "2", "abc"], handler), "test", "Verify handler response" );
134 test("toggle(Function, Function)", function() {
137 fn1 = function(e) { count++; },
138 fn2 = function(e) { count--; },
139 preventDefault = function(e) { e.preventDefault() },
141 link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
142 ok( count == 1, "Check for toggle(fn, fn)" );
145 $("#simon1").one("click", function() {
146 ok( true, "Execute event only once" );
147 $(this).toggle(function() {
148 ok( first++ == 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
150 ok( first == 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
153 }).click().click().click();