]> source.dussan.org Git - jquery.git/commitdiff
Ticket #8777 undelegate by namespace 302/head
authorrwldrn <waldron.rick@gmail.com>
Tue, 5 Apr 2011 22:12:50 +0000 (18:12 -0400)
committerrwldrn <waldron.rick@gmail.com>
Tue, 5 Apr 2011 22:55:07 +0000 (18:55 -0400)
src/event.js
test/unit/event.js

index bc2cf76eb1d07488afb71ee796b17e13e98c1128..6fac59c746e830b6abcf41115efd4ed0c3295e33 100644 (file)
@@ -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 );
+
index 2a6d8a669883d349c227ce35d77e9692dea7c39c..cc6901ff63d49ec0a8c764ff0e4b0e20d85b3d33 100644 (file)
@@ -685,7 +685,7 @@ test("hover()", function() {
 
 test("mouseover triggers mouseenter", function() {
        expect(1);
-       
+
        var count = 0,
                elem = jQuery("<a />");
        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( '<input type="text" />' ).prependTo( "body" ), 
+
+       var input = jQuery( '<input type="text" />' ).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();
 });
 */
+