]> source.dussan.org Git - jquery.git/commitdiff
Fixes #12736. Move hover event hack to deprecated.js for removal in 1.9. Closes gh...
authorGreg Lavallee <greglavallee@wapolabs.com>
Tue, 16 Oct 2012 18:36:47 +0000 (14:36 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Tue, 16 Oct 2012 18:47:11 +0000 (14:47 -0400)
Signed-off-by: Timmy Willison <timmywillisn@gmail.com>
src/deprecated.js
src/event.js
test/unit/deprecated.js
test/unit/event.js

index 4ea47b333430982c31af8dd80792c14a5875f2ab..3c2763ddc73c1edbae1f86d7ccb902304887aba4 100644 (file)
@@ -1,7 +1,12 @@
 // Limit scope pollution from any deprecated API
 (function() {
 
-var matched, browser;
+var matched, browser, eventAdd, eventRemove,
+       oldToggle = jQuery.fn.toggle,
+       rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
+       hoverHack = function( events ) {
+               return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
+       };
 
 // Use of jQuery.browser is frowned upon.
 // More details: http://api.jquery.com/jQuery.browser
@@ -60,10 +65,6 @@ jQuery.sub = function() {
        return jQuerySub;
 };
 
-// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9
-jQuery.attrFn = {};
-
-var oldToggle = jQuery.fn.toggle;
 jQuery.fn.toggle = function( fn, fn2 ) {
 
        if ( !jQuery.isFunction( fn ) || !jQuery.isFunction( fn2 ) ) {
@@ -72,19 +73,19 @@ jQuery.fn.toggle = function( fn, fn2 ) {
 
        // Save reference to arguments for access in closure
        var args = arguments,
-           guid = fn.guid || jQuery.guid++,
-           i = 0,
-           toggler = function( event ) {
-                   // Figure out which function to execute
-                   var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
-                   jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
+                       guid = fn.guid || jQuery.guid++,
+                       i = 0,
+                       toggler = function( event ) {
+                               // Figure out which function to execute
+                               var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
+                               jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
 
-                   // Make sure that clicks stop
-                   event.preventDefault();
+                               // Make sure that clicks stop
+                               event.preventDefault();
 
-                   // and execute the function
-                   return args[ lastToggle ].apply( this, arguments ) || false;
-           };
+                               // and execute the function
+                               return args[ lastToggle ].apply( this, arguments ) || false;
+                       };
 
        // link all the functions, so any of them can unbind this click handler
        toggler.guid = guid;
@@ -95,4 +96,32 @@ jQuery.fn.toggle = function( fn, fn2 ) {
        return this.click( toggler );
 };
 
+
+// Support for 'hover' type
+eventAdd = jQuery.event.add;
+
+//     Duck punch jQuery.event.add, and jquery.event.remove
+//     Signatures:
+//     jQuery.event = {
+//     add: function( elem, types, handler, data, selector ) {
+//     remove: function( elem, types, handler, selector, mappedTypes ) {
+jQuery.event.add = function( elem, types, handler, data, selector ){
+       if ( types ) {
+               types = hoverHack( types );
+       }
+       eventAdd.call( this, elem, types, handler, data, selector );
+};
+
+eventRemove = jQuery.event.remove;
+
+jQuery.event.remove = function( elem, types, handler, selector, mappedTypes ){
+       if ( types ) {
+               types = hoverHack( types );
+       }
+       eventRemove.call( this, elem, types, handler, selector, mappedTypes );
+};
+
+// Unused in 1.8, left in so attrFn-stabbers won't die; remove in 1.9
+jQuery.attrFn = {};
+
 })();
index 3fea1a1be2225b154d512fee27366e840feb9787..f68a09c547d8967decee174ca8d44f04d405bb27 100644 (file)
@@ -1,12 +1,8 @@
 var rformElems = /^(?:textarea|input|select)$/i,
        rtypenamespace = /^([^\.]*|)(?:\.(.+)|)$/,
-       rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
        rkeyEvent = /^key/,
        rmouseEvent = /^(?:mouse|contextmenu)|click/,
-       rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
-       hoverHack = function( events ) {
-               return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
-       };
+       rfocusMorph = /^(?:focusinfocus|focusoutblur)$/;
 
 /*
  * Helper functions for managing events -- not part of the public interface.
@@ -56,7 +52,7 @@ jQuery.event = {
 
                // Handle multiple events separated by a space
                // jQuery(...).bind("mouseover mouseout", fn);
-               types = jQuery.trim( hoverHack(types) ).split( " " );
+               types = jQuery.trim( types ).split( " " );
                for ( t = 0; t < types.length; t++ ) {
 
                        tns = rtypenamespace.exec( types[t] ) || [];
@@ -139,7 +135,7 @@ jQuery.event = {
                }
 
                // Once for each type.namespace in types; type may be omitted
-               types = jQuery.trim( hoverHack( types || "" ) ).split(" ");
+               types = jQuery.trim( types ).split(" ");
                for ( t = 0; t < types.length; t++ ) {
                        tns = rtypenamespace.exec( types[t] ) || [];
                        type = origType = tns[1];
index f5787e5181d644c4345ed0a2a2020902d4345bbb..3bce98d5744a5d864cba8c8fa95f8c301fc93ffd 100644 (file)
@@ -107,4 +107,33 @@ if ( jQuery.browser ) {
                ok(!!jQuery.attrFn, "attrFnPresent");
        });
 
+       test("hover pseudo-event", function() {
+               expect(2);
+
+               var balance = 0;
+               jQuery( "#firstp" )
+                       .on( "hovercraft", function() {
+                               ok( false, "hovercraft is full of ills" );
+                       })
+                       .on( "click.hover.me.not", function( e ) {
+                               equal( e.handleObj.namespace, "hover.me.not", "hover hack doesn't mangle namespaces" );
+                       })
+                       .bind("hover", function( e ) {
+                               if ( e.type === "mouseenter" ) {
+                                       balance++;
+                               } else if ( e.type === "mouseleave" ) {
+                                       balance--;
+                               } else {
+                                       ok( false, "hover pseudo: unknown event type "+e.type );
+                               }
+                       })
+                       .trigger("click")
+                       .trigger("mouseenter")
+                       .trigger("mouseleave")
+                       .unbind("hover")
+                       .trigger("mouseenter");
+
+               equal( balance, 0, "hover pseudo-event" );
+       });
+
 }
index e626ede1d3ecf75c359e75710c36c4e4a3a8cf41..d6c24436a3ec82058a28291767a84ad0052a1323 100644 (file)
@@ -798,8 +798,8 @@ test("unbind(eventObject)", function() {
        assert( 0 );
 });
 
-test("hover() and hover pseudo-event", function() {
-       expect(3);
+test("hover() mouseenter mouseleave", function() {
+       expect(1);
 
        var times = 0,
                handler1 = function( event ) { ++times; },
@@ -817,30 +817,6 @@ test("hover() and hover pseudo-event", function() {
 
        equal( times, 4, "hover handlers fired" );
 
-       var balance = 0;
-       jQuery( "#firstp" )
-               .on( "hovercraft", function() {
-                       ok( false, "hovercraft is full of ills" );
-               })
-               .on( "click.hover.me.not", function( e ) {
-                       equal( e.handleObj.namespace, "hover.me.not", "hover hack doesn't mangle namespaces" );
-               })
-               .bind("hover", function( e ) {
-                       if ( e.type === "mouseenter" ) {
-                               balance++;
-                       } else if ( e.type === "mouseleave" ) {
-                               balance--;
-                       } else {
-                               ok( false, "hover pseudo: unknown event type "+e.type );
-                       }
-               })
-               .trigger("click")
-               .trigger("mouseenter")
-               .trigger("mouseleave")
-               .unbind("hover")
-               .trigger("mouseenter");
-
-       equal( balance, 0, "hover pseudo-event" );
 });
 
 test("mouseover triggers mouseenter", function() {