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();
13 var handler = function(event, data) {
14 ok( event.data, "check passed data exists" );
15 ok( event.data.foo == "bar", "Check value of passed data" );
16 ok( data, "Check trigger data" );
17 ok( data.bar == "foo", "Check value of trigger data" );
19 $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]);
21 // events don't work with iframes, see #939
22 var tmp = document.createElement('iframe');
23 document.body.appendChild( tmp );
24 var doc = tmp.contentWindow.document;
26 doc.write("<html><body><input type='text'/></body></html>");
29 var input = doc.getElementsByTagName("input")[0];
31 $(input).bind("click",function() {
32 ok( true, "Binding to element inside iframe" );
35 triggerEvent( input, "click" );
37 document.body.removeChild( tmp );
40 function selectOnChange(event) {
41 equals( event.data, counter++, "Event.data is not a global event object" );
43 $("select").each(function(i){
44 $(this).bind('change', i, selectOnChange);
48 test("click()", function() {
50 $('<li><a href="#">Change location</a></li>').prependTo('#firstUL').find('a').bind('click', function() {
51 var close = $('spanx', this); // same with $(this).find('span');
52 ok( close.length == 0, "Context element does not exist, length must be zero" );
53 ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
57 $("#check1").click(function() {
58 ok( true, "click event handler for checkbox gets fired twice, see #815" );
62 test("unbind(event)", function() {
64 var el = $("#firstp");
66 ok( true, "Fake normal bind" );
68 el.click(function(event) {
70 ok( true, "Fake onebind" );
74 el.click(function() { return; });
76 ok( !el[0].onclick, "Handler is removed" ); // Bug #964
78 el.click(function() { return; });
79 el.unbind('change',function(){ return; });
80 for (var ret in el[0].$events['click']) break;
81 ok( ret, "Extra handlers weren't accidentally removed." );
84 ok( !el[0].$events, "Removed the events expando after all handlers are unbound." );
87 test("trigger(event, [data]", function() {
89 var handler = function(event, a, b, c) {
90 ok( a == 1, "check passed data" );
91 ok( b == "2", "check passed data" );
92 ok( c == "abc", "check passed data" );
94 $("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
97 test("toggle(Function, Function)", function() {
100 fn1 = function(e) { count++; },
101 fn2 = function(e) { count--; },
102 preventDefault = function(e) { e.preventDefault() },
104 link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
105 ok( count == 1, "Check for toggle(fn, fn)" );
108 $("#simon1").one("click", function() {
109 ok( true, "Execute event only once" );
110 $(this).toggle(function() {
111 ok( first++ == 0, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
113 ok( first == 1, "toggle(Function,Function) assigned from within one('xxx'), see #1054" );
116 }).click().click().click();