Adding in backwards-compatiblity support for jQuery().bind/unbind/trigger - and immed...
[jquery.git] / test / unit / event.js
index 80a2e6a..7111bb5 100644 (file)
@@ -118,6 +118,19 @@ test("bind(), trigger change on select", function() {
        }).trigger('change');
 });
 
+test("bind/unbind/trigger on empty jQuery set", function() {
+       expect(1);
+
+       jQuery().bind("test", function(){
+               equals( this, document, "Handler triggered and bound on document." );
+       });
+
+       jQuery().trigger("test");
+
+       jQuery().unbind("test");
+       jQuery().trigger("test");
+});
+
 test("bind(), namespaced events, cloned events", function() {
        expect(6);
 
@@ -232,8 +245,8 @@ test("bind(), with different this object", function() {
                };
        
        jQuery("#firstp")
-               .bind("click", handler1, thisObject).click().unbind("click", handler1)
-               .bind("click", data, handler2, thisObject).click().unbind("click", handler2);
+               .bind("click", jQuery.proxy(handler1, thisObject)).click().unbind("click", handler1)
+               .bind("click", data, jQuery.proxy(handler2, thisObject)).click().unbind("click", handler2);
 
        ok( !jQuery.data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
 });
@@ -706,15 +719,15 @@ test(".live()/.die()", function() {
        jQuery("#foo").trigger("click", true).die("click");
 
        // Test binding with different this object
-       jQuery("#foo").live("click", function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" });
+       jQuery("#foo").live("click", jQuery.proxy(function(e){ equals( this.foo, "bar", "live with event scope" ); }, { foo: "bar" }));
        jQuery("#foo").trigger("click").die("click");
 
        // Test binding with different this object, event data, and trigger data
-       jQuery("#foo").live("click", true, function(e, data){
+       jQuery("#foo").live("click", true, jQuery.proxy(function(e, data){
                equals( e.data, true, "live with with different this object, event data, and trigger data" );
                equals( this.foo, "bar", "live with with different this object, event data, and trigger data" ); 
                equals( data, true, "live with with different this object, event data, and trigger data")
-       }, { foo: "bar" });
+       }, { foo: "bar" }));
        jQuery("#foo").trigger("click", true).die("click");
 
        // Verify that return false prevents default action
@@ -873,26 +886,20 @@ test("live with change", function(){
        
        // test click on select
 
-       // first click sets data
-       if ( !jQuery.support.changeBubbles ) {
-               select[0].selectedIndex = 1;
-               select.trigger("keyup");
-       }
-
        // second click that changed it
        selectChange = 0;
        select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
-       select.trigger(jQuery.support.changeBubbles ? "change" : "click");
+       select.trigger("change");
        equals( selectChange, 1, "Change on click." );
        
        // test keys on select
        selectChange = 0;
        select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
-       select.trigger(jQuery.support.changeBubbles ? "change" : "keyup");
+       select.trigger("change");
        equals( selectChange, 1, "Change on keyup." );
        
        // test click on checkbox
-       checkbox.trigger(jQuery.support.changeBubbles ? "change" : "click");
+       checkbox.trigger("change");
        equals( checkboxChange, 1, "Change on checkbox." );
        
        // test before activate on radio
@@ -903,12 +910,8 @@ test("live with change", function(){
                textareaChange++;
        });
 
-       if ( !jQuery.support.changeBubbles ) {
-               textarea.trigger("focus");
-       }
-
        textarea.val(oldVal + "foo");
-       textarea.trigger(jQuery.support.changeBubbles ? "change" : "blur");
+       textarea.trigger("change");
        equals( textareaChange, 1, "Change on textarea." );
 
        textarea.val(oldVal);
@@ -920,12 +923,8 @@ test("live with change", function(){
                textChange++;
        });
 
-       if ( !jQuery.support.changeBubbles ) {
-               text.trigger("focus");
-       }
-
        text.val(oldVal+"foo");
-       text.trigger(jQuery.support.changeBubbles ? "change" : "blur");
+       text.trigger("change");
        equals( textChange, 1, "Change on text input." );
 
        text.val(oldTextVal);
@@ -937,12 +936,8 @@ test("live with change", function(){
                passwordChange++;
        });
 
-       if ( !jQuery.support.changeBubbles ) {
-               password.trigger("focus");
-       }
-
        password.val(oldPasswordVal + "foo");
-       password.trigger(jQuery.support.changeBubbles ? "change" : "blur");
+       password.trigger("change");
        equals( passwordChange, 1, "Change on password input." );
 
        password.val(oldPasswordVal);
@@ -954,17 +949,17 @@ test("live with change", function(){
        selectChange = 0;
        select.die("change");
        select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
-       select.trigger(jQuery.support.changeBubbles ? "change" : "click");
+       select.trigger("change");
        equals( selectChange, 0, "Die on click works." );
 
        selectChange = 0;
        select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
-       select.trigger(jQuery.support.changeBubbles ? "change" : "keyup");
+       select.trigger("change");
        equals( selectChange, 0, "Die on keyup works." );
        
        // die specific checkbox
        checkbox.die("change", checkboxFunction);
-       checkbox.trigger(jQuery.support.changeBubbles ? "change" : "click");
+       checkbox.trigger("change");
        equals( checkboxChange, 1, "Die on checkbox." );
 });