test("null or undefined handler", function() {
expect(2);
- // Supports Fixes bug #7229
- try {
-
- jQuery("#firstp").click(null);
-
- ok(true, "Passing a null handler will not throw an exception");
-
- } catch (e) {}
-
- try {
-
- jQuery("#firstp").click(undefined);
-
- ok(true, "Passing an undefined handler will not throw an exception");
+ // Supports Fixes bug #7229
+ try {
+ jQuery("#firstp").click(null);
+ ok(true, "Passing a null handler will not throw an exception");
+ } catch (e) {}
- } catch (e) {}
+ try {
+ jQuery("#firstp").click(undefined);
+ ok(true, "Passing an undefined handler will not throw an exception");
+ } catch (e) {}
});
test("bind(), with data", function() {
}).trigger('change');
});
-test("bind(), namespaced events, cloned events", function() {
- expect(6);
+test("bind(), namespaced events, cloned events", 18, function() {
+ var firstp = jQuery( "#firstp" );
- jQuery("#firstp").bind("custom.test",function(e){
- ok(true, "Custom event triggered");
+ firstp.bind("custom.test",function(e){
+ ok(false, "Custom event triggered");
});
- jQuery("#firstp").bind("click",function(e){
+ firstp.bind("click",function(e){
ok(true, "Normal click triggered");
+ equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
});
- jQuery("#firstp").bind("click.test",function(e){
- ok(true, "Namespaced click triggered");
+ firstp.bind("click.test",function(e){
+ var check = "click";
+ ok( true, "Namespaced click triggered" );
+ if ( e.namespace ) {
+ check += "test";
+ }
+ equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
});
- // Trigger both bound fn (2)
- jQuery("#firstp").trigger("click");
+ //clone(true) element to verify events are cloned correctly
+ firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
- // Trigger one bound fn (1)
- jQuery("#firstp").trigger("click.test");
+ // Trigger both bound fn (8)
+ firstp.trigger("click");
+
+ // Trigger one bound fn (4)
+ firstp.trigger("click.test");
// Remove only the one fn
- jQuery("#firstp").unbind("click.test");
+ firstp.unbind("click.test");
- // Trigger the remaining fn (1)
- jQuery("#firstp").trigger("click");
+ // Trigger the remaining fn (4)
+ firstp.trigger("click");
- // Remove the remaining fn
- jQuery("#firstp").unbind(".test");
+ // Remove the remaining namespaced fn
+ firstp.unbind(".test");
- // Trigger the remaining fn (0)
- jQuery("#firstp").trigger("custom");
+ // Try triggering the custom event (0)
+ firstp.trigger("custom");
// using contents will get comments regular, text, and comment nodes
jQuery("#nonnodes").contents().bind("tester", function () {
test("bind(), with same function", function() {
expect(2)
- var count = 0 , func = function(){
+ var count = 0, func = function(){
count++;
};
jQuery(obj).unbind("test");
equals( obj && obj[ jQuery.expando ] &&
- obj[ jQuery.expando ][ jQuery.expando ] &&
+ obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" );
});