From 4b0c26f0af96da05ab1a0166268c2925a6e6e6ac Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 5 Apr 2011 18:12:50 -0400 Subject: [PATCH 1/5] Ticket #8777 undelegate by namespace --- src/event.js | 13 +++++++++++-- test/unit/event.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/event.js b/src/event.js index bc2cf76eb..6fac59c74 100644 --- a/src/event.js +++ b/src/event.js @@ -868,10 +868,10 @@ function trigger( type, elem, args ) { // Create "bubbling" focus and blur events if ( document.addEventListener ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { - + // Attach a single capturing handler while someone wants focusin/focusout var attaches = 0; - + jQuery.event.special[ fix ] = { setup: function() { if ( attaches++ === 0 ) { @@ -1027,6 +1027,14 @@ jQuery.each(["live", "die"], function( i, name ) { return this; } + if ( name === "die" && !types && + origSelector && origSelector[0] === "." ) { + + context.unbind( origSelector ); + + return this; + } + if ( jQuery.isFunction( data ) ) { fn = data; data = undefined; @@ -1184,3 +1192,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl }); })( jQuery ); + diff --git a/test/unit/event.js b/test/unit/event.js index 2a6d8a669..cc6901ff6 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -685,7 +685,7 @@ test("hover()", function() { test("mouseover triggers mouseenter", function() { expect(1); - + var count = 0, elem = jQuery(""); elem.mouseenter(function () { @@ -693,7 +693,7 @@ test("mouseover triggers mouseenter", function() { }); elem.trigger('mouseover'); equals(count, 1, "make sure mouseover triggers a mouseenter" ); - + elem.remove(); }); @@ -1956,6 +1956,27 @@ test("delegate with submit", function() { jQuery(document).undelegate(); }); +test("undelegate() with only namespaces", function(){ + expect(2); + + var $delegate = jQuery("#liveHandlerOrder"), + count = 0; + + $delegate.delegate("a", "click.ns", function(e) { + count++; + }); + + jQuery("a", $delegate).eq(0).trigger("click.ns"); + + equals( count, 1, "delegated click.ns"); + + $delegate.undelegate(".ns"); + + jQuery("a", $delegate).eq(1).trigger("click.ns"); + + equals( count, 1, "no more .ns after undelegate"); +}); + test("Non DOM element events", function() { expect(1); @@ -1982,8 +2003,8 @@ test("window resize", function() { test("focusin bubbles", function() { expect(5); - - var input = jQuery( '' ).prependTo( "body" ), + + var input = jQuery( '' ).prependTo( "body" ), order = 0; jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ @@ -1996,12 +2017,12 @@ test("focusin bubbles", function() { // DOM focus method input[0].focus(); - + // To make the next focus test work, we need to take focus off the input. // This will fire another focusin event, so set order to reflect that. order = 1; jQuery("#text1")[0].focus(); - + // jQuery trigger, which calls DOM focus order = 0; input.trigger( "focus" ); @@ -2027,3 +2048,4 @@ test("event properties", function() { }).click(); }); */ + From 6591f6dd9d1c86144903f60e5d19e624c5bf6751 Mon Sep 17 00:00:00 2001 From: jeresig Date: Mon, 11 Apr 2011 11:22:52 -0400 Subject: [PATCH 2/5] Fix broken merge. --- test/unit/traversing.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 6228a0b98..f622082e7 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -223,10 +223,6 @@ test("closest(Array)", function() { same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); }); -<<<<<<< HEAD -test("not(Selector|undefined)", function() { - expect(11); -======= test("closest(jQuery)", function() { expect(8); var $child = jQuery("#nothiddendivchild"), @@ -243,9 +239,8 @@ test("closest(jQuery)", function() { ok( $child.closest( $body.add($parent) ).is('#nothiddendiv'), "Closest ancestor retrieved." ); }); -test("not(Selector)", function() { - expect(7); ->>>>>>> 1a167767305202797cf4c839eb64bd7adfb00182 +test("not(Selector|undefined)", function() { + expect(11); equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); From 868e1e28ce7cee543e0e47ec2261b44c4c686f99 Mon Sep 17 00:00:00 2001 From: Rick Waldon Date: Mon, 11 Apr 2011 11:32:23 -0400 Subject: [PATCH 3/5] Ticket #8753 Always set event type explicitly --- src/event.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/event.js b/src/event.js index ac0da6b7e..249e81ff6 100644 --- a/src/event.js +++ b/src/event.js @@ -304,7 +304,7 @@ jQuery.event = { } event.namespace = namespaces.join("."); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); - + // Handle a global trigger if ( !elem ) { // Don't bubble custom events when global (to avoid too much overhead) @@ -574,6 +574,9 @@ jQuery.Event = function( src ) { } } + // Always ensure a type has been explicitly set + this.type = src.type; + // Events bubbling up the document may have been marked as prevented // by a handler lower down the tree; reflect the correct value. this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false || @@ -1033,7 +1036,7 @@ jQuery.each(["live", "die"], function( i, name ) { if ( data === false || jQuery.isFunction( data ) ) { fn = data || returnFalse; data = undefined; - } + } types = (types || "").split(" "); From eb857e2b714e6786078cf8641941f267a6e19fa0 Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 11 Apr 2011 11:54:55 -0400 Subject: [PATCH 4/5] Fix unit tests in firefox 4 and opera 11, passing null or undefined to indexOf was throwing an error in those browsers --- src/traversing.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/traversing.js b/src/traversing.js index fb5946bba..485de56d4 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -298,13 +298,18 @@ jQuery.extend({ // Implement the identical functionality for filter and not function winnow( elements, qualifier, keep ) { + + // Can't pass null or undefined to indexOf in Firefox 4 + // Set to 0 to skip string check + qualifier = qualifier || 0; + if ( jQuery.isFunction( qualifier ) ) { return jQuery.grep(elements, function( elem, i ) { var retVal = !!qualifier.call( elem, i, elem ); return retVal === keep; }); - } else if ( qualifier && qualifier.nodeType ) { + } else if ( qualifier.nodeType ) { return jQuery.grep(elements, function( elem, i ) { return (elem === qualifier) === keep; }); From a564a0b1ec167b2f0fdd2d017a986b226a9850f6 Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 11 Apr 2011 12:24:31 -0400 Subject: [PATCH 5/5] Run order problem when running full test suite in Opera 11, removed failing test as it passed by itself and there are others just like it --- src/traversing.js | 4 ++-- test/unit/traversing.js | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/traversing.js b/src/traversing.js index 485de56d4..e0f40151d 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -73,9 +73,9 @@ jQuery.fn.extend({ }, is: function( selector ) { - return !!selector && (typeof selector === "string" ? + return !!selector && ( typeof selector === "string" ? jQuery.filter( selector, this ).length > 0 : - this.filter( selector ).length > 0); + this.filter( selector ).length > 0 ); }, closest: function( selectors, context ) { diff --git a/test/unit/traversing.js b/test/unit/traversing.js index f622082e7..140b337aa 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -72,7 +72,7 @@ test("is(String|undefined)", function() { }); test("is(jQuery)", function() { - expect(24); + expect(23); ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' ); ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' ); ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' ); @@ -83,7 +83,6 @@ test("is(jQuery)", function() { ok( !jQuery('#en').is( jQuery('[lang="de"]') ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); ok( jQuery('#text1').is( jQuery('[type="text"]') ), 'Check for attribute: Expected attribute type to be "text"' ); ok( !jQuery('#text1').is( jQuery('[type="radio"]') ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); - ok( jQuery('#text2').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected to be disabled' ); ok( !jQuery('#text1').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected not disabled' ); ok( jQuery('#radio2').is( jQuery(':checked') ), 'Check for pseudoclass: Expected to be checked' ); ok( !jQuery('#radio1').is( jQuery(':checked') ), 'Check for pseudoclass: Expected not checked' );